diff options
Diffstat (limited to 'deps/v8/src/symbol.js')
-rw-r--r-- | deps/v8/src/symbol.js | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/deps/v8/src/symbol.js b/deps/v8/src/symbol.js index b7f9dc9496..fb7476f438 100644 --- a/deps/v8/src/symbol.js +++ b/deps/v8/src/symbol.js @@ -27,13 +27,55 @@ "use strict"; -var $Symbol = function() { return %CreateSymbol() } -global.Symbol = $Symbol +var $Symbol = global.Symbol; -// Symbols only have a toString method and no prototype. -var SymbolDelegate = { - __proto__: null, - toString: $Object.prototype.toString +function SymbolConstructor(x) { + var value = + IS_SYMBOL(x) ? x : %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x)); + if (%_IsConstructCall()) { + %_SetValueOf(this, value); + } else { + return value; + } } -$Object.freeze(SymbolDelegate) +function SymbolGetName() { + var symbol = IS_SYMBOL_WRAPPER(this) ? %_ValueOf(this) : this; + if (!IS_SYMBOL(symbol)) { + throw MakeTypeError( + 'incompatible_method_receiver', ["Symbol.prototype.name", this]); + } + return %SymbolName(symbol); +} + +function SymbolToString() { + throw MakeTypeError('symbol_to_string'); +} + +function SymbolValueOf() { + // NOTE: Both Symbol objects and values can enter here as + // 'this'. This is not as dictated by ECMA-262. + if (!IS_SYMBOL(this) && !IS_SYMBOL_WRAPPER(this)) { + throw MakeTypeError( + 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); + } + return %_ValueOf(this); +} + +//------------------------------------------------------------------- + +function SetUpSymbol() { + %CheckIsBootstrapping(); + + %SetCode($Symbol, SymbolConstructor); + %FunctionSetPrototype($Symbol, new $Symbol()); + %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); + + InstallGetter($Symbol.prototype, "name", SymbolGetName); + InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( + "toString", SymbolToString, + "valueOf", SymbolValueOf + )); +} + +SetUpSymbol(); |