Commit fb52f5c5 authored by binji's avatar binji Committed by Commit bot

[SAB] Implement SharedArrayBuffer.prototype.slice

BUG=v8:5897

Review-Url: https://codereview.chromium.org/2741413006
Cr-Commit-Position: refs/heads/master@{#44075}
parent d71ef941
...@@ -221,8 +221,10 @@ class Genesis BASE_EMBEDDED { ...@@ -221,8 +221,10 @@ class Genesis BASE_EMBEDDED {
void InitializeGlobal_experimental_fast_array_builtins(); void InitializeGlobal_experimental_fast_array_builtins();
Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target, Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
const char* name, Builtins::Name call, const char* name,
BuiltinFunctionId id, bool is_shared); Builtins::Name call_byteLength,
BuiltinFunctionId byteLength_id,
Builtins::Name call_slice);
Handle<JSFunction> InstallInternalArray(Handle<JSObject> target, Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
const char* name, const char* name,
ElementsKind elements_kind); ElementsKind elements_kind);
...@@ -2562,7 +2564,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2562,7 +2564,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- A r r a y B u f f e r { // -- A r r a y B u f f e r
Handle<JSFunction> array_buffer_fun = InstallArrayBuffer( Handle<JSFunction> array_buffer_fun = InstallArrayBuffer(
global, "ArrayBuffer", Builtins::kArrayBufferPrototypeGetByteLength, global, "ArrayBuffer", Builtins::kArrayBufferPrototypeGetByteLength,
BuiltinFunctionId::kArrayBufferByteLength, false); BuiltinFunctionId::kArrayBufferByteLength,
Builtins::kArrayBufferPrototypeSlice);
InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun, InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun,
Context::ARRAY_BUFFER_FUN_INDEX); Context::ARRAY_BUFFER_FUN_INDEX);
InstallSpeciesGetter(array_buffer_fun); InstallSpeciesGetter(array_buffer_fun);
...@@ -3723,7 +3726,8 @@ void Genesis::InitializeGlobal_harmony_sharedarraybuffer() { ...@@ -3723,7 +3726,8 @@ void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
Handle<JSFunction> shared_array_buffer_fun = Handle<JSFunction> shared_array_buffer_fun =
InstallArrayBuffer(global, "SharedArrayBuffer", InstallArrayBuffer(global, "SharedArrayBuffer",
Builtins::kSharedArrayBufferPrototypeGetByteLength, Builtins::kSharedArrayBufferPrototypeGetByteLength,
BuiltinFunctionId::kSharedArrayBufferByteLength, true); BuiltinFunctionId::kSharedArrayBufferByteLength,
Builtins::kSharedArrayBufferPrototypeSlice);
native_context()->set_shared_array_buffer_fun(*shared_array_buffer_fun); native_context()->set_shared_array_buffer_fun(*shared_array_buffer_fun);
Handle<String> name = factory->InternalizeUtf8String("Atomics"); Handle<String> name = factory->InternalizeUtf8String("Atomics");
...@@ -3927,9 +3931,9 @@ void Genesis::InitializeGlobal_icu_case_mapping() { ...@@ -3927,9 +3931,9 @@ void Genesis::InitializeGlobal_icu_case_mapping() {
Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target, Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target,
const char* name, const char* name,
Builtins::Name call, Builtins::Name call_byteLength,
BuiltinFunctionId id, BuiltinFunctionId byteLength_id,
bool is_shared) { Builtins::Name call_slice) {
// Create the %ArrayBufferPrototype% // Create the %ArrayBufferPrototype%
// Setup the {prototype} with the given {name} for @@toStringTag. // Setup the {prototype} with the given {name} for @@toStringTag.
Handle<JSObject> prototype = Handle<JSObject> prototype =
...@@ -3956,14 +3960,10 @@ Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target, ...@@ -3956,14 +3960,10 @@ Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target,
Builtins::kArrayBufferIsView, 1, true); Builtins::kArrayBufferIsView, 1, true);
// Install the "byteLength" getter on the {prototype}. // Install the "byteLength" getter on the {prototype}.
SimpleInstallGetter(prototype, factory()->byte_length_string(), call, false, SimpleInstallGetter(prototype, factory()->byte_length_string(),
id); call_byteLength, false, byteLength_id);
// TODO(binji): support SharedArrayBuffer.prototype.slice as well. SimpleInstallFunction(prototype, "slice", call_slice, 2, true);
if (!is_shared) {
SimpleInstallFunction(prototype, "slice",
Builtins::kArrayBufferPrototypeSlice, 2, true);
}
return array_buffer_fun; return array_buffer_fun;
} }
......
This diff is collapsed.
...@@ -18,20 +18,8 @@ ...@@ -18,20 +18,8 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// ES7 sharedmem 6.3.4.1 get SharedArrayBuffer.prototype.byteLength // See builtins-arraybuffer.cc for implementations of
BUILTIN(SharedArrayBufferPrototypeGetByteLength) { // SharedArrayBuffer.prototye.byteLength and SharedArrayBuffer.prototype.slice
HandleScope scope(isolate);
CHECK_RECEIVER(JSArrayBuffer, array_buffer,
"get SharedArrayBuffer.prototype.byteLength");
if (!array_buffer->is_shared()) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
isolate->factory()->NewStringFromAsciiChecked(
"get SharedArrayBuffer.prototype.byteLength"),
args.receiver()));
}
return array_buffer->byte_length();
}
inline bool AtomicIsLockFree(uint32_t size) { inline bool AtomicIsLockFree(uint32_t size) {
return size == 1 || size == 2 || size == 4; return size == 1 || size == 2 || size == 4;
......
...@@ -792,6 +792,7 @@ class Isolate; ...@@ -792,6 +792,7 @@ class Isolate;
\ \
/* SharedArrayBuffer */ \ /* SharedArrayBuffer */ \
CPP(SharedArrayBufferPrototypeGetByteLength) \ CPP(SharedArrayBufferPrototypeGetByteLength) \
CPP(SharedArrayBufferPrototypeSlice) \
TFJ(AtomicsLoad, 2, kArray, kIndex) \ TFJ(AtomicsLoad, 2, kArray, kIndex) \
TFJ(AtomicsStore, 3, kArray, kIndex, kValue) \ TFJ(AtomicsStore, 3, kArray, kIndex, kValue) \
TFJ(AtomicsExchange, 3, kArray, kIndex, kValue) \ TFJ(AtomicsExchange, 3, kArray, kIndex, kValue) \
......
...@@ -465,6 +465,11 @@ class ErrorUtils : public AllStatic { ...@@ -465,6 +465,11 @@ class ErrorUtils : public AllStatic {
"'caller' and 'arguments' are restricted function properties and cannot " \ "'caller' and 'arguments' are restricted function properties and cannot " \
"be accessed in this context.") \ "be accessed in this context.") \
T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \ T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \
T(SharedArrayBufferTooShort, \
"Derived SharedArrayBuffer constructor created a buffer which was too " \
"small") \
T(SharedArrayBufferSpeciesThis, \
"SharedArrayBuffer subclass returned this from species constructor") \
T(StaticPrototype, "Classes may not have static property named prototype") \ T(StaticPrototype, "Classes may not have static property named prototype") \
T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode") \ T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode") \
T(StrictDeleteProperty, "Cannot delete property '%' of %") \ T(StrictDeleteProperty, "Cannot delete property '%' of %") \
......
...@@ -70,13 +70,6 @@ function TestByteLengthNotWritable() { ...@@ -70,13 +70,6 @@ function TestByteLengthNotWritable() {
TestByteLengthNotWritable(); TestByteLengthNotWritable();
function TestArrayBufferNoSlice() {
var sab = new SharedArrayBuffer(10);
assertEquals(undefined, sab.slice);
}
TestArrayBufferNoSlice();
// Typed arrays using SharedArrayBuffers // Typed arrays using SharedArrayBuffers
// TODO(binji): how many of these tests are necessary if there are no new // TODO(binji): how many of these tests are necessary if there are no new
......
...@@ -515,9 +515,6 @@ ...@@ -515,9 +515,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=5984 # https://bugs.chromium.org/p/v8/issues/detail?id=5984
'built-ins/SharedArrayBuffer/proto-from-ctor-realm': [FAIL], 'built-ins/SharedArrayBuffer/proto-from-ctor-realm': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=5897
'built-ins/SharedArrayBuffer/prototype/slice/*': [SKIP],
# https://bugs.chromium.org/p/v8/issues/detail?id=6045 # https://bugs.chromium.org/p/v8/issues/detail?id=6045
'intl402/NumberFormat/prototype/format/11.3.2_TRF': [FAIL], 'intl402/NumberFormat/prototype/format/11.3.2_TRF': [FAIL],
'intl402/NumberFormat/prototype/format/11.3.2_TRP': [FAIL], 'intl402/NumberFormat/prototype/format/11.3.2_TRP': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment