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
This commit is contained in:
rossberg@chromium.org 2014-03-24 15:45:52 +00:00
parent 72932ae417
commit 6704bbce82
2 changed files with 41 additions and 23 deletions

View File

@ -65,7 +65,7 @@ function SymbolValueOf() {
function GetSymbolRegistry() { function GetSymbolRegistry() {
var registry = %SymbolRegistry(); var registry = %SymbolRegistry();
if (!('internal' in registry)) { if (IS_UNDEFINED(registry.internal)) {
registry.internal = {__proto__: null}; registry.internal = {__proto__: null};
registry.for = {__proto__: null}; registry.for = {__proto__: null};
registry.keyFor = {__proto__: null}; registry.keyFor = {__proto__: null};
@ -76,7 +76,7 @@ function GetSymbolRegistry() {
function InternalSymbol(key) { function InternalSymbol(key) {
var registry = GetSymbolRegistry(); var registry = GetSymbolRegistry();
if (!(key in registry.internal)) { if (IS_UNDEFINED(registry.internal[key])) {
registry.internal[key] = %CreateSymbol(key); registry.internal[key] = %CreateSymbol(key);
} }
return registry.internal[key]; return registry.internal[key];
@ -86,7 +86,7 @@ function InternalSymbol(key) {
function SymbolFor(key) { function SymbolFor(key) {
key = TO_STRING_INLINE(key); key = TO_STRING_INLINE(key);
var registry = GetSymbolRegistry(); var registry = GetSymbolRegistry();
if (!(key in registry.for)) { if (IS_UNDEFINED(registry.for[key])) {
var symbol = %CreateSymbol(key); var symbol = %CreateSymbol(key);
registry.for[key] = symbol; registry.for[key] = symbol;
registry.keyFor[symbol] = key; registry.keyFor[symbol] = key;
@ -118,13 +118,13 @@ function ObjectGetOwnPropertySymbols(obj) {
//------------------------------------------------------------------- //-------------------------------------------------------------------
var symbolCreate = InternalSymbol("@@create"); var symbolCreate = InternalSymbol("Symbol.create");
var symbolHasInstance = InternalSymbol("@@hasInstance"); var symbolHasInstance = InternalSymbol("Symbol.hasInstance");
var symbolIsConcatSpreadable = InternalSymbol("@@isConcatSpreadable"); var symbolIsConcatSpreadable = InternalSymbol("Symbol.isConcatSpreadable");
var symbolIsRegExp = InternalSymbol("@@isRegExp"); var symbolIsRegExp = InternalSymbol("Symbol.isRegExp");
var symbolIterator = InternalSymbol("@@iterator"); var symbolIterator = InternalSymbol("Symbol.iterator");
var symbolToStringTag = InternalSymbol("@@toStringTag"); var symbolToStringTag = InternalSymbol("Symbol.toStringTag");
var symbolUnscopables = InternalSymbol("@@unscopables"); var symbolUnscopables = InternalSymbol("Symbol.unscopables");
//------------------------------------------------------------------- //-------------------------------------------------------------------
@ -135,14 +135,15 @@ function SetUpSymbol() {
%SetCode($Symbol, SymbolConstructor); %SetCode($Symbol, SymbolConstructor);
%FunctionSetPrototype($Symbol, new $Object()); %FunctionSetPrototype($Symbol, new $Object());
%SetProperty($Symbol, "create", symbolCreate, DONT_ENUM); InstallConstants($Symbol, $Array(
%SetProperty($Symbol, "hasInstance", symbolHasInstance, DONT_ENUM); "create", symbolCreate,
%SetProperty($Symbol, "isConcatSpreadable", "hasInstance", symbolHasInstance,
symbolIsConcatSpreadable, DONT_ENUM); "isConcatSpreadable", symbolIsConcatSpreadable,
%SetProperty($Symbol, "isRegExp", symbolIsRegExp, DONT_ENUM); "isRegExp", symbolIsRegExp,
%SetProperty($Symbol, "iterator", symbolIterator, DONT_ENUM); "iterator", symbolIterator,
%SetProperty($Symbol, "toStringTag", symbolToStringTag, DONT_ENUM); "toStringTag", symbolToStringTag,
%SetProperty($Symbol, "unscopables", symbolUnscopables, DONT_ENUM); "unscopables", symbolUnscopables
));
InstallFunctions($Symbol, DONT_ENUM, $Array( InstallFunctions($Symbol, DONT_ENUM, $Array(
"for", SymbolFor, "for", SymbolFor,
"keyFor", SymbolKeyFor "keyFor", SymbolKeyFor

View File

@ -410,12 +410,29 @@ function TestGetOwnPropertySymbolsWithProto() {
TestGetOwnPropertySymbolsWithProto() TestGetOwnPropertySymbolsWithProto()
function TestRegistry() { function TestWellKnown() {
assertFalse(Symbol.for("@@create") === Symbol.create) var symbols = [
assertFalse(Symbol.for("@@iterator") === Symbol.iterator) "create", "hasInstance", "isConcatSpreadable", "isRegExp",
assertTrue(Symbol.keyFor(Symbol.create) === undefined) "iterator", "toStringTag", "unscopables"
assertTrue(Symbol.keyFor(Symbol.iterator) === undefined) ]
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 symbol1 = Symbol.for("x1")
var symbol2 = Symbol.for("x2") var symbol2 = Symbol.for("x2")
assertFalse(symbol1 === symbol2) assertFalse(symbol1 === symbol2)