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

Unified Diff: src/symbol.js

Issue 12459026: ES6 symbols: implement name property (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 7 years, 9 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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/symbol.js
diff --git a/src/symbol.js b/src/symbol.js
index 1e65cb859da2543629f22028aa619a1b02e1a15e..897d78e146d9a19299c9e4fa0b804a5b6a4b99d7 100644
--- a/src/symbol.js
+++ b/src/symbol.js
@@ -30,7 +30,8 @@
var $Symbol = global.Symbol;
function SymbolConstructor(x) {
- var value = IS_SYMBOL(x) ? x : %CreateSymbol();
+ var value =
+ IS_SYMBOL(x) ? x : %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
if (%_IsConstructCall()) {
%_SetValueOf(this, value);
} else {
@@ -38,6 +39,16 @@ function SymbolConstructor(x) {
}
}
+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 new $TypeError("Symbol.prototype.toString is not allowed");
}
@@ -60,6 +71,7 @@ function SetUpSymbol() {
%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
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698