Reviewers: arv, Michael Starzinger,
Description:
Spec adjustments for well-known symbols
[email protected], [email protected]
BUG=
Please review this at https://codereview.chromium.org/208423013/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+40, -23 lines):
M src/symbol.js
M test/mjsunit/harmony/symbols.js
Index: src/symbol.js
diff --git a/src/symbol.js b/src/symbol.js
index
49f909694c19f3ee44c60a39def7fbbd0f39c6a5..8c6ae89a8a562ece29215fe894aa9225e3a9a551
100644
--- a/src/symbol.js
+++ b/src/symbol.js
@@ -65,7 +65,7 @@ function SymbolValueOf() {
function GetSymbolRegistry() {
var registry = %SymbolRegistry();
- if (!('internal' in registry)) {
+ if (IS_UNDEFINED(registry.internal)) {
registry.internal = {__proto__: null};
registry.for = {__proto__: null};
registry.keyFor = {__proto__: null};
@@ -76,7 +76,7 @@ function GetSymbolRegistry() {
function InternalSymbol(key) {
var registry = GetSymbolRegistry();
- if (!(key in registry.internal)) {
+ if (IS_UNDEFINED(registry.internal[key])) {
registry.internal[key] = %CreateSymbol(key);
}
return registry.internal[key];
@@ -86,7 +86,7 @@ function InternalSymbol(key) {
function SymbolFor(key) {
key = TO_STRING_INLINE(key);
var registry = GetSymbolRegistry();
- if (!(key in registry.for)) {
+ if (IS_UNDEFINED(registry.for[key])) {
var symbol = %CreateSymbol(key);
registry.for[key] = symbol;
registry.keyFor[symbol] = key;
@@ -118,13 +118,13 @@ function ObjectGetOwnPropertySymbols(obj) {
//-------------------------------------------------------------------
-var symbolCreate = InternalSymbol("@@create");
-var symbolHasInstance = InternalSymbol("@@hasInstance");
-var symbolIsConcatSpreadable = InternalSymbol("@@isConcatSpreadable");
-var symbolIsRegExp = InternalSymbol("@@isRegExp");
-var symbolIterator = InternalSymbol("@@iterator");
-var symbolToStringTag = InternalSymbol("@@toStringTag");
-var symbolUnscopables = InternalSymbol("@@unscopables");
+var symbolCreate = InternalSymbol("Symbol.create");
+var symbolHasInstance = InternalSymbol("Symbol.hasInstance");
+var symbolIsConcatSpreadable = InternalSymbol("Symbol.isConcatSpreadable");
+var symbolIsRegExp = InternalSymbol("Symbol.isRegExp");
+var symbolIterator = InternalSymbol("Symbol.iterator");
+var symbolToStringTag = InternalSymbol("Symbol.toStringTag");
+var symbolUnscopables = InternalSymbol("Symbol.unscopables");
//-------------------------------------------------------------------
@@ -135,14 +135,14 @@ function SetUpSymbol() {
%SetCode($Symbol, SymbolConstructor);
%FunctionSetPrototype($Symbol, new $Object());
- %SetProperty($Symbol, "create", symbolCreate, DONT_ENUM);
- %SetProperty($Symbol, "hasInstance", symbolHasInstance, DONT_ENUM);
- %SetProperty($Symbol, "isConcatSpreadable",
- symbolIsConcatSpreadable, DONT_ENUM);
- %SetProperty($Symbol, "isRegExp", symbolIsRegExp, DONT_ENUM);
- %SetProperty($Symbol, "iterator", symbolIterator, DONT_ENUM);
- %SetProperty($Symbol, "toStringTag", symbolToStringTag, DONT_ENUM);
- %SetProperty($Symbol, "unscopables", symbolUnscopables, DONT_ENUM);
+ var attr = READ_ONLY | DONT_DELETE | DONT_ENUM;
+ %SetProperty($Symbol, "create", symbolCreate, attr);
+ %SetProperty($Symbol, "hasInstance", symbolHasInstance, attr);
+ %SetProperty($Symbol, "isConcatSpreadable", symbolIsConcatSpreadable,
attr);
+ %SetProperty($Symbol, "isRegExp", symbolIsRegExp, attr);
+ %SetProperty($Symbol, "iterator", symbolIterator, attr);
+ %SetProperty($Symbol, "toStringTag", symbolToStringTag, attr);
+ %SetProperty($Symbol, "unscopables", symbolUnscopables, attr);
InstallFunctions($Symbol, DONT_ENUM, $Array(
"for", SymbolFor,
"keyFor", SymbolKeyFor
Index: test/mjsunit/harmony/symbols.js
diff --git a/test/mjsunit/harmony/symbols.js
b/test/mjsunit/harmony/symbols.js
index
d19aece5b17202f6bd1b9e841561f5691c56fc86..e7bf36040621d5541378614d2d5e657b1b2ea463
100644
--- a/test/mjsunit/harmony/symbols.js
+++ b/test/mjsunit/harmony/symbols.js
@@ -410,12 +410,29 @@ function TestGetOwnPropertySymbolsWithProto() {
TestGetOwnPropertySymbolsWithProto()
-function TestRegistry() {
- assertFalse(Symbol.for("@@create") === Symbol.create)
- assertFalse(Symbol.for("@@iterator") === Symbol.iterator)
- assertTrue(Symbol.keyFor(Symbol.create) === undefined)
- assertTrue(Symbol.keyFor(Symbol.iterator) === undefined)
+function TestWellKnown() {
+ var symbols = [
+ "create", "hasInstance", "isConcatSpreadable", "isRegExp",
+ "iterator", "toStringTag", "unscopables"
+ ]
+ for (var i in symbols) {
+ var name = symbols[i]
+ var desc = Object.getOwnPropertyDescriptor(Symbol, name)
+ assertSame("symbol", typeof desc.value)
+ assertSame("Symbol(Symbol." + name + ")", desc.value.toString())
+ assertFalse(desc.writable)
+ assertFalse(desc.configurable)
+ assertFalse(desc.enumerable)
+
+ assertFalse(Symbol.for("Symbol." + name) === desc.value)
+ assertTrue(Symbol.keyFor(desc.value) === undefined)
+ }
+}
+TestWellKnown()
+
+
+function TestRegistry() {
var symbol1 = Symbol.for("x1")
var symbol2 = Symbol.for("x2")
assertFalse(symbol1 === symbol2)
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.