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