| 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() { |
| 6 |
| 5 "use strict"; | 7 "use strict"; |
| 6 | 8 |
| 7 // This file relies on the fact that the following declaration has been made | 9 %CheckIsBootstrapping(); |
| 8 // in runtime.js: | |
| 9 // var $Array = global.Array; | |
| 10 var $ArrayBuffer = global.ArrayBuffer; | |
| 11 | 10 |
| 11 var GlobalArray = global.Array; |
| 12 var GlobalArrayBuffer = global.ArrayBuffer; |
| 12 | 13 |
| 13 // --------------- Typed Arrays --------------------- | 14 // --------------- Typed Arrays --------------------- |
| 14 macro TYPED_ARRAYS(FUNCTION) | 15 macro TYPED_ARRAYS(FUNCTION) |
| 15 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 16 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 16 FUNCTION(1, Uint8Array, 1) | 17 FUNCTION(1, Uint8Array, 1) |
| 17 FUNCTION(2, Int8Array, 1) | 18 FUNCTION(2, Int8Array, 1) |
| 18 FUNCTION(3, Uint16Array, 2) | 19 FUNCTION(3, Uint16Array, 2) |
| 19 FUNCTION(4, Int16Array, 2) | 20 FUNCTION(4, Int16Array, 2) |
| 20 FUNCTION(5, Uint32Array, 4) | 21 FUNCTION(5, Uint32Array, 4) |
| 21 FUNCTION(6, Int32Array, 4) | 22 FUNCTION(6, Int32Array, 4) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 72 } |
| 72 | 73 |
| 73 function NAMEConstructByLength(obj, length) { | 74 function NAMEConstructByLength(obj, length) { |
| 74 var l = IS_UNDEFINED(length) ? | 75 var l = IS_UNDEFINED(length) ? |
| 75 0 : ToPositiveInteger(length, "invalid_typed_array_length"); | 76 0 : ToPositiveInteger(length, "invalid_typed_array_length"); |
| 76 if (l > %_MaxSmi()) { | 77 if (l > %_MaxSmi()) { |
| 77 throw MakeRangeError("invalid_typed_array_length"); | 78 throw MakeRangeError("invalid_typed_array_length"); |
| 78 } | 79 } |
| 79 var byteLength = l * ELEMENT_SIZE; | 80 var byteLength = l * ELEMENT_SIZE; |
| 80 if (byteLength > %_TypedArrayMaxSizeInHeap()) { | 81 if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
| 81 var buffer = new $ArrayBuffer(byteLength); | 82 var buffer = new GlobalArrayBuffer(byteLength); |
| 82 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); | 83 %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
| 83 } else { | 84 } else { |
| 84 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); | 85 %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 function NAMEConstructByArrayLike(obj, arrayLike) { | 89 function NAMEConstructByArrayLike(obj, arrayLike) { |
| 89 var length = arrayLike.length; | 90 var length = arrayLike.length; |
| 90 var l = ToPositiveInteger(length, "invalid_typed_array_length"); | 91 var l = ToPositiveInteger(length, "invalid_typed_array_length"); |
| 91 | 92 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 rightIndex >= leftIndex && targetPtr >= sourcePtr; | 237 rightIndex >= leftIndex && targetPtr >= sourcePtr; |
| 237 rightIndex--) { | 238 rightIndex--) { |
| 238 target[offset + rightIndex] = source[rightIndex]; | 239 target[offset + rightIndex] = source[rightIndex]; |
| 239 targetPtr -= targetElementSize; | 240 targetPtr -= targetElementSize; |
| 240 sourcePtr -= sourceElementSize; | 241 sourcePtr -= sourceElementSize; |
| 241 } | 242 } |
| 242 return rightIndex; | 243 return rightIndex; |
| 243 } | 244 } |
| 244 var rightIndex = CopyRightPart(); | 245 var rightIndex = CopyRightPart(); |
| 245 | 246 |
| 246 var temp = new $Array(rightIndex + 1 - leftIndex); | 247 var temp = new GlobalArray(rightIndex + 1 - leftIndex); |
| 247 for (var i = leftIndex; i <= rightIndex; i++) { | 248 for (var i = leftIndex; i <= rightIndex; i++) { |
| 248 temp[i - leftIndex] = source[i]; | 249 temp[i - leftIndex] = source[i]; |
| 249 } | 250 } |
| 250 for (i = leftIndex; i <= rightIndex; i++) { | 251 for (i = leftIndex; i <= rightIndex; i++) { |
| 251 target[offset + i] = temp[i - leftIndex]; | 252 target[offset + i] = temp[i - leftIndex]; |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 function TypedArraySet(obj, offset) { | 256 function TypedArraySet(obj, offset) { |
| 256 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); | 257 var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 294 |
| 294 function TypedArrayGetToStringTag() { | 295 function TypedArrayGetToStringTag() { |
| 295 if (!%IsTypedArray(this)) return; | 296 if (!%IsTypedArray(this)) return; |
| 296 var name = %_ClassOf(this); | 297 var name = %_ClassOf(this); |
| 297 if (IS_UNDEFINED(name)) return; | 298 if (IS_UNDEFINED(name)) return; |
| 298 return name; | 299 return name; |
| 299 } | 300 } |
| 300 | 301 |
| 301 // ------------------------------------------------------------------- | 302 // ------------------------------------------------------------------- |
| 302 | 303 |
| 303 function SetupTypedArrays() { | |
| 304 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | 304 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 305 %CheckIsBootstrapping(); | 305 %CheckIsBootstrapping(); |
| 306 %SetCode(global.NAME, NAMEConstructor); | 306 %SetCode(global.NAME, NAMEConstructor); |
| 307 %FunctionSetPrototype(global.NAME, new $Object()); | 307 %FunctionSetPrototype(global.NAME, new $Object()); |
| 308 | 308 |
| 309 %AddNamedProperty(global.NAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 309 %AddNamedProperty(global.NAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 310 READ_ONLY | DONT_ENUM | DONT_DELETE); | 310 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 311 %AddNamedProperty(global.NAME.prototype, | 311 %AddNamedProperty(global.NAME.prototype, |
| 312 "constructor", global.NAME, DONT_ENUM); | 312 "constructor", global.NAME, DONT_ENUM); |
| 313 %AddNamedProperty(global.NAME.prototype, | 313 %AddNamedProperty(global.NAME.prototype, |
| 314 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 314 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 315 READ_ONLY | DONT_ENUM | DONT_DELETE); | 315 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 316 InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer); | 316 InstallGetter(global.NAME.prototype, "buffer", NAME_GetBuffer); |
| 317 InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset, | 317 InstallGetter(global.NAME.prototype, "byteOffset", NAME_GetByteOffset, |
| 318 DONT_ENUM | DONT_DELETE); | 318 DONT_ENUM | DONT_DELETE); |
| 319 InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength, | 319 InstallGetter(global.NAME.prototype, "byteLength", NAME_GetByteLength, |
| 320 DONT_ENUM | DONT_DELETE); | 320 DONT_ENUM | DONT_DELETE); |
| 321 InstallGetter(global.NAME.prototype, "length", NAME_GetLength, | 321 InstallGetter(global.NAME.prototype, "length", NAME_GetLength, |
| 322 DONT_ENUM | DONT_DELETE); | 322 DONT_ENUM | DONT_DELETE); |
| 323 InstallGetter(global.NAME.prototype, symbolToStringTag, | 323 InstallGetter(global.NAME.prototype, symbolToStringTag, |
| 324 TypedArrayGetToStringTag); | 324 TypedArrayGetToStringTag); |
| 325 InstallFunctions(global.NAME.prototype, DONT_ENUM, [ | 325 InstallFunctions(global.NAME.prototype, DONT_ENUM, [ |
| 326 "subarray", NAMESubArray, | 326 "subarray", NAMESubArray, |
| 327 "set", TypedArraySet | 327 "set", TypedArraySet |
| 328 ]); | 328 ]); |
| 329 endmacro | 329 endmacro |
| 330 | 330 |
| 331 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 331 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 332 } | |
| 333 | |
| 334 SetupTypedArrays(); | |
| 335 | 332 |
| 336 // --------------------------- DataView ----------------------------- | 333 // --------------------------- DataView ----------------------------- |
| 337 | 334 |
| 338 var $DataView = global.DataView; | 335 var $DataView = global.DataView; |
| 339 | 336 |
| 340 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 | 337 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
| 341 if (%_IsConstructCall()) { | 338 if (%_IsConstructCall()) { |
| 342 if (!IS_ARRAYBUFFER(buffer)) { | 339 if (!IS_ARRAYBUFFER(buffer)) { |
| 343 throw MakeTypeError('data_view_not_array_buffer', []); | 340 throw MakeTypeError('data_view_not_array_buffer', []); |
| 344 } | 341 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 } | 429 } |
| 433 %DataViewSetTYPENAME(this, | 430 %DataViewSetTYPENAME(this, |
| 434 ToPositiveDataViewOffset(offset), | 431 ToPositiveDataViewOffset(offset), |
| 435 TO_NUMBER_INLINE(value), | 432 TO_NUMBER_INLINE(value), |
| 436 !!little_endian); | 433 !!little_endian); |
| 437 } | 434 } |
| 438 endmacro | 435 endmacro |
| 439 | 436 |
| 440 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) | 437 DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
| 441 | 438 |
| 442 function SetupDataView() { | 439 // Setup the DataView constructor. |
| 443 %CheckIsBootstrapping(); | 440 %SetCode($DataView, DataViewConstructor); |
| 441 %FunctionSetPrototype($DataView, new $Object); |
| 444 | 442 |
| 445 // Setup the DataView constructor. | 443 // Set up constructor property on the DataView prototype. |
| 446 %SetCode($DataView, DataViewConstructor); | 444 %AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); |
| 447 %FunctionSetPrototype($DataView, new $Object); | 445 %AddNamedProperty( |
| 446 $DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|DONT_ENUM); |
| 448 | 447 |
| 449 // Set up constructor property on the DataView prototype. | 448 InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS); |
| 450 %AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); | 449 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset); |
| 451 %AddNamedProperty( | 450 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength); |
| 452 $DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|DONT_ENUM); | |
| 453 | 451 |
| 454 InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS); | 452 InstallFunctions($DataView.prototype, DONT_ENUM, [ |
| 455 InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset); | 453 "getInt8", DataViewGetInt8JS, |
| 456 InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength); | 454 "setInt8", DataViewSetInt8JS, |
| 457 | 455 |
| 458 InstallFunctions($DataView.prototype, DONT_ENUM, [ | 456 "getUint8", DataViewGetUint8JS, |
| 459 "getInt8", DataViewGetInt8JS, | 457 "setUint8", DataViewSetUint8JS, |
| 460 "setInt8", DataViewSetInt8JS, | |
| 461 | 458 |
| 462 "getUint8", DataViewGetUint8JS, | 459 "getInt16", DataViewGetInt16JS, |
| 463 "setUint8", DataViewSetUint8JS, | 460 "setInt16", DataViewSetInt16JS, |
| 464 | 461 |
| 465 "getInt16", DataViewGetInt16JS, | 462 "getUint16", DataViewGetUint16JS, |
| 466 "setInt16", DataViewSetInt16JS, | 463 "setUint16", DataViewSetUint16JS, |
| 467 | 464 |
| 468 "getUint16", DataViewGetUint16JS, | 465 "getInt32", DataViewGetInt32JS, |
| 469 "setUint16", DataViewSetUint16JS, | 466 "setInt32", DataViewSetInt32JS, |
| 470 | 467 |
| 471 "getInt32", DataViewGetInt32JS, | 468 "getUint32", DataViewGetUint32JS, |
| 472 "setInt32", DataViewSetInt32JS, | 469 "setUint32", DataViewSetUint32JS, |
| 473 | 470 |
| 474 "getUint32", DataViewGetUint32JS, | 471 "getFloat32", DataViewGetFloat32JS, |
| 475 "setUint32", DataViewSetUint32JS, | 472 "setFloat32", DataViewSetFloat32JS, |
| 476 | 473 |
| 477 "getFloat32", DataViewGetFloat32JS, | 474 "getFloat64", DataViewGetFloat64JS, |
| 478 "setFloat32", DataViewSetFloat32JS, | 475 "setFloat64", DataViewSetFloat64JS |
| 476 ]); |
| 479 | 477 |
| 480 "getFloat64", DataViewGetFloat64JS, | 478 })(); |
| 481 "setFloat64", DataViewSetFloat64JS | |
| 482 ]); | |
| 483 } | |
| 484 | |
| 485 SetupDataView(); | |
| OLD | NEW |