| 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 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 // array.js has to come before typedarray.js for this to work | 14 // array.js has to come before typedarray.js for this to work |
| 15 var ArrayToString = utils.ImportNow("ArrayToString"); | 15 var ArrayToString = utils.ImportNow("ArrayToString"); |
| 16 var ArrayValues; | 16 var ArrayValues; |
| 17 var GetIterator; | 17 var GetIterator; |
| 18 var GetMethod; | 18 var GetMethod; |
| 19 var GlobalArray = global.Array; | 19 var GlobalArray = global.Array; |
| 20 var GlobalArrayBuffer = global.ArrayBuffer; | 20 var GlobalArrayBuffer = global.ArrayBuffer; |
| 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; | 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; |
| 22 var GlobalDataView = global.DataView; | 22 var GlobalDataView = global.DataView; |
| 23 var GlobalObject = global.Object; | 23 var GlobalObject = global.Object; |
| 24 var GlobalTypedArray = global.TypedArray; |
| 24 var InnerArrayCopyWithin; | 25 var InnerArrayCopyWithin; |
| 25 var InnerArrayEvery; | 26 var InnerArrayEvery; |
| 26 var InnerArrayFill; | 27 var InnerArrayFill; |
| 27 var InnerArrayFilter; | 28 var InnerArrayFilter; |
| 28 var InnerArrayFind; | 29 var InnerArrayFind; |
| 29 var InnerArrayFindIndex; | 30 var InnerArrayFindIndex; |
| 30 var InnerArrayForEach; | 31 var InnerArrayForEach; |
| 31 var InnerArrayIncludes; | 32 var InnerArrayIncludes; |
| 32 var InnerArrayIndexOf; | 33 var InnerArrayIndexOf; |
| 33 var InnerArrayJoin; | 34 var InnerArrayJoin; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 case "NAME": | 323 case "NAME": |
| 323 return %_Call(NAMESubArray, this, begin, end); | 324 return %_Call(NAMESubArray, this, begin, end); |
| 324 endmacro | 325 endmacro |
| 325 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) | 326 TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE) |
| 326 } | 327 } |
| 327 throw MakeTypeError(kIncompatibleMethodReceiver, | 328 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 328 "get TypedArray.prototype.subarray", this); | 329 "get TypedArray.prototype.subarray", this); |
| 329 } | 330 } |
| 330 %SetForceInlineFlag(TypedArraySubArray); | 331 %SetForceInlineFlag(TypedArraySubArray); |
| 331 | 332 |
| 332 function TypedArrayGetBuffer() { | |
| 333 if (!IS_TYPEDARRAY(this)) { | |
| 334 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 335 "get TypedArray.prototype.buffer", this); | |
| 336 } | |
| 337 return %TypedArrayGetBuffer(this); | |
| 338 } | |
| 339 %SetForceInlineFlag(TypedArrayGetBuffer); | |
| 340 | |
| 341 function TypedArrayGetByteLength() { | |
| 342 if (!IS_TYPEDARRAY(this)) { | |
| 343 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 344 "get TypedArray.prototype.byteLength", this); | |
| 345 } | |
| 346 return %_ArrayBufferViewGetByteLength(this); | |
| 347 } | |
| 348 %SetForceInlineFlag(TypedArrayGetByteLength); | |
| 349 | |
| 350 function TypedArrayGetByteOffset() { | |
| 351 if (!IS_TYPEDARRAY(this)) { | |
| 352 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 353 "get TypedArray.prototype.byteOffset", this); | |
| 354 } | |
| 355 return %_ArrayBufferViewGetByteOffset(this); | |
| 356 } | |
| 357 %SetForceInlineFlag(TypedArrayGetByteOffset); | |
| 358 | |
| 359 function TypedArrayGetLength() { | |
| 360 if (!IS_TYPEDARRAY(this)) { | |
| 361 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 362 "get TypedArray.prototype.length", this); | |
| 363 } | |
| 364 return %_TypedArrayGetLength(this); | |
| 365 } | |
| 366 %SetForceInlineFlag(TypedArrayGetLength); | |
| 367 | |
| 368 | 333 |
| 369 | 334 |
| 370 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { | 335 function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
| 371 if (offset > 0) { | 336 if (offset > 0) { |
| 372 for (var i = 0; i < sourceLength; i++) { | 337 for (var i = 0; i < sourceLength; i++) { |
| 373 target[offset + i] = source[i]; | 338 target[offset + i] = source[i]; |
| 374 } | 339 } |
| 375 } | 340 } |
| 376 else { | 341 else { |
| 377 for (var i = 0; i < sourceLength; i++) { | 342 for (var i = 0; i < sourceLength; i++) { |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 mappedValue = %_Call(mapfn, thisArg, value, i); | 766 mappedValue = %_Call(mapfn, thisArg, value, i); |
| 802 } else { | 767 } else { |
| 803 mappedValue = value; | 768 mappedValue = value; |
| 804 } | 769 } |
| 805 targetObject[i] = mappedValue; | 770 targetObject[i] = mappedValue; |
| 806 } | 771 } |
| 807 return targetObject; | 772 return targetObject; |
| 808 } | 773 } |
| 809 %FunctionSetLength(TypedArrayFrom, 1); | 774 %FunctionSetLength(TypedArrayFrom, 1); |
| 810 | 775 |
| 811 function TypedArray() { | 776 // TODO(bmeurer): Migrate this to a proper builtin. |
| 777 function TypedArrayConstructor() { |
| 812 if (IS_UNDEFINED(new.target)) { | 778 if (IS_UNDEFINED(new.target)) { |
| 813 throw MakeTypeError(kConstructorNonCallable, "TypedArray"); | 779 throw MakeTypeError(kConstructorNonCallable, "TypedArray"); |
| 814 } | 780 } |
| 815 if (new.target === TypedArray) { | 781 if (new.target === GlobalTypedArray) { |
| 816 throw MakeTypeError(kConstructAbstractClass, "TypedArray"); | 782 throw MakeTypeError(kConstructAbstractClass, "TypedArray"); |
| 817 } | 783 } |
| 818 } | 784 } |
| 819 | 785 |
| 820 // ------------------------------------------------------------------- | 786 // ------------------------------------------------------------------- |
| 821 | 787 |
| 822 %FunctionSetPrototype(TypedArray, new GlobalObject()); | 788 %SetCode(GlobalTypedArray, TypedArrayConstructor); |
| 823 %AddNamedProperty(TypedArray.prototype, | 789 utils.InstallFunctions(GlobalTypedArray, DONT_ENUM, [ |
| 824 "constructor", TypedArray, DONT_ENUM); | |
| 825 utils.InstallFunctions(TypedArray, DONT_ENUM, [ | |
| 826 "from", TypedArrayFrom, | 790 "from", TypedArrayFrom, |
| 827 "of", TypedArrayOf | 791 "of", TypedArrayOf |
| 828 ]); | 792 ]); |
| 829 utils.InstallGetter(TypedArray.prototype, "buffer", TypedArrayGetBuffer); | 793 utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol, |
| 830 utils.InstallGetter(TypedArray.prototype, "byteOffset", | |
| 831 TypedArrayGetByteOffset); | |
| 832 utils.InstallGetter(TypedArray.prototype, "byteLength", | |
| 833 TypedArrayGetByteLength); | |
| 834 utils.InstallGetter(TypedArray.prototype, "length", TypedArrayGetLength); | |
| 835 utils.InstallGetter(TypedArray.prototype, toStringTagSymbol, | |
| 836 TypedArrayGetToStringTag); | 794 TypedArrayGetToStringTag); |
| 837 utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [ | 795 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ |
| 838 "subarray", TypedArraySubArray, | 796 "subarray", TypedArraySubArray, |
| 839 "set", TypedArraySet, | 797 "set", TypedArraySet, |
| 840 "copyWithin", TypedArrayCopyWithin, | 798 "copyWithin", TypedArrayCopyWithin, |
| 841 "every", TypedArrayEvery, | 799 "every", TypedArrayEvery, |
| 842 "fill", TypedArrayFill, | 800 "fill", TypedArrayFill, |
| 843 "filter", TypedArrayFilter, | 801 "filter", TypedArrayFilter, |
| 844 "find", TypedArrayFind, | 802 "find", TypedArrayFind, |
| 845 "findIndex", TypedArrayFindIndex, | 803 "findIndex", TypedArrayFindIndex, |
| 846 "includes", TypedArrayIncludes, | 804 "includes", TypedArrayIncludes, |
| 847 "indexOf", TypedArrayIndexOf, | 805 "indexOf", TypedArrayIndexOf, |
| 848 "join", TypedArrayJoin, | 806 "join", TypedArrayJoin, |
| 849 "lastIndexOf", TypedArrayLastIndexOf, | 807 "lastIndexOf", TypedArrayLastIndexOf, |
| 850 "forEach", TypedArrayForEach, | 808 "forEach", TypedArrayForEach, |
| 851 "map", TypedArrayMap, | 809 "map", TypedArrayMap, |
| 852 "reduce", TypedArrayReduce, | 810 "reduce", TypedArrayReduce, |
| 853 "reduceRight", TypedArrayReduceRight, | 811 "reduceRight", TypedArrayReduceRight, |
| 854 "reverse", TypedArrayReverse, | 812 "reverse", TypedArrayReverse, |
| 855 "slice", TypedArraySlice, | 813 "slice", TypedArraySlice, |
| 856 "some", TypedArraySome, | 814 "some", TypedArraySome, |
| 857 "sort", TypedArraySort, | 815 "sort", TypedArraySort, |
| 858 "toLocaleString", TypedArrayToLocaleString | 816 "toLocaleString", TypedArrayToLocaleString |
| 859 ]); | 817 ]); |
| 860 | 818 |
| 861 %AddNamedProperty(TypedArray.prototype, "toString", ArrayToString, | 819 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, |
| 862 DONT_ENUM); | 820 DONT_ENUM); |
| 863 | 821 |
| 864 | 822 |
| 865 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | 823 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 866 %SetCode(GlobalNAME, NAMEConstructor); | 824 %SetCode(GlobalNAME, NAMEConstructor); |
| 867 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); | 825 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); |
| 868 %InternalSetPrototype(GlobalNAME, TypedArray); | 826 %InternalSetPrototype(GlobalNAME, GlobalTypedArray); |
| 869 %InternalSetPrototype(GlobalNAME.prototype, TypedArray.prototype); | 827 %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype); |
| 870 | 828 |
| 871 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 829 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 872 READ_ONLY | DONT_ENUM | DONT_DELETE); | 830 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 873 | 831 |
| 874 %AddNamedProperty(GlobalNAME.prototype, | 832 %AddNamedProperty(GlobalNAME.prototype, |
| 875 "constructor", global.NAME, DONT_ENUM); | 833 "constructor", global.NAME, DONT_ENUM); |
| 876 %AddNamedProperty(GlobalNAME.prototype, | 834 %AddNamedProperty(GlobalNAME.prototype, |
| 877 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 835 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 878 READ_ONLY | DONT_ENUM | DONT_DELETE); | 836 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 879 endmacro | 837 endmacro |
| 880 | 838 |
| 881 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 839 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 882 | 840 |
| 883 // --------------------------- DataView ----------------------------- | 841 // --------------------------- DataView ----------------------------- |
| 884 | 842 |
| 885 function DataViewGetBufferJS() { | |
| 886 if (!IS_DATAVIEW(this)) { | |
| 887 throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this); | |
| 888 } | |
| 889 return %DataViewGetBuffer(this); | |
| 890 } | |
| 891 | |
| 892 function DataViewGetByteOffset() { | |
| 893 if (!IS_DATAVIEW(this)) { | |
| 894 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 895 'DataView.byteOffset', this); | |
| 896 } | |
| 897 return %_ArrayBufferViewGetByteOffset(this); | |
| 898 } | |
| 899 | |
| 900 function DataViewGetByteLength() { | |
| 901 if (!IS_DATAVIEW(this)) { | |
| 902 throw MakeTypeError(kIncompatibleMethodReceiver, | |
| 903 'DataView.byteLength', this); | |
| 904 } | |
| 905 return %_ArrayBufferViewGetByteLength(this); | |
| 906 } | |
| 907 | |
| 908 macro DATA_VIEW_TYPES(FUNCTION) | 843 macro DATA_VIEW_TYPES(FUNCTION) |
| 909 FUNCTION(Int8) | 844 FUNCTION(Int8) |
| 910 FUNCTION(Uint8) | 845 FUNCTION(Uint8) |
| 911 FUNCTION(Int16) | 846 FUNCTION(Int16) |
| 912 FUNCTION(Uint16) | 847 FUNCTION(Uint16) |
| 913 FUNCTION(Int32) | 848 FUNCTION(Int32) |
| 914 FUNCTION(Uint32) | 849 FUNCTION(Uint32) |
| 915 FUNCTION(Float32) | 850 FUNCTION(Float32) |
| 916 FUNCTION(Float64) | 851 FUNCTION(Float64) |
| 917 endmacro | 852 endmacro |
| (...skipping 18 matching lines...) Expand all Loading... |
| 936 } | 871 } |
| 937 if (arguments.length < 2) throw MakeTypeError(kInvalidArgument); | 872 if (arguments.length < 2) throw MakeTypeError(kInvalidArgument); |
| 938 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); | 873 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
| 939 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); | 874 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); |
| 940 } | 875 } |
| 941 %FunctionSetLength(DataViewSetTYPENAMEJS, 2); | 876 %FunctionSetLength(DataViewSetTYPENAMEJS, 2); |
| 942 endmacro | 877 endmacro |
| 943 | 878 |
| 944 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) | 879 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
| 945 | 880 |
| 946 // Setup the DataView constructor. | |
| 947 %FunctionSetPrototype(GlobalDataView, new GlobalObject); | |
| 948 | |
| 949 // Set up constructor property on the DataView prototype. | |
| 950 %AddNamedProperty(GlobalDataView.prototype, "constructor", GlobalDataView, | |
| 951 DONT_ENUM); | |
| 952 %AddNamedProperty(GlobalDataView.prototype, toStringTagSymbol, "DataView", | |
| 953 READ_ONLY|DONT_ENUM); | |
| 954 | |
| 955 utils.InstallGetter(GlobalDataView.prototype, "buffer", DataViewGetBufferJS); | |
| 956 utils.InstallGetter(GlobalDataView.prototype, "byteOffset", | |
| 957 DataViewGetByteOffset); | |
| 958 utils.InstallGetter(GlobalDataView.prototype, "byteLength", | |
| 959 DataViewGetByteLength); | |
| 960 | |
| 961 utils.InstallFunctions(GlobalDataView.prototype, DONT_ENUM, [ | 881 utils.InstallFunctions(GlobalDataView.prototype, DONT_ENUM, [ |
| 962 "getInt8", DataViewGetInt8JS, | 882 "getInt8", DataViewGetInt8JS, |
| 963 "setInt8", DataViewSetInt8JS, | 883 "setInt8", DataViewSetInt8JS, |
| 964 | 884 |
| 965 "getUint8", DataViewGetUint8JS, | 885 "getUint8", DataViewGetUint8JS, |
| 966 "setUint8", DataViewSetUint8JS, | 886 "setUint8", DataViewSetUint8JS, |
| 967 | 887 |
| 968 "getInt16", DataViewGetInt16JS, | 888 "getInt16", DataViewGetInt16JS, |
| 969 "setInt16", DataViewSetInt16JS, | 889 "setInt16", DataViewSetInt16JS, |
| 970 | 890 |
| 971 "getUint16", DataViewGetUint16JS, | 891 "getUint16", DataViewGetUint16JS, |
| 972 "setUint16", DataViewSetUint16JS, | 892 "setUint16", DataViewSetUint16JS, |
| 973 | 893 |
| 974 "getInt32", DataViewGetInt32JS, | 894 "getInt32", DataViewGetInt32JS, |
| 975 "setInt32", DataViewSetInt32JS, | 895 "setInt32", DataViewSetInt32JS, |
| 976 | 896 |
| 977 "getUint32", DataViewGetUint32JS, | 897 "getUint32", DataViewGetUint32JS, |
| 978 "setUint32", DataViewSetUint32JS, | 898 "setUint32", DataViewSetUint32JS, |
| 979 | 899 |
| 980 "getFloat32", DataViewGetFloat32JS, | 900 "getFloat32", DataViewGetFloat32JS, |
| 981 "setFloat32", DataViewSetFloat32JS, | 901 "setFloat32", DataViewSetFloat32JS, |
| 982 | 902 |
| 983 "getFloat64", DataViewGetFloat64JS, | 903 "getFloat64", DataViewGetFloat64JS, |
| 984 "setFloat64", DataViewSetFloat64JS | 904 "setFloat64", DataViewSetFloat64JS |
| 985 ]); | 905 ]); |
| 986 | 906 |
| 987 }) | 907 }) |
| OLD | NEW |