Bug 1343481 - Part 4: Add Add GeneratorObject.{isAfterYield,isAfterAwait}. r=shu
authorTooru Fujisawa <arai_a@mac.com>
Wed, 01 Mar 2017 20:40:05 +0900
changeset 374320 616903dd928563c67134208132320f43e38249e0
parent 374319 53a92e2f749e1263e72e0d38089758948d5d720a
child 374321 be60a3cf158e177f70a3f48d7904c0267676fe47
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1343481
milestone54.0a1
Bug 1343481 - Part 4: Add Add GeneratorObject.{isAfterYield,isAfterAwait}. r=shu
js/src/vm/GeneratorObject.cpp
js/src/vm/GeneratorObject.h
--- a/js/src/vm/GeneratorObject.cpp
+++ b/js/src/vm/GeneratorObject.cpp
@@ -371,8 +371,39 @@ js::CheckStarGeneratorResumptionValue(JS
         return false;
     if (!prop.isNativeProperty())
         return false;
     if (!prop.shape()->hasDefaultGetter())
         return false;
 
     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;
+}
--- a/js/src/vm/GeneratorObject.h
+++ b/js/src/vm/GeneratorObject.h
@@ -174,16 +174,23 @@ class GeneratorObject : public NativeObj
         setFixedSlot(CALLEE_SLOT, NullValue());
         setFixedSlot(ENV_CHAIN_SLOT, NullValue());
         setFixedSlot(ARGS_OBJ_SLOT, NullValue());
         setFixedSlot(EXPRESSION_STACK_SLOT, NullValue());
         setFixedSlot(YIELD_AND_AWAIT_INDEX_SLOT, NullValue());
         setFixedSlot(NEWTARGET_SLOT, NullValue());
     }
 
+    bool isAfterYield();
+    bool isAfterAwait();
+
+private:
+    bool isAfterYieldOrAwait(JSOp op);
+
+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);