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() { | 5 (function() { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 endmacro | 31 endmacro |
32 | 32 |
33 TYPED_ARRAYS(DECLARE_GLOBALS) | 33 TYPED_ARRAYS(DECLARE_GLOBALS) |
34 | 34 |
35 // --------------- Typed Arrays --------------------- | 35 // --------------- Typed Arrays --------------------- |
36 | 36 |
37 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) | 37 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
38 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { | 38 function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
39 if (!IS_UNDEFINED(byteOffset)) { | 39 if (!IS_UNDEFINED(byteOffset)) { |
40 byteOffset = | 40 byteOffset = |
41 $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); | 41 ToPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
42 } | 42 } |
43 if (!IS_UNDEFINED(length)) { | 43 if (!IS_UNDEFINED(length)) { |
44 length = $toPositiveInteger(length, kInvalidTypedArrayLength); | 44 length = ToPositiveInteger(length, kInvalidTypedArrayLength); |
45 } | 45 } |
46 | 46 |
47 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); | 47 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
48 var offset; | 48 var offset; |
49 if (IS_UNDEFINED(byteOffset)) { | 49 if (IS_UNDEFINED(byteOffset)) { |
50 offset = 0; | 50 offset = 0; |
51 } else { | 51 } else { |
52 offset = byteOffset; | 52 offset = byteOffset; |
53 | 53 |
54 if (offset % ELEMENT_SIZE !== 0) { | 54 if (offset % ELEMENT_SIZE !== 0) { |
(...skipping 20 matching lines...) Expand all Loading... |
75 } | 75 } |
76 if ((offset + newByteLength > bufferByteLength) | 76 if ((offset + newByteLength > bufferByteLength) |
77 || (newLength > %_MaxSmi())) { | 77 || (newLength > %_MaxSmi())) { |
78 throw MakeRangeError(kInvalidTypedArrayLength); | 78 throw MakeRangeError(kInvalidTypedArrayLength); |
79 } | 79 } |
80 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); | 80 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); |
81 } | 81 } |
82 | 82 |
83 function NAMEConstructByLength(obj, length) { | 83 function NAMEConstructByLength(obj, length) { |
84 var l = IS_UNDEFINED(length) ? | 84 var l = IS_UNDEFINED(length) ? |
85 0 : $toPositiveInteger(length, kInvalidTypedArrayLength); | 85 0 : ToPositiveInteger(length, kInvalidTypedArrayLength); |
86 if (l > %_MaxSmi()) { | 86 if (l > %_MaxSmi()) { |
87 throw MakeRangeError(kInvalidTypedArrayLength); | 87 throw MakeRangeError(kInvalidTypedArrayLength); |
88 } | 88 } |
89 var byteLength = l * ELEMENT_SIZE; | 89 var byteLength = l * ELEMENT_SIZE; |
90 if (byteLength > %_TypedArrayMaxSizeInHeap()) { | 90 if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
91 var buffer = new GlobalArrayBuffer(byteLength); | 91 var buffer = new GlobalArrayBuffer(byteLength); |
92 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); | 92 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
93 } else { | 93 } else { |
94 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); | 94 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 function NAMEConstructByArrayLike(obj, arrayLike) { | 98 function NAMEConstructByArrayLike(obj, arrayLike) { |
99 var length = arrayLike.length; | 99 var length = arrayLike.length; |
100 var l = $toPositiveInteger(length, kInvalidTypedArrayLength); | 100 var l = ToPositiveInteger(length, kInvalidTypedArrayLength); |
101 | 101 |
102 if (l > %_MaxSmi()) { | 102 if (l > %_MaxSmi()) { |
103 throw MakeRangeError(kInvalidTypedArrayLength); | 103 throw MakeRangeError(kInvalidTypedArrayLength); |
104 } | 104 } |
105 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { | 105 if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { |
106 for (var i = 0; i < l; i++) { | 106 for (var i = 0; i < l; i++) { |
107 // It is crucial that we let any execptions from arrayLike[i] | 107 // It is crucial that we let any execptions from arrayLike[i] |
108 // propagate outside the function. | 108 // propagate outside the function. |
109 obj[i] = arrayLike[i]; | 109 obj[i] = arrayLike[i]; |
110 } | 110 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 endmacro | 328 endmacro |
329 | 329 |
330 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 330 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
331 | 331 |
332 // --------------------------- DataView ----------------------------- | 332 // --------------------------- DataView ----------------------------- |
333 | 333 |
334 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 334 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
335 if (%_IsConstructCall()) { | 335 if (%_IsConstructCall()) { |
336 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer); | 336 if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer); |
337 if (!IS_UNDEFINED(byteOffset)) { | 337 if (!IS_UNDEFINED(byteOffset)) { |
338 byteOffset = $toPositiveInteger(byteOffset, kInvalidDataViewOffset); | 338 byteOffset = ToPositiveInteger(byteOffset, kInvalidDataViewOffset); |
339 } | 339 } |
340 if (!IS_UNDEFINED(byteLength)) { | 340 if (!IS_UNDEFINED(byteLength)) { |
341 byteLength = TO_INTEGER(byteLength); | 341 byteLength = TO_INTEGER(byteLength); |
342 } | 342 } |
343 | 343 |
344 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); | 344 var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
345 | 345 |
346 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; | 346 var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; |
347 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset); | 347 if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset); |
348 | 348 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 FUNCTION(Int8) | 385 FUNCTION(Int8) |
386 FUNCTION(Uint8) | 386 FUNCTION(Uint8) |
387 FUNCTION(Int16) | 387 FUNCTION(Int16) |
388 FUNCTION(Uint16) | 388 FUNCTION(Uint16) |
389 FUNCTION(Int32) | 389 FUNCTION(Int32) |
390 FUNCTION(Uint32) | 390 FUNCTION(Uint32) |
391 FUNCTION(Float32) | 391 FUNCTION(Float32) |
392 FUNCTION(Float64) | 392 FUNCTION(Float64) |
393 endmacro | 393 endmacro |
394 | 394 |
| 395 function ToPositiveDataViewOffset(offset) { |
| 396 return ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
| 397 } |
| 398 |
395 | 399 |
396 macro DATA_VIEW_GETTER_SETTER(TYPENAME) | 400 macro DATA_VIEW_GETTER_SETTER(TYPENAME) |
397 function DataViewGetTYPENAMEJS(offset, little_endian) { | 401 function DataViewGetTYPENAMEJS(offset, little_endian) { |
398 if (!IS_DATAVIEW(this)) { | 402 if (!IS_DATAVIEW(this)) { |
399 throw MakeTypeError(kIncompatibleMethodReceiver, | 403 throw MakeTypeError(kIncompatibleMethodReceiver, |
400 'DataView.getTYPENAME', this); | 404 'DataView.getTYPENAME', this); |
401 } | 405 } |
402 if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument); | 406 if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument); |
403 offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset); | 407 return %DataViewGetTYPENAME(this, |
404 return %DataViewGetTYPENAME(this, offset, !!little_endian); | 408 ToPositiveDataViewOffset(offset), |
| 409 !!little_endian); |
405 } | 410 } |
406 | 411 |
407 function DataViewSetTYPENAMEJS(offset, value, little_endian) { | 412 function DataViewSetTYPENAMEJS(offset, value, little_endian) { |
408 if (!IS_DATAVIEW(this)) { | 413 if (!IS_DATAVIEW(this)) { |
409 throw MakeTypeError(kIncompatibleMethodReceiver, | 414 throw MakeTypeError(kIncompatibleMethodReceiver, |
410 'DataView.setTYPENAME', this); | 415 'DataView.setTYPENAME', this); |
411 } | 416 } |
412 if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument); | 417 if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument); |
413 offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset); | 418 %DataViewSetTYPENAME(this, |
414 %DataViewSetTYPENAME(this, offset, TO_NUMBER_INLINE(value), !!little_endian); | 419 ToPositiveDataViewOffset(offset), |
| 420 TO_NUMBER_INLINE(value), |
| 421 !!little_endian); |
415 } | 422 } |
416 endmacro | 423 endmacro |
417 | 424 |
418 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) | 425 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
419 | 426 |
420 // Setup the DataView constructor. | 427 // Setup the DataView constructor. |
421 %SetCode(GlobalDataView, DataViewConstructor); | 428 %SetCode(GlobalDataView, DataViewConstructor); |
422 %FunctionSetPrototype(GlobalDataView, new GlobalObject); | 429 %FunctionSetPrototype(GlobalDataView, new GlobalObject); |
423 | 430 |
424 // Set up constructor property on the DataView prototype. | 431 // Set up constructor property on the DataView prototype. |
(...skipping 26 matching lines...) Expand all Loading... |
451 "setUint32", DataViewSetUint32JS, | 458 "setUint32", DataViewSetUint32JS, |
452 | 459 |
453 "getFloat32", DataViewGetFloat32JS, | 460 "getFloat32", DataViewGetFloat32JS, |
454 "setFloat32", DataViewSetFloat32JS, | 461 "setFloat32", DataViewSetFloat32JS, |
455 | 462 |
456 "getFloat64", DataViewGetFloat64JS, | 463 "getFloat64", DataViewGetFloat64JS, |
457 "setFloat64", DataViewSetFloat64JS | 464 "setFloat64", DataViewSetFloat64JS |
458 ]); | 465 ]); |
459 | 466 |
460 })(); | 467 })(); |
OLD | NEW |