[builtins] Also simplify the Symbol constructor.
No need to rely on the %_IsConstructCall magic here, we can just implement the Symbol constructor in C++ altogether (it was just a stupid wrapper around %CreateSymbol anyway). R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/1349643002 Cr-Commit-Position: refs/heads/master@{#30762}
This commit is contained in:
parent
d0e77b2909
commit
04087a7e45
@ -1147,7 +1147,11 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> 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::kIllegal);
|
||||
isolate->initial_object_prototype(), Builtins::kSymbolConstructor);
|
||||
symbol_fun->shared()->set_construct_stub(isolate->builtins()->builtin(
|
||||
Builtins::kSymbolConstructor_ConstructStub));
|
||||
symbol_fun->shared()->set_internal_formal_parameter_count(1);
|
||||
symbol_fun->shared()->set_length(1);
|
||||
native_context()->set_symbol_function(*symbol_fun);
|
||||
}
|
||||
|
||||
|
@ -1445,11 +1445,7 @@ BUILTIN(ArrayConcat) {
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
|
||||
// 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint )
|
||||
// ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint )
|
||||
BUILTIN(DateToPrimitive) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK_EQ(2, args.length());
|
||||
@ -1469,6 +1465,30 @@ BUILTIN(DateToPrimitive) {
|
||||
}
|
||||
|
||||
|
||||
// ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case.
|
||||
BUILTIN(SymbolConstructor) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK_EQ(2, args.length());
|
||||
Handle<Symbol> result = isolate->factory()->NewSymbol();
|
||||
Handle<Object> description = args.at<Object>(1);
|
||||
if (!description->IsUndefined()) {
|
||||
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description,
|
||||
Object::ToString(isolate, description));
|
||||
result->set_name(*description);
|
||||
}
|
||||
return *result;
|
||||
}
|
||||
|
||||
|
||||
// ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case.
|
||||
BUILTIN(SymbolConstructor_ConstructStub) {
|
||||
HandleScope scope(isolate);
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kNotConstructor,
|
||||
isolate->factory()->Symbol_string()));
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Throwers for restricted function properties and strict arguments object
|
||||
// properties
|
||||
|
@ -59,6 +59,9 @@ enum BuiltinExtraArguments {
|
||||
\
|
||||
V(DateToPrimitive, NO_EXTRA_ARGUMENTS) \
|
||||
\
|
||||
V(SymbolConstructor, NO_EXTRA_ARGUMENTS) \
|
||||
V(SymbolConstructor_ConstructStub, NO_EXTRA_ARGUMENTS) \
|
||||
\
|
||||
V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
|
||||
V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
|
||||
V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
|
||||
|
@ -20,24 +20,15 @@ var isRegExpSymbol = utils.ImportNow("is_regexp_symbol");
|
||||
var iteratorSymbol = utils.ImportNow("iterator_symbol");
|
||||
var ObjectGetOwnPropertyKeys;
|
||||
var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol");
|
||||
var ToString;
|
||||
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
|
||||
var unscopablesSymbol = utils.ImportNow("unscopables_symbol");
|
||||
|
||||
utils.Import(function(from) {
|
||||
ObjectGetOwnPropertyKeys = from.ObjectGetOwnPropertyKeys;
|
||||
ToString = from.ToString;
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
function SymbolConstructor(x) {
|
||||
if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Symbol");
|
||||
// NOTE: Passing in a Symbol value will throw on ToString().
|
||||
return %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
|
||||
}
|
||||
|
||||
|
||||
// 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )
|
||||
function SymbolToPrimitive(hint) {
|
||||
if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
|
||||
@ -95,7 +86,6 @@ function ObjectGetOwnPropertySymbols(obj) {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
%SetCode(GlobalSymbol, SymbolConstructor);
|
||||
%FunctionSetPrototype(GlobalSymbol, new GlobalObject());
|
||||
|
||||
utils.InstallConstants(GlobalSymbol, [
|
||||
|
Loading…
Reference in New Issue
Block a user