Bug 1083482 part 6 - Merge GeneratorObject and StarGeneratorObject. r=arai
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 02 Nov 2017 13:58:45 +0100
changeset 440612 0ad093cafc3034a9fc1b925a53e603306de36d5c
parent 440611 efaccf22b2533dc2f58382649c72de56e0545b3f
child 440613 def80dfc06543c1fe60518bbb8d21a456bef9f01
push id8118
push userryanvm@gmail.com
push dateFri, 03 Nov 2017 00:38:34 +0000
treeherdermozilla-beta@1c336e874ae8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1083482
milestone58.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 1083482 part 6 - Merge GeneratorObject and StarGeneratorObject. r=arai
js/src/jit/BaselineIC.cpp
js/src/vm/GeneratorObject.cpp
js/src/vm/GeneratorObject.h
js/src/vm/SelfHosting.cpp
--- a/js/src/jit/BaselineIC.cpp
+++ b/js/src/jit/BaselineIC.cpp
@@ -3449,26 +3449,26 @@ ICCall_IsSuspendedStarGenerator::Compile
     // Check if it's an object.
     Label returnFalse;
     Register genObj = regs.takeAny();
     masm.branchTestObject(Assembler::NotEqual, argVal, &returnFalse);
     masm.unboxObject(argVal, genObj);
 
     // Check if it's a StarGeneratorObject.
     Register scratch = regs.takeAny();
-    masm.branchTestObjClass(Assembler::NotEqual, genObj, scratch, &StarGeneratorObject::class_,
+    masm.branchTestObjClass(Assembler::NotEqual, genObj, scratch, &GeneratorObject::class_,
                             &returnFalse);
 
     // If the yield index slot holds an int32 value < YIELD_AND_AWAIT_INDEX_CLOSING,
     // the generator is suspended.
     masm.loadValue(Address(genObj, GeneratorObject::offsetOfYieldAndAwaitIndexSlot()), argVal);
     masm.branchTestInt32(Assembler::NotEqual, argVal, &returnFalse);
     masm.unboxInt32(argVal, scratch);
     masm.branch32(Assembler::AboveOrEqual, scratch,
-                  Imm32(StarGeneratorObject::YIELD_AND_AWAIT_INDEX_CLOSING),
+                  Imm32(GeneratorObject::YIELD_AND_AWAIT_INDEX_CLOSING),
                   &returnFalse);
 
     masm.moveValue(BooleanValue(true), R0);
     EmitReturnFromIC(masm);
 
     masm.bind(&returnFalse);
     masm.moveValue(BooleanValue(false), R0);
     EmitReturnFromIC(masm);
--- a/js/src/vm/GeneratorObject.cpp
+++ b/js/src/vm/GeneratorObject.cpp
@@ -33,17 +33,17 @@ GeneratorObject::create(JSContext* cx, A
         return nullptr;
     RootedObject proto(cx, pval.isObject() ? &pval.toObject() : nullptr);
     if (!proto) {
         proto = GlobalObject::getOrCreateStarGeneratorObjectPrototype(cx, global);
         if (!proto)
             return nullptr;
     }
     RootedNativeObject obj(cx,
-                           NewNativeObjectWithGivenProto(cx, &StarGeneratorObject::class_, proto));
+                           NewNativeObjectWithGivenProto(cx, &GeneratorObject::class_, proto));
     if (!obj)
         return nullptr;
 
     GeneratorObject* genObj = &obj->as<GeneratorObject>();
     genObj->setCallee(*frame.callee());
     genObj->setNewTarget(frame.newTarget());
     genObj->setEnvironmentChain(*frame.environmentChain());
     if (frame.script()->needsArgsObj())
@@ -118,22 +118,18 @@ js::GeneratorThrowOrClose(JSContext* cx,
                           HandleValue arg, uint32_t resumeKind)
 {
     if (resumeKind == GeneratorObject::THROW) {
         cx->setPendingException(arg);
         genObj->setRunning();
     } else {
         MOZ_ASSERT(resumeKind == GeneratorObject::CLOSE);
 
-        if (genObj->is<StarGeneratorObject>()) {
-            MOZ_ASSERT(arg.isObject());
-            frame.setReturnValue(arg);
-        } else {
-            MOZ_ASSERT(arg.isUndefined());
-        }
+        MOZ_ASSERT(arg.isObject());
+        frame.setReturnValue(arg);
 
         cx->setPendingException(MagicValue(JS_GENERATOR_CLOSING));
         genObj->setClosing();
     }
     return false;
 }
 
 bool
@@ -182,17 +178,17 @@ GeneratorObject::resume(JSContext* cx, I
       case CLOSE:
         return GeneratorThrowOrClose(cx, activation.regs().fp(), genObj, arg, resumeKind);
 
       default:
         MOZ_CRASH("bad resumeKind");
     }
 }
 
-const Class StarGeneratorObject::class_ = {
+const Class GeneratorObject::class_ = {
     "Generator",
     JSCLASS_HAS_RESERVED_SLOTS(GeneratorObject::RESERVED_SLOTS)
 };
 
 static const JSFunctionSpec star_generator_methods[] = {
     JS_SELF_HOSTED_FN("next", "StarGeneratorNext", 1, 0),
     JS_SELF_HOSTED_FN("throw", "StarGeneratorThrow", 1, 0),
     JS_SELF_HOSTED_FN("return", "StarGeneratorReturn", 1, 0),
--- a/js/src/vm/GeneratorObject.h
+++ b/js/src/vm/GeneratorObject.h
@@ -31,16 +31,18 @@ class GeneratorObject : public NativeObj
         EXPRESSION_STACK_SLOT,
         YIELD_AND_AWAIT_INDEX_SLOT,
         NEWTARGET_SLOT,
         RESERVED_SLOTS
     };
 
     enum ResumeKind { NEXT, THROW, CLOSE };
 
+    static const Class class_;
+
   private:
     static bool suspend(JSContext* cx, HandleObject obj, AbstractFramePtr frame, jsbytecode* pc,
                         Value* vp, unsigned nvalues);
 
   public:
     static inline ResumeKind getResumeKind(jsbytecode* pc) {
         MOZ_ASSERT(*pc == JSOP_RESUME);
         unsigned arg = GET_UINT16(pc);
@@ -180,20 +182,20 @@ class GeneratorObject : public NativeObj
         setFixedSlot(EXPRESSION_STACK_SLOT, NullValue());
         setFixedSlot(YIELD_AND_AWAIT_INDEX_SLOT, NullValue());
         setFixedSlot(NEWTARGET_SLOT, NullValue());
     }
 
     bool isAfterYield();
     bool isAfterAwait();
 
-private:
+  private:
     bool isAfterYieldOrAwait(JSOp op);
 
-public:
+  public:
     static size_t offsetOfCalleeSlot() {
         return getFixedSlotOffset(CALLEE_SLOT);
     }
     static size_t offsetOfEnvironmentChainSlot() {
         return getFixedSlotOffset(ENV_CHAIN_SLOT);
     }
     static size_t offsetOfArgsObjSlot() {
         return getFixedSlotOffset(ARGS_OBJ_SLOT);
@@ -204,31 +206,18 @@ public:
     static size_t offsetOfExpressionStackSlot() {
         return getFixedSlotOffset(EXPRESSION_STACK_SLOT);
     }
     static size_t offsetOfNewTargetSlot() {
         return getFixedSlotOffset(NEWTARGET_SLOT);
     }
 };
 
-class StarGeneratorObject : public GeneratorObject
-{
-  public:
-    static const Class class_;
-};
-
 bool GeneratorThrowOrClose(JSContext* cx, AbstractFramePtr frame, Handle<GeneratorObject*> obj,
                            HandleValue val, uint32_t resumeKind);
 void SetGeneratorClosed(JSContext* cx, AbstractFramePtr frame);
 
 MOZ_MUST_USE bool
 CheckStarGeneratorResumptionValue(JSContext* cx, HandleValue v);
 
 } // namespace js
 
-template<>
-inline bool
-JSObject::is<js::GeneratorObject>() const
-{
-    return is<js::StarGeneratorObject>();
-}
-
 #endif /* vm_GeneratorObject_h */
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -835,33 +835,33 @@ intrinsic_SetCanonicalName(JSContext* cx
 
 static bool
 intrinsic_StarGeneratorObjectIsClosed(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     MOZ_ASSERT(args.length() == 1);
     MOZ_ASSERT(args[0].isObject());
 
-    StarGeneratorObject* genObj = &args[0].toObject().as<StarGeneratorObject>();
+    GeneratorObject* genObj = &args[0].toObject().as<GeneratorObject>();
     args.rval().setBoolean(genObj->isClosed());
     return true;
 }
 
 bool
 js::intrinsic_IsSuspendedStarGenerator(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     MOZ_ASSERT(args.length() == 1);
 
-    if (!args[0].isObject() || !args[0].toObject().is<StarGeneratorObject>()) {
+    if (!args[0].isObject() || !args[0].toObject().is<GeneratorObject>()) {
         args.rval().setBoolean(false);
         return true;
     }
 
-    StarGeneratorObject& genObj = args[0].toObject().as<StarGeneratorObject>();
+    GeneratorObject& genObj = args[0].toObject().as<GeneratorObject>();
     args.rval().setBoolean(!genObj.isClosed() && genObj.isSuspended());
     return true;
 }
 
 static bool
 intrinsic_GeneratorIsRunning(JSContext* cx, unsigned argc, Value* vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
@@ -2372,17 +2372,17 @@ static const JSFunctionSpec intrinsic_fu
 
 
     JS_INLINABLE_FN("NewStringIterator", intrinsic_NewStringIterator,   0,0,
                     IntrinsicNewStringIterator),
     JS_FN("CallStringIteratorMethodIfWrapped",
           CallNonGenericSelfhostedMethod<Is<StringIteratorObject>>,     2,0),
 
     JS_FN("IsStarGeneratorObject",
-          intrinsic_IsInstanceOfBuiltin<StarGeneratorObject>,           1,0),
+          intrinsic_IsInstanceOfBuiltin<GeneratorObject>,               1,0),
     JS_FN("StarGeneratorObjectIsClosed", intrinsic_StarGeneratorObjectIsClosed, 1,0),
     JS_FN("IsSuspendedStarGenerator",intrinsic_IsSuspendedStarGenerator,1,0),
 
     JS_FN("GeneratorIsRunning",      intrinsic_GeneratorIsRunning,      1,0),
     JS_FN("GeneratorSetClosed",      intrinsic_GeneratorSetClosed,      1,0),
 
     JS_FN("IsArrayBuffer",
           intrinsic_IsInstanceOfBuiltin<ArrayBufferObject>,             1,0),
@@ -2445,17 +2445,17 @@ static const JSFunctionSpec intrinsic_fu
     JS_FN("CallArrayBufferMethodIfWrapped",
           CallNonGenericSelfhostedMethod<Is<ArrayBufferObject>>, 2, 0),
     JS_FN("CallSharedArrayBufferMethodIfWrapped",
           CallNonGenericSelfhostedMethod<Is<SharedArrayBufferObject>>, 2, 0),
     JS_FN("CallTypedArrayMethodIfWrapped",
           CallNonGenericSelfhostedMethod<Is<TypedArrayObject>>, 2, 0),
 
     JS_FN("CallStarGeneratorMethodIfWrapped",
-          CallNonGenericSelfhostedMethod<Is<StarGeneratorObject>>, 2, 0),
+          CallNonGenericSelfhostedMethod<Is<GeneratorObject>>, 2, 0),
 
     JS_INLINABLE_FN("IsMapObject", intrinsic_IsInstanceOfBuiltin<MapObject>, 1, 0,
                     IntrinsicIsMapObject),
     JS_FN("CallMapMethodIfWrapped", CallNonGenericSelfhostedMethod<Is<MapObject>>, 2, 0),
 
     JS_INLINABLE_FN("IsSetObject", intrinsic_IsInstanceOfBuiltin<SetObject>, 1, 0,
                     IntrinsicIsSetObject),
     JS_FN("CallSetMethodIfWrapped", CallNonGenericSelfhostedMethod<Is<SetObject>>, 2, 0),