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