From: bmeurer Date: Wed, 16 Sep 2015 11:35:15 +0000 (-0700) Subject: [builtins] Also simplify the Symbol constructor. X-Git-Tag: upstream/4.7.83~278 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04087a7e45648a41b791e335ca852e53676f11f8;p=platform%2Fupstream%2Fv8.git [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} --- diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 0346c8c52..45051024a 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -1147,7 +1147,11 @@ void Genesis::InitializeGlobal(Handle global_object, // --- S y m b o l --- Handle 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); } diff --git a/src/builtins.cc b/src/builtins.cc index ac6c9fa93..87f1037ce 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -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 result = isolate->factory()->NewSymbol(); + Handle description = args.at(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 diff --git a/src/builtins.h b/src/builtins.h index aff47f259..f2b6b1e5d 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -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) \ diff --git a/src/symbol.js b/src/symbol.js index c65cda7c4..600d4fd9e 100644 --- a/src/symbol.js +++ b/src/symbol.js @@ -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, [