diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2019-12-03 17:34:06 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2019-12-17 06:25:24 -0500 |
commit | 73c8732000a5d594322c8aa33840a3449cf8bd4e (patch) | |
tree | fa688737684140c660c2a15fca453d091c5cceee /js | |
parent | 3a3de55aadd9d3a2aafc3638c7a9b0c23584cef4 (diff) | |
download | UXP-73c8732000a5d594322c8aa33840a3449cf8bd4e.tar UXP-73c8732000a5d594322c8aa33840a3449cf8bd4e.tar.gz UXP-73c8732000a5d594322c8aa33840a3449cf8bd4e.tar.lz UXP-73c8732000a5d594322c8aa33840a3449cf8bd4e.tar.xz UXP-73c8732000a5d594322c8aa33840a3449cf8bd4e.zip |
Bug 1343481 - Part 4: Add Add GeneratorObject.{isAfterYield,isAfterAwait}.
Tag #1287
Diffstat (limited to 'js')
-rw-r--r-- | js/src/vm/GeneratorObject.cpp | 31 | ||||
-rw-r--r-- | js/src/vm/GeneratorObject.h | 7 |
2 files changed, 38 insertions, 0 deletions
diff --git a/js/src/vm/GeneratorObject.cpp b/js/src/vm/GeneratorObject.cpp index a61d37132..11c686f28 100644 --- a/js/src/vm/GeneratorObject.cpp +++ b/js/src/vm/GeneratorObject.cpp @@ -370,3 +370,34 @@ js::CheckStarGeneratorResumptionValue(JSContext* cx, HandleValue v) return true; } + +bool +GeneratorObject::isAfterYield() +{ + return isAfterYieldOrAwait(JSOP_YIELD); +} + +bool +GeneratorObject::isAfterAwait() +{ + return isAfterYieldOrAwait(JSOP_AWAIT); +} + +bool +GeneratorObject::isAfterYieldOrAwait(JSOp op) +{ + if (isClosed() || isClosing() || isRunning()) + return false; + + JSScript* script = callee().nonLazyScript(); + jsbytecode* code = script->code(); + uint32_t nextOffset = script->yieldAndAwaitOffsets()[yieldAndAwaitIndex()]; + if (code[nextOffset] != JSOP_DEBUGAFTERYIELD) + return false; + + uint32_t offset = nextOffset - JSOP_YIELD_LENGTH; + MOZ_ASSERT(code[offset] == JSOP_INITIALYIELD || code[offset] == JSOP_YIELD || + code[offset] == JSOP_AWAIT); + + return code[offset] == op; +} diff --git a/js/src/vm/GeneratorObject.h b/js/src/vm/GeneratorObject.h index beb15f790..f19ca2aac 100644 --- a/js/src/vm/GeneratorObject.h +++ b/js/src/vm/GeneratorObject.h @@ -179,6 +179,13 @@ class GeneratorObject : public NativeObject setFixedSlot(NEWTARGET_SLOT, NullValue()); } + bool isAfterYield(); + bool isAfterAwait(); + +private: + bool isAfterYieldOrAwait(JSOp op); + +public: static size_t offsetOfCalleeSlot() { return getFixedSlotOffset(CALLEE_SLOT); } |