Commit 3fdd37b0 authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Migrate Object.getOwnPropertyDescriptor to C++.

The implementation of Object.getOwnPropertyDescriptor always called into
C++ anyway, so there's no need to have this JavaScript wrapper around at
all.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33379}
parent 8e918ea2
...@@ -1098,6 +1098,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1098,6 +1098,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> object_freeze = SimpleInstallFunction( Handle<JSFunction> object_freeze = SimpleInstallFunction(
object_function, "freeze", Builtins::kObjectFreeze, 1, false); object_function, "freeze", Builtins::kObjectFreeze, 1, false);
native_context()->set_object_freeze(*object_freeze); native_context()->set_object_freeze(*object_freeze);
SimpleInstallFunction(object_function, "getOwnPropertyDescriptor",
Builtins::kObjectGetOwnPropertyDescriptor, 2, false);
SimpleInstallFunction(object_function, "getOwnPropertySymbols", SimpleInstallFunction(object_function, "getOwnPropertySymbols",
Builtins::kObjectGetOwnPropertySymbols, 1, false); Builtins::kObjectGetOwnPropertySymbols, 1, false);
Handle<JSFunction> object_is_extensible = Handle<JSFunction> object_is_extensible =
......
...@@ -1566,6 +1566,30 @@ BUILTIN(ObjectFreeze) { ...@@ -1566,6 +1566,30 @@ BUILTIN(ObjectFreeze) {
} }
// ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P )
BUILTIN(ObjectGetOwnPropertyDescriptor) {
HandleScope scope(isolate);
// 1. Let obj be ? ToObject(O).
Handle<Object> object = args.atOrUndefined(isolate, 1);
Handle<JSReceiver> receiver;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
Object::ToObject(isolate, object));
// 2. Let key be ? ToPropertyKey(P).
Handle<Object> property = args.atOrUndefined(isolate, 2);
Handle<Name> key;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
Object::ToName(isolate, property));
// 3. Let desc be ? obj.[[GetOwnProperty]](key).
PropertyDescriptor desc;
Maybe<bool> found =
JSReceiver::GetOwnPropertyDescriptor(isolate, receiver, key, &desc);
MAYBE_RETURN(found, isolate->heap()->exception());
// 4. Return FromPropertyDescriptor(desc).
if (!found.FromJust()) return isolate->heap()->undefined_value();
return *desc.ToObject(isolate);
}
// ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O ) // ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O )
BUILTIN(ObjectGetOwnPropertySymbols) { BUILTIN(ObjectGetOwnPropertySymbols) {
HandleScope scope(isolate); HandleScope scope(isolate);
......
...@@ -110,6 +110,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) { ...@@ -110,6 +110,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(ObjectAssign, kNone) \ V(ObjectAssign, kNone) \
V(ObjectCreate, kNone) \ V(ObjectCreate, kNone) \
V(ObjectFreeze, kNone) \ V(ObjectFreeze, kNone) \
V(ObjectGetOwnPropertyDescriptor, kNone) \
V(ObjectGetOwnPropertySymbols, kNone) \ V(ObjectGetOwnPropertySymbols, kNone) \
V(ObjectIsExtensible, kNone) \ V(ObjectIsExtensible, kNone) \
V(ObjectIsFrozen, kNone) \ V(ObjectIsFrozen, kNone) \
......
...@@ -772,12 +772,6 @@ function ObjectSetPrototypeOf(obj, proto) { ...@@ -772,12 +772,6 @@ function ObjectSetPrototypeOf(obj, proto) {
} }
// ES6 section 19.1.2.6
function ObjectGetOwnPropertyDescriptor(obj, p) {
return %GetOwnProperty(obj, p);
}
// ES5 section 15.2.3.4. // ES5 section 15.2.3.4.
function ObjectGetOwnPropertyNames(obj) { function ObjectGetOwnPropertyNames(obj) {
obj = TO_OBJECT(obj); obj = TO_OBJECT(obj);
...@@ -889,7 +883,6 @@ utils.InstallFunctions(GlobalObject, DONT_ENUM, [ ...@@ -889,7 +883,6 @@ utils.InstallFunctions(GlobalObject, DONT_ENUM, [
"defineProperties", ObjectDefineProperties, "defineProperties", ObjectDefineProperties,
"getPrototypeOf", ObjectGetPrototypeOf, "getPrototypeOf", ObjectGetPrototypeOf,
"setPrototypeOf", ObjectSetPrototypeOf, "setPrototypeOf", ObjectSetPrototypeOf,
"getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
"getOwnPropertyNames", ObjectGetOwnPropertyNames, "getOwnPropertyNames", ObjectGetOwnPropertyNames,
// getOwnPropertySymbols is added in symbol.js. // getOwnPropertySymbols is added in symbol.js.
"is", SameValue, // ECMA-262, Edition 6, section 19.1.2.10 "is", SameValue, // ECMA-262, Edition 6, section 19.1.2.10
......
...@@ -266,31 +266,6 @@ RUNTIME_FUNCTION(Runtime_GetOwnProperty_Legacy) { ...@@ -266,31 +266,6 @@ RUNTIME_FUNCTION(Runtime_GetOwnProperty_Legacy) {
} }
// ES6 19.1.2.6
RUNTIME_FUNCTION(Runtime_GetOwnProperty) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, raw_name, 1);
// 1. Let obj be ? ToObject(O).
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, object,
Object::ToObject(isolate, object));
// 2. Let key be ? ToPropertyKey(P).
Handle<Name> key;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
Object::ToName(isolate, raw_name));
// 3. Let desc be ? obj.[[GetOwnProperty]](key).
PropertyDescriptor desc;
Maybe<bool> found = JSReceiver::GetOwnPropertyDescriptor(
isolate, Handle<JSReceiver>::cast(object), key, &desc);
MAYBE_RETURN(found, isolate->heap()->exception());
// 4. Return FromPropertyDescriptor(desc).
if (!found.FromJust()) return isolate->heap()->undefined_value();
return *desc.ToObject(isolate);
}
RUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) { RUNTIME_FUNCTION(Runtime_OptimizeObjectForAddingMultipleProperties) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 2); DCHECK(args.length() == 2);
......
...@@ -414,7 +414,6 @@ namespace internal { ...@@ -414,7 +414,6 @@ namespace internal {
F(GetPrototype, 1, 1) \ F(GetPrototype, 1, 1) \
F(InternalSetPrototype, 2, 1) \ F(InternalSetPrototype, 2, 1) \
F(SetPrototype, 2, 1) \ F(SetPrototype, 2, 1) \
F(GetOwnProperty, 2, 1) \
F(GetOwnProperty_Legacy, 2, 1) \ F(GetOwnProperty_Legacy, 2, 1) \
F(OptimizeObjectForAddingMultipleProperties, 2, 1) \ F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
F(GetProperty, 2, 1) \ F(GetProperty, 2, 1) \
......
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