Commit 406f5577 authored by jkummerow's avatar jkummerow Committed by Commit bot

API: Let v8::Object::DefineOwnProperty use new C++ implementation

Now that we have a C++ implementation, calling into JS builtins is needlessly inefficient.

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

Cr-Commit-Position: refs/heads/master@{#31637}
parent 720c531a
......@@ -43,6 +43,7 @@
#include "src/profiler/profile-generator-inl.h"
#include "src/profiler/sampler.h"
#include "src/property.h"
#include "src/property-descriptor.h"
#include "src/property-details.h"
#include "src/prototype.h"
#include "src/runtime/runtime.h"
......@@ -3532,9 +3533,9 @@ Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
v8::PropertyAttribute attributes) {
PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()",
bool);
auto self = Utils::OpenHandle(this);
auto key_obj = Utils::OpenHandle(*key);
auto value_obj = Utils::OpenHandle(*value);
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Name> key_obj = Utils::OpenHandle(*key);
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
if (self->IsAccessCheckNeeded() &&
!isolate->MayAccess(handle(isolate->context()), self)) {
......@@ -3542,21 +3543,16 @@ Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
return Nothing<bool>();
}
i::Handle<i::FixedArray> desc = isolate->factory()->NewFixedArray(3);
desc->set(0, isolate->heap()->ToBoolean(!(attributes & v8::ReadOnly)));
desc->set(1, isolate->heap()->ToBoolean(!(attributes & v8::DontEnum)));
desc->set(2, isolate->heap()->ToBoolean(!(attributes & v8::DontDelete)));
i::Handle<i::JSArray> desc_array =
isolate->factory()->NewJSArrayWithElements(desc, i::FAST_ELEMENTS, 3);
i::Handle<i::Object> args[] = {self, key_obj, value_obj, desc_array};
i::Handle<i::Object> undefined = isolate->factory()->undefined_value();
i::Handle<i::JSFunction> fun = isolate->object_define_own_property();
i::Handle<i::Object> result;
has_pending_exception =
!i::Execution::Call(isolate, fun, undefined, arraysize(args), args)
.ToHandle(&result);
i::PropertyDescriptor desc;
desc.set_writable(!(attributes & v8::ReadOnly));
desc.set_enumerable(!(attributes & v8::DontEnum));
desc.set_configurable(!(attributes & v8::DontDelete));
desc.set_value(value_obj);
bool success = i::JSReceiver::DefineOwnProperty(isolate, self, key_obj, &desc,
i::Object::DONT_THROW);
// Even though we said DONT_THROW, there might be accessors that do throw.
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(result->BooleanValue());
return Just(success);
}
......
......@@ -133,7 +133,6 @@ enum BindingFlags {
no_side_effect_to_string_fun) \
V(OBJECT_VALUE_OF, JSFunction, object_value_of) \
V(OBJECT_TO_STRING, JSFunction, object_to_string) \
V(OBJECT_DEFINE_OWN_PROPERTY_INDEX, JSFunction, object_define_own_property) \
V(OBJECT_GET_OWN_PROPERTY_DESCROPTOR_INDEX, JSFunction, \
object_get_own_property_descriptor) \
V(OBSERVERS_BEGIN_SPLICE_INDEX, JSFunction, observers_begin_perform_splice) \
......
......@@ -866,17 +866,6 @@ function DefineOwnProperty(obj, p, desc, should_throw) {
}
function DefineOwnPropertyFromAPI(obj, p, value, desc) {
return DefineOwnProperty(obj, p, ToPropertyDescriptor({
value: value,
writable: desc[0],
enumerable: desc[1],
configurable: desc[2]
}),
false);
}
// ES6 section 19.1.2.9
function ObjectGetPrototypeOf(obj) {
return %_GetPrototype(TO_OBJECT(obj));
......@@ -1860,7 +1849,6 @@ utils.Export(function(to) {
"global_eval_fun", GlobalEval,
"object_value_of", ObjectValueOf,
"object_to_string", ObjectToString,
"object_define_own_property", DefineOwnPropertyFromAPI,
"object_get_own_property_descriptor", ObjectGetOwnPropertyDescriptor,
"to_complete_property_descriptor", ToCompletePropertyDescriptor,
]);
......
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