Index: src/harmony-sharedtypedarray.js |
diff --git a/src/typedarray.js b/src/harmony-sharedtypedarray.js |
similarity index 59% |
copy from src/typedarray.js |
copy to src/harmony-sharedtypedarray.js |
index baf8edb99128af2a1b7a26f07107d91fd8f59daf..284d507f73b5648e0d405af74959d22ac7e7c40e 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,36 +9,36 @@ |
%CheckIsBootstrapping(); |
var GlobalArray = global.Array; |
-var GlobalArrayBuffer = global.ArrayBuffer; |
+var GlobalSharedArrayBuffer = global.SharedArrayBuffer; |
var GlobalDataView = global.DataView; |
var GlobalObject = global.Object; |
-macro TYPED_ARRAYS(FUNCTION) |
+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 DECLARE_GLOBALS(INDEX, NAME, SIZE) |
var GlobalNAME = global.NAME; |
endmacro |
-TYPED_ARRAYS(DECLARE_GLOBALS) |
+SHARED_TYPED_ARRAYS(DECLARE_GLOBALS) |
-// --------------- Typed Arrays --------------------- |
+// --------------- Shared Typed Arrays --------------------- |
-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 = |
- $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
+ $toPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
} |
if (!IS_UNDEFINED(length)) { |
length = $toPositiveInteger(length, kInvalidTypedArrayLength); |
@@ -52,8 +52,8 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
offset = byteOffset; |
if (offset % ELEMENT_SIZE !== 0) { |
- throw MakeRangeError(kInvalidTypedArrayAlignment, |
- "start offset", "NAME", ELEMENT_SIZE); |
+ throw MakeRangeError(kInvalidTypedArrayAlignment, "start offset", "NAME", |
+ ELEMENT_SIZE); |
} |
if (offset > bufferByteLength) { |
throw MakeRangeError(kInvalidTypedArrayOffset); |
@@ -64,8 +64,8 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
var newLength; |
if (IS_UNDEFINED(length)) { |
if (bufferByteLength % ELEMENT_SIZE !== 0) { |
- throw MakeRangeError(kInvalidTypedArrayAlignment, |
- "byte length", "NAME", ELEMENT_SIZE); |
+ throw MakeRangeError(kInvalidTypedArrayAlignment, "byte length", "NAME", |
+ ELEMENT_SIZE); |
} |
newByteLength = bufferByteLength - offset; |
newLength = newByteLength / ELEMENT_SIZE; |
@@ -87,39 +87,19 @@ function NAMEConstructByLength(obj, length) { |
throw MakeRangeError(kInvalidTypedArrayLength); |
} |
var byteLength = l * ELEMENT_SIZE; |
- if (byteLength > %_TypedArrayMaxSizeInHeap()) { |
- var buffer = new GlobalArrayBuffer(byteLength); |
- %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
- } else { |
- %_TypedArrayInitialize(obj, ARRAY_ID, null, 0, byteLength); |
- } |
-} |
- |
-function NAMEConstructByArrayLike(obj, arrayLike) { |
- var length = arrayLike.length; |
- var l = $toPositiveInteger(length, kInvalidTypedArrayLength); |
- |
- if (l > %_MaxSmi()) { |
- throw MakeRangeError(kInvalidTypedArrayLength); |
- } |
- 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]; |
- } |
- } |
+ var buffer = new GlobalSharedArrayBuffer(byteLength); |
+ %_TypedArrayInitialize(obj, ARRAY_ID, buffer, 0, byteLength); |
} |
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(kInvalidArgument); |
} |
} else { |
throw MakeTypeError(kConstructorNotFunction, "NAME") |
@@ -182,13 +162,12 @@ function NAMESubArray(begin, end) { |
var newLength = endInt - beginInt; |
var beginByteOffset = |
%_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE; |
- return new GlobalNAME(%TypedArrayGetBuffer(this), |
- beginByteOffset, newLength); |
+ return new GlobalNAME(%TypedArrayGetBuffer(this), beginByteOffset, |
+ newLength); |
} |
endmacro |
-TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
- |
+SHARED_TYPED_ARRAYS(SHARED_TYPED_ARRAY_CONSTRUCTOR) |
function TypedArraySetFromArrayLike(target, source, sourceLength, offset) { |
if (offset > 0) { |
@@ -301,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(GlobalNAME, NAMEConstructor); |
%FunctionSetPrototype(GlobalNAME, new GlobalObject()); |
@@ -327,134 +307,6 @@ macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
]); |
endmacro |
-TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
- |
-// --------------------------- DataView ----------------------------- |
- |
-function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 |
- if (%_IsConstructCall()) { |
- if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer); |
- if (!IS_UNDEFINED(byteOffset)) { |
- byteOffset = $toPositiveInteger(byteOffset, kInvalidDataViewOffset); |
- } |
- if (!IS_UNDEFINED(byteLength)) { |
- byteLength = TO_INTEGER(byteLength); |
- } |
- |
- var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
- |
- var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; |
- if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset); |
- |
- var length = IS_UNDEFINED(byteLength) |
- ? bufferByteLength - offset |
- : byteLength; |
- if (length < 0 || offset + length > bufferByteLength) { |
- throw new MakeRangeError(kInvalidDataViewLength); |
- } |
- %_DataViewInitialize(this, buffer, offset, length); |
- } else { |
- throw MakeTypeError(kConstructorNotFunction, "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 |
- |
- |
-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(kInvalidArgument); |
- offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
- return %DataViewGetTYPENAME(this, offset, !!little_endian); |
-} |
- |
-function DataViewSetTYPENAMEJS(offset, value, little_endian) { |
- if (!IS_DATAVIEW(this)) { |
- throw MakeTypeError(kIncompatibleMethodReceiver, |
- 'DataView.setTYPENAME', this); |
- } |
- if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument); |
- offset = $toPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
- %DataViewSetTYPENAME(this, offset, TO_NUMBER_INLINE(value), !!little_endian); |
-} |
-endmacro |
- |
-DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER) |
- |
-// Setup the DataView constructor. |
-%SetCode(GlobalDataView, DataViewConstructor); |
-%FunctionSetPrototype(GlobalDataView, new GlobalObject); |
- |
-// Set up constructor property on the DataView prototype. |
-%AddNamedProperty(GlobalDataView.prototype, "constructor", GlobalDataView, |
- DONT_ENUM); |
-%AddNamedProperty(GlobalDataView.prototype, symbolToStringTag, "DataView", |
- READ_ONLY|DONT_ENUM); |
- |
-$installGetter(GlobalDataView.prototype, "buffer", DataViewGetBufferJS); |
-$installGetter(GlobalDataView.prototype, "byteOffset", DataViewGetByteOffset); |
-$installGetter(GlobalDataView.prototype, "byteLength", DataViewGetByteLength); |
- |
-$installFunctions(GlobalDataView.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) |
}) |