Chromium Code Reviews| Index: src/symbol.js |
| diff --git a/src/symbol.js b/src/symbol.js |
| index b7f9dc9496aac589e89e2d2761ebe6431a36008e..1e65cb859da2543629f22028aa619a1b02e1a15e 100644 |
| --- a/src/symbol.js |
| +++ b/src/symbol.js |
| @@ -27,13 +27,43 @@ |
| "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(); |
| + if (%_IsConstructCall()) { |
| + %_SetValueOf(this, value); |
| + } else { |
| + return value; |
| + } |
| } |
| -$Object.freeze(SymbolDelegate) |
| +function SymbolToString() { |
| + throw new $TypeError("Symbol.prototype.toString is not allowed"); |
|
Michael Starzinger
2013/03/22 11:39:04
See comments below about MakeTypeError, maybe you
rossberg
2013/03/22 12:37:44
Done.
|
| +} |
| + |
| +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 new $TypeError("Symbol.prototype.valueOf is not generic"); |
|
Michael Starzinger
2013/03/22 11:39:04
Use the following to generate the TypeError instea
rossberg
2013/03/22 12:37:44
Done.
|
| + } |
| + return %_ValueOf(this); |
| +} |
| + |
| +//------------------------------------------------------------------- |
| + |
| +function SetUpSymbol() { |
| + %CheckIsBootstrapping(); |
| + |
| + %SetCode($Symbol, SymbolConstructor); |
| + %FunctionSetPrototype($Symbol, new $Symbol()); |
| + %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); |
| + |
| + InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( |
| + "toString", SymbolToString, |
| + "valueOf", SymbolValueOf |
| + )); |
| +} |
| + |
| +SetUpSymbol(); |