Commit bf027fe7 authored by bmeurer's avatar bmeurer Committed by Commit bot

[runtime] Migrate Object.getOwnPropertyNames to C++.

The Object.getOwnPropertyNames method always calls into C++ anyway,
so there's no point in having the JavaScript wrapper around at all.

Drive-by-fix: Inline GetOwnEnumerablePropertyNames into its single
call site.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33380}
parent 3fdd37b0
......@@ -1100,6 +1100,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
native_context()->set_object_freeze(*object_freeze);
SimpleInstallFunction(object_function, "getOwnPropertyDescriptor",
Builtins::kObjectGetOwnPropertyDescriptor, 2, false);
SimpleInstallFunction(object_function, "getOwnPropertyNames",
Builtins::kObjectGetOwnPropertyNames, 1, false);
SimpleInstallFunction(object_function, "getOwnPropertySymbols",
Builtins::kObjectGetOwnPropertySymbols, 1, false);
Handle<JSFunction> object_is_extensible =
......
......@@ -1590,8 +1590,11 @@ BUILTIN(ObjectGetOwnPropertyDescriptor) {
}
// ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O )
BUILTIN(ObjectGetOwnPropertySymbols) {
namespace {
Object* GetOwnPropertyKeys(Isolate* isolate,
BuiltinArguments<BuiltinExtraArguments::kNone> args,
PropertyFilter filter) {
HandleScope scope(isolate);
Handle<Object> object = args.atOrUndefined(isolate, 1);
Handle<JSReceiver> receiver;
......@@ -1599,11 +1602,25 @@ BUILTIN(ObjectGetOwnPropertySymbols) {
Object::ToObject(isolate, object));
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys, JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY,
SKIP_STRINGS, CONVERT_TO_STRING));
isolate, keys, JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, filter,
CONVERT_TO_STRING));
return *isolate->factory()->NewJSArrayWithElements(keys);
}
} // namespace
// ES6 section 19.1.2.7 Object.getOwnPropertyNames ( O )
BUILTIN(ObjectGetOwnPropertyNames) {
return GetOwnPropertyKeys(isolate, args, SKIP_SYMBOLS);
}
// ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O )
BUILTIN(ObjectGetOwnPropertySymbols) {
return GetOwnPropertyKeys(isolate, args, SKIP_STRINGS);
}
// ES6 section 19.1.2.11 Object.isExtensible ( O )
BUILTIN(ObjectIsExtensible) {
......
......@@ -111,6 +111,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(ObjectCreate, kNone) \
V(ObjectFreeze, kNone) \
V(ObjectGetOwnPropertyDescriptor, kNone) \
V(ObjectGetOwnPropertyNames, kNone) \
V(ObjectGetOwnPropertySymbols, kNone) \
V(ObjectIsExtensible, kNone) \
V(ObjectIsFrozen, kNone) \
......
......@@ -772,13 +772,6 @@ function ObjectSetPrototypeOf(obj, proto) {
}
// ES5 section 15.2.3.4.
function ObjectGetOwnPropertyNames(obj) {
obj = TO_OBJECT(obj);
return %GetOwnPropertyKeys(obj, PROPERTY_FILTER_SKIP_SYMBOLS);
}
// ES5 section 15.2.3.6.
function ObjectDefineProperty(obj, p, attributes) {
// The new pure-C++ implementation doesn't support O.o.
......@@ -796,11 +789,6 @@ function ObjectDefineProperty(obj, p, attributes) {
}
function GetOwnEnumerablePropertyNames(object) {
return %GetOwnPropertyKeys(object, PROPERTY_FILTER_ONLY_ENUMERABLE);
}
// ES5 section 15.2.3.7.
function ObjectDefineProperties(obj, properties) {
// The new pure-C++ implementation doesn't support O.o.
......@@ -810,7 +798,7 @@ function ObjectDefineProperties(obj, properties) {
throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties");
}
var props = TO_OBJECT(properties);
var names = GetOwnEnumerablePropertyNames(props);
var names = %GetOwnPropertyKeys(props, PROPERTY_FILTER_ONLY_ENUMERABLE);
var descriptors = new InternalArray();
for (var i = 0; i < names.length; i++) {
descriptors.push(ToPropertyDescriptor(props[names[i]]));
......@@ -883,7 +871,6 @@ utils.InstallFunctions(GlobalObject, DONT_ENUM, [
"defineProperties", ObjectDefineProperties,
"getPrototypeOf", ObjectGetPrototypeOf,
"setPrototypeOf", ObjectSetPrototypeOf,
"getOwnPropertyNames", ObjectGetOwnPropertyNames,
// getOwnPropertySymbols is added in symbol.js.
"is", SameValue, // ECMA-262, Edition 6, section 19.1.2.10
// deliverChangeRecords, getNotifier, observe and unobserve are added
......
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