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 {
void InitializeGlobal_experimental_fast_array_builtins();
Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
const char* name, Builtins::Name call,
BuiltinFunctionId id, bool is_shared);
const char* name,
Builtins::Name call_byteLength,
BuiltinFunctionId byteLength_id,
Builtins::Name call_slice);
Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
const char* name,
ElementsKind elements_kind);
......@@ -2562,7 +2564,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // -- A r r a y B u f f e r
Handle<JSFunction> array_buffer_fun = InstallArrayBuffer(
global, "ArrayBuffer", Builtins::kArrayBufferPrototypeGetByteLength,
BuiltinFunctionId::kArrayBufferByteLength, false);
BuiltinFunctionId::kArrayBufferByteLength,
Builtins::kArrayBufferPrototypeSlice);
InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun,
Context::ARRAY_BUFFER_FUN_INDEX);
InstallSpeciesGetter(array_buffer_fun);
......@@ -3723,7 +3726,8 @@ void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
Handle<JSFunction> shared_array_buffer_fun =
InstallArrayBuffer(global, "SharedArrayBuffer",
Builtins::kSharedArrayBufferPrototypeGetByteLength,
BuiltinFunctionId::kSharedArrayBufferByteLength, true);
BuiltinFunctionId::kSharedArrayBufferByteLength,
Builtins::kSharedArrayBufferPrototypeSlice);
native_context()->set_shared_array_buffer_fun(*shared_array_buffer_fun);
Handle<String> name = factory->InternalizeUtf8String("Atomics");
......@@ -3927,9 +3931,9 @@ void Genesis::InitializeGlobal_icu_case_mapping() {
Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target,
const char* name,
Builtins::Name call,
BuiltinFunctionId id,
bool is_shared) {
Builtins::Name call_byteLength,
BuiltinFunctionId byteLength_id,
Builtins::Name call_slice) {
// Create the %ArrayBufferPrototype%
// Setup the {prototype} with the given {name} for @@toStringTag.
Handle<JSObject> prototype =
......@@ -3956,14 +3960,10 @@ Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target,
Builtins::kArrayBufferIsView, 1, true);
// Install the "byteLength" getter on the {prototype}.
SimpleInstallGetter(prototype, factory()->byte_length_string(), call, false,
id);
SimpleInstallGetter(prototype, factory()->byte_length_string(),
call_byteLength, false, byteLength_id);
// TODO(binji): support SharedArrayBuffer.prototype.slice as well.
if (!is_shared) {
SimpleInstallFunction(prototype, "slice",
Builtins::kArrayBufferPrototypeSlice, 2, true);
}
SimpleInstallFunction(prototype, "slice", call_slice, 2, true);
return array_buffer_fun;
}
......
This diff is collapsed.
......@@ -18,20 +18,8 @@
namespace v8 {
namespace internal {
// ES7 sharedmem 6.3.4.1 get SharedArrayBuffer.prototype.byteLength
BUILTIN(SharedArrayBufferPrototypeGetByteLength) {
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();
}
// See builtins-arraybuffer.cc for implementations of
// SharedArrayBuffer.prototye.byteLength and SharedArrayBuffer.prototype.slice
inline bool AtomicIsLockFree(uint32_t size) {
return size == 1 || size == 2 || size == 4;
......
......@@ -792,6 +792,7 @@ class Isolate;
\
/* SharedArrayBuffer */ \
CPP(SharedArrayBufferPrototypeGetByteLength) \
CPP(SharedArrayBufferPrototypeSlice) \
TFJ(AtomicsLoad, 2, kArray, kIndex) \
TFJ(AtomicsStore, 3, kArray, kIndex, kValue) \
TFJ(AtomicsExchange, 3, kArray, kIndex, kValue) \
......
......@@ -465,6 +465,11 @@ class ErrorUtils : public AllStatic {
"'caller' and 'arguments' are restricted function properties and cannot " \
"be accessed in this context.") \
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(StrictCannotAssign, "Cannot assign to read only '%' in strict mode") \
T(StrictDeleteProperty, "Cannot delete property '%' of %") \
......
......@@ -70,13 +70,6 @@ function TestByteLengthNotWritable() {
TestByteLengthNotWritable();
function TestArrayBufferNoSlice() {
var sab = new SharedArrayBuffer(10);
assertEquals(undefined, sab.slice);
}
TestArrayBufferNoSlice();
// Typed arrays using SharedArrayBuffers
// TODO(binji): how many of these tests are necessary if there are no new
......
......@@ -515,9 +515,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=5984
'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
'intl402/NumberFormat/prototype/format/11.3.2_TRF': [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