Bug 1549340 - Use macro instead of static method to pass reinterpret_cast to constexpr. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Tue, 07 May 2019 06:53:28 +0000
changeset 531669 65ffa078d3b25af64079af4d0a443389c19f065b
parent 531668 067fd517e656b6276034dca9f0ed139fcf55b450
child 531670 71efb056f9e087b9c9213391a108ee73ca1d9610
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1549340
milestone68.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 1549340 - Use macro instead of static method to pass reinterpret_cast to constexpr. r=jandem Differential Revision: https://phabricator.services.mozilla.com/D30158
js/public/PropertySpec.h
--- a/js/public/PropertySpec.h
+++ b/js/public/PropertySpec.h
@@ -200,23 +200,16 @@ struct JSPropertySpec {
 
   static constexpr JSPropertySpec sentinel() {
     return JSPropertySpec(nullptr, 0,
                           AccessorsOrValue::fromAccessors(
                               JSPropertySpec::Accessor::noAccessor(),
                               JSPropertySpec::Accessor::noAccessor()));
   }
 
-  // Because reinterpret_cast cannot be used in constexpr, expose the
-  // static method to convert JS::SymbolCode to `name` parameter for
-  // {nativeAccessors, selfHostedAccessors,int32Value,stringValue}.
-  static const char* symbolToName(JS::SymbolCode symbol) {
-    return reinterpret_cast<const char*>(uint32_t(symbol) + 1);
-  }
-
   bool isAccessor() const { return !(flags & JSPROP_INTERNAL_USE_BIT); }
   JS_PUBLIC_API bool getValue(JSContext* cx,
                               JS::MutableHandle<JS::Value> value) const;
 
   bool isSelfHosted() const {
     MOZ_ASSERT(isAccessor());
 
 #ifdef DEBUG
@@ -251,46 +244,60 @@ struct JSPropertySpec {
   }
 
   void checkAccessorsAreSelfHosted() const {
     MOZ_ASSERT(!u.accessors.getter.selfHosted.unused);
     MOZ_ASSERT(!u.accessors.setter.selfHosted.unused);
   }
 };
 
+// JSPropertySpec::{nativeAccessors, selfHostedAccessors,int32Value,
+// stringValue} methods require symbol names to be casted to `const char*`,
+// and the cast is `reinterpret_cast`.
+//
+// Provide a macro for the cast because of the following reasons:
+//
+//   * `reinterpret_cast` cannot be used in constexpr
+//   * using non-constexpr static method in parameter disables constexpr of
+//     above methods
+//   * top-level `reinterpret_cast` doesn't disable constexpr of above methods
+//
+#define SYMBOL_TO_PROPERTY_NAME(symbol) \
+  reinterpret_cast<const char*>(uint32_t(symbol) + 1)
+
 #define JS_CHECK_ACCESSOR_FLAGS(flags)                                         \
   (static_cast<std::enable_if<((flags) & ~(JSPROP_ENUMERATE |                  \
                                            JSPROP_PERMANENT)) == 0>::type>(0), \
    (flags))
 
 #define JS_PSG(name, getter, flags)                                     \
   JSPropertySpec::nativeAccessors(name, JS_CHECK_ACCESSOR_FLAGS(flags), \
                                   getter, nullptr)
 #define JS_PSGS(name, getter, setter, flags)                            \
   JSPropertySpec::nativeAccessors(name, JS_CHECK_ACCESSOR_FLAGS(flags), \
                                   getter, nullptr, setter, nullptr)
-#define JS_SYM_GET(symbol, getter, flags)                     \
-  JSPropertySpec::nativeAccessors(                            \
-      JSPropertySpec::symbolToName(::JS::SymbolCode::symbol), \
+#define JS_SYM_GET(symbol, getter, flags)                \
+  JSPropertySpec::nativeAccessors(                       \
+      SYMBOL_TO_PROPERTY_NAME(::JS::SymbolCode::symbol), \
       JS_CHECK_ACCESSOR_FLAGS(flags), getter, nullptr)
 #define JS_SELF_HOSTED_GET(name, getterName, flags)                         \
   JSPropertySpec::selfHostedAccessors(name, JS_CHECK_ACCESSOR_FLAGS(flags), \
                                       getterName)
 #define JS_SELF_HOSTED_GETSET(name, getterName, setterName, flags)          \
   JSPropertySpec::selfHostedAccessors(name, JS_CHECK_ACCESSOR_FLAGS(flags), \
                                       getterName, setterName)
-#define JS_SELF_HOSTED_SYM_GET(symbol, getterName, flags)     \
-  JSPropertySpec::selfHostedAccessors(                        \
-      JSPropertySpec::symbolToName(::JS::SymbolCode::symbol), \
+#define JS_SELF_HOSTED_SYM_GET(symbol, getterName, flags) \
+  JSPropertySpec::selfHostedAccessors(                    \
+      SYMBOL_TO_PROPERTY_NAME(::JS::SymbolCode::symbol),  \
       JS_CHECK_ACCESSOR_FLAGS(flags), getterName)
 #define JS_STRING_PS(name, string, flags) \
   JSPropertySpec::stringValue(name, flags, string)
 #define JS_STRING_SYM_PS(symbol, string, flags) \
   JSPropertySpec::stringValue(                  \
-      JSPropertySpec::symbolToName(::JS::SymbolCode::symbol), flags, string)
+      SYMBOL_TO_PROPERTY_NAME(::JS::SymbolCode::symbol), flags, string)
 #define JS_INT32_PS(name, value, flags) \
   JSPropertySpec::int32Value(name, flags, value)
 #define JS_PS_END JSPropertySpec::sentinel()
 
 /**
  * To define a native function, set call to a JSNativeWrapper. To define a
  * self-hosted function, set selfHostedName to the name of a function
  * compiled during JSRuntime::initSelfHosting.