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