mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1635839 - Part 1: Add PrivateName Symbol code. r=jorendorff
Differential Revision: https://phabricator.services.mozilla.com/D74102
This commit is contained in:
parent
904cf26dfd
commit
2e3e2805a9
@ -75,6 +75,7 @@ enum class SymbolCode : uint32_t {
|
||||
WellKnownAPILimit =
|
||||
0x80000000, // matches JS::shadow::Symbol::WellKnownAPILimit for inline
|
||||
// use
|
||||
PrivateNameSymbol = 0xfffffffd, // created by the #PrivateName syntax.
|
||||
InSymbolRegistry =
|
||||
0xfffffffe, // created by Symbol.for() or JS::GetSymbolFor()
|
||||
UniqueSymbol = 0xffffffff // created by Symbol() or JS::NewSymbol()
|
||||
|
@ -12,6 +12,7 @@ from mozilla.CellHeader import get_header_ptr
|
||||
mozilla.prettyprinters.clear_module_printers(__name__)
|
||||
|
||||
# JS::SymbolCode enumerators
|
||||
PrivateNameSymbol = 0xfffffffd
|
||||
InSymbolRegistry = 0xfffffffe
|
||||
UniqueSymbol = 0xffffffff
|
||||
|
||||
@ -30,6 +31,8 @@ class JSSymbolPtr(mozilla.prettyprinters.Pointer):
|
||||
return "Symbol.for({})".format(desc)
|
||||
elif code == UniqueSymbol:
|
||||
return "Symbol({})".format(desc)
|
||||
elif code == PrivateNameSymbol:
|
||||
return "#{}".format(desc)
|
||||
else:
|
||||
# Well-known symbol. Strip off the quotes added by the JSString *
|
||||
# pretty-printer.
|
||||
|
@ -103,6 +103,11 @@ void Symbol::dump(js::GenericPrinter& out) {
|
||||
if (code_ == SymbolCode::UniqueSymbol) {
|
||||
out.printf("@%p", (void*)this);
|
||||
}
|
||||
} else if (code_ == SymbolCode::PrivateNameSymbol) {
|
||||
MOZ_ASSERT(description());
|
||||
out.putChar('#');
|
||||
description()->dumpCharsNoNewline(out);
|
||||
out.printf("@%p", (void*)this);
|
||||
} else {
|
||||
out.printf("<Invalid Symbol code=%u>", unsigned(code_));
|
||||
}
|
||||
|
@ -59,26 +59,34 @@ static JSString* StringToSource(JSContext* cx, JSString* str) {
|
||||
static JSString* SymbolToSource(JSContext* cx, Symbol* symbol) {
|
||||
RootedString desc(cx, symbol->description());
|
||||
SymbolCode code = symbol->code();
|
||||
if (code != SymbolCode::InSymbolRegistry &&
|
||||
code != SymbolCode::UniqueSymbol) {
|
||||
if (symbol->isWellKnownSymbol()) {
|
||||
// Well-known symbol.
|
||||
MOZ_ASSERT(uint32_t(code) < JS::WellKnownSymbolLimit);
|
||||
return desc;
|
||||
}
|
||||
|
||||
JSStringBuilder buf(cx);
|
||||
if (code == SymbolCode::InSymbolRegistry ? !buf.append("Symbol.for(")
|
||||
: !buf.append("Symbol(")) {
|
||||
return nullptr;
|
||||
}
|
||||
if (desc) {
|
||||
UniqueChars quoted = QuoteString(cx, desc, '"');
|
||||
if (!quoted || !buf.append(quoted.get(), strlen(quoted.get()))) {
|
||||
if (code == SymbolCode::PrivateNameSymbol) {
|
||||
MOZ_ASSERT(desc);
|
||||
if (!buf.append('#') || !buf.append(desc)) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
MOZ_ASSERT(code == SymbolCode::InSymbolRegistry ||
|
||||
code == SymbolCode::UniqueSymbol);
|
||||
|
||||
if (code == SymbolCode::InSymbolRegistry ? !buf.append("Symbol.for(")
|
||||
: !buf.append("Symbol(")) {
|
||||
return nullptr;
|
||||
}
|
||||
if (desc) {
|
||||
UniqueChars quoted = QuoteString(cx, desc, '"');
|
||||
if (!quoted || !buf.append(quoted.get(), strlen(quoted.get()))) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (!buf.append(')')) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (!buf.append(')')) {
|
||||
return nullptr;
|
||||
}
|
||||
return buf.finishString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user