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

Unified Diff: src/symbol.js

Issue 1306303003: [es6] Implement spec compliant ToPrimitive in the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address Michis comments. Created 5 years, 4 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 8cac2c56a2f69cfa8397c6c13bb0d07ef9f33f1f..3f6e281777086cb9317071a730767db99c9db157 100644
--- a/src/symbol.js
+++ b/src/symbol.js
@@ -7,6 +7,7 @@
// - symbolIsConcatSpreadable
// - symbolIsRegExp
// - symbolIterator
+// - symbolToPrimitive
// - symbolToStringTag
// - symbolUnscopables
@@ -40,6 +41,16 @@ function SymbolConstructor(x) {
}
+// 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )
+function SymbolToPrimitive(hint) {
+ if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
+ throw MakeTypeError(kIncompatibleMethodReceiver,
+ "Symbol.prototype [ @@toPrimitive ]", this);
+ }
+ return %_ValueOf(this);
+}
+
+
function SymbolToString() {
if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
throw MakeTypeError(kIncompatibleMethodReceiver,
@@ -97,6 +108,7 @@ utils.InstallConstants(GlobalSymbol, [
// "isConcatSpreadable", symbolIsConcatSpreadable,
// "isRegExp", symbolIsRegExp,
"iterator", symbolIterator,
+ "toPrimitive", symbolToPrimitive,
// TODO(dslomov, caitp): Currently defined in harmony-tostring.js ---
// Move here when shipping
// "toStringTag", symbolToStringTag,
@@ -110,6 +122,10 @@ utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [
%AddNamedProperty(
GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM);
+utils.SetFunctionName(SymbolToPrimitive, symbolToPrimitive);
+%AddNamedProperty(
+ GlobalSymbol.prototype, symbolToPrimitive, SymbolToPrimitive,
+ DONT_ENUM | READ_ONLY);
%AddNamedProperty(
GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY);
« src/objects.cc ('K') | « src/runtime/runtime-scopes.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698