Index: src/harmony-typedarray.js |
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js |
index 3c4c4a40fedd69f97bc46813fd624edcf3f93f7b..c162ae8a43e132c0058ee663d422840f3c8c2144 100644 |
--- a/src/harmony-typedarray.js |
+++ b/src/harmony-typedarray.js |
@@ -26,6 +26,7 @@ var GlobalNAME = global.NAME; |
endmacro |
TYPED_ARRAYS(DECLARE_GLOBALS) |
+DECLARE_GLOBALS(Array) |
// ------------------------------------------------------------------- |
@@ -34,7 +35,7 @@ function TypedArrayCopyWithin(target, start, end) { |
var length = %_TypedArrayGetLength(this); |
- // TODO(dehrenberg): Replace with a memcpy for better performance |
+ // TODO(littledan): Replace with a memcpy for better performance |
return $innerArrayCopyWithin(target, start, end, this, length); |
} |
%FunctionSetLength(TypedArrayCopyWithin, 2); |
@@ -100,9 +101,33 @@ function TypedArrayOf() { |
return array; |
} |
+function ConstructTypedArray(constructor, array) { |
+ // TODO(littledan): This is an approximation of the spec, which requires |
+ // that only real TypedArray classes should be accepted (22.2.2.1.1) |
+ if (!IS_SPEC_OBJECT(constructor) || IS_UNDEFINED(constructor.prototype) || |
+ !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT")) { |
+ throw MakeTypeError(kNotTypedArray); |
+ } |
+ |
+ // TODO(littledan): The spec requires that, rather than directly calling |
+ // the constructor, a TypedArray is created with the proper proto and |
+ // underlying size and element size, and elements are put in one by one. |
+ // By contrast, this would allow subclasses to make a radically different |
+ // constructor with different semantics. |
+ return new constructor(array); |
+} |
+ |
+function TypedArrayFrom(source, mapfn, thisArg) { |
+ var array = %_CallFunction(GlobalArray, source, mapfn, thisArg, $arrayFrom); |
arv (Not doing code reviews)
2015/05/16 18:23:45
Add todo. It would surely be better to not have a
dehrenberg
2015/05/18 17:56:50
The problem is that, if the source is iterable, th
|
+ return ConstructTypedArray(this, array); |
+} |
+%FunctionSetLength(TypedArrayFrom, 1); |
+ |
+// TODO(littledan): Fix the TypedArray proto chain (bug v8:4085). |
macro EXTEND_TYPED_ARRAY(NAME) |
// Set up non-enumerable functions on the object. |
$installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ |
+ "from", TypedArrayFrom, |
"of", TypedArrayOf |
]); |