[runtime] Migrate Object.getOwnPropertySymbols to C++.
The Object.getOwnPropertySymbols() calls into C++ at least once on every possible path, so no point in having the JavaScript wrapper. Drive-by-cleanup: Also move Symbol.prototype creation to C++ as well. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/1587153003 Cr-Commit-Position: refs/heads/master@{#33318}
This commit is contained in:
parent
9a6e85552f
commit
489e7e3915
@ -1095,6 +1095,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
||||
Handle<JSFunction> object_freeze = SimpleInstallFunction(
|
||||
object_function, "freeze", Builtins::kObjectFreeze, 1, false);
|
||||
native_context()->set_object_freeze(*object_freeze);
|
||||
SimpleInstallFunction(object_function, "getOwnPropertySymbols",
|
||||
Builtins::kObjectGetOwnPropertySymbols, 1, false);
|
||||
Handle<JSFunction> object_is_extensible =
|
||||
SimpleInstallFunction(object_function, "isExtensible",
|
||||
Builtins::kObjectIsExtensible, 1, false);
|
||||
@ -1250,14 +1252,20 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
||||
|
||||
{
|
||||
// --- S y m b o l ---
|
||||
Handle<JSFunction> symbol_fun = InstallFunction(
|
||||
global, "Symbol", JS_VALUE_TYPE, JSValue::kSize,
|
||||
isolate->initial_object_prototype(), Builtins::kSymbolConstructor);
|
||||
Handle<JSObject> prototype =
|
||||
factory->NewJSObject(isolate->object_function(), TENURED);
|
||||
Handle<JSFunction> symbol_fun =
|
||||
InstallFunction(global, "Symbol", JS_VALUE_TYPE, JSValue::kSize,
|
||||
prototype, Builtins::kSymbolConstructor);
|
||||
symbol_fun->shared()->set_construct_stub(
|
||||
*isolate->builtins()->SymbolConstructor_ConstructStub());
|
||||
symbol_fun->shared()->set_length(1);
|
||||
symbol_fun->shared()->DontAdaptArguments();
|
||||
native_context()->set_symbol_function(*symbol_fun);
|
||||
|
||||
// Install the "constructor" property on the {prototype}.
|
||||
JSObject::AddProperty(prototype, factory->constructor_string(), symbol_fun,
|
||||
DONT_ENUM);
|
||||
}
|
||||
|
||||
{ // --- D a t e ---
|
||||
|
@ -1563,6 +1563,21 @@ BUILTIN(ObjectFreeze) {
|
||||
}
|
||||
|
||||
|
||||
// ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O )
|
||||
BUILTIN(ObjectGetOwnPropertySymbols) {
|
||||
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,
|
||||
SKIP_STRINGS, CONVERT_TO_STRING));
|
||||
return *isolate->factory()->NewJSArrayWithElements(keys);
|
||||
}
|
||||
|
||||
|
||||
// ES6 section 19.1.2.11 Object.isExtensible ( O )
|
||||
BUILTIN(ObjectIsExtensible) {
|
||||
HandleScope scope(isolate);
|
||||
|
@ -110,6 +110,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
|
||||
V(ObjectAssign, kNone) \
|
||||
V(ObjectCreate, kNone) \
|
||||
V(ObjectFreeze, kNone) \
|
||||
V(ObjectGetOwnPropertySymbols, kNone) \
|
||||
V(ObjectIsExtensible, kNone) \
|
||||
V(ObjectIsFrozen, kNone) \
|
||||
V(ObjectIsSealed, kNone) \
|
||||
|
@ -11,7 +11,6 @@
|
||||
// -------------------------------------------------------------------
|
||||
// Imports
|
||||
|
||||
var GlobalObject = global.Object;
|
||||
var GlobalSymbol = global.Symbol;
|
||||
var hasInstanceSymbol = utils.ImportNow("has_instance_symbol");
|
||||
var isConcatSpreadableSymbol =
|
||||
@ -73,18 +72,8 @@ function SymbolKeyFor(symbol) {
|
||||
return %SymbolRegistry().keyFor[symbol];
|
||||
}
|
||||
|
||||
|
||||
// ES6 19.1.2.8
|
||||
function ObjectGetOwnPropertySymbols(obj) {
|
||||
obj = TO_OBJECT(obj);
|
||||
|
||||
return %GetOwnPropertyKeys(obj, PROPERTY_FILTER_SKIP_STRINGS);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
%FunctionSetPrototype(GlobalSymbol, new GlobalObject());
|
||||
|
||||
utils.InstallConstants(GlobalSymbol, [
|
||||
// TODO(rossberg): expose when implemented.
|
||||
// "hasInstance", hasInstanceSymbol,
|
||||
@ -107,8 +96,6 @@ utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [
|
||||
"keyFor", SymbolKeyFor
|
||||
]);
|
||||
|
||||
%AddNamedProperty(
|
||||
GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM);
|
||||
%AddNamedProperty(
|
||||
GlobalSymbol.prototype, toStringTagSymbol, "Symbol", DONT_ENUM | READ_ONLY);
|
||||
|
||||
@ -121,10 +108,6 @@ utils.InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, [
|
||||
"valueOf", SymbolValueOf
|
||||
]);
|
||||
|
||||
utils.InstallFunctions(GlobalObject, DONT_ENUM, [
|
||||
"getOwnPropertySymbols", ObjectGetOwnPropertySymbols
|
||||
]);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Exports
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user