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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 newByteLength = bufferByteLength - offset; | 81 newByteLength = bufferByteLength - offset; |
82 newLength = newByteLength / ELEMENT_SIZE; | 82 newLength = newByteLength / ELEMENT_SIZE; |
83 } else { | 83 } else { |
84 var newLength = length; | 84 var newLength = length; |
85 newByteLength = newLength * ELEMENT_SIZE; | 85 newByteLength = newLength * ELEMENT_SIZE; |
86 } | 86 } |
87 if ((offset + newByteLength > bufferByteLength) | 87 if ((offset + newByteLength > bufferByteLength) |
88 || (newLength > %_MaxSmi())) { | 88 || (newLength > %_MaxSmi())) { |
89 throw MakeRangeError(kInvalidTypedArrayLength); | 89 throw MakeRangeError(kInvalidTypedArrayLength); |
90 } | 90 } |
91 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); | 91 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength, true); |
92 } | 92 } |
93 | 93 |
94 function NAMEConstructByLength(obj, length) { | 94 function NAMEConstructByLength(obj, length) { |
95 var l = IS_UNDEFINED(length) ? | 95 var l = IS_UNDEFINED(length) ? |
96 0 : $toPositiveInteger(length, kInvalidTypedArrayLength); | 96 0 : $toPositiveInteger(length, kInvalidTypedArrayLength); |
97 if (l > %_MaxSmi()) { | 97 if (l > %_MaxSmi()) { |
98 throw MakeRangeError(kInvalidTypedArrayLength); | 98 throw MakeRangeError(kInvalidTypedArrayLength); |
99 } | 99 } |
100 var byteLength = l * ELEMENT_SIZE; | 100 var byteLength = l * ELEMENT_SIZE; |
101 if (byteLength > %_TypedArrayMaxSizeInHeap()) { | 101 if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
102 var buffer = new GlobalArrayBuffer(byteLength); | 102 var buffer = new GlobalArrayBuffer(byteLength); |
103 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); | 103 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength, true); |
104 } else { | 104 } else { |
105 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); | 105 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, true); |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 function NAMEConstructByArrayLike(obj, arrayLike) { | 109 function NAMEConstructByArrayLike(obj, arrayLike) { |
110 var length = arrayLike.length; | 110 var length = arrayLike.length; |
111 var l = $toPositiveInteger(length, kInvalidTypedArrayLength); | 111 var l = $toPositiveInteger(length, kInvalidTypedArrayLength); |
112 | 112 |
113 if (l > %_MaxSmi()) { | 113 if (l > %_MaxSmi()) { |
114 throw MakeRangeError(kInvalidTypedArrayLength); | 114 throw MakeRangeError(kInvalidTypedArrayLength); |
115 } | 115 } |
116 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { | 116 var initialized = false; |
| 117 var byteLength = l * ELEMENT_SIZE; |
| 118 if (byteLength <= %_TypedArrayMaxSizeInHeap()) { |
| 119 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength, false); |
| 120 } else { |
| 121 initialized = |
| 122 %TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l); |
| 123 } |
| 124 if (!initialized) { |
117 for (var i = 0; i < l; i++) { | 125 for (var i = 0; i < l; i++) { |
118 // It is crucial that we let any execptions from arrayLike[i] | 126 // It is crucial that we let any execptions from arrayLike[i] |
119 // propagate outside the function. | 127 // propagate outside the function. |
120 obj[i] = arrayLike[i]; | 128 obj[i] = arrayLike[i]; |
121 } | 129 } |
122 } | 130 } |
123 } | 131 } |
124 | 132 |
125 function NAMEConstructor(arg1, arg2, arg3) { | 133 function NAMEConstructor(arg1, arg2, arg3) { |
126 if (%_IsConstructCall()) { | 134 if (%_IsConstructCall()) { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 "setUint32", DataViewSetUint32JS, | 473 "setUint32", DataViewSetUint32JS, |
466 | 474 |
467 "getFloat32", DataViewGetFloat32JS, | 475 "getFloat32", DataViewGetFloat32JS, |
468 "setFloat32", DataViewSetFloat32JS, | 476 "setFloat32", DataViewSetFloat32JS, |
469 | 477 |
470 "getFloat64", DataViewGetFloat64JS, | 478 "getFloat64", DataViewGetFloat64JS, |
471 "setFloat64", DataViewSetFloat64JS | 479 "setFloat64", DataViewSetFloat64JS |
472 ]); | 480 ]); |
473 | 481 |
474 }) | 482 }) |
OLD | NEW |