mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1544737 - Make AbstractGeneratorObject::ResumeKind an enum class, rename to js::GeneratorResumeKind. r=arai
Differential Revision: https://phabricator.services.mozilla.com/D27662 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b353df61ec
commit
f0d37eef6a
@ -7025,8 +7025,8 @@ bool BytecodeEmitter::emitSelfHostedResumeGenerator(BinaryNode* callNode) {
|
||||
|
||||
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)) {
|
||||
|
@ -5743,7 +5743,7 @@ bool BaselineCompilerCodeGen::emit_JSOP_RESUME() {
|
||||
|
||||
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(
|
||||
@ -5763,8 +5763,8 @@ bool BaselineCompilerCodeGen::emit_JSOP_RESUME() {
|
||||
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(
|
||||
@ -5776,7 +5776,7 @@ bool BaselineCompilerCodeGen::emit_JSOP_RESUME() {
|
||||
masm.loadBaselineFramePtr(BaselineFrameReg, scratch2);
|
||||
|
||||
prepareVMCall();
|
||||
pushArg(Imm32(resumeKind));
|
||||
pushArg(Imm32(int32_t(resumeKind)));
|
||||
pushArg(retVal);
|
||||
pushArg(genObj);
|
||||
pushArg(scratch2);
|
||||
@ -5821,12 +5821,12 @@ bool BaselineCompilerCodeGen::emit_JSOP_RESUME() {
|
||||
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_));
|
||||
}
|
||||
|
||||
|
@ -1023,7 +1023,7 @@ bool DebugAfterYield(JSContext* cx, BaselineFrame* frame, jsbytecode* pc,
|
||||
|
||||
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.
|
||||
@ -1040,8 +1040,10 @@ bool GeneratorThrowOrReturn(JSContext* cx, BaselineFrame* frame,
|
||||
if (!DebugAfterYield(cx, frame, pc, &mustReturn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GeneratorResumeKind resumeKind = GeneratorResumeKind(resumeKindArg);
|
||||
if (mustReturn) {
|
||||
resumeKind = AbstractGeneratorObject::RETURN;
|
||||
resumeKind = GeneratorResumeKind::Return;
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_FALSE(
|
||||
|
@ -944,7 +944,7 @@ MOZ_MUST_USE bool DebugAfterYield(JSContext* cx, BaselineFrame* frame,
|
||||
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);
|
||||
|
@ -137,11 +137,12 @@ void js::SetGeneratorClosed(JSContext* cx, AbstractFramePtr frame) {
|
||||
|
||||
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);
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
namespace js {
|
||||
|
||||
enum class GeneratorResumeKind { Next, Throw, Return };
|
||||
|
||||
class AbstractGeneratorObject : public NativeObject {
|
||||
public:
|
||||
// Magic values stored in the resumeIndex slot when the generator is
|
||||
@ -32,29 +34,27 @@ class AbstractGeneratorObject : public NativeObject {
|
||||
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);
|
||||
@ -213,7 +213,7 @@ class GeneratorObject : public AbstractGeneratorObject {
|
||||
|
||||
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
|
||||
|
@ -4108,10 +4108,10 @@ static MOZ_NEVER_INLINE JS_HAZ_JSNATIVE_CALLER bool Interpret(JSContext* cx,
|
||||
}
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user