Add TypedArray constructors with SharedArrayBuffer to the external API.
BUG=chromium:497295 LOG=n Review URL: https://codereview.chromium.org/1168723002 Cr-Commit-Position: refs/heads/master@{#28850}
This commit is contained in:
parent
e036a34870
commit
f145765524
22
include/v8.h
22
include/v8.h
@ -94,6 +94,7 @@ class Primitive;
|
||||
class Promise;
|
||||
class RawOperationDescriptor;
|
||||
class Script;
|
||||
class SharedArrayBuffer;
|
||||
class Signature;
|
||||
class StartupData;
|
||||
class StackFrame;
|
||||
@ -3556,6 +3557,8 @@ class V8_EXPORT Uint8Array : public TypedArray {
|
||||
public:
|
||||
static Local<Uint8Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Uint8Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Uint8Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3572,6 +3575,9 @@ class V8_EXPORT Uint8ClampedArray : public TypedArray {
|
||||
public:
|
||||
static Local<Uint8ClampedArray> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Uint8ClampedArray> New(
|
||||
Handle<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
|
||||
size_t length);
|
||||
V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3587,6 +3593,8 @@ class V8_EXPORT Int8Array : public TypedArray {
|
||||
public:
|
||||
static Local<Int8Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Int8Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Int8Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3603,6 +3611,8 @@ class V8_EXPORT Uint16Array : public TypedArray {
|
||||
public:
|
||||
static Local<Uint16Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Uint16Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Uint16Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3619,6 +3629,8 @@ class V8_EXPORT Int16Array : public TypedArray {
|
||||
public:
|
||||
static Local<Int16Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Int16Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Int16Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3635,6 +3647,8 @@ class V8_EXPORT Uint32Array : public TypedArray {
|
||||
public:
|
||||
static Local<Uint32Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Uint32Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Uint32Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3651,6 +3665,8 @@ class V8_EXPORT Int32Array : public TypedArray {
|
||||
public:
|
||||
static Local<Int32Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Int32Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Int32Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3667,6 +3683,8 @@ class V8_EXPORT Float32Array : public TypedArray {
|
||||
public:
|
||||
static Local<Float32Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Float32Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Float32Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3683,6 +3701,8 @@ class V8_EXPORT Float64Array : public TypedArray {
|
||||
public:
|
||||
static Local<Float64Array> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<Float64Array> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static Float64Array* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
@ -3699,6 +3719,8 @@ class V8_EXPORT DataView : public ArrayBufferView {
|
||||
public:
|
||||
static Local<DataView> New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
static Local<DataView> New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t length);
|
||||
V8_INLINE static DataView* Cast(Value* obj);
|
||||
|
||||
private:
|
||||
|
40
src/api.cc
40
src/api.cc
@ -6682,6 +6682,28 @@ size_t v8::TypedArray::Length() {
|
||||
i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \
|
||||
i::kExternal##Type##Array, buffer, byte_offset, length); \
|
||||
return Utils::ToLocal##Type##Array(obj); \
|
||||
} \
|
||||
Local<Type##Array> Type##Array::New( \
|
||||
Handle<SharedArrayBuffer> shared_array_buffer, size_t byte_offset, \
|
||||
size_t length) { \
|
||||
CHECK(i::FLAG_harmony_sharedarraybuffer); \
|
||||
i::Isolate* isolate = \
|
||||
Utils::OpenHandle(*shared_array_buffer)->GetIsolate(); \
|
||||
LOG_API(isolate, "v8::" #Type \
|
||||
"Array::New(Handle<SharedArrayBuffer>, size_t, size_t)"); \
|
||||
ENTER_V8(isolate); \
|
||||
if (!Utils::ApiCheck( \
|
||||
length <= static_cast<size_t>(i::Smi::kMaxValue), \
|
||||
"v8::" #Type \
|
||||
"Array::New(Handle<SharedArrayBuffer>, size_t, size_t)", \
|
||||
"length exceeds max allowed value")) { \
|
||||
return Local<Type##Array>(); \
|
||||
} \
|
||||
i::Handle<i::JSArrayBuffer> buffer = \
|
||||
Utils::OpenHandle(*shared_array_buffer); \
|
||||
i::Handle<i::JSTypedArray> obj = isolate->factory()->NewJSTypedArray( \
|
||||
i::kExternal##Type##Array, buffer, byte_offset, length); \
|
||||
return Utils::ToLocal##Type##Array(obj); \
|
||||
}
|
||||
|
||||
|
||||
@ -6692,7 +6714,21 @@ Local<DataView> DataView::New(Handle<ArrayBuffer> array_buffer,
|
||||
size_t byte_offset, size_t byte_length) {
|
||||
i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
|
||||
i::Isolate* isolate = buffer->GetIsolate();
|
||||
LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)");
|
||||
LOG_API(isolate, "v8::DataView::New(Handle<ArrayBuffer>, size_t, size_t)");
|
||||
ENTER_V8(isolate);
|
||||
i::Handle<i::JSDataView> obj =
|
||||
isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
|
||||
return Utils::ToLocal(obj);
|
||||
}
|
||||
|
||||
|
||||
Local<DataView> DataView::New(Handle<SharedArrayBuffer> shared_array_buffer,
|
||||
size_t byte_offset, size_t byte_length) {
|
||||
CHECK(i::FLAG_harmony_sharedarraybuffer);
|
||||
i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*shared_array_buffer);
|
||||
i::Isolate* isolate = buffer->GetIsolate();
|
||||
LOG_API(isolate,
|
||||
"v8::DataView::New(Handle<SharedArrayBuffer>, size_t, size_t)");
|
||||
ENTER_V8(isolate);
|
||||
i::Handle<i::JSDataView> obj =
|
||||
isolate->factory()->NewJSDataView(buffer, byte_offset, byte_length);
|
||||
@ -6734,6 +6770,7 @@ size_t v8::SharedArrayBuffer::ByteLength() const {
|
||||
|
||||
Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate,
|
||||
size_t byte_length) {
|
||||
CHECK(i::FLAG_harmony_sharedarraybuffer);
|
||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||
LOG_API(i_isolate, "v8::SharedArrayBuffer::New(size_t)");
|
||||
ENTER_V8(i_isolate);
|
||||
@ -6748,6 +6785,7 @@ Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(Isolate* isolate,
|
||||
Local<SharedArrayBuffer> v8::SharedArrayBuffer::New(
|
||||
Isolate* isolate, void* data, size_t byte_length,
|
||||
ArrayBufferCreationMode mode) {
|
||||
CHECK(i::FLAG_harmony_sharedarraybuffer);
|
||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||
LOG_API(i_isolate, "v8::SharedArrayBuffer::New(void*, size_t)");
|
||||
ENTER_V8(i_isolate);
|
||||
|
@ -14061,7 +14061,8 @@ THREADED_TEST(FixedFloat64Array) {
|
||||
}
|
||||
|
||||
|
||||
template <typename ElementType, typename TypedArray, class ExternalArrayClass>
|
||||
template <typename ElementType, typename TypedArray, class ExternalArrayClass,
|
||||
class ArrayBufferType>
|
||||
void TypedArrayTestHelper(i::ExternalArrayType array_type, int64_t low,
|
||||
int64_t high) {
|
||||
const int kElementCount = 50;
|
||||
@ -14072,8 +14073,8 @@ void TypedArrayTestHelper(i::ExternalArrayType array_type, int64_t low,
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
Local<v8::ArrayBuffer> ab =
|
||||
v8::ArrayBuffer::New(isolate, backing_store.start(),
|
||||
Local<ArrayBufferType> ab =
|
||||
ArrayBufferType::New(isolate, backing_store.start(),
|
||||
(kElementCount + 2) * sizeof(ElementType));
|
||||
Local<TypedArray> ta =
|
||||
TypedArray::New(ab, 2*sizeof(ElementType), kElementCount);
|
||||
@ -14094,56 +14095,58 @@ void TypedArrayTestHelper(i::ExternalArrayType array_type, int64_t low,
|
||||
|
||||
|
||||
THREADED_TEST(Uint8Array) {
|
||||
TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array>(
|
||||
i::kExternalUint8Array, 0, 0xFF);
|
||||
TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array,
|
||||
v8::ArrayBuffer>(i::kExternalUint8Array, 0, 0xFF);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Int8Array) {
|
||||
TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array>(
|
||||
i::kExternalInt8Array, -0x80, 0x7F);
|
||||
TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array,
|
||||
v8::ArrayBuffer>(i::kExternalInt8Array, -0x80, 0x7F);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Uint16Array) {
|
||||
TypedArrayTestHelper<uint16_t, v8::Uint16Array, i::ExternalUint16Array>(
|
||||
i::kExternalUint16Array, 0, 0xFFFF);
|
||||
TypedArrayTestHelper<uint16_t, v8::Uint16Array, i::ExternalUint16Array,
|
||||
v8::ArrayBuffer>(i::kExternalUint16Array, 0, 0xFFFF);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Int16Array) {
|
||||
TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array>(
|
||||
i::kExternalInt16Array, -0x8000, 0x7FFF);
|
||||
TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array,
|
||||
v8::ArrayBuffer>(i::kExternalInt16Array, -0x8000,
|
||||
0x7FFF);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Uint32Array) {
|
||||
TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array>(
|
||||
i::kExternalUint32Array, 0, UINT_MAX);
|
||||
TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array,
|
||||
v8::ArrayBuffer>(i::kExternalUint32Array, 0, UINT_MAX);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Int32Array) {
|
||||
TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array>(
|
||||
i::kExternalInt32Array, INT_MIN, INT_MAX);
|
||||
TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array,
|
||||
v8::ArrayBuffer>(i::kExternalInt32Array, INT_MIN,
|
||||
INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Float32Array) {
|
||||
TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array>(
|
||||
i::kExternalFloat32Array, -500, 500);
|
||||
TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array,
|
||||
v8::ArrayBuffer>(i::kExternalFloat32Array, -500, 500);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Float64Array) {
|
||||
TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array>(
|
||||
i::kExternalFloat64Array, -500, 500);
|
||||
TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array,
|
||||
v8::ArrayBuffer>(i::kExternalFloat64Array, -500, 500);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(Uint8ClampedArray) {
|
||||
TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray,
|
||||
i::ExternalUint8ClampedArray>(
|
||||
i::ExternalUint8ClampedArray, v8::ArrayBuffer>(
|
||||
i::kExternalUint8ClampedArray, 0, 0xFF);
|
||||
}
|
||||
|
||||
@ -14159,6 +14162,97 @@ THREADED_TEST(DataView) {
|
||||
|
||||
Local<v8::ArrayBuffer> ab =
|
||||
v8::ArrayBuffer::New(isolate, backing_store.start(), 2 + kSize);
|
||||
Local<v8::DataView> dv = v8::DataView::New(ab, 2, kSize);
|
||||
CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
|
||||
CHECK_EQ(2u, dv->ByteOffset());
|
||||
CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
|
||||
CHECK(ab->Equals(dv->Buffer()));
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedUint8Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUint8Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalUint8Array, 0, 0xFF);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedInt8Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<int8_t, v8::Int8Array, i::ExternalInt8Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalInt8Array, -0x80,
|
||||
0x7F);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedUint16Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<uint16_t, v8::Uint16Array, i::ExternalUint16Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalUint16Array, 0,
|
||||
0xFFFF);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedInt16Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<int16_t, v8::Int16Array, i::ExternalInt16Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalInt16Array, -0x8000,
|
||||
0x7FFF);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedUint32Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<uint32_t, v8::Uint32Array, i::ExternalUint32Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalUint32Array, 0,
|
||||
UINT_MAX);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedInt32Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<int32_t, v8::Int32Array, i::ExternalInt32Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalInt32Array, INT_MIN,
|
||||
INT_MAX);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedFloat32Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<float, v8::Float32Array, i::ExternalFloat32Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalFloat32Array, -500,
|
||||
500);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedFloat64Array) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<double, v8::Float64Array, i::ExternalFloat64Array,
|
||||
v8::SharedArrayBuffer>(i::kExternalFloat64Array, -500,
|
||||
500);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedUint8ClampedArray) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray,
|
||||
i::ExternalUint8ClampedArray, v8::SharedArrayBuffer>(
|
||||
i::kExternalUint8ClampedArray, 0, 0xFF);
|
||||
}
|
||||
|
||||
|
||||
THREADED_TEST(SharedDataView) {
|
||||
i::FLAG_harmony_sharedarraybuffer = true;
|
||||
const int kSize = 50;
|
||||
|
||||
i::ScopedVector<uint8_t> backing_store(kSize + 2);
|
||||
|
||||
LocalContext env;
|
||||
v8::Isolate* isolate = env->GetIsolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
Local<v8::SharedArrayBuffer> ab =
|
||||
v8::SharedArrayBuffer::New(isolate, backing_store.start(), 2 + kSize);
|
||||
Local<v8::DataView> dv =
|
||||
v8::DataView::New(ab, 2, kSize);
|
||||
CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
|
||||
|
Loading…
Reference in New Issue
Block a user