Bug 1635839 - Part 1: Add PrivateName Symbol code. r=jorendorff
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 02 Jun 2020 20:57:34 +0000
changeset 597698 0880c9f6821008953ea4f4f12d2d6ee84767a636
parent 597697 925f89a10fc8beb0e7c5ca02c8b873b0ebd138d7
child 597699 e739f15aeaf8997dc22a28131b754c1a001e1deb
push id13310
push userffxbld-merge
push dateMon, 29 Jun 2020 14:50:06 +0000
treeherdermozilla-beta@15a59a0afa5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1635839
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1635839 - Part 1: Add PrivateName Symbol code. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D74102
js/public/Symbol.h
js/src/gdb/mozilla/JSSymbol.py
js/src/vm/SymbolType.cpp
js/src/vm/ToSource.cpp
--- a/js/public/Symbol.h
+++ b/js/public/Symbol.h
@@ -70,16 +70,17 @@ enum class SymbolCode : uint32_t {
 #define JS_DEFINE_SYMBOL_ENUM(name) name,
   JS_FOR_EACH_WELL_KNOWN_SYMBOL(
       JS_DEFINE_SYMBOL_ENUM)  // SymbolCode::iterator, etc.
 #undef JS_DEFINE_SYMBOL_ENUM
   Limit,
   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()
 };
 
 /* For use in loops that iterate over the well-known symbols. */
 const size_t WellKnownSymbolLimit = size_t(SymbolCode::Limit);
 
--- a/js/src/gdb/mozilla/JSSymbol.py
+++ b/js/src/gdb/mozilla/JSSymbol.py
@@ -7,16 +7,17 @@
 import mozilla.prettyprinters
 from mozilla.prettyprinters import ptr_pretty_printer
 from mozilla.CellHeader import get_header_ptr
 
 # Forget any printers from previous loads of this module.
 mozilla.prettyprinters.clear_module_printers(__name__)
 
 # JS::SymbolCode enumerators
+PrivateNameSymbol = 0xfffffffd
 InSymbolRegistry = 0xfffffffe
 UniqueSymbol = 0xffffffff
 
 
 @ptr_pretty_printer("JS::Symbol")
 class JSSymbolPtr(mozilla.prettyprinters.Pointer):
     def __init__(self, value, cache):
         super(JSSymbolPtr, self).__init__(value, cache)
@@ -25,14 +26,16 @@ class JSSymbolPtr(mozilla.prettyprinters
     def to_string(self):
         code = int(self.value['code_']) & 0xffffffff
         desc = str(get_header_ptr(self.value['headerAndDescription_'],
                                   self.cache.JSString_ptr_t))
         if code == InSymbolRegistry:
             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.
             assert desc[0] == '"'
             assert desc[-1] == '"'
             return desc[1:-1]
--- a/js/src/vm/SymbolType.cpp
+++ b/js/src/vm/SymbolType.cpp
@@ -98,16 +98,21 @@ void Symbol::dump(js::GenericPrinter& ou
       out.printf("undefined");
     }
 
     out.putChar(')');
 
     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_));
   }
 }
 #endif  // defined(DEBUG) || defined(JS_JITSPEW)
 
 bool js::SymbolDescriptiveString(JSContext* cx, Symbol* sym,
                                  MutableHandleValue result) {
--- a/js/src/vm/ToSource.cpp
+++ b/js/src/vm/ToSource.cpp
@@ -54,36 +54,44 @@ static JSString* StringToSource(JSContex
     return nullptr;
   }
   return NewStringCopyZ<CanGC>(cx, chars.get());
 }
 
 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;
     }
-  }
-  if (!buf.append(')')) {
-    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;
+    }
   }
   return buf.finishString();
 }
 
 static JSString* BoxedToSource(JSContext* cx, HandleObject obj,
                                const char* constructor) {
   RootedValue value(cx);
   if (!Unbox(cx, obj, &value)) {