Commit 04087a7e authored by bmeurer's avatar bmeurer Committed by Commit bot

[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}
parent d0e77b29
...@@ -1147,7 +1147,11 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object, ...@@ -1147,7 +1147,11 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
// --- S y m b o l --- // --- S y m b o l ---
Handle<JSFunction> symbol_fun = InstallFunction( Handle<JSFunction> symbol_fun = InstallFunction(
global, "Symbol", JS_VALUE_TYPE, JSValue::kSize, 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); native_context()->set_symbol_function(*symbol_fun);
} }
......
...@@ -1445,11 +1445,7 @@ BUILTIN(ArrayConcat) { ...@@ -1445,11 +1445,7 @@ BUILTIN(ArrayConcat) {
} }
// ----------------------------------------------------------------------------- // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint )
//
// 20.3.4.45 Date.prototype [ @@toPrimitive ] ( hint )
BUILTIN(DateToPrimitive) { BUILTIN(DateToPrimitive) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(2, args.length()); DCHECK_EQ(2, args.length());
...@@ -1469,6 +1465,30 @@ BUILTIN(DateToPrimitive) { ...@@ -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 // Throwers for restricted function properties and strict arguments object
// properties // properties
......
...@@ -59,6 +59,9 @@ enum BuiltinExtraArguments { ...@@ -59,6 +59,9 @@ enum BuiltinExtraArguments {
\ \
V(DateToPrimitive, NO_EXTRA_ARGUMENTS) \ V(DateToPrimitive, NO_EXTRA_ARGUMENTS) \
\ \
V(SymbolConstructor, NO_EXTRA_ARGUMENTS) \
V(SymbolConstructor_ConstructStub, NO_EXTRA_ARGUMENTS) \
\
V(HandleApiCall, NEEDS_CALLED_FUNCTION) \ V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \ V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \ V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
......
...@@ -20,24 +20,15 @@ var isRegExpSymbol = utils.ImportNow("is_regexp_symbol"); ...@@ -20,24 +20,15 @@ var isRegExpSymbol = utils.ImportNow("is_regexp_symbol");
var iteratorSymbol = utils.ImportNow("iterator_symbol"); var iteratorSymbol = utils.ImportNow("iterator_symbol");
var ObjectGetOwnPropertyKeys; var ObjectGetOwnPropertyKeys;
var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol"); var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol");
var ToString;
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); var unscopablesSymbol = utils.ImportNow("unscopables_symbol");
utils.Import(function(from) { utils.Import(function(from) {
ObjectGetOwnPropertyKeys = from.ObjectGetOwnPropertyKeys; 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 ) // 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )
function SymbolToPrimitive(hint) { function SymbolToPrimitive(hint) {
if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
...@@ -95,7 +86,6 @@ function ObjectGetOwnPropertySymbols(obj) { ...@@ -95,7 +86,6 @@ function ObjectGetOwnPropertySymbols(obj) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
%SetCode(GlobalSymbol, SymbolConstructor);
%FunctionSetPrototype(GlobalSymbol, new GlobalObject()); %FunctionSetPrototype(GlobalSymbol, new GlobalObject());
utils.InstallConstants(GlobalSymbol, [ utils.InstallConstants(GlobalSymbol, [
......
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