Bug 1447442 - Part 2: Clean-up various calls to clarity. r=jorendorff
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 13 Apr 2018 02:25:58 -0700
changeset 413330 f1921838273471f888fa7de7874587cd879f987b
parent 413329 fde411a83e7f419be5c48b2a07e52c4c567059f5
child 413331 236f58368a5035b629217ccfeff52ed80f46142e
push id33843
push usernerli@mozilla.com
push dateSat, 14 Apr 2018 09:49:25 +0000
treeherdermozilla-central@37b8862d354e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1447442
milestone61.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 1447442 - Part 2: Clean-up various calls to clarity. r=jorendorff
js/src/jsapi.cpp
js/src/vm/AsyncIteration.cpp
js/src/vm/AsyncIteration.h
js/src/vm/JSObject-inl.h
js/src/vm/JSObject.cpp
js/src/vm/SelfHosting.cpp
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -957,18 +957,16 @@ JS_InitStandardClasses(JSContext* cx, Ha
     CHECK_REQUEST(cx);
 
     assertSameCompartment(cx, obj);
 
     Rooted<GlobalObject*> global(cx, &obj->global());
     return GlobalObject::initStandardClasses(cx, global);
 }
 
-#define EAGER_ATOM(name)            NAME_OFFSET(name)
-
 typedef struct JSStdName {
     size_t      atomOffset;     /* offset of atom pointer in JSAtomState */
     JSProtoKey  key;
     bool isDummy() const { return key == JSProto_Null; }
     bool isSentinel() const { return key == JSProto_LIMIT; }
 } JSStdName;
 
 static const JSStdName*
@@ -986,52 +984,50 @@ LookupStdName(const JSAtomState& names, 
     return nullptr;
 }
 
 /*
  * Table of standard classes, indexed by JSProtoKey. For entries where the
  * JSProtoKey does not correspond to a class with a meaningful constructor, we
  * insert a null entry into the table.
  */
-#define STD_NAME_ENTRY(name, init, clasp) { EAGER_ATOM(name), JSProto_##name },
+#define STD_NAME_ENTRY(name, init, clasp) { NAME_OFFSET(name), JSProto_##name },
 #define STD_DUMMY_ENTRY(name, init, dummy) { 0, JSProto_Null },
 static const JSStdName standard_class_names[] = {
   JS_FOR_PROTOTYPES(STD_NAME_ENTRY, STD_DUMMY_ENTRY)
   { 0, JSProto_LIMIT }
 };
 
 /*
  * Table of top-level function and constant names and the JSProtoKey of the
  * standard class that initializes them.
  */
 static const JSStdName builtin_property_names[] = {
-    { EAGER_ATOM(eval), JSProto_Object },
+    { NAME_OFFSET(eval), JSProto_Object },
 
     /* Global properties and functions defined by the Number class. */
-    { EAGER_ATOM(NaN), JSProto_Number },
-    { EAGER_ATOM(Infinity), JSProto_Number },
-    { EAGER_ATOM(isNaN), JSProto_Number },
-    { EAGER_ATOM(isFinite), JSProto_Number },
-    { EAGER_ATOM(parseFloat), JSProto_Number },
-    { EAGER_ATOM(parseInt), JSProto_Number },
+    { NAME_OFFSET(NaN), JSProto_Number },
+    { NAME_OFFSET(Infinity), JSProto_Number },
+    { NAME_OFFSET(isNaN), JSProto_Number },
+    { NAME_OFFSET(isFinite), JSProto_Number },
+    { NAME_OFFSET(parseFloat), JSProto_Number },
+    { NAME_OFFSET(parseInt), JSProto_Number },
 
     /* String global functions. */
-    { EAGER_ATOM(escape), JSProto_String },
-    { EAGER_ATOM(unescape), JSProto_String },
-    { EAGER_ATOM(decodeURI), JSProto_String },
-    { EAGER_ATOM(encodeURI), JSProto_String },
-    { EAGER_ATOM(decodeURIComponent), JSProto_String },
-    { EAGER_ATOM(encodeURIComponent), JSProto_String },
-    { EAGER_ATOM(uneval), JSProto_String },
+    { NAME_OFFSET(escape), JSProto_String },
+    { NAME_OFFSET(unescape), JSProto_String },
+    { NAME_OFFSET(decodeURI), JSProto_String },
+    { NAME_OFFSET(encodeURI), JSProto_String },
+    { NAME_OFFSET(decodeURIComponent), JSProto_String },
+    { NAME_OFFSET(encodeURIComponent), JSProto_String },
+    { NAME_OFFSET(uneval), JSProto_String },
 
     { 0, JSProto_LIMIT }
 };
 
-#undef EAGER_ATOM
-
 JS_PUBLIC_API(bool)
 JS_ResolveStandardClass(JSContext* cx, HandleObject obj, HandleId id, bool* resolved)
 {
     const JSStdName* stdnm;
 
     AssertHeapIsIdle();
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, obj, id);
@@ -6234,17 +6230,17 @@ JS_PUBLIC_API(JS::SymbolCode)
 JS::GetSymbolCode(Handle<Symbol*> symbol)
 {
     return symbol->code();
 }
 
 JS_PUBLIC_API(JS::Symbol*)
 JS::GetWellKnownSymbol(JSContext* cx, JS::SymbolCode which)
 {
-    return cx->wellKnownSymbols().get(uint32_t(which));
+    return cx->wellKnownSymbols().get(which);
 }
 
 #ifdef DEBUG
 static bool
 PropertySpecNameIsDigits(const char* s) {
     if (JS::PropertySpecNameIsSymbol(s))
         return false;
     if (!*s)
--- a/js/src/vm/AsyncIteration.cpp
+++ b/js/src/vm/AsyncIteration.cpp
@@ -189,21 +189,17 @@ AsyncFromSyncIteratorObject::create(JSCo
 
     RootedObject obj(cx, NewNativeObjectWithGivenProto(cx, &class_, proto));
     if (!obj)
         return nullptr;
 
     Handle<AsyncFromSyncIteratorObject*> asyncIter = obj.as<AsyncFromSyncIteratorObject>();
 
     // Step 3.
-    asyncIter->setIterator(iter);
-
-    // Spec update pending:
-    // https://github.com/tc39/proposal-async-iteration/issues/116
-    asyncIter->setNextMethod(nextMethod);
+    asyncIter->init(iter, nextMethod);
 
     // Step 4.
     return asyncIter;
 }
 
 // Async Iteration proposal 11.1.3.2.1 %AsyncFromSyncIteratorPrototype%.next.
 static bool
 AsyncFromSyncIteratorNext(JSContext* cx, unsigned argc, Value* vp)
--- a/js/src/vm/AsyncIteration.h
+++ b/js/src/vm/AsyncIteration.h
@@ -268,21 +268,18 @@ class AsyncFromSyncIteratorObject : publ
 {
   private:
     enum AsyncFromSyncIteratorObjectSlots {
         Slot_Iterator = 0,
         Slot_NextMethod = 1,
         Slots
     };
 
-    void setIterator(HandleObject iterator) {
+    void init(JSObject* iterator, const Value& nextMethod) {
         setFixedSlot(Slot_Iterator, ObjectValue(*iterator));
-    }
-
-    void setNextMethod(HandleValue nextMethod) {
         setFixedSlot(Slot_NextMethod, nextMethod);
     }
 
   public:
     static const Class class_;
 
     static JSObject*
     create(JSContext* cx, HandleObject iter, HandleValue nextMethod);
--- a/js/src/vm/JSObject-inl.h
+++ b/js/src/vm/JSObject-inl.h
@@ -622,17 +622,17 @@ NewObjectWithGivenTaggedProto(JSContext*
     return obj ? &obj->as<T>() : nullptr;
 }
 
 template <typename T>
 inline T*
 NewObjectWithNullTaggedProto(JSContext* cx, NewObjectKind newKind = GenericObject,
                              uint32_t initialShapeFlags = 0)
 {
-    Rooted<TaggedProto> nullProto(cx, TaggedProto(nullptr));
+    Handle<TaggedProto> nullProto = AsTaggedProto(nullptr);
     return NewObjectWithGivenTaggedProto<T>(cx, nullProto, newKind, initialShapeFlags);
 }
 
 inline JSObject*
 NewObjectWithGivenProto(JSContext* cx, const Class* clasp, HandleObject proto,
                         gc::AllocKind allocKind, NewObjectKind newKind)
 {
     return NewObjectWithGivenTaggedProto(cx, clasp, AsTaggedProto(proto), allocKind,
--- a/js/src/vm/JSObject.cpp
+++ b/js/src/vm/JSObject.cpp
@@ -4061,19 +4061,19 @@ js::SpeciesConstructor(JSContext* cx, Ha
                               "[Symbol.species] property of object's constructor");
     return nullptr;
 }
 
 MOZ_MUST_USE JSObject*
 js::SpeciesConstructor(JSContext* cx, HandleObject obj, JSProtoKey ctorKey,
                        bool (*isDefaultSpecies)(JSContext*, JSFunction*))
 {
-    if (!GlobalObject::ensureConstructor(cx, cx->global(), ctorKey))
+    RootedObject defaultCtor(cx, GlobalObject::getOrCreateConstructor(cx, ctorKey));
+    if (!defaultCtor)
         return nullptr;
-    RootedObject defaultCtor(cx, &cx->global()->getConstructor(ctorKey).toObject());
     return SpeciesConstructor(cx, obj, defaultCtor, isDefaultSpecies);
 }
 
 bool
 js::Unbox(JSContext* cx, HandleObject obj, MutableHandleValue vp)
 {
     if (MOZ_UNLIKELY(obj->is<ProxyObject>()))
         return Proxy::boxedValue_unbox(cx, obj, vp);
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -3078,17 +3078,17 @@ CloneValue(JSContext* cx, HandleValue se
         JSString* clone = CloneString(cx, selfHostedString);
         if (!clone)
             return false;
         vp.setString(clone);
     } else if (selfHostedValue.isSymbol()) {
         // Well-known symbols are shared.
         mozilla::DebugOnly<JS::Symbol*> sym = selfHostedValue.toSymbol();
         MOZ_ASSERT(sym->isWellKnownSymbol());
-        MOZ_ASSERT(cx->wellKnownSymbols().get(size_t(sym->code())) == sym);
+        MOZ_ASSERT(cx->wellKnownSymbols().get(sym->code()) == sym);
         vp.set(selfHostedValue);
     } else {
         MOZ_CRASH("Self-hosting CloneValue can't clone given value.");
     }
     return true;
 }
 
 bool