Index: src/symbol.js |
diff --git a/src/symbol.js b/src/symbol.js |
index b7f9dc9496aac589e89e2d2761ebe6431a36008e..b67e00b89548e34d4ec32d60ad1043356b567624 100644 |
--- a/src/symbol.js |
+++ b/src/symbol.js |
@@ -27,13 +27,44 @@ |
"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 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); |
+ |
+ InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( |
+ "toString", SymbolToString, |
+ "valueOf", SymbolValueOf |
+ )); |
+} |
+ |
+SetUpSymbol(); |