Commit 50e1e751 authored by bmeurer's avatar bmeurer Committed by Commit bot

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

Everything necessary to implement Object.keys efficiently is already
available in C++ land for quite some time now, and only the thin
JavaScript wrapper was left, so get rid of that as well and move the
whole builtin to C++ instead.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33167}
parent 30cf31ea
...@@ -1105,6 +1105,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -1105,6 +1105,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Handle<JSFunction> object_is_sealed = SimpleInstallFunction( Handle<JSFunction> object_is_sealed = SimpleInstallFunction(
object_function, "isSealed", Builtins::kObjectIsSealed, 1, false); object_function, "isSealed", Builtins::kObjectIsSealed, 1, false);
native_context()->set_object_is_sealed(*object_is_sealed); native_context()->set_object_is_sealed(*object_is_sealed);
Handle<JSFunction> object_keys = SimpleInstallFunction(
object_function, "keys", Builtins::kObjectKeys, 1, false);
native_context()->set_object_keys(*object_keys);
SimpleInstallFunction(object_function, "preventExtensions", SimpleInstallFunction(object_function, "preventExtensions",
Builtins::kObjectPreventExtensions, 1, false); Builtins::kObjectPreventExtensions, 1, false);
SimpleInstallFunction(object_function, "seal", Builtins::kObjectSeal, 1, SimpleInstallFunction(object_function, "seal", Builtins::kObjectSeal, 1,
......
...@@ -1602,6 +1602,22 @@ BUILTIN(ObjectIsSealed) { ...@@ -1602,6 +1602,22 @@ BUILTIN(ObjectIsSealed) {
} }
// ES6 section 19.1.2.14 Object.keys ( O )
BUILTIN(ObjectKeys) {
HandleScope scope(isolate);
Handle<Object> object = args.atOrUndefined(isolate, 1);
Handle<JSReceiver> receiver;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
Execution::ToObject(isolate, object));
Handle<FixedArray> keys;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, keys,
JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS,
CONVERT_TO_STRING));
return *isolate->factory()->NewJSArrayWithElements(keys);
}
// ES6 section 19.1.2.15 Object.preventExtensions ( O ) // ES6 section 19.1.2.15 Object.preventExtensions ( O )
BUILTIN(ObjectPreventExtensions) { BUILTIN(ObjectPreventExtensions) {
HandleScope scope(isolate); HandleScope scope(isolate);
......
...@@ -92,6 +92,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) { ...@@ -92,6 +92,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(ObjectIsExtensible, kNone) \ V(ObjectIsExtensible, kNone) \
V(ObjectIsFrozen, kNone) \ V(ObjectIsFrozen, kNone) \
V(ObjectIsSealed, kNone) \ V(ObjectIsSealed, kNone) \
V(ObjectKeys, kNone) \
V(ObjectPreventExtensions, kNone) \ V(ObjectPreventExtensions, kNone) \
V(ObjectSeal, kNone) \ V(ObjectSeal, kNone) \
V(ObjectProtoToString, kNone) \ V(ObjectProtoToString, kNone) \
......
...@@ -87,6 +87,7 @@ enum BindingFlags { ...@@ -87,6 +87,7 @@ enum BindingFlags {
V(OBJECT_IS_EXTENSIBLE, JSFunction, object_is_extensible) \ V(OBJECT_IS_EXTENSIBLE, JSFunction, object_is_extensible) \
V(OBJECT_IS_FROZEN, JSFunction, object_is_frozen) \ V(OBJECT_IS_FROZEN, JSFunction, object_is_frozen) \
V(OBJECT_IS_SEALED, JSFunction, object_is_sealed) \ V(OBJECT_IS_SEALED, JSFunction, object_is_sealed) \
V(OBJECT_KEYS, JSFunction, object_keys) \
V(REFLECT_APPLY_INDEX, JSFunction, reflect_apply) \ V(REFLECT_APPLY_INDEX, JSFunction, reflect_apply) \
V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \ V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \
V(REFLECT_DEFINE_PROPERTY_INDEX, JSFunction, reflect_define_property) \ V(REFLECT_DEFINE_PROPERTY_INDEX, JSFunction, reflect_define_property) \
......
...@@ -421,13 +421,15 @@ void StackGuard::InitThread(const ExecutionAccess& lock) { ...@@ -421,13 +421,15 @@ void StackGuard::InitThread(const ExecutionAccess& lock) {
// --- C a l l s t o n a t i v e s --- // --- C a l l s t o n a t i v e s ---
MaybeHandle<Object> Execution::ToObject(Isolate* isolate, Handle<Object> obj) { MaybeHandle<JSReceiver> Execution::ToObject(Isolate* isolate,
Handle<Object> obj) {
Handle<JSReceiver> receiver; Handle<JSReceiver> receiver;
if (JSReceiver::ToObject(isolate, obj).ToHandle(&receiver)) { if (JSReceiver::ToObject(isolate, obj).ToHandle(&receiver)) {
return receiver; return receiver;
} }
THROW_NEW_ERROR( THROW_NEW_ERROR(isolate,
isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject), Object); NewTypeError(MessageTemplate::kUndefinedOrNullToObject),
JSReceiver);
} }
......
...@@ -50,8 +50,8 @@ class Execution final : public AllStatic { ...@@ -50,8 +50,8 @@ class Execution final : public AllStatic {
MaybeHandle<Object>* exception_out = NULL); MaybeHandle<Object>* exception_out = NULL);
// ECMA-262 9.9 // ECMA-262 9.9
MUST_USE_RESULT static MaybeHandle<Object> ToObject( MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
Isolate* isolate, Handle<Object> obj); Handle<Object> obj);
static Handle<String> GetStackTraceLine(Handle<Object> recv, static Handle<String> GetStackTraceLine(Handle<Object> recv,
Handle<JSFunction> fun, Handle<JSFunction> fun,
......
...@@ -18,7 +18,6 @@ var MakeTypeError; ...@@ -18,7 +18,6 @@ var MakeTypeError;
var MaxSimple; var MaxSimple;
var MinSimple; var MinSimple;
var ObjectHasOwnProperty; var ObjectHasOwnProperty;
var ObjectKeys;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) { utils.Import(function(from) {
...@@ -26,7 +25,6 @@ utils.Import(function(from) { ...@@ -26,7 +25,6 @@ utils.Import(function(from) {
MaxSimple = from.MaxSimple; MaxSimple = from.MaxSimple;
MinSimple = from.MinSimple; MinSimple = from.MinSimple;
ObjectHasOwnProperty = from.ObjectHasOwnProperty; ObjectHasOwnProperty = from.ObjectHasOwnProperty;
ObjectKeys = from.ObjectKeys;
}); });
// ------------------------------------------------------------------- // -------------------------------------------------------------------
...@@ -52,7 +50,7 @@ function InternalizeJSONProperty(holder, name, reviver) { ...@@ -52,7 +50,7 @@ function InternalizeJSONProperty(holder, name, reviver) {
} }
} }
} else { } else {
for (var p of ObjectKeys(val)) { for (var p of %object_keys(val)) {
var newElement = InternalizeJSONProperty(val, p, reviver); var newElement = InternalizeJSONProperty(val, p, reviver);
if (IS_UNDEFINED(newElement)) { if (IS_UNDEFINED(newElement)) {
%reflect_delete_property(val, p); %reflect_delete_property(val, p);
...@@ -123,7 +121,7 @@ function SerializeObject(value, replacer, stack, indent, gap) { ...@@ -123,7 +121,7 @@ function SerializeObject(value, replacer, stack, indent, gap) {
} }
} }
} else { } else {
for (var p of ObjectKeys(value)) { for (var p of %object_keys(value)) {
var strP = JSONSerialize(p, value, replacer, stack, indent, gap); var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
if (!IS_UNDEFINED(strP)) { if (!IS_UNDEFINED(strP)) {
var member = %QuoteJSONString(p) + ":"; var member = %QuoteJSONString(p) + ":";
......
...@@ -211,13 +211,6 @@ function ObjectLookupSetter(name) { ...@@ -211,13 +211,6 @@ function ObjectLookupSetter(name) {
} }
function ObjectKeys(obj) {
obj = TO_OBJECT(obj);
var filter = PROPERTY_FILTER_ONLY_ENUMERABLE | PROPERTY_FILTER_SKIP_SYMBOLS;
return %GetOwnPropertyKeys(obj, filter);
}
// ES6 6.2.4.1 // ES6 6.2.4.1
function IsAccessorDescriptor(desc) { function IsAccessorDescriptor(desc) {
if (IS_UNDEFINED(desc)) return false; if (IS_UNDEFINED(desc)) return false;
...@@ -892,7 +885,7 @@ utils.InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto, ...@@ -892,7 +885,7 @@ utils.InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto,
// Set up non-enumerable functions in the Object object. // Set up non-enumerable functions in the Object object.
utils.InstallFunctions(GlobalObject, DONT_ENUM, [ utils.InstallFunctions(GlobalObject, DONT_ENUM, [
// assign is added in bootstrapper.cc. // assign is added in bootstrapper.cc.
"keys", ObjectKeys, // keys is added in bootstrapper.cc.
"defineProperty", ObjectDefineProperty, "defineProperty", ObjectDefineProperty,
"defineProperties", ObjectDefineProperties, "defineProperties", ObjectDefineProperties,
"getPrototypeOf", ObjectGetPrototypeOf, "getPrototypeOf", ObjectGetPrototypeOf,
...@@ -1210,7 +1203,6 @@ utils.Export(function(to) { ...@@ -1210,7 +1203,6 @@ utils.Export(function(to) {
to.ObjectDefineProperties = ObjectDefineProperties; to.ObjectDefineProperties = ObjectDefineProperties;
to.ObjectDefineProperty = ObjectDefineProperty; to.ObjectDefineProperty = ObjectDefineProperty;
to.ObjectHasOwnProperty = ObjectHasOwnProperty; to.ObjectHasOwnProperty = ObjectHasOwnProperty;
to.ObjectKeys = ObjectKeys;
}); });
%InstallToContext([ %InstallToContext([
......
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