Commit 6704bbce authored by rossberg@chromium.org's avatar rossberg@chromium.org

Spec adjustments for well-known symbols

R=arv@chromium.org, mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/208423013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20204 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 72932ae4
......@@ -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,15 @@ 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);
InstallConstants($Symbol, $Array(
"create", symbolCreate,
"hasInstance", symbolHasInstance,
"isConcatSpreadable", symbolIsConcatSpreadable,
"isRegExp", symbolIsRegExp,
"iterator", symbolIterator,
"toStringTag", symbolToStringTag,
"unscopables", symbolUnscopables
));
InstallFunctions($Symbol, DONT_ENUM, $Array(
"for", SymbolFor,
"keyFor", SymbolKeyFor
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment