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,
Handle<JSFunction> object_is_sealed = SimpleInstallFunction(
object_function, "isSealed", Builtins::kObjectIsSealed, 1, false);
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",
Builtins::kObjectPreventExtensions, 1, false);
SimpleInstallFunction(object_function, "seal", Builtins::kObjectSeal, 1,
......
......@@ -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 )
BUILTIN(ObjectPreventExtensions) {
HandleScope scope(isolate);
......
......@@ -92,6 +92,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(ObjectIsExtensible, kNone) \
V(ObjectIsFrozen, kNone) \
V(ObjectIsSealed, kNone) \
V(ObjectKeys, kNone) \
V(ObjectPreventExtensions, kNone) \
V(ObjectSeal, kNone) \
V(ObjectProtoToString, kNone) \
......
......@@ -87,6 +87,7 @@ enum BindingFlags {
V(OBJECT_IS_EXTENSIBLE, JSFunction, object_is_extensible) \
V(OBJECT_IS_FROZEN, JSFunction, object_is_frozen) \
V(OBJECT_IS_SEALED, JSFunction, object_is_sealed) \
V(OBJECT_KEYS, JSFunction, object_keys) \
V(REFLECT_APPLY_INDEX, JSFunction, reflect_apply) \
V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \
V(REFLECT_DEFINE_PROPERTY_INDEX, JSFunction, reflect_define_property) \
......
......@@ -421,13 +421,15 @@ void StackGuard::InitThread(const ExecutionAccess& lock) {
// --- 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;
if (JSReceiver::ToObject(isolate, obj).ToHandle(&receiver)) {
return receiver;
}
THROW_NEW_ERROR(
isolate, NewTypeError(MessageTemplate::kUndefinedOrNullToObject), Object);
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kUndefinedOrNullToObject),
JSReceiver);
}
......
......@@ -50,8 +50,8 @@ class Execution final : public AllStatic {
MaybeHandle<Object>* exception_out = NULL);
// ECMA-262 9.9
MUST_USE_RESULT static MaybeHandle<Object> ToObject(
Isolate* isolate, Handle<Object> obj);
MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject(Isolate* isolate,
Handle<Object> obj);
static Handle<String> GetStackTraceLine(Handle<Object> recv,
Handle<JSFunction> fun,
......
......@@ -18,7 +18,6 @@ var MakeTypeError;
var MaxSimple;
var MinSimple;
var ObjectHasOwnProperty;
var ObjectKeys;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
utils.Import(function(from) {
......@@ -26,7 +25,6 @@ utils.Import(function(from) {
MaxSimple = from.MaxSimple;
MinSimple = from.MinSimple;
ObjectHasOwnProperty = from.ObjectHasOwnProperty;
ObjectKeys = from.ObjectKeys;
});
// -------------------------------------------------------------------
......@@ -52,7 +50,7 @@ function InternalizeJSONProperty(holder, name, reviver) {
}
}
} else {
for (var p of ObjectKeys(val)) {
for (var p of %object_keys(val)) {
var newElement = InternalizeJSONProperty(val, p, reviver);
if (IS_UNDEFINED(newElement)) {
%reflect_delete_property(val, p);
......@@ -123,7 +121,7 @@ function SerializeObject(value, replacer, stack, indent, gap) {
}
}
} else {
for (var p of ObjectKeys(value)) {
for (var p of %object_keys(value)) {
var strP = JSONSerialize(p, value, replacer, stack, indent, gap);
if (!IS_UNDEFINED(strP)) {
var member = %QuoteJSONString(p) + ":";
......
......@@ -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
function IsAccessorDescriptor(desc) {
if (IS_UNDEFINED(desc)) return false;
......@@ -892,7 +885,7 @@ utils.InstallGetterSetter(GlobalObject.prototype, "__proto__", ObjectGetProto,
// Set up non-enumerable functions in the Object object.
utils.InstallFunctions(GlobalObject, DONT_ENUM, [
// assign is added in bootstrapper.cc.
"keys", ObjectKeys,
// keys is added in bootstrapper.cc.
"defineProperty", ObjectDefineProperty,
"defineProperties", ObjectDefineProperties,
"getPrototypeOf", ObjectGetPrototypeOf,
......@@ -1210,7 +1203,6 @@ utils.Export(function(to) {
to.ObjectDefineProperties = ObjectDefineProperties;
to.ObjectDefineProperty = ObjectDefineProperty;
to.ObjectHasOwnProperty = ObjectHasOwnProperty;
to.ObjectKeys = ObjectKeys;
});
%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