Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(729)

Unified Diff: src/symbol.js

Issue 118553003: Upgrade Symbol implementation to match current ES6 behavior. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Remove uninteresting equality test Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/symbol.js
diff --git a/src/symbol.js b/src/symbol.js
index be308d947cb0353dd9eb10aa4077a473536884f7..ff05d28421ed65a2ebe2df989afa54dbcf45981c 100644
--- a/src/symbol.js
+++ b/src/symbol.js
@@ -36,34 +36,30 @@ var $Symbol = global.Symbol;
// -------------------------------------------------------------------
function SymbolConstructor(x) {
- var value =
- IS_SYMBOL(x) ? x : %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
if (%_IsConstructCall()) {
- %_SetValueOf(this, value);
- } else {
- return value;
+ throw MakeTypeError('not_constructor', ["Symbol"]);
}
+ // NOTE: Passing in a Symbol value will throw on ToString().
+ return %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
}
-function SymbolGetName() {
- var symbol = IS_SYMBOL_WRAPPER(this) ? %_ValueOf(this) : this;
- if (!IS_SYMBOL(symbol)) {
+function SymbolToString() {
+ if (IS_SYMBOL(this)) {
+ throw MakeTypeError('symbol_to_string', []);
+ } else if (!IS_SYMBOL_WRAPPER(this)) {
throw MakeTypeError(
- 'incompatible_method_receiver', ["Symbol.prototype.name", this]);
+ 'incompatible_method_receiver', ["Symbol.prototype.toString", this]);
}
- return %SymbolName(symbol);
-}
-
-function SymbolToString() {
- throw MakeTypeError('symbol_to_string');
+ var description = %SymbolDescription(%_ValueOf(this));
+ return "Symbol(" + (IS_UNDEFINED(description) ? "" : description) + ")";
}
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)) {
+ if (IS_SYMBOL(this)) {
+ throw MakeTypeError('symbol_to_value', []);
rossberg 2014/02/04 15:16:25 We should leave this out for now (and also not do
sof 2014/02/04 15:40:58 Not just non-strict, but the methods would also ha
+ } else if (!IS_SYMBOL_WRAPPER(this)) {
throw MakeTypeError(
- 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]);
+ 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]);
}
return %_ValueOf(this);
}
@@ -88,10 +84,9 @@ function SetUpSymbol() {
%CheckIsBootstrapping();
%SetCode($Symbol, SymbolConstructor);
- %FunctionSetPrototype($Symbol, new $Symbol());
- %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM);
+ %FunctionSetPrototype($Symbol, new $Object());
- InstallGetter($Symbol.prototype, "name", SymbolGetName);
+ %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM);
InstallFunctions($Symbol.prototype, DONT_ENUM, $Array(
"toString", SymbolToString,
"valueOf", SymbolValueOf
« no previous file with comments | « src/stub-cache.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | test/mjsunit/harmony/symbols.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698