| 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 28 matching lines...) Expand all Loading... |
| 39 var InnerArrayToLocaleString; | 39 var InnerArrayToLocaleString; |
| 40 var InternalArray = utils.InternalArray; | 40 var InternalArray = utils.InternalArray; |
| 41 var IsNaN; | 41 var IsNaN; |
| 42 var MakeRangeError; | 42 var MakeRangeError; |
| 43 var MakeTypeError; | 43 var MakeTypeError; |
| 44 var MaxSimple; | 44 var MaxSimple; |
| 45 var MinSimple; | 45 var MinSimple; |
| 46 var PackedArrayReverse; | 46 var PackedArrayReverse; |
| 47 var SpeciesConstructor; | 47 var SpeciesConstructor; |
| 48 var ToPositiveInteger; | 48 var ToPositiveInteger; |
| 49 var ToIndex; | |
| 50 var iteratorSymbol = utils.ImportNow("iterator_symbol"); | 49 var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
| 51 var speciesSymbol = utils.ImportNow("species_symbol"); | 50 var speciesSymbol = utils.ImportNow("species_symbol"); |
| 52 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 51 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
| 53 | 52 |
| 54 macro TYPED_ARRAYS(FUNCTION) | 53 macro TYPED_ARRAYS(FUNCTION) |
| 55 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 54 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 56 FUNCTION(1, Uint8Array, 1) | 55 FUNCTION(1, Uint8Array, 1) |
| 57 FUNCTION(2, Int8Array, 1) | 56 FUNCTION(2, Int8Array, 1) |
| 58 FUNCTION(3, Uint16Array, 2) | 57 FUNCTION(3, Uint16Array, 2) |
| 59 FUNCTION(4, Int16Array, 2) | 58 FUNCTION(4, Int16Array, 2) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 InnerArraySort = from.InnerArraySort; | 92 InnerArraySort = from.InnerArraySort; |
| 94 InnerArrayToLocaleString = from.InnerArrayToLocaleString; | 93 InnerArrayToLocaleString = from.InnerArrayToLocaleString; |
| 95 IsNaN = from.IsNaN; | 94 IsNaN = from.IsNaN; |
| 96 MakeRangeError = from.MakeRangeError; | 95 MakeRangeError = from.MakeRangeError; |
| 97 MakeTypeError = from.MakeTypeError; | 96 MakeTypeError = from.MakeTypeError; |
| 98 MaxSimple = from.MaxSimple; | 97 MaxSimple = from.MaxSimple; |
| 99 MinSimple = from.MinSimple; | 98 MinSimple = from.MinSimple; |
| 100 PackedArrayReverse = from.PackedArrayReverse; | 99 PackedArrayReverse = from.PackedArrayReverse; |
| 101 SpeciesConstructor = from.SpeciesConstructor; | 100 SpeciesConstructor = from.SpeciesConstructor; |
| 102 ToPositiveInteger = from.ToPositiveInteger; | 101 ToPositiveInteger = from.ToPositiveInteger; |
| 103 ToIndex = from.ToIndex; | |
| 104 }); | 102 }); |
| 105 | 103 |
| 106 // --------------- Typed Arrays --------------------- | 104 // --------------- Typed Arrays --------------------- |
| 107 | 105 |
| 108 function TypedArrayDefaultConstructor(typedArray) { | 106 function TypedArrayDefaultConstructor(typedArray) { |
| 109 switch (%_ClassOf(typedArray)) { | 107 switch (%_ClassOf(typedArray)) { |
| 110 macro TYPED_ARRAY_CONSTRUCTOR_CASE(ARRAY_ID, NAME, ELEMENT_SIZE) | 108 macro TYPED_ARRAY_CONSTRUCTOR_CASE(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 111 case "NAME": | 109 case "NAME": |
| 112 return GlobalNAME; | 110 return GlobalNAME; |
| 113 endmacro | 111 endmacro |
| (...skipping 24 matching lines...) Expand all Loading... |
| 138 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { | 136 function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { |
| 139 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); | 137 var defaultConstructor = TypedArrayDefaultConstructor(exemplar); |
| 140 var constructor = SpeciesConstructor(exemplar, defaultConstructor, | 138 var constructor = SpeciesConstructor(exemplar, defaultConstructor, |
| 141 conservative); | 139 conservative); |
| 142 return TypedArrayCreate(constructor, arg0, arg1, arg2); | 140 return TypedArrayCreate(constructor, arg0, arg1, arg2); |
| 143 } | 141 } |
| 144 | 142 |
| 145 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 143 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 146 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 144 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| 147 if (!IS_UNDEFINED(byteOffset)) { | 145 if (!IS_UNDEFINED(byteOffset)) { |
| 148 byteOffset = ToIndex(byteOffset, kInvalidTypedArrayLength); | 146 byteOffset = ToPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
| 149 } | 147 } |
| 150 if (!IS_UNDEFINED(length)) { | 148 if (!IS_UNDEFINED(length)) { |
| 151 length = ToIndex(length, kInvalidTypedArrayLength); | 149 length = ToPositiveInteger(length, kInvalidTypedArrayLength); |
| 152 } | |
| 153 if (length > %_MaxSmi()) { | |
| 154 // Note: this is not per spec, but rather a constraint of our current | |
| 155 // representation (which uses smi's). | |
| 156 throw MakeRangeError(kInvalidTypedArrayLength); | |
| 157 } | 150 } |
| 158 | 151 |
| 159 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); | 152 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
| 160 var offset; | 153 var offset; |
| 161 if (IS_UNDEFINED(byteOffset)) { | 154 if (IS_UNDEFINED(byteOffset)) { |
| 162 offset = 0; | 155 offset = 0; |
| 163 } else { | 156 } else { |
| 164 offset = byteOffset; | 157 offset = byteOffset; |
| 165 | 158 |
| 166 if (offset % ELEMENT_SIZE !== 0) { | 159 if (offset % ELEMENT_SIZE !== 0) { |
| 167 throw MakeRangeError(kInvalidTypedArrayAlignment, | 160 throw MakeRangeError(kInvalidTypedArrayAlignment, |
| 168 "start offset", "NAME", ELEMENT_SIZE); | 161 "start offset", "NAME", ELEMENT_SIZE); |
| 169 } | 162 } |
| 163 if (offset > bufferByteLength) { |
| 164 throw MakeRangeError(kInvalidTypedArrayOffset); |
| 165 } |
| 170 } | 166 } |
| 171 | 167 |
| 172 var newByteLength; | 168 var newByteLength; |
| 169 var newLength; |
| 173 if (IS_UNDEFINED(length)) { | 170 if (IS_UNDEFINED(length)) { |
| 174 if (bufferByteLength % ELEMENT_SIZE !== 0) { | 171 if (bufferByteLength % ELEMENT_SIZE !== 0) { |
| 175 throw MakeRangeError(kInvalidTypedArrayAlignment, | 172 throw MakeRangeError(kInvalidTypedArrayAlignment, |
| 176 "byte length", "NAME", ELEMENT_SIZE); | 173 "byte length", "NAME", ELEMENT_SIZE); |
| 177 } | 174 } |
| 178 newByteLength = bufferByteLength - offset; | 175 newByteLength = bufferByteLength - offset; |
| 179 if (newByteLength < 0) { | 176 newLength = newByteLength / ELEMENT_SIZE; |
| 180 throw MakeRangeError(kInvalidTypedArrayAlignment, | |
| 181 "byte length", "NAME", ELEMENT_SIZE); | |
| 182 } | |
| 183 } else { | 177 } else { |
| 184 newByteLength = length * ELEMENT_SIZE; | 178 var newLength = length; |
| 185 if (offset + newByteLength > bufferByteLength) { | 179 newByteLength = newLength * ELEMENT_SIZE; |
| 186 throw MakeRangeError(kInvalidTypedArrayAlignment, | 180 } |
| 187 "byte length", "NAME", ELEMENT_SIZE); | 181 if ((offset + newByteLength > bufferByteLength) |
| 188 } | 182 || (newLength > %_MaxSmi())) { |
| 183 throw MakeRangeError(kInvalidTypedArrayLength); |
| 189 } | 184 } |
| 190 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength, true); | 185 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength, true); |
| 191 } | 186 } |
| 192 | 187 |
| 193 function NAMEConstructByLength(obj, length) { | 188 function NAMEConstructByLength(obj, length) { |
| 194 var l = IS_UNDEFINED(length) ? | 189 var l = IS_UNDEFINED(length) ? |
| 195 0 : ToIndex(length, kInvalidTypedArrayLength); | 190 0 : ToPositiveInteger(length, kInvalidTypedArrayLength); |
| 196 if (length > %_MaxSmi()) { | 191 if (l > %_MaxSmi()) { |
| 197 // Note: this is not per spec, but rather a constraint of our current | |
| 198 // representation (which uses smi's). | |
| 199 throw MakeRangeError(kInvalidTypedArrayLength); | 192 throw MakeRangeError(kInvalidTypedArrayLength); |
| 200 } | 193 } |
| 201 var byteLength = l * ELEMENT_SIZE; | 194 var byteLength = l * ELEMENT_SIZE; |
| 202 if (byteLength > %_TypedArrayMaxSizeInHeap()) { | 195 if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
| 203 var buffer = new GlobalArrayBuffer(byteLength); | 196 var buffer = new GlobalArrayBuffer(byteLength); |
| 204 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); | 197 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); |
| 205 } else { | 198 } else { |
| 206 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); | 199 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); |
| 207 } | 200 } |
| 208 } | 201 } |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 FUNCTION(Float64) | 858 FUNCTION(Float64) |
| 866 endmacro | 859 endmacro |
| 867 | 860 |
| 868 | 861 |
| 869 macro DATA_VIEW_GETTER_SETTER(TYPENAME) | 862 macro DATA_VIEW_GETTER_SETTER(TYPENAME) |
| 870 function DataViewGetTYPENAMEJS(offset, little_endian) { | 863 function DataViewGetTYPENAMEJS(offset, little_endian) { |
| 871 if (!IS_DATAVIEW(this)) { | 864 if (!IS_DATAVIEW(this)) { |
| 872 throw MakeTypeError(kIncompatibleMethodReceiver, | 865 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 873 'DataView.getTYPENAME', this); | 866 'DataView.getTYPENAME', this); |
| 874 } | 867 } |
| 875 offset = IS_UNDEFINED(offset) ? 0 : ToIndex(offset, kInvalidDataViewAccessorOf
fset); | 868 if (arguments.length < 1) throw MakeTypeError(kInvalidArgument); |
| 869 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
| 876 return %DataViewGetTYPENAME(this, offset, !!little_endian); | 870 return %DataViewGetTYPENAME(this, offset, !!little_endian); |
| 877 } | 871 } |
| 878 %FunctionSetLength(DataViewGetTYPENAMEJS, 1); | 872 %FunctionSetLength(DataViewGetTYPENAMEJS, 1); |
| 879 | 873 |
| 880 function DataViewSetTYPENAMEJS(offset, value, little_endian) { | 874 function DataViewSetTYPENAMEJS(offset, value, little_endian) { |
| 881 if (!IS_DATAVIEW(this)) { | 875 if (!IS_DATAVIEW(this)) { |
| 882 throw MakeTypeError(kIncompatibleMethodReceiver, | 876 throw MakeTypeError(kIncompatibleMethodReceiver, |
| 883 'DataView.setTYPENAME', this); | 877 'DataView.setTYPENAME', this); |
| 884 } | 878 } |
| 885 offset = IS_UNDEFINED(offset) ? 0 : ToIndex(offset, kInvalidDataViewAccessorOf
fset); | 879 if (arguments.length < 2) throw MakeTypeError(kInvalidArgument); |
| 880 offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
| 886 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); | 881 %DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); |
| 887 } | 882 } |
| 888 %FunctionSetLength(DataViewSetTYPENAMEJS, 2); | 883 %FunctionSetLength(DataViewSetTYPENAMEJS, 2); |
| 889 endmacro | 884 endmacro |
| 890 | 885 |
| 891 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) | 886 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
| 892 | 887 |
| 893 utils.InstallFunctions(GlobalDataView.prototype, DONT_ENUM, [ | 888 utils.InstallFunctions(GlobalDataView.prototype, DONT_ENUM, [ |
| 894 "getInt8", DataViewGetInt8JS, | 889 "getInt8", DataViewGetInt8JS, |
| 895 "setInt8", DataViewSetInt8JS, | 890 "setInt8", DataViewSetInt8JS, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 910 "setUint32", DataViewSetUint32JS, | 905 "setUint32", DataViewSetUint32JS, |
| 911 | 906 |
| 912 "getFloat32", DataViewGetFloat32JS, | 907 "getFloat32", DataViewGetFloat32JS, |
| 913 "setFloat32", DataViewSetFloat32JS, | 908 "setFloat32", DataViewSetFloat32JS, |
| 914 | 909 |
| 915 "getFloat64", DataViewGetFloat64JS, | 910 "getFloat64", DataViewGetFloat64JS, |
| 916 "setFloat64", DataViewSetFloat64JS | 911 "setFloat64", DataViewSetFloat64JS |
| 917 ]); | 912 ]); |
| 918 | 913 |
| 919 }) | 914 }) |
| OLD | NEW |