| OLD | NEW | 
|    1 // Copyright 2013 the V8 project authors. All rights reserved. |    1 // Copyright 2013 the V8 project authors. All rights reserved. | 
|    2 // Redistribution and use in source and binary forms, with or without |    2 // Redistribution and use in source and binary forms, with or without | 
|    3 // modification, are permitted provided that the following conditions are |    3 // modification, are permitted provided that the following conditions are | 
|    4 // met: |    4 // met: | 
|    5 // |    5 // | 
|    6 //     * Redistributions of source code must retain the above copyright |    6 //     * Redistributions of source code must retain the above copyright | 
|    7 //       notice, this list of conditions and the following disclaimer. |    7 //       notice, this list of conditions and the following disclaimer. | 
|    8 //     * Redistributions in binary form must reproduce the above |    8 //     * Redistributions in binary form must reproduce the above | 
|    9 //       copyright notice, this list of conditions and the following |    9 //       copyright notice, this list of conditions and the following | 
|   10 //       disclaimer in the documentation and/or other materials provided |   10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   42 FUNCTION(4, Int16Array, 2) |   42 FUNCTION(4, Int16Array, 2) | 
|   43 FUNCTION(5, Uint32Array, 4) |   43 FUNCTION(5, Uint32Array, 4) | 
|   44 FUNCTION(6, Int32Array, 4) |   44 FUNCTION(6, Int32Array, 4) | 
|   45 FUNCTION(7, Float32Array, 4) |   45 FUNCTION(7, Float32Array, 4) | 
|   46 FUNCTION(8, Float64Array, 8) |   46 FUNCTION(8, Float64Array, 8) | 
|   47 FUNCTION(9, Uint8ClampedArray, 1) |   47 FUNCTION(9, Uint8ClampedArray, 1) | 
|   48 endmacro |   48 endmacro | 
|   49  |   49  | 
|   50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |   50 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 
|   51   function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |   51   function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 
 |   52     if (!IS_UNDEFINED(byteOffset)) { | 
 |   53         byteOffset = | 
 |   54             ToPositiveInteger(byteOffset,  "invalid_typed_array_length"); | 
 |   55     } | 
 |   56     if (!IS_UNDEFINED(length)) { | 
 |   57         length = ToPositiveInteger(length, "invalid_typed_array_length"); | 
 |   58     } | 
 |   59  | 
|   52     var bufferByteLength = %ArrayBufferGetByteLength(buffer); |   60     var bufferByteLength = %ArrayBufferGetByteLength(buffer); | 
|   53     var offset; |   61     var offset; | 
|   54     if (IS_UNDEFINED(byteOffset)) { |   62     if (IS_UNDEFINED(byteOffset)) { | 
|   55       offset = 0; |   63       offset = 0; | 
|   56     } else { |   64     } else { | 
|   57       offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length"); |   65       offset = byteOffset; | 
|   58  |   66  | 
|   59       if (offset % ELEMENT_SIZE !== 0) { |   67       if (offset % ELEMENT_SIZE !== 0) { | 
|   60         throw MakeRangeError("invalid_typed_array_alignment", |   68         throw MakeRangeError("invalid_typed_array_alignment", | 
|   61             ["start offset", "NAME", ELEMENT_SIZE]); |   69             ["start offset", "NAME", ELEMENT_SIZE]); | 
|   62       } |   70       } | 
|   63       if (offset > bufferByteLength) { |   71       if (offset > bufferByteLength) { | 
|   64         throw MakeRangeError("invalid_typed_array_offset"); |   72         throw MakeRangeError("invalid_typed_array_offset"); | 
|   65       } |   73       } | 
|   66     } |   74     } | 
|   67  |   75  | 
|   68     var newByteLength; |   76     var newByteLength; | 
|   69     var newLength; |   77     var newLength; | 
|   70     if (IS_UNDEFINED(length)) { |   78     if (IS_UNDEFINED(length)) { | 
|   71       if (bufferByteLength % ELEMENT_SIZE !== 0) { |   79       if (bufferByteLength % ELEMENT_SIZE !== 0) { | 
|   72         throw MakeRangeError("invalid_typed_array_alignment", |   80         throw MakeRangeError("invalid_typed_array_alignment", | 
|   73           ["byte length", "NAME", ELEMENT_SIZE]); |   81           ["byte length", "NAME", ELEMENT_SIZE]); | 
|   74       } |   82       } | 
|   75       newByteLength = bufferByteLength - offset; |   83       newByteLength = bufferByteLength - offset; | 
|   76       newLength = newByteLength / ELEMENT_SIZE; |   84       newLength = newByteLength / ELEMENT_SIZE; | 
|   77     } else { |   85     } else { | 
|   78       var newLength = ToPositiveInteger(length, "invalid_typed_array_length"); |   86       var newLength = length; | 
|   79       newByteLength = newLength * ELEMENT_SIZE; |   87       newByteLength = newLength * ELEMENT_SIZE; | 
|   80     } |   88     } | 
|   81     if ((offset + newByteLength > bufferByteLength) |   89     if ((offset + newByteLength > bufferByteLength) | 
|   82         || (newLength > %MaxSmi())) { |   90         || (newLength > %MaxSmi())) { | 
|   83       throw MakeRangeError("invalid_typed_array_length"); |   91       throw MakeRangeError("invalid_typed_array_length"); | 
|   84     } |   92     } | 
|   85     %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); |   93     %TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); | 
|   86   } |   94   } | 
|   87  |   95  | 
|   88   function NAMEConstructByLength(obj, length) { |   96   function NAMEConstructByLength(obj, length) { | 
|   89     var l = IS_UNDEFINED(length) ? |   97     var l = IS_UNDEFINED(length) ? | 
|   90       0 : ToPositiveInteger(length, "invalid_typed_array_length"); |   98       0 : ToPositiveInteger(length, "invalid_typed_array_length"); | 
|   91     if (l > %MaxSmi()) { |   99     if (l > %MaxSmi()) { | 
|   92       throw MakeRangeError("invalid_typed_array_length"); |  100       throw MakeRangeError("invalid_typed_array_length"); | 
|   93     } |  101     } | 
|   94     var byteLength = l * ELEMENT_SIZE; |  102     var byteLength = l * ELEMENT_SIZE; | 
|   95     var buffer = new $ArrayBuffer(byteLength); |  103     var buffer = new $ArrayBuffer(byteLength); | 
|   96     %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |  104     %TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); | 
|   97   } |  105   } | 
|   98  |  106  | 
|   99   function NAMEConstructByArrayLike(obj, arrayLike) { |  107   function NAMEConstructByArrayLike(obj, arrayLike) { | 
|  100     var length = arrayLike.length; |  108     var length = arrayLike.length; | 
|  101     var l = ToPositiveInteger(length, "invalid_typed_array_length"); |  109     var l = ToPositiveInteger(length, "invalid_typed_array_length"); | 
 |  110  | 
|  102     if (l > %MaxSmi()) { |  111     if (l > %MaxSmi()) { | 
|  103       throw MakeRangeError("invalid_typed_array_length"); |  112       throw MakeRangeError("invalid_typed_array_length"); | 
|  104     } |  113     } | 
|  105     if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { |  114     if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { | 
|  106       for (var i = 0; i < l; i++) { |  115       for (var i = 0; i < l; i++) { | 
|  107         // It is crucial that we let any execptions from arrayLike[i] |  116         // It is crucial that we let any execptions from arrayLike[i] | 
|  108         // propagate outside the function. |  117         // propagate outside the function. | 
|  109         obj[i] = arrayLike[i]; |  118         obj[i] = arrayLike[i]; | 
|  110       } |  119       } | 
|  111     } |  120     } | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|  141 function TypedArrayGetByteOffset() { |  150 function TypedArrayGetByteOffset() { | 
|  142   return %TypedArrayGetByteOffset(this); |  151   return %TypedArrayGetByteOffset(this); | 
|  143 } |  152 } | 
|  144  |  153  | 
|  145 function TypedArrayGetLength() { |  154 function TypedArrayGetLength() { | 
|  146   return %TypedArrayGetLength(this); |  155   return %TypedArrayGetLength(this); | 
|  147 } |  156 } | 
|  148  |  157  | 
|  149 function CreateSubArray(elementSize, constructor) { |  158 function CreateSubArray(elementSize, constructor) { | 
|  150   return function(begin, end) { |  159   return function(begin, end) { | 
 |  160     var beginInt = TO_INTEGER(begin); | 
 |  161     if (!IS_UNDEFINED(end)) { | 
 |  162       end = TO_INTEGER(end); | 
 |  163     } | 
 |  164  | 
|  151     var srcLength = %TypedArrayGetLength(this); |  165     var srcLength = %TypedArrayGetLength(this); | 
|  152     var beginInt = TO_INTEGER(begin); |  | 
|  153     if (beginInt < 0) { |  166     if (beginInt < 0) { | 
|  154       beginInt = MathMax(0, srcLength + beginInt); |  167       beginInt = MathMax(0, srcLength + beginInt); | 
|  155     } else { |  168     } else { | 
|  156       beginInt = MathMin(srcLength, beginInt); |  169       beginInt = MathMin(srcLength, beginInt); | 
|  157     } |  170     } | 
|  158  |  171  | 
|  159     var endInt = IS_UNDEFINED(end) ? srcLength : TO_INTEGER(end); |  172     var endInt = IS_UNDEFINED(end) ? srcLength : end; | 
|  160     if (endInt < 0) { |  173     if (endInt < 0) { | 
|  161       endInt = MathMax(0, srcLength + endInt); |  174       endInt = MathMax(0, srcLength + endInt); | 
|  162     } else { |  175     } else { | 
|  163       endInt = MathMin(endInt, srcLength); |  176       endInt = MathMin(endInt, srcLength); | 
|  164     } |  177     } | 
|  165     if (endInt < beginInt) { |  178     if (endInt < beginInt) { | 
|  166       endInt = beginInt; |  179       endInt = beginInt; | 
|  167     } |  180     } | 
|  168     var newLength = endInt - beginInt; |  181     var newLength = endInt - beginInt; | 
|  169     var beginByteOffset = |  182     var beginByteOffset = | 
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  310  |  323  | 
|  311 // --------------------------- DataView ----------------------------- |  324 // --------------------------- DataView ----------------------------- | 
|  312  |  325  | 
|  313 var $DataView = global.DataView; |  326 var $DataView = global.DataView; | 
|  314  |  327  | 
|  315 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |  328 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 
|  316   if (%_IsConstructCall()) { |  329   if (%_IsConstructCall()) { | 
|  317     if (!IS_ARRAYBUFFER(buffer)) { |  330     if (!IS_ARRAYBUFFER(buffer)) { | 
|  318       throw MakeTypeError('data_view_not_array_buffer', []); |  331       throw MakeTypeError('data_view_not_array_buffer', []); | 
|  319     } |  332     } | 
 |  333     if (!IS_UNDEFINED(byteOffset)) { | 
 |  334         byteOffset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); | 
 |  335     } | 
 |  336     if (!IS_UNDEFINED(byteLength)) { | 
 |  337         byteLength = TO_INTEGER(byteLength); | 
 |  338     } | 
 |  339  | 
|  320     var bufferByteLength = %ArrayBufferGetByteLength(buffer); |  340     var bufferByteLength = %ArrayBufferGetByteLength(buffer); | 
|  321     var offset = IS_UNDEFINED(byteOffset) ? |  341  | 
|  322       0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); |  342     var offset = IS_UNDEFINED(byteOffset) ?  0 : byteOffset; | 
|  323     if (offset > bufferByteLength) { |  343     if (offset > bufferByteLength) { | 
|  324       throw MakeRangeError('invalid_data_view_offset'); |  344       throw MakeRangeError('invalid_data_view_offset'); | 
|  325     } |  345     } | 
|  326     var length = IS_UNDEFINED(byteLength) ? |  346  | 
|  327       bufferByteLength - offset : TO_INTEGER(byteLength); |  347     var length = IS_UNDEFINED(byteLength) | 
 |  348         ? bufferByteLength - offset | 
 |  349         : byteLength; | 
|  328     if (length < 0 || offset + length > bufferByteLength) { |  350     if (length < 0 || offset + length > bufferByteLength) { | 
|  329       throw new MakeRangeError('invalid_data_view_length'); |  351       throw new MakeRangeError('invalid_data_view_length'); | 
|  330     } |  352     } | 
|  331     %DataViewInitialize(this, buffer, offset, length); |  353     %DataViewInitialize(this, buffer, offset, length); | 
|  332   } else { |  354   } else { | 
|  333     throw MakeTypeError('constructor_not_function', ["DataView"]); |  355     throw MakeTypeError('constructor_not_function', ["DataView"]); | 
|  334   } |  356   } | 
|  335 } |  357 } | 
|  336  |  358  | 
|  337 function DataViewGetBuffer() { |  359 function DataViewGetBuffer() { | 
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  440  |  462  | 
|  441       "getFloat32", DataViewGetFloat32, |  463       "getFloat32", DataViewGetFloat32, | 
|  442       "setFloat32", DataViewSetFloat32, |  464       "setFloat32", DataViewSetFloat32, | 
|  443  |  465  | 
|  444       "getFloat64", DataViewGetFloat64, |  466       "getFloat64", DataViewGetFloat64, | 
|  445       "setFloat64", DataViewSetFloat64 |  467       "setFloat64", DataViewSetFloat64 | 
|  446   )); |  468   )); | 
|  447 } |  469 } | 
|  448  |  470  | 
|  449 SetupDataView(); |  471 SetupDataView(); | 
| OLD | NEW |