Skip to content

Commit

Permalink
Bug 1334314 - Fix debug mode OSR exception handling for IteratorClose…
Browse files Browse the repository at this point in the history
… trynotes

Issue #74
  • Loading branch information
janekptacijarabaci committed Mar 25, 2018
1 parent e7a220a commit 2818e8d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
16 changes: 16 additions & 0 deletions js/src/jit-test/tests/ion/bug1334314.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// |jit-test| error: TypeError

var g = newGlobal();
g.parent = this;
g.eval("new Debugger(parent).onExceptionUnwind = function () { };");

function f() {
[[]] = [];
}
try {
f();
} catch (e) {};
try {
f();
} catch (e) {};
f();
41 changes: 32 additions & 9 deletions js/src/jit/BaselineBailouts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ GetNextNonLoopEntryPc(jsbytecode* pc)
}

static bool
HasLiveIteratorAtStackDepth(JSScript* script, jsbytecode* pc, uint32_t stackDepth)
HasLiveStackValueAtDepth(JSScript* script, jsbytecode* pc, uint32_t stackDepth)
{
if (!script->hasTrynotes())
return false;
Expand All @@ -501,14 +501,37 @@ HasLiveIteratorAtStackDepth(JSScript* script, jsbytecode* pc, uint32_t stackDept
if (pcOffset >= tn->start + tn->length)
continue;

// For-in loops have only the iterator on stack.
if (tn->kind == JSTRY_FOR_IN && stackDepth == tn->stackDepth)
return true;
switch (tn->kind) {
case JSTRY_FOR_IN:
// For-in loops have only the iterator on stack.
if (stackDepth == tn->stackDepth)
return true;
break;

case JSTRY_FOR_OF:
// For-of loops have both the iterator and the result object on
// stack. The iterator is below the result object.
if (stackDepth == tn->stackDepth - 1)
return true;
break;

case JSTRY_ITERCLOSE:
// Code that need to call IteratorClose have the iterator on the
// stack.
if (stackDepth == tn->stackDepth)
return true;
break;

// For-of loops have both the iterator and the result object on
// stack. The iterator is below the result object.
if (tn->kind == JSTRY_FOR_OF && stackDepth == tn->stackDepth - 1)
return true;
case JSTRY_DESTRUCTURING_ITERCLOSE:
// Destructuring code that need to call IteratorClose have both
// the iterator and the "done" value on the stack.
if (stackDepth == tn->stackDepth || stackDepth == tn->stackDepth - 1)
return true;
break;

default:
break;
}
}

return false;
Expand Down Expand Up @@ -945,7 +968,7 @@ InitFromBailout(JSContext* cx, HandleScript caller, jsbytecode* callerPC,
// iterators, however, so read them out. They will be closed by
// HandleExceptionBaseline.
MOZ_ASSERT(cx->compartment()->isDebuggee());
if (iter.moreFrames() || HasLiveIteratorAtStackDepth(script, pc, i + 1)) {
if (iter.moreFrames() || HasLiveStackValueAtDepth(script, pc, i + 1)) {
v = iter.read();
} else {
iter.skip();
Expand Down

0 comments on commit 2818e8d

Please sign in to comment.