diff options
author | Chad Austin <chad@imvu.com> | 2013-03-26 14:27:57 -0700 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2013-04-12 14:26:45 +0300 |
commit | 638478a9a9234e7adb14259735432babd31bddba (patch) | |
tree | c2abfd5bc6ed6c47e1f837873fb94e195fc6e89d /src | |
parent | 56783851c34932a3e6196c38865905d966666ba0 (diff) |
Typed array objects require use of operator new. You can't just call them directly.
Diffstat (limited to 'src')
-rwxr-xr-x | src/embind/emval.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/embind/emval.js b/src/embind/emval.js index 7153ae6d..7cdac6d9 100755 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -73,14 +73,35 @@ function __emval_take_value(type, v) { return __emval_register(v); } +var __newers = {}; // arity -> function + function __emval_new(handle, argCount, argTypes) { var args = parseParameters( argCount, argTypes, Array.prototype.slice.call(arguments, 3)); - // implement what amounts to operator new + // Alas, we are forced to use operator new until WebKit enables + // constructing typed arrays without new. + // In WebKit, Uint8Array(10) throws an error. + // In every other browser, it's identical to new Uint8Array(10). + + var newer = __newers[argCount]; + if (!newer) { + var parameters = new Array(argCount); + for (var i = 0; i < argCount; ++i) { + parameters[i] = 'a' + i; + } + /*jshint evil:true*/ + newer = __newers[argCount] = new Function( + ['c'].concat(parameters), + "return new c(" + parameters.join(',') + ");"); + } + var constructor = _emval_handle_array[handle].value; + var obj = newer.apply(undefined, [constructor].concat(args)); +/* + // implement what amounts to operator new function dummy(){} dummy.prototype = constructor.prototype; var obj = new constructor; @@ -88,6 +109,7 @@ function __emval_new(handle, argCount, argTypes) { if (typeof rv === 'object') { obj = rv; } +*/ return __emval_register(obj); } |