Bug 645417, part 10 - Well-known symbols. r=terrence,r=efaust.

At present there is only one, Symbol.iterator, and it is not hooked up to
anything (this happens in bug 918828). ES6 defines 8 well-known symbols. Each
one is attached to a feature, so we'll add the symbols as we add features.
Symbol.create will appear when @@create semantics are implemented.
This commit is contained in:
Jason Orendorff
2014-06-23 10:56:49 -05:00
parent 78c612a012
commit 259f0c6a8c
16 changed files with 251 additions and 35 deletions

View File

@@ -126,6 +126,7 @@ JSRuntime::initializeAtoms(JSContext *cx)
commonNames = parentRuntime->commonNames;
emptyString = parentRuntime->emptyString;
permanentAtoms = parentRuntime->permanentAtoms;
wellKnownSymbols = parentRuntime->wellKnownSymbols;
return true;
}
@@ -160,30 +161,43 @@ JSRuntime::initializeAtoms(JSContext *cx)
JS_ASSERT(uintptr_t(names) == uintptr_t(commonNames + 1));
emptyString = commonNames->empty;
// Create the well-known symbols.
wellKnownSymbols = cx->new_<WellKnownSymbols>();
if (!wellKnownSymbols)
return false;
ImmutablePropertyNamePtr *descriptions = &commonNames->Symbol_iterator;
ImmutableSymbolPtr *symbols = reinterpret_cast<ImmutableSymbolPtr *>(wellKnownSymbols);
for (size_t i = 0; i < JS::WellKnownSymbolLimit; i++) {
JS::Symbol *symbol = JS::Symbol::new_(cx, JS::SymbolCode(i), descriptions[i]);
if (!symbol) {
js_ReportOutOfMemory(cx);
return false;
}
symbols[i].init(symbol);
}
return true;
}
void
JSRuntime::finishAtoms()
{
if (atoms_)
js_delete(atoms_);
js_delete(atoms_);
if (!parentRuntime) {
if (staticStrings)
js_delete(staticStrings);
if (commonNames)
js_delete(commonNames);
if (permanentAtoms)
js_delete(permanentAtoms);
js_delete(staticStrings);
js_delete(commonNames);
js_delete(permanentAtoms);
js_delete(wellKnownSymbols);
}
atoms_ = nullptr;
staticStrings = nullptr;
commonNames = nullptr;
permanentAtoms = nullptr;
wellKnownSymbols = nullptr;
emptyString = nullptr;
}
@@ -227,6 +241,20 @@ js::MarkPermanentAtoms(JSTracer *trc)
}
}
void
js::MarkWellKnownSymbols(JSTracer *trc)
{
JSRuntime *rt = trc->runtime();
if (rt->parentRuntime)
return;
if (WellKnownSymbols *wks = rt->wellKnownSymbols) {
for (size_t i = 0; i < JS::WellKnownSymbolLimit; i++)
MarkWellKnownSymbol(trc, wks->get(i));
}
}
void
JSRuntime::sweepAtoms()
{