Skip to content

Commit

Permalink
[builtins] Migrate SharedArrayBuffer.byteLength to C++.
Browse files Browse the repository at this point in the history
Drive-by-fix: hydrogen code does not blindly return the
byteLength offset, instead it executes what is defined
in the byteLength getter.

BUG=

Review-Url: https://codereview.chromium.org/2123263002
Cr-Commit-Position: refs/heads/master@{#37595}
  • Loading branch information
fhinkel authored and Commit bot committed Jul 7, 2016
1 parent 0058f82 commit 2f36ee7
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 186 deletions.
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ action("js2c_experimental") {
"src/messages.h",
"src/js/harmony-async-await.js",
"src/js/harmony-atomics.js",
"src/js/harmony-sharedarraybuffer.js",
"src/js/harmony-simd.js",
"src/js/harmony-string-padding.js",
"src/js/promise-extra.js",
Expand Down
3 changes: 0 additions & 3 deletions src/accessors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ bool Accessors::IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name,
return
CheckForName(name, isolate->factory()->length_string(),
JSArray::kLengthOffset, object_offset);
case JS_ARRAY_BUFFER_TYPE:
return CheckForName(name, isolate->factory()->byte_length_string(),
JSArrayBuffer::kByteLengthOffset, object_offset);
default:
if (map->instance_type() < FIRST_NONSTRING_TYPE) {
return CheckForName(name, isolate->factory()->length_string(),
Expand Down
23 changes: 14 additions & 9 deletions src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class Genesis BASE_EMBEDDED {
#undef DECLARE_FEATURE_INITIALIZATION

Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
const char* name);
const char* name, Builtins::Name call,
BuiltinFunctionId id);
Handle<JSFunction> InstallInternalArray(Handle<JSObject> target,
const char* name,
ElementsKind elements_kind);
Expand Down Expand Up @@ -1815,8 +1816,9 @@ 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");
Handle<JSFunction> array_buffer_fun = InstallArrayBuffer(
global, "ArrayBuffer", Builtins::kArrayBufferPrototypeGetByteLength,
BuiltinFunctionId::kArrayBufferByteLength);
InstallWithIntrinsicDefaultProto(isolate, array_buffer_fun,
Context::ARRAY_BUFFER_FUN_INDEX);
}
Expand Down Expand Up @@ -2799,7 +2801,9 @@ void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
Factory* factory = isolate->factory();

Handle<JSFunction> shared_array_buffer_fun =
InstallArrayBuffer(global, "SharedArrayBuffer");
InstallArrayBuffer(global, "SharedArrayBuffer",
Builtins::kSharedArrayBufferPrototypeGetByteLength,
BuiltinFunctionId::kSharedArrayBufferByteLength);
native_context()->set_shared_array_buffer_fun(*shared_array_buffer_fun);

Handle<String> name = factory->InternalizeUtf8String("Atomics");
Expand Down Expand Up @@ -2900,7 +2904,9 @@ void Genesis::InitializeGlobal_harmony_array_prototype_values() {
}

Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target,
const char* name) {
const char* name,
Builtins::Name call,
BuiltinFunctionId id) {
// Create the %ArrayBufferPrototype%
// Setup the {prototype} with the given {name} for @@toStringTag.
Handle<JSObject> prototype =
Expand All @@ -2927,9 +2933,8 @@ Handle<JSFunction> Genesis::InstallArrayBuffer(Handle<JSObject> target,
Builtins::kArrayBufferIsView, 1, true);

// Install the "byteLength" getter on the {prototype}.
SimpleInstallGetter(prototype, factory()->byte_length_string(),
Builtins::kArrayBufferPrototypeGetByteLength, false,
kArrayBufferByteLength);
SimpleInstallGetter(prototype, factory()->byte_length_string(), call, false,
id);

return array_buffer_fun;
}
Expand Down Expand Up @@ -3333,7 +3338,7 @@ bool Genesis::InstallExperimentalNatives() {
static const char* harmony_explicit_tailcalls_natives[] = {nullptr};
static const char* harmony_tailcalls_natives[] = {nullptr};
static const char* harmony_sharedarraybuffer_natives[] = {
"native harmony-sharedarraybuffer.js", "native harmony-atomics.js", NULL};
"native harmony-atomics.js", NULL};
static const char* harmony_simd_natives[] = {"native harmony-simd.js",
nullptr};
static const char* harmony_do_expressions_natives[] = {nullptr};
Expand Down
22 changes: 22 additions & 0 deletions src/builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,14 @@ BUILTIN(ArrayBufferPrototypeGetByteLength) {
HandleScope scope(isolate);
CHECK_RECEIVER(JSArrayBuffer, array_buffer,
"get ArrayBuffer.prototype.byteLength");

if (array_buffer->is_shared()) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
isolate->factory()->NewStringFromAsciiChecked(
"get ArrayBuffer.prototype.byteLength"),
args.receiver()));
}
// TODO(franzih): According to the ES6 spec, we should throw a TypeError
// here if the JSArrayBuffer is detached.
return array_buffer->byte_length();
Expand All @@ -5640,6 +5648,20 @@ BUILTIN(ArrayBufferIsView) {
return isolate->heap()->ToBoolean(arg->IsJSArrayBufferView());
}

// 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();
}

// ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case.
BUILTIN(ProxyConstructor) {
Expand Down
Loading

0 comments on commit 2f36ee7

Please sign in to comment.