Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: src/harmony-typedarray.js

Issue 1132163011: Add TypedArray.from method (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, exports) { 5 (function(global, exports) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // ES6 draft 08-24-14, section 22.2.2.2 93 // ES6 draft 08-24-14, section 22.2.2.2
94 function TypedArrayOf() { 94 function TypedArrayOf() {
95 var length = %_ArgumentsLength(); 95 var length = %_ArgumentsLength();
96 var array = new this(length); 96 var array = new this(length);
97 for (var i = 0; i < length; i++) { 97 for (var i = 0; i < length; i++) {
98 array[i] = %_Arguments(i); 98 array[i] = %_Arguments(i);
99 } 99 }
100 return array; 100 return array;
101 } 101 }
102 102
103 function ConstructTypedArray(constructor, array) {
104 // TODO(dehrenberg): This is an approximation of the spec, which requires
arv (Not doing code reviews) 2015/05/15 00:20:22 I thought you wanted littledan?
dehrenberg 2015/05/15 23:39:14 Done.
105 // that only real TypedArray classes should be accepted (22.2.2.1.1)
106 if (!IS_SPEC_OBJECT(constructor) || constructor.prototype === undefined ||
arv (Not doing code reviews) 2015/05/15 00:20:22 Use IS_UNDEFINED since undefined can be redefined.
dehrenberg 2015/05/15 23:39:14 Done.
107 !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT"))
arv (Not doing code reviews) 2015/05/15 00:20:22 Use {}
dehrenberg 2015/05/15 23:39:14 Done.
108 throw MakeTypeError(kNotTypedArray);
109
110 // TODO(dehrenberg): The spec requires that, rather than directly calling
111 // the constructor, a TypedArray is created with the proper proto and
112 // underlying size and element size, and elements are put in one by one.
113 // By contrast, this would allow subclasses to make a radically different
114 // constructor with different semantics.
115 return new constructor(array);
116 }
117
118 function TypedArrayFrom(source, mapfn, thisArg) {
119 var array = $arrayFrom.call(global.Array, source, mapfn, thisArg);
arv (Not doing code reviews) 2015/05/15 00:20:22 Use %_CallFunction since Function.prototype.call c
arv (Not doing code reviews) 2015/05/15 00:20:22 Is global.Array correct here? Shouldn't Uint8Array
arv (Not doing code reviews) 2015/05/15 00:20:22 Please add var GlobalArray = global.Array; to t
dehrenberg 2015/05/15 23:39:14 Done.
dehrenberg 2015/05/15 23:39:14 Done.
dehrenberg 2015/05/15 23:39:14 I'm first making an array with the contents and th
120 return ConstructTypedArray(this, array);
121 }
122 %FunctionSetLength(TypedArrayFrom, 1);
123
103 macro EXTEND_TYPED_ARRAY(NAME) 124 macro EXTEND_TYPED_ARRAY(NAME)
104 // Set up non-enumerable functions on the object. 125 // Set up non-enumerable functions on the object.
105 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ 126 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [
127 "from", TypedArrayFrom,
arv (Not doing code reviews) 2015/05/15 00:20:22 This needs one more object in the [[Prototype]] ch
dehrenberg 2015/05/15 23:39:14 I have a bug open for this https://code.google.com
106 "of", TypedArrayOf 128 "of", TypedArrayOf
107 ]); 129 ]);
108 130
109 // Set up non-enumerable functions on the prototype object. 131 // Set up non-enumerable functions on the prototype object.
110 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ 132 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [
111 "copyWithin", TypedArrayCopyWithin, 133 "copyWithin", TypedArrayCopyWithin,
112 "every", TypedArrayEvery, 134 "every", TypedArrayEvery,
113 "forEach", TypedArrayForEach, 135 "forEach", TypedArrayForEach,
114 "find", TypedArrayFind, 136 "find", TypedArrayFind,
115 "findIndex", TypedArrayFindIndex, 137 "findIndex", TypedArrayFindIndex,
116 "fill", TypedArrayFill 138 "fill", TypedArrayFill
117 ]); 139 ]);
118 endmacro 140 endmacro
119 141
120 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) 142 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
121 143
122 }) 144 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698