Bug 1544737 - Make AbstractGeneratorObject::ResumeKind an enum class, rename to js::GeneratorResumeKind. r=arai
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 16 Apr 2019 11:32:10 +0000
changeset 469662 6c23754dcb40
parent 469661 82531c8a2d73
child 469663 4b227d4b3377
push id35879
push usernerli@mozilla.com
push dateTue, 16 Apr 2019 22:01:48 +0000
treeherdermozilla-central@12a60898fdc1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1544737
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 1544737 - Make AbstractGeneratorObject::ResumeKind an enum class, rename to js::GeneratorResumeKind. r=arai Differential Revision: https://phabricator.services.mozilla.com/D27662
js/src/frontend/BytecodeEmitter.cpp
js/src/jit/BaselineCompiler.cpp
js/src/jit/VMFunctions.cpp
js/src/jit/VMFunctions.h
js/src/vm/GeneratorObject.cpp
js/src/vm/GeneratorObject.h
js/src/vm/Interpreter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -7020,18 +7020,18 @@ bool BytecodeEmitter::emitSelfHostedResu
 
   ParseNode* valNode = genNode->pn_next;
   if (!emitTree(valNode)) {
     return false;
   }
 
   ParseNode* kindNode = valNode->pn_next;
   MOZ_ASSERT(kindNode->isKind(ParseNodeKind::StringExpr));
-  uint8_t operand = AbstractGeneratorObject::getResumeKind(
-      cx, kindNode->as<NameNode>().atom());
+  uint8_t operand = uint8_t(AbstractGeneratorObject::getResumeKind(
+      cx, kindNode->as<NameNode>().atom()));
   MOZ_ASSERT(!kindNode->pn_next);
 
   if (!emit2(JSOP_RESUME, operand)) {
     return false;
   }
 
   return true;
 }
--- a/js/src/jit/BaselineCompiler.cpp
+++ b/js/src/jit/BaselineCompiler.cpp
@@ -5738,17 +5738,17 @@ bool BaselineCompilerCodeGen::emit_JSOP_
     regs.add(initLength);
   }
 
   masm.bind(&noExprStack);
   masm.pushValue(retVal);
 
   masm.switchToObjectRealm(genObj, scratch2);
 
-  if (resumeKind == AbstractGeneratorObject::NEXT) {
+  if (resumeKind == GeneratorResumeKind::Next) {
     // Determine the resume address based on the resumeIndex and the
     // resumeIndex -> native table in the BaselineScript.
     masm.load32(
         Address(scratch1, BaselineScript::offsetOfResumeEntriesOffset()),
         scratch2);
     masm.addPtr(scratch2, scratch1);
     masm.unboxInt32(
         Address(genObj, AbstractGeneratorObject::offsetOfResumeIndexSlot()),
@@ -5758,30 +5758,30 @@ bool BaselineCompilerCodeGen::emit_JSOP_
         scratch1);
 
     // Mark as running and jump to the generator's JIT code.
     masm.storeValue(
         Int32Value(AbstractGeneratorObject::RESUME_INDEX_RUNNING),
         Address(genObj, AbstractGeneratorObject::offsetOfResumeIndexSlot()));
     masm.jump(scratch1);
   } else {
-    MOZ_ASSERT(resumeKind == AbstractGeneratorObject::THROW ||
-               resumeKind == AbstractGeneratorObject::RETURN);
+    MOZ_ASSERT(resumeKind == GeneratorResumeKind::Throw ||
+               resumeKind == GeneratorResumeKind::Return);
 
     // Update the frame's frameSize field.
     masm.computeEffectiveAddress(
         Address(BaselineFrameReg, BaselineFrame::FramePointerOffset), scratch2);
     masm.movePtr(scratch2, scratch1);
     masm.subStackPtrFrom(scratch2);
     masm.store32(scratch2, Address(BaselineFrameReg,
                                    BaselineFrame::reverseOffsetOfFrameSize()));
     masm.loadBaselineFramePtr(BaselineFrameReg, scratch2);
 
     prepareVMCall();
-    pushArg(Imm32(resumeKind));
+    pushArg(Imm32(int32_t(resumeKind)));
     pushArg(retVal);
     pushArg(genObj);
     pushArg(scratch2);
 
     using Fn =
         bool (*)(JSContext*, BaselineFrame*, Handle<AbstractGeneratorObject*>,
                  HandleValue, uint32_t);
     TailCallVMFunctionId id =
@@ -5816,22 +5816,22 @@ bool BaselineCompilerCodeGen::emit_JSOP_
     // framePushed.
     masm.implicitPop((fun.explicitStackSlots() + 1) * sizeof(void*));
   }
 
   // If the generator script has no JIT code, call into the VM.
   masm.bind(&interpret);
 
   prepareVMCall();
-  if (resumeKind == AbstractGeneratorObject::NEXT) {
+  if (resumeKind == GeneratorResumeKind::Next) {
     pushArg(ImmGCPtr(cx->names().next));
-  } else if (resumeKind == AbstractGeneratorObject::THROW) {
+  } else if (resumeKind == GeneratorResumeKind::Throw) {
     pushArg(ImmGCPtr(cx->names().throw_));
   } else {
-    MOZ_ASSERT(resumeKind == AbstractGeneratorObject::RETURN);
+    MOZ_ASSERT(resumeKind == GeneratorResumeKind::Return);
     pushArg(ImmGCPtr(cx->names().return_));
   }
 
   masm.loadValue(frame.addressOfStackValue(-1), retVal);
   pushArg(retVal);
   pushArg(genObj);
 
   using Fn = bool (*)(JSContext*, HandleObject, HandleValue, HandlePropertyName,
--- a/js/src/jit/VMFunctions.cpp
+++ b/js/src/jit/VMFunctions.cpp
@@ -1018,35 +1018,37 @@ bool DebugAfterYield(JSContext* cx, Base
   }
 
   *mustReturn = false;
   return true;
 }
 
 bool GeneratorThrowOrReturn(JSContext* cx, BaselineFrame* frame,
                             Handle<AbstractGeneratorObject*> genObj,
-                            HandleValue arg, uint32_t resumeKind) {
+                            HandleValue arg, uint32_t resumeKindArg) {
   // Set the frame's pc to the current resume pc, so that frame iterators
   // work. This function always returns false, so we're guaranteed to enter
   // the exception handler where we will clear the pc.
   JSScript* script = frame->script();
   uint32_t offset = script->resumeOffsets()[genObj->resumeIndex()];
   jsbytecode* pc = script->offsetToPC(offset);
   frame->setOverridePc(pc);
 
   // In the interpreter, AbstractGeneratorObject::resume marks the generator as
   // running, so we do the same.
   genObj->setRunning();
 
   bool mustReturn = false;
   if (!DebugAfterYield(cx, frame, pc, &mustReturn)) {
     return false;
   }
+
+  GeneratorResumeKind resumeKind = GeneratorResumeKind(resumeKindArg);
   if (mustReturn) {
-    resumeKind = AbstractGeneratorObject::RETURN;
+    resumeKind = GeneratorResumeKind::Return;
   }
 
   MOZ_ALWAYS_FALSE(
       js::GeneratorThrowOrReturn(cx, frame, genObj, arg, resumeKind));
   return false;
 }
 
 bool GlobalNameConflictsCheckFromIon(JSContext* cx, HandleScript script) {
--- a/js/src/jit/VMFunctions.h
+++ b/js/src/jit/VMFunctions.h
@@ -939,17 +939,17 @@ MOZ_MUST_USE bool FinalSuspend(JSContext
 MOZ_MUST_USE bool InterpretResume(JSContext* cx, HandleObject obj,
                                   HandleValue val, HandlePropertyName kind,
                                   MutableHandleValue rval);
 MOZ_MUST_USE bool DebugAfterYield(JSContext* cx, BaselineFrame* frame,
                                   jsbytecode* pc, bool* mustReturn);
 MOZ_MUST_USE bool GeneratorThrowOrReturn(
     JSContext* cx, BaselineFrame* frame,
     Handle<AbstractGeneratorObject*> genObj, HandleValue arg,
-    uint32_t resumeKind);
+    uint32_t resumeKindArg);
 
 MOZ_MUST_USE bool GlobalNameConflictsCheckFromIon(JSContext* cx,
                                                   HandleScript script);
 MOZ_MUST_USE bool InitFunctionEnvironmentObjects(JSContext* cx,
                                                  BaselineFrame* frame);
 
 MOZ_MUST_USE bool NewArgumentsObject(JSContext* cx, BaselineFrame* frame,
                                      MutableHandleValue res);
--- a/js/src/vm/GeneratorObject.cpp
+++ b/js/src/vm/GeneratorObject.cpp
@@ -132,21 +132,22 @@ void js::SetGeneratorClosed(JSContext* c
   Shape* shape = callObj.lookup(cx, cx->names().dotGenerator);
   auto& genObj =
       callObj.getSlot(shape->slot()).toObject().as<AbstractGeneratorObject>();
   genObj.setClosed();
 }
 
 bool js::GeneratorThrowOrReturn(JSContext* cx, AbstractFramePtr frame,
                                 Handle<AbstractGeneratorObject*> genObj,
-                                HandleValue arg, uint32_t resumeKind) {
-  if (resumeKind == AbstractGeneratorObject::THROW) {
+                                HandleValue arg,
+                                GeneratorResumeKind resumeKind) {
+  if (resumeKind == GeneratorResumeKind::Throw) {
     cx->setPendingExceptionAndCaptureStack(arg);
   } else {
-    MOZ_ASSERT(resumeKind == AbstractGeneratorObject::RETURN);
+    MOZ_ASSERT(resumeKind == GeneratorResumeKind::Return);
 
     MOZ_ASSERT_IF(genObj->is<GeneratorObject>(), arg.isObject());
     frame.setReturnValue(arg);
 
     RootedValue closing(cx, MagicValue(JS_GENERATOR_CLOSING));
     cx->setPendingException(closing, nullptr);
     genObj->setClosing();
   }
--- a/js/src/vm/GeneratorObject.h
+++ b/js/src/vm/GeneratorObject.h
@@ -11,55 +11,55 @@
 #include "vm/ArgumentsObject.h"
 #include "vm/ArrayObject.h"
 #include "vm/JSContext.h"
 #include "vm/JSObject.h"
 #include "vm/Stack.h"
 
 namespace js {
 
+enum class GeneratorResumeKind { Next, Throw, Return };
+
 class AbstractGeneratorObject : public NativeObject {
  public:
   // Magic values stored in the resumeIndex slot when the generator is
   // running or closing. See the resumeIndex comment below.
   static const int32_t RESUME_INDEX_RUNNING = INT32_MAX;
   static const int32_t RESUME_INDEX_CLOSING = INT32_MAX - 1;
 
   enum {
     CALLEE_SLOT = 0,
     ENV_CHAIN_SLOT,
     ARGS_OBJ_SLOT,
     EXPRESSION_STACK_SLOT,
     RESUME_INDEX_SLOT,
     RESERVED_SLOTS
   };
 
-  enum ResumeKind { NEXT, THROW, RETURN };
-
  private:
   static bool suspend(JSContext* cx, HandleObject obj, AbstractFramePtr frame,
                       jsbytecode* pc, Value* vp, unsigned nvalues);
 
  public:
-  static inline ResumeKind getResumeKind(jsbytecode* pc) {
+  static GeneratorResumeKind getResumeKind(jsbytecode* pc) {
     MOZ_ASSERT(*pc == JSOP_RESUME);
     unsigned arg = GET_UINT8(pc);
-    MOZ_ASSERT(arg <= RETURN);
-    return static_cast<ResumeKind>(arg);
+    MOZ_ASSERT(arg <= unsigned(GeneratorResumeKind::Return));
+    return static_cast<GeneratorResumeKind>(arg);
   }
 
-  static inline ResumeKind getResumeKind(JSContext* cx, JSAtom* atom) {
+  static GeneratorResumeKind getResumeKind(JSContext* cx, JSAtom* atom) {
     if (atom == cx->names().next) {
-      return NEXT;
+      return GeneratorResumeKind::Next;
     }
     if (atom == cx->names().throw_) {
-      return THROW;
+      return GeneratorResumeKind::Throw;
     }
     MOZ_ASSERT(atom == cx->names().return_);
-    return RETURN;
+    return GeneratorResumeKind::Return;
   }
 
   static JSObject* create(JSContext* cx, AbstractFramePtr frame);
 
   static bool resume(JSContext* cx, InterpreterActivation& activation,
                      Handle<AbstractGeneratorObject*> genObj, HandleValue arg);
 
   static bool initialSuspend(JSContext* cx, HandleObject obj,
@@ -208,17 +208,17 @@ class GeneratorObject : public AbstractG
 
   static const Class class_;
 
   static GeneratorObject* create(JSContext* cx, HandleFunction fun);
 };
 
 bool GeneratorThrowOrReturn(JSContext* cx, AbstractFramePtr frame,
                             Handle<AbstractGeneratorObject*> obj,
-                            HandleValue val, uint32_t resumeKind);
+                            HandleValue val, GeneratorResumeKind resumeKind);
 
 /**
  * Return the generator object associated with the given frame. The frame must
  * be a call frame for a generator. If the generator object hasn't been created
  * yet, or hasn't been stored in the stack slot yet, this returns null.
  */
 AbstractGeneratorObject* GetGeneratorObjectForFrame(JSContext* cx,
                                                     AbstractFramePtr frame);
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -4103,20 +4103,20 @@ static MOZ_NEVER_INLINE JS_HAZ_JSNATIVE_
                 gen->isClosed());
             if (!ForcedReturn(cx, REGS)) {
               goto error;
             }
             goto successful_return_continuation;
         }
 
         switch (resumeKind) {
-          case AbstractGeneratorObject::NEXT:
+          case GeneratorResumeKind::Next:
             break;
-          case AbstractGeneratorObject::THROW:
-          case AbstractGeneratorObject::RETURN:
+          case GeneratorResumeKind::Throw:
+          case GeneratorResumeKind::Return:
             MOZ_ALWAYS_FALSE(GeneratorThrowOrReturn(cx, activation.regs().fp(),
                                                     gen, val, resumeKind));
             goto error;
           default:
             MOZ_CRASH("bad resumeKind");
         }
       }
       ADVANCE_AND_DISPATCH(0);