Commit 7320830d authored by jochen's avatar jochen Committed by Commit bot

Attempt to speed up v8::Object::SetPrivate

By short-cutting the DefineOwnProperty machinery similar to how ForceSet
does it, we should get a few cycles out of this heavily used API.

BUG=chromium:569668
R=verwaest@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1702353002

Cr-Commit-Position: refs/heads/master@{#34102}
parent f0090eee
......@@ -3603,8 +3603,27 @@ bool v8::Object::ForceSet(v8::Local<Value> key, v8::Local<Value> value,
Maybe<bool> v8::Object::SetPrivate(Local<Context> context, Local<Private> key,
Local<Value> value) {
return DefineOwnProperty(context, Local<Name>(reinterpret_cast<Name*>(*key)),
value, DontEnum);
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::SetPrivate()", bool);
auto self = Utils::OpenHandle(this);
auto key_obj = Utils::OpenHandle(reinterpret_cast<Name*>(*key));
auto value_obj = Utils::OpenHandle(*value);
if (self->IsJSProxy()) {
i::PropertyDescriptor desc;
desc.set_writable(true);
desc.set_enumerable(false);
desc.set_configurable(true);
desc.set_value(value_obj);
return i::JSProxy::SetPrivateProperty(
isolate, i::Handle<i::JSProxy>::cast(self),
i::Handle<i::Symbol>::cast(key_obj), &desc, i::Object::DONT_THROW);
}
auto js_object = i::Handle<i::JSObject>::cast(self);
i::LookupIterator it(js_object, key_obj);
has_pending_exception = i::JSObject::DefineOwnPropertyIgnoreAttributes(
&it, value_obj, i::DONT_ENUM)
.is_null();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(true);
}
......
......@@ -7015,7 +7015,7 @@ Maybe<bool> JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy,
ShouldThrow should_throw) {
STACK_CHECK(Nothing<bool>());
if (key->IsSymbol() && Handle<Symbol>::cast(key)->IsPrivate()) {
return AddPrivateProperty(isolate, proxy, Handle<Symbol>::cast(key), desc,
return SetPrivateProperty(isolate, proxy, Handle<Symbol>::cast(key), desc,
should_throw);
}
Handle<String> trap_name = isolate->factory()->defineProperty_string();
......@@ -7121,7 +7121,7 @@ Maybe<bool> JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> proxy,
// static
Maybe<bool> JSProxy::AddPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy,
Maybe<bool> JSProxy::SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy,
Handle<Symbol> private_name,
PropertyDescriptor* desc,
ShouldThrow should_throw) {
......
......@@ -9778,12 +9778,12 @@ class JSProxy: public JSReceiver {
static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
private:
static Maybe<bool> AddPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy,
static Maybe<bool> SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy,
Handle<Symbol> private_name,
PropertyDescriptor* desc,
ShouldThrow should_throw);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
};
......
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