Bug 1147371: Implement IteratorClose for for-of

Issue #74
This commit is contained in:
janekptacijarabaci 2018-03-24 12:09:30 +01:00 committed by Roy Tam
commit 5f3e5dc3fb
13 changed files with 704 additions and 203 deletions

View file

@ -1171,13 +1171,19 @@ ProcessTryNotes(JSContext* cx, EnvironmentIter& ei, InterpreterRegs& regs)
SettleOnTryNote(cx, tn, ei, regs);
return FinallyContinuation;
case JSTRY_FOR_IN: {
case JSTRY_FOR_IN:
case JSTRY_ITERCLOSE: {
/* This is similar to JSOP_ENDITER in the interpreter loop. */
DebugOnly<jsbytecode*> pc = regs.fp()->script()->main() + tn->start + tn->length;
MOZ_ASSERT(JSOp(*pc) == JSOP_ENDITER);
MOZ_ASSERT_IF(tn->kind == JSTRY_FOR_IN, JSOp(*pc) == JSOP_ENDITER);
Value* sp = regs.spForStackDepth(tn->stackDepth);
RootedObject obj(cx, &sp[-1].toObject());
if (!UnwindIteratorForException(cx, obj)) {
bool ok;
if (tn->kind == JSTRY_FOR_IN)
ok = UnwindIteratorForException(cx, obj);
else
ok = IteratorCloseForException(cx, obj);
if (!ok) {
// We should only settle on the note only if
// UnwindIteratorForException itself threw, as
// onExceptionUnwind should be called anew with the new
@ -5040,7 +5046,12 @@ js::ThrowCheckIsObject(JSContext* cx, CheckIsObjectKind kind)
{
switch (kind) {
case CheckIsObjectKind::IteratorNext:
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_NEXT_RETURNED_PRIMITIVE);
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
JSMSG_ITER_METHOD_RETURNED_PRIMITIVE, "next");
break;
case CheckIsObjectKind::IteratorReturn:
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
JSMSG_ITER_METHOD_RETURNED_PRIMITIVE, "return");
break;
case CheckIsObjectKind::GetIterator:
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_GET_ITER_RETURNED_PRIMITIVE);