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

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

Issue 1554523002: Revert of Use ES2015-style TypedArray prototype chain (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « src/js/array-iterator.js ('k') | src/messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 NAMEConstructByArrayLike(this, arg1); 217 NAMEConstructByArrayLike(this, arg1);
218 } else { 218 } else {
219 NAMEConstructByIterable(this, arg1, iteratorFn); 219 NAMEConstructByIterable(this, arg1, iteratorFn);
220 } 220 }
221 } 221 }
222 } else { 222 } else {
223 throw MakeTypeError(kConstructorNotFunction, "NAME") 223 throw MakeTypeError(kConstructorNotFunction, "NAME")
224 } 224 }
225 } 225 }
226 226
227 function NAME_GetBuffer() {
228 if (!(%_ClassOf(this) === 'NAME')) {
229 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this);
230 }
231 return %TypedArrayGetBuffer(this);
232 }
233
234 function NAME_GetByteLength() {
235 if (!(%_ClassOf(this) === 'NAME')) {
236 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteLength", this);
237 }
238 return %_ArrayBufferViewGetByteLength(this);
239 }
240
241 function NAME_GetByteOffset() {
242 if (!(%_ClassOf(this) === 'NAME')) {
243 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteOffset", this);
244 }
245 return %_ArrayBufferViewGetByteOffset(this);
246 }
247
248 function NAME_GetLength() {
249 if (!(%_ClassOf(this) === 'NAME')) {
250 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this);
251 }
252 return %_TypedArrayGetLength(this);
253 }
254
227 function NAMESubArray(begin, end) { 255 function NAMESubArray(begin, end) {
256 if (!(%_ClassOf(this) === 'NAME')) {
257 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this);
258 }
228 var beginInt = TO_INTEGER(begin); 259 var beginInt = TO_INTEGER(begin);
229 if (!IS_UNDEFINED(end)) { 260 if (!IS_UNDEFINED(end)) {
230 var endInt = TO_INTEGER(end); 261 var endInt = TO_INTEGER(end);
231 var srcLength = %_TypedArrayGetLength(this); 262 var srcLength = %_TypedArrayGetLength(this);
232 } else { 263 } else {
233 var srcLength = %_TypedArrayGetLength(this); 264 var srcLength = %_TypedArrayGetLength(this);
234 var endInt = srcLength; 265 var endInt = srcLength;
235 } 266 }
236 267
237 if (beginInt < 0) { 268 if (beginInt < 0) {
(...skipping 15 matching lines...) Expand all
253 var newLength = endInt - beginInt; 284 var newLength = endInt - beginInt;
254 var beginByteOffset = 285 var beginByteOffset =
255 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; 286 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
256 return new GlobalNAME(%TypedArrayGetBuffer(this), 287 return new GlobalNAME(%TypedArrayGetBuffer(this),
257 beginByteOffset, newLength); 288 beginByteOffset, newLength);
258 } 289 }
259 endmacro 290 endmacro
260 291
261 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) 292 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
262 293
263 function TypedArraySubArray(begin, end) {
264 switch (%_ClassOf(this)) {
265 macro TYPED_ARRAY_SUBARRAY_CASE(ARRAY_ID, NAME, ELEMENT_SIZE)
266 case "NAME":
267 return %_Call(NAMESubArray, this, begin, end);
268 endmacro
269 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE)
270 }
271 throw MakeTypeError(kIncompatibleMethodReceiver,
272 "get TypedArray.prototype.subarray", this);
273 }
274 %SetForceInlineFlag(TypedArraySubArray);
275
276 function TypedArrayGetBuffer() {
277 if (!%_IsTypedArray(this)) {
278 throw MakeTypeError(kIncompatibleMethodReceiver,
279 "get TypedArray.prototype.buffer", this);
280 }
281 return %TypedArrayGetBuffer(this);
282 }
283 %SetForceInlineFlag(TypedArrayGetBuffer);
284
285 function TypedArrayGetByteLength() {
286 if (!%_IsTypedArray(this)) {
287 throw MakeTypeError(kIncompatibleMethodReceiver,
288 "get TypedArray.prototype.byteLength", this);
289 }
290 return %_ArrayBufferViewGetByteLength(this);
291 }
292 %SetForceInlineFlag(TypedArrayGetByteLength);
293
294 function TypedArrayGetByteOffset() {
295 if (!%_IsTypedArray(this)) {
296 throw MakeTypeError(kIncompatibleMethodReceiver,
297 "get TypedArray.prototype.byteOffset", this);
298 }
299 return %_ArrayBufferViewGetByteOffset(this);
300 }
301 %SetForceInlineFlag(TypedArrayGetByteOffset);
302
303 function TypedArrayGetLength() {
304 if (!%_IsTypedArray(this)) {
305 throw MakeTypeError(kIncompatibleMethodReceiver,
306 "get TypedArray.prototype.length", this);
307 }
308 return %_TypedArrayGetLength(this);
309 }
310 %SetForceInlineFlag(TypedArrayGetLength);
311
312
313 294
314 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { 295 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) {
315 if (offset > 0) { 296 if (offset > 0) {
316 for (var i = 0; i < sourceLength; i++) { 297 for (var i = 0; i < sourceLength; i++) {
317 target[offset + i] = source[i]; 298 target[offset + i] = source[i];
318 } 299 }
319 } 300 }
320 else { 301 else {
321 for (var i = 0; i < sourceLength; i++) { 302 for (var i = 0; i < sourceLength; i++) {
322 target[i] = source[i]; 303 target[i] = source[i];
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 712
732 713
733 function TypedArrayFrom(source, mapfn, thisArg) { 714 function TypedArrayFrom(source, mapfn, thisArg) {
734 // TODO(littledan): Investigate if there is a receiver which could be 715 // TODO(littledan): Investigate if there is a receiver which could be
735 // faster to accumulate on than Array, e.g., a TypedVector. 716 // faster to accumulate on than Array, e.g., a TypedVector.
736 var array = %_Call(ArrayFrom, GlobalArray, source, mapfn, thisArg); 717 var array = %_Call(ArrayFrom, GlobalArray, source, mapfn, thisArg);
737 return ConstructTypedArray(this, array); 718 return ConstructTypedArray(this, array);
738 } 719 }
739 %FunctionSetLength(TypedArrayFrom, 1); 720 %FunctionSetLength(TypedArrayFrom, 1);
740 721
741 function TypedArray() {
742 if (IS_UNDEFINED(new.target)) {
743 throw MakeTypeError(kConstructorNonCallable, "TypedArray");
744 }
745 if (new.target === TypedArray) {
746 throw MakeTypeError(kConstructAbstractClass, "TypedArray");
747 }
748 }
749
750 // ------------------------------------------------------------------- 722 // -------------------------------------------------------------------
751 723
752 %FunctionSetPrototype(TypedArray, new GlobalObject()); 724 // TODO(littledan): Fix the TypedArray proto chain (bug v8:4085).
753 %AddNamedProperty(TypedArray.prototype,
754 "constructor", TypedArray, DONT_ENUM);
755 utils.InstallFunctions(TypedArray, DONT_ENUM | DONT_DELETE | READ_ONLY, [
756 "from", TypedArrayFrom,
757 "of", TypedArrayOf
758 ]);
759 utils.InstallGetter(TypedArray.prototype, "buffer", TypedArrayGetBuffer);
760 utils.InstallGetter(TypedArray.prototype, "byteOffset", TypedArrayGetByteOffset,
761 DONT_ENUM | DONT_DELETE);
762 utils.InstallGetter(TypedArray.prototype, "byteLength",
763 TypedArrayGetByteLength, DONT_ENUM | DONT_DELETE);
764 utils.InstallGetter(TypedArray.prototype, "length", TypedArrayGetLength,
765 DONT_ENUM | DONT_DELETE);
766 utils.InstallGetter(TypedArray.prototype, toStringTagSymbol,
767 TypedArrayGetToStringTag);
768 utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [
769 "subarray", TypedArraySubArray,
770 "set", TypedArraySet,
771 "copyWithin", TypedArrayCopyWithin,
772 "every", TypedArrayEvery,
773 "fill", TypedArrayFill,
774 "filter", TypedArrayFilter,
775 "find", TypedArrayFind,
776 "findIndex", TypedArrayFindIndex,
777 "includes", TypedArrayIncludes,
778 "indexOf", TypedArrayIndexOf,
779 "join", TypedArrayJoin,
780 "lastIndexOf", TypedArrayLastIndexOf,
781 "forEach", TypedArrayForEach,
782 "map", TypedArrayMap,
783 "reduce", TypedArrayReduce,
784 "reduceRight", TypedArrayReduceRight,
785 "reverse", TypedArrayReverse,
786 "slice", TypedArraySlice,
787 "some", TypedArraySome,
788 "sort", TypedArraySort,
789 "toString", TypedArrayToString,
790 "toLocaleString", TypedArrayToLocaleString
791 ]);
792
793
794 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 725 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
795 %SetCode(GlobalNAME, NAMEConstructor); 726 %SetCode(GlobalNAME, NAMEConstructor);
796 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); 727 %FunctionSetPrototype(GlobalNAME, new GlobalObject());
797 %InternalSetPrototype(GlobalNAME, TypedArray);
798 %InternalSetPrototype(GlobalNAME.prototype, TypedArray.prototype);
799 728
800 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, 729 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
801 READ_ONLY | DONT_ENUM | DONT_DELETE); 730 READ_ONLY | DONT_ENUM | DONT_DELETE);
802 731
732 utils.InstallFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [
733 "from", TypedArrayFrom,
734 "of", TypedArrayOf
735 ]);
736
803 %AddNamedProperty(GlobalNAME.prototype, 737 %AddNamedProperty(GlobalNAME.prototype,
804 "constructor", global.NAME, DONT_ENUM); 738 "constructor", global.NAME, DONT_ENUM);
805 %AddNamedProperty(GlobalNAME.prototype, 739 %AddNamedProperty(GlobalNAME.prototype,
806 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 740 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
807 READ_ONLY | DONT_ENUM | DONT_DELETE); 741 READ_ONLY | DONT_ENUM | DONT_DELETE);
742 utils.InstallGetter(GlobalNAME.prototype, "buffer", NAME_GetBuffer);
743 utils.InstallGetter(GlobalNAME.prototype, "byteOffset", NAME_GetByteOffset,
744 DONT_ENUM | DONT_DELETE);
745 utils.InstallGetter(GlobalNAME.prototype, "byteLength", NAME_GetByteLength,
746 DONT_ENUM | DONT_DELETE);
747 utils.InstallGetter(GlobalNAME.prototype, "length", NAME_GetLength,
748 DONT_ENUM | DONT_DELETE);
749 utils.InstallGetter(GlobalNAME.prototype, toStringTagSymbol,
750 TypedArrayGetToStringTag);
751 utils.InstallFunctions(GlobalNAME.prototype, DONT_ENUM, [
752 "subarray", NAMESubArray,
753 "set", TypedArraySet,
754 "copyWithin", TypedArrayCopyWithin,
755 "every", TypedArrayEvery,
756 "fill", TypedArrayFill,
757 "filter", TypedArrayFilter,
758 "find", TypedArrayFind,
759 "findIndex", TypedArrayFindIndex,
760 "includes", TypedArrayIncludes,
761 "indexOf", TypedArrayIndexOf,
762 "join", TypedArrayJoin,
763 "lastIndexOf", TypedArrayLastIndexOf,
764 "forEach", TypedArrayForEach,
765 "map", TypedArrayMap,
766 "reduce", TypedArrayReduce,
767 "reduceRight", TypedArrayReduceRight,
768 "reverse", TypedArrayReverse,
769 "slice", TypedArraySlice,
770 "some", TypedArraySome,
771 "sort", TypedArraySort,
772 "toString", TypedArrayToString,
773 "toLocaleString", TypedArrayToLocaleString
774 ]);
808 endmacro 775 endmacro
809 776
810 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 777 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
811 778
812 // --------------------------- DataView ----------------------------- 779 // --------------------------- DataView -----------------------------
813 780
814 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 781 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
815 if (IS_UNDEFINED(new.target)) { 782 if (IS_UNDEFINED(new.target)) {
816 throw MakeTypeError(kConstructorNotFunction, "DataView"); 783 throw MakeTypeError(kConstructorNotFunction, "DataView");
817 } 784 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 "setUint32", DataViewSetUint32JS, 903 "setUint32", DataViewSetUint32JS,
937 904
938 "getFloat32", DataViewGetFloat32JS, 905 "getFloat32", DataViewGetFloat32JS,
939 "setFloat32", DataViewSetFloat32JS, 906 "setFloat32", DataViewSetFloat32JS,
940 907
941 "getFloat64", DataViewGetFloat64JS, 908 "getFloat64", DataViewGetFloat64JS,
942 "setFloat64", DataViewSetFloat64JS 909 "setFloat64", DataViewSetFloat64JS
943 ]); 910 ]);
944 911
945 }) 912 })
OLDNEW
« no previous file with comments | « src/js/array-iterator.js ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698