| OLD | NEW |
| 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 Loading... |
| 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 | |
| 255 function NAMESubArray(begin, end) { | 227 function NAMESubArray(begin, end) { |
| 256 if (!(%_ClassOf(this) === 'NAME')) { | |
| 257 throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this); | |
| 258 } | |
| 259 var beginInt = TO_INTEGER(begin); | 228 var beginInt = TO_INTEGER(begin); |
| 260 if (!IS_UNDEFINED(end)) { | 229 if (!IS_UNDEFINED(end)) { |
| 261 var endInt = TO_INTEGER(end); | 230 var endInt = TO_INTEGER(end); |
| 262 var srcLength = %_TypedArrayGetLength(this); | 231 var srcLength = %_TypedArrayGetLength(this); |
| 263 } else { | 232 } else { |
| 264 var srcLength = %_TypedArrayGetLength(this); | 233 var srcLength = %_TypedArrayGetLength(this); |
| 265 var endInt = srcLength; | 234 var endInt = srcLength; |
| 266 } | 235 } |
| 267 | 236 |
| 268 if (beginInt < 0) { | 237 if (beginInt < 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 284 var newLength = endInt - beginInt; | 253 var newLength = endInt - beginInt; |
| 285 var beginByteOffset = | 254 var beginByteOffset = |
| 286 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; | 255 %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
| 287 return new GlobalNAME(%TypedArrayGetBuffer(this), | 256 return new GlobalNAME(%TypedArrayGetBuffer(this), |
| 288 beginByteOffset, newLength); | 257 beginByteOffset, newLength); |
| 289 } | 258 } |
| 290 endmacro | 259 endmacro |
| 291 | 260 |
| 292 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | 261 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| 293 | 262 |
| 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 |
| 294 | 313 |
| 295 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { | 314 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
| 296 if (offset > 0) { | 315 if (offset > 0) { |
| 297 for (var i = 0; i < sourceLength; i++) { | 316 for (var i = 0; i < sourceLength; i++) { |
| 298 target[offset + i] = source[i]; | 317 target[offset + i] = source[i]; |
| 299 } | 318 } |
| 300 } | 319 } |
| 301 else { | 320 else { |
| 302 for (var i = 0; i < sourceLength; i++) { | 321 for (var i = 0; i < sourceLength; i++) { |
| 303 target[i] = source[i]; | 322 target[i] = source[i]; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 | 731 |
| 713 | 732 |
| 714 function TypedArrayFrom(source, mapfn, thisArg) { | 733 function TypedArrayFrom(source, mapfn, thisArg) { |
| 715 // TODO(littledan): Investigate if there is a receiver which could be | 734 // TODO(littledan): Investigate if there is a receiver which could be |
| 716 // faster to accumulate on than Array, e.g., a TypedVector. | 735 // faster to accumulate on than Array, e.g., a TypedVector. |
| 717 var array = %_Call(ArrayFrom, GlobalArray, source, mapfn, thisArg); | 736 var array = %_Call(ArrayFrom, GlobalArray, source, mapfn, thisArg); |
| 718 return ConstructTypedArray(this, array); | 737 return ConstructTypedArray(this, array); |
| 719 } | 738 } |
| 720 %FunctionSetLength(TypedArrayFrom, 1); | 739 %FunctionSetLength(TypedArrayFrom, 1); |
| 721 | 740 |
| 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 |
| 722 // ------------------------------------------------------------------- | 750 // ------------------------------------------------------------------- |
| 723 | 751 |
| 724 // TODO(littledan): Fix the TypedArray proto chain (bug v8:4085). | 752 %FunctionSetPrototype(TypedArray, new GlobalObject()); |
| 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 |
| 725 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | 794 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 726 %SetCode(GlobalNAME, NAMEConstructor); | 795 %SetCode(GlobalNAME, NAMEConstructor); |
| 727 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); | 796 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); |
| 797 %InternalSetPrototype(GlobalNAME, TypedArray); |
| 798 %InternalSetPrototype(GlobalNAME.prototype, TypedArray.prototype); |
| 728 | 799 |
| 729 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 800 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 730 READ_ONLY | DONT_ENUM | DONT_DELETE); | 801 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 731 | 802 |
| 732 utils.InstallFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ | |
| 733 "from", TypedArrayFrom, | |
| 734 "of", TypedArrayOf | |
| 735 ]); | |
| 736 | |
| 737 %AddNamedProperty(GlobalNAME.prototype, | 803 %AddNamedProperty(GlobalNAME.prototype, |
| 738 "constructor", global.NAME, DONT_ENUM); | 804 "constructor", global.NAME, DONT_ENUM); |
| 739 %AddNamedProperty(GlobalNAME.prototype, | 805 %AddNamedProperty(GlobalNAME.prototype, |
| 740 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 806 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 741 READ_ONLY | DONT_ENUM | DONT_DELETE); | 807 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 ]); | |
| 775 endmacro | 808 endmacro |
| 776 | 809 |
| 777 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 810 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 778 | 811 |
| 779 // --------------------------- DataView ----------------------------- | 812 // --------------------------- DataView ----------------------------- |
| 780 | 813 |
| 781 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 814 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
| 782 if (IS_UNDEFINED(new.target)) { | 815 if (IS_UNDEFINED(new.target)) { |
| 783 throw MakeTypeError(kConstructorNotFunction, "DataView"); | 816 throw MakeTypeError(kConstructorNotFunction, "DataView"); |
| 784 } | 817 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 "setUint32", DataViewSetUint32JS, | 936 "setUint32", DataViewSetUint32JS, |
| 904 | 937 |
| 905 "getFloat32", DataViewGetFloat32JS, | 938 "getFloat32", DataViewGetFloat32JS, |
| 906 "setFloat32", DataViewSetFloat32JS, | 939 "setFloat32", DataViewSetFloat32JS, |
| 907 | 940 |
| 908 "getFloat64", DataViewGetFloat64JS, | 941 "getFloat64", DataViewGetFloat64JS, |
| 909 "setFloat64", DataViewSetFloat64JS | 942 "setFloat64", DataViewSetFloat64JS |
| 910 ]); | 943 ]); |
| 911 | 944 |
| 912 }) | 945 }) |
| OLD | NEW |