Chromium Code Reviews| Index: src/harmony-sharedtypedarray.js |
| diff --git a/src/typedarray.js b/src/harmony-sharedtypedarray.js |
| similarity index 62% |
| copy from src/typedarray.js |
| copy to src/harmony-sharedtypedarray.js |
| index 4e3b9385863a20c94234d3dc63bafb31191e31f1..f60e700137602a7465383405736b1ffcd7db43de 100644 |
| --- a/src/typedarray.js |
| +++ b/src/harmony-sharedtypedarray.js |
| @@ -1,4 +1,4 @@ |
| -// Copyright 2013 the V8 project authors. All rights reserved. |
| +// Copyright 2015 the V8 project authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -9,23 +9,24 @@ |
| %CheckIsBootstrapping(); |
| var GlobalArray = global.Array; |
| -var GlobalArrayBuffer = global.ArrayBuffer; |
| +var GlobalSharedArrayBuffer = global.SharedArrayBuffer; |
| -// --------------- Typed Arrays --------------------- |
| -macro TYPED_ARRAYS(FUNCTION) |
| +// --------------- Shared Typed Arrays --------------------- |
| + |
| +macro SHARED_TYPED_ARRAYS(FUNCTION) |
| // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| -FUNCTION(1, Uint8Array, 1) |
| -FUNCTION(2, Int8Array, 1) |
| -FUNCTION(3, Uint16Array, 2) |
| -FUNCTION(4, Int16Array, 2) |
| -FUNCTION(5, Uint32Array, 4) |
| -FUNCTION(6, Int32Array, 4) |
| -FUNCTION(7, Float32Array, 4) |
| -FUNCTION(8, Float64Array, 8) |
| -FUNCTION(9, Uint8ClampedArray, 1) |
| +FUNCTION(1, SharedUint8Array, 1) |
| +FUNCTION(2, SharedInt8Array, 1) |
| +FUNCTION(3, SharedUint16Array, 2) |
| +FUNCTION(4, SharedInt16Array, 2) |
| +FUNCTION(5, SharedUint32Array, 4) |
| +FUNCTION(6, SharedInt32Array, 4) |
| +FUNCTION(7, SharedFloat32Array, 4) |
| +FUNCTION(8, SharedFloat64Array, 8) |
| +FUNCTION(9, SharedUint8ClampedArray, 1) |
| endmacro |
| -macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| +macro SHARED_TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
| if (!IS_UNDEFINED(byteOffset)) { |
| byteOffset = |
| @@ -79,38 +80,22 @@ function NAMEConstructByLength(obj, length) { |
| } |
| var byteLength = l * ELEMENT_SIZE; |
| if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
| - var buffer = new GlobalArrayBuffer(byteLength); |
| + var buffer = new GlobalSharedArrayBuffer(byteLength); |
| %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
| } else { |
| %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); |
|
jochen (gone - plz use gerrit)
2015/04/28 18:31:46
what's the point of having an on-heap shared typed
binji
2015/04/29 18:27:22
Done.
|
| } |
| } |
| -function NAMEConstructByArrayLike(obj, arrayLike) { |
| - var length = arrayLike.length; |
| - var l = ToPositiveInteger(length, "invalid_typed_array_length"); |
| - |
| - if (l > %_MaxSmi()) { |
| - throw MakeRangeError("invalid_typed_array_length"); |
| - } |
| - if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { |
| - for (var i = 0; i < l; i++) { |
| - // It is crucial that we let any execptions from arrayLike[i] |
| - // propagate outside the function. |
| - obj[i] = arrayLike[i]; |
| - } |
| - } |
| -} |
| - |
| function NAMEConstructor(arg1, arg2, arg3) { |
| if (%_IsConstructCall()) { |
| - if (IS_ARRAYBUFFER(arg1)) { |
| + if (IS_SHAREDARRAYBUFFER(arg1)) { |
| NAMEConstructByArrayBuffer(this, arg1, arg2, arg3); |
| } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || |
| IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| NAMEConstructByLength(this, arg1); |
| } else { |
| - NAMEConstructByArrayLike(this, arg1); |
| + throw MakeTypeError("invalid_argument"); |
| } |
| } else { |
| throw MakeTypeError("constructor_not_function", ["NAME"]) |
| @@ -180,8 +165,7 @@ function NAMESubArray(begin, end) { |
| } |
| endmacro |
| -TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| - |
| +SHARED_TYPED_ARRAYS(SHARED_TYPED_ARRAY_CONSTRUCTOR) |
| function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
| if (offset > 0) { |
| @@ -296,7 +280,8 @@ function TypedArrayGetToStringTag() { |
| // ------------------------------------------------------------------- |
| -macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| + |
| +macro SETUP_SHARED_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| %SetCode(global.NAME, NAMEConstructor); |
| %FunctionSetPrototype(global.NAME, new $Object()); |
| @@ -322,150 +307,6 @@ macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| ]); |
| endmacro |
| -TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| - |
| -// --------------------------- DataView ----------------------------- |
| - |
| -var $DataView = global.DataView; |
| - |
| -function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
| - if (%_IsConstructCall()) { |
| - if (!IS_ARRAYBUFFER(buffer)) { |
| - throw MakeTypeError('data_view_not_array_buffer', []); |
| - } |
| - if (!IS_UNDEFINED(byteOffset)) { |
| - byteOffset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); |
| - } |
| - if (!IS_UNDEFINED(byteLength)) { |
| - byteLength = TO_INTEGER(byteLength); |
| - } |
| - |
| - var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
| - |
| - var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; |
| - if (offset > bufferByteLength) { |
| - throw MakeRangeError('invalid_data_view_offset'); |
| - } |
| - |
| - var length = IS_UNDEFINED(byteLength) |
| - ? bufferByteLength - offset |
| - : byteLength; |
| - if (length < 0 || offset + length > bufferByteLength) { |
| - throw new MakeRangeError('invalid_data_view_length'); |
| - } |
| - %_DataViewInitialize(this, buffer, offset, length); |
| - } else { |
| - throw MakeTypeError('constructor_not_function', ["DataView"]); |
| - } |
| -} |
| - |
| -function DataViewGetBufferJS() { |
| - if (!IS_DATAVIEW(this)) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this); |
| - } |
| - return %DataViewGetBuffer(this); |
| -} |
| - |
| -function DataViewGetByteOffset() { |
| - if (!IS_DATAVIEW(this)) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, |
| - 'DataView.byteOffset', this); |
| - } |
| - return %_ArrayBufferViewGetByteOffset(this); |
| -} |
| - |
| -function DataViewGetByteLength() { |
| - if (!IS_DATAVIEW(this)) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, |
| - 'DataView.byteLength', this); |
| - } |
| - return %_ArrayBufferViewGetByteLength(this); |
| -} |
| - |
| -macro DATA_VIEW_TYPES(FUNCTION) |
| - FUNCTION(Int8) |
| - FUNCTION(Uint8) |
| - FUNCTION(Int16) |
| - FUNCTION(Uint16) |
| - FUNCTION(Int32) |
| - FUNCTION(Uint32) |
| - FUNCTION(Float32) |
| - FUNCTION(Float64) |
| -endmacro |
| - |
| -function ToPositiveDataViewOffset(offset) { |
| - return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); |
| -} |
| - |
| - |
| -macro DATA_VIEW_GETTER_SETTER(TYPENAME) |
| -function DataViewGetTYPENAMEJS(offset, little_endian) { |
| - if (!IS_DATAVIEW(this)) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, |
| - 'DataView.getTYPENAME', this); |
| - } |
| - if (%_ArgumentsLength() < 1) { |
| - throw MakeTypeError('invalid_argument'); |
| - } |
| - return %DataViewGetTYPENAME(this, |
| - ToPositiveDataViewOffset(offset), |
| - !!little_endian); |
| -} |
| - |
| -function DataViewSetTYPENAMEJS(offset, value, little_endian) { |
| - if (!IS_DATAVIEW(this)) { |
| - throw MakeTypeError(kIncompatibleMethodReceiver, |
| - 'DataView.setTYPENAME', this); |
| - } |
| - if (%_ArgumentsLength() < 2) { |
| - throw MakeTypeError('invalid_argument'); |
| - } |
| - %DataViewSetTYPENAME(this, |
| - ToPositiveDataViewOffset(offset), |
| - TO_NUMBER_INLINE(value), |
| - !!little_endian); |
| -} |
| -endmacro |
| - |
| -DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
| - |
| -// Setup the DataView constructor. |
| -%SetCode($DataView, DataViewConstructor); |
| -%FunctionSetPrototype($DataView, new $Object); |
| - |
| -// Set up constructor property on the DataView prototype. |
| -%AddNamedProperty($DataView.prototype, "constructor", $DataView, DONT_ENUM); |
| -%AddNamedProperty( |
| - $DataView.prototype, symbolToStringTag, "DataView", READ_ONLY|DONT_ENUM); |
| - |
| -InstallGetter($DataView.prototype, "buffer", DataViewGetBufferJS); |
| -InstallGetter($DataView.prototype, "byteOffset", DataViewGetByteOffset); |
| -InstallGetter($DataView.prototype, "byteLength", DataViewGetByteLength); |
| - |
| -InstallFunctions($DataView.prototype, DONT_ENUM, [ |
| - "getInt8", DataViewGetInt8JS, |
| - "setInt8", DataViewSetInt8JS, |
| - |
| - "getUint8", DataViewGetUint8JS, |
| - "setUint8", DataViewSetUint8JS, |
| - |
| - "getInt16", DataViewGetInt16JS, |
| - "setInt16", DataViewSetInt16JS, |
| - |
| - "getUint16", DataViewGetUint16JS, |
| - "setUint16", DataViewSetUint16JS, |
| - |
| - "getInt32", DataViewGetInt32JS, |
| - "setInt32", DataViewSetInt32JS, |
| - |
| - "getUint32", DataViewGetUint32JS, |
| - "setUint32", DataViewSetUint32JS, |
| - |
| - "getFloat32", DataViewGetFloat32JS, |
| - "setFloat32", DataViewSetFloat32JS, |
| - |
| - "getFloat64", DataViewGetFloat64JS, |
| - "setFloat64", DataViewSetFloat64JS |
| -]); |
| +SHARED_TYPED_ARRAYS(SETUP_SHARED_TYPED_ARRAY) |
| })(); |