JSTrapStatus js::ScriptDebugPrologue(JSContext *cx, AbstractFramePtr frame) { JS_ASSERT_IF(frame.isStackFrame(), frame.asStackFrame() == cx->fp()); if (frame.isFramePushedByExecute()) { if (JSInterpreterHook hook = cx->runtime->debugHooks.executeHook) frame.setHookData(hook(cx, Jsvalify(frame), IsTopFrameConstructing(cx, frame), true, 0, cx->runtime->debugHooks.executeHookData)); } else { if (JSInterpreterHook hook = cx->runtime->debugHooks.callHook) frame.setHookData(hook(cx, Jsvalify(frame), IsTopFrameConstructing(cx, frame), true, 0, cx->runtime->debugHooks.callHookData)); } RootedValue rval(cx); JSTrapStatus status = Debugger::onEnterFrame(cx, &rval); switch (status) { case JSTRAP_CONTINUE: break; case JSTRAP_THROW: cx->setPendingException(rval); break; case JSTRAP_ERROR: cx->clearPendingException(); break; case JSTRAP_RETURN: frame.setReturnValue(rval); break; default: JS_NOT_REACHED("bad Debugger::onEnterFrame JSTrapStatus value"); } return status; }
void js::SetReturnValueForClosingGenerator(JSContext* cx, AbstractFramePtr frame) { CallObject& callObj = frame.callObj(); // Get the generator object stored on the scope chain and close it. Shape* shape = callObj.lookup(cx, cx->names().dotGenerator); GeneratorObject& genObj = callObj.getSlot(shape->slot()).toObject().as<GeneratorObject>(); genObj.setClosed(); // Return value is already set in GeneratorThrowOrClose. if (genObj.is<StarGeneratorObject>()) return; // Legacy generator .close() always returns |undefined|. MOZ_ASSERT(genObj.is<LegacyGeneratorObject>()); frame.setReturnValue(UndefinedValue()); }
JSTrapStatus js::DebugExceptionUnwind(JSContext *cx, AbstractFramePtr frame, jsbytecode *pc) { JS_ASSERT(cx->compartment()->debugMode()); if (!cx->runtime()->debugHooks.throwHook && cx->compartment()->getDebuggees().empty()) return JSTRAP_CONTINUE; /* Call debugger throw hook if set. */ RootedValue rval(cx); JSTrapStatus status = Debugger::onExceptionUnwind(cx, &rval); if (status == JSTRAP_CONTINUE) { if (JSThrowHook handler = cx->runtime()->debugHooks.throwHook) { RootedScript script(cx, frame.script()); status = handler(cx, script, pc, rval.address(), cx->runtime()->debugHooks.throwHookData); } } switch (status) { case JSTRAP_ERROR: cx->clearPendingException(); break; case JSTRAP_RETURN: cx->clearPendingException(); frame.setReturnValue(rval); break; case JSTRAP_THROW: cx->setPendingException(rval); break; case JSTRAP_CONTINUE: break; default: MOZ_ASSUME_UNREACHABLE("Invalid trap status"); } return status; }
bool js::GeneratorThrowOrClose(JSContext* cx, AbstractFramePtr frame, Handle<GeneratorObject*> genObj, HandleValue arg, uint32_t resumeKind) { if (resumeKind == GeneratorObject::THROW) { cx->setPendingException(arg); genObj->setRunning(); } else { MOZ_ASSERT(resumeKind == GeneratorObject::CLOSE); if (genObj->is<StarGeneratorObject>()) { MOZ_ASSERT(arg.isObject()); frame.setReturnValue(arg); } else { MOZ_ASSERT(arg.isUndefined()); } cx->setPendingException(MagicValue(JS_GENERATOR_CLOSING)); genObj->setClosing(); } return false; }
void js::SetReturnValueForClosingGenerator(JSContext *cx, AbstractFramePtr frame) { CallObject &callObj = frame.callObj(); // Get the generator object stored on the scope chain and close it. Shape *shape = callObj.lookup(cx, cx->names().dotGenerator); GeneratorObject &genObj = callObj.getSlot(shape->slot()).toObject().as<GeneratorObject>(); genObj.setClosed(); Value v; if (genObj.is<StarGeneratorObject>()) { // The return value is stored in the .genrval slot. shape = callObj.lookup(cx, cx->names().dotGenRVal); v = callObj.getSlot(shape->slot()); } else { // Legacy generator .close() always returns |undefined|. MOZ_ASSERT(genObj.is<LegacyGeneratorObject>()); v = UndefinedValue(); } frame.setReturnValue(v); }
JSTrapStatus js::ScriptDebugPrologue(JSContext *cx, AbstractFramePtr frame, jsbytecode *pc) { JS_ASSERT_IF(frame.isInterpreterFrame(), frame.asInterpreterFrame() == cx->interpreterFrame()); if (!frame.script()->selfHosted()) { JSAbstractFramePtr jsframe(frame.raw(), pc); if (frame.isFramePushedByExecute()) { if (JSInterpreterHook hook = cx->runtime()->debugHooks.executeHook) frame.setHookData(hook(cx, jsframe, IsTopFrameConstructing(cx, frame), true, 0, cx->runtime()->debugHooks.executeHookData)); } else { if (JSInterpreterHook hook = cx->runtime()->debugHooks.callHook) frame.setHookData(hook(cx, jsframe, IsTopFrameConstructing(cx, frame), true, 0, cx->runtime()->debugHooks.callHookData)); } } RootedValue rval(cx); JSTrapStatus status = Debugger::onEnterFrame(cx, frame, &rval); switch (status) { case JSTRAP_CONTINUE: break; case JSTRAP_THROW: cx->setPendingException(rval); break; case JSTRAP_ERROR: cx->clearPendingException(); break; case JSTRAP_RETURN: frame.setReturnValue(rval); break; default: MOZ_ASSUME_UNREACHABLE("bad Debugger::onEnterFrame JSTrapStatus value"); } return status; }