Bug 830369 - Refactor ScriptDebugPrologue and ScriptDebugEpilogue to use AbstractFramePtr. r=djvj

--HG--
extra : rebase_source : 86e1709f8b46556152001f890caa7baf2e2bddb0
This commit is contained in:
Jan de Mooij 2013-01-15 09:29:23 +01:00
parent 30851a942d
commit 553bca6cb2
4 changed files with 56 additions and 18 deletions

View File

@ -73,16 +73,18 @@ JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug)
}
JSTrapStatus
js::ScriptDebugPrologue(JSContext *cx, StackFrame *fp)
js::ScriptDebugPrologue(JSContext *cx, AbstractFramePtr frame)
{
JS_ASSERT(fp == cx->fp());
JS_ASSERT_IF(frame.isStackFrame(), frame.asStackFrame() == cx->fp());
if (fp->isFramePushedByExecute()) {
if (frame.isFramePushedByExecute()) {
if (JSInterpreterHook hook = cx->runtime->debugHooks.executeHook)
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->runtime->debugHooks.executeHookData));
frame.setHookData(hook(cx, Jsvalify(frame.asStackFrame()), true, 0,
cx->runtime->debugHooks.executeHookData));
} else {
if (JSInterpreterHook hook = cx->runtime->debugHooks.callHook)
fp->setHookData(hook(cx, Jsvalify(fp), true, 0, cx->runtime->debugHooks.callHookData));
frame.setHookData(hook(cx, Jsvalify(frame.asStackFrame()), true, 0,
cx->runtime->debugHooks.callHookData));
}
Value rval;
@ -97,7 +99,7 @@ js::ScriptDebugPrologue(JSContext *cx, StackFrame *fp)
cx->clearPendingException();
break;
case JSTRAP_RETURN:
fp->setReturnValue(rval);
frame.setReturnValue(rval);
break;
default:
JS_NOT_REACHED("bad Debugger::onEnterFrame JSTrapStatus value");
@ -106,18 +108,18 @@ js::ScriptDebugPrologue(JSContext *cx, StackFrame *fp)
}
bool
js::ScriptDebugEpilogue(JSContext *cx, StackFrame *fp, bool okArg)
js::ScriptDebugEpilogue(JSContext *cx, AbstractFramePtr frame, bool okArg)
{
JS_ASSERT(fp == cx->fp());
JS_ASSERT_IF(frame.isStackFrame(), frame.asStackFrame() == cx->fp());
JSBool ok = okArg;
if (void *hookData = fp->maybeHookData()) {
if (fp->isFramePushedByExecute()) {
if (void *hookData = frame.maybeHookData()) {
if (frame.isFramePushedByExecute()) {
if (JSInterpreterHook hook = cx->runtime->debugHooks.executeHook)
hook(cx, Jsvalify(fp), false, &ok, hookData);
hook(cx, Jsvalify(frame.asStackFrame()), false, &ok, hookData);
} else {
if (JSInterpreterHook hook = cx->runtime->debugHooks.callHook)
hook(cx, Jsvalify(fp), false, &ok, hookData);
hook(cx, Jsvalify(frame.asStackFrame()), false, &ok, hookData);
}
}

View File

@ -22,7 +22,7 @@ namespace js {
/*
* Announce to the debugger that the thread has entered a new JavaScript frame,
* |fp|. Call whatever hooks have been registered to observe new frames, and
* |frame|. Call whatever hooks have been registered to observe new frames, and
* return a JSTrapStatus code indication how execution should proceed:
*
* - JSTRAP_CONTINUE: Continue execution normally.
@ -35,18 +35,18 @@ namespace js {
* exception.
*
* - JSTRAP_RETURN: Return from the new frame immediately. ScriptDebugPrologue
* has set |cx->fp()|'s return value appropriately.
* has set |frame|'s return value appropriately.
*/
extern JSTrapStatus
ScriptDebugPrologue(JSContext *cx, StackFrame *fp);
ScriptDebugPrologue(JSContext *cx, AbstractFramePtr frame);
/*
* Announce to the debugger that the thread has exited a JavaScript frame, |fp|.
* Announce to the debugger that the thread has exited a JavaScript frame, |frame|.
* If |ok| is true, the frame is returning normally; if |ok| is false, the frame
* is throwing an exception or terminating.
*
* Call whatever hooks have been registered to observe frame exits. Change cx's
* current exception and |fp|'s return value to reflect the changes in behavior
* current exception and |frame|'s return value to reflect the changes in behavior
* the hooks request, if any. Return the new error/success value.
*
* This function may be called twice for the same outgoing frame; only the
@ -56,7 +56,7 @@ ScriptDebugPrologue(JSContext *cx, StackFrame *fp);
* alternative path, containing its own call to ScriptDebugEpilogue.)
*/
extern bool
ScriptDebugEpilogue(JSContext *cx, StackFrame *fp, bool ok);
ScriptDebugEpilogue(JSContext *cx, AbstractFramePtr frame, bool ok);
/*
* For a given |call|, convert null/undefined |this| into the global object for

View File

@ -609,6 +609,35 @@ StackIter::ionForEachCanonicalActualArg(Op op)
#endif
}
inline void *
AbstractFramePtr::maybeHookData() const
{
if (isStackFrame())
return asStackFrame()->maybeHookData();
JS_NOT_REACHED("Invalid frame");
return NULL;
}
inline void
AbstractFramePtr::setHookData(void *data) const
{
if (isStackFrame()) {
asStackFrame()->setHookData(data);
return;
}
JS_NOT_REACHED("Invalid frame");
}
inline void
AbstractFramePtr::setReturnValue(const Value &rval) const
{
if (isStackFrame()) {
asStackFrame()->setReturnValue(rval);
return;
}
JS_NOT_REACHED("Invalid frame");
}
inline UnrootedObject
AbstractFramePtr::scopeChain() const
{

View File

@ -1790,6 +1790,9 @@ class AbstractFramePtr
JS_NOT_REACHED("Invalid frame");
return false;
}
bool isFramePushedByExecute() const {
return isGlobalFrame() || isEvalFrame();
}
bool isDebuggerFrame() const {
if (isStackFrame())
return asStackFrame()->isDebuggerFrame();
@ -1898,6 +1901,10 @@ class AbstractFramePtr
JS_NOT_REACHED("Invalid frame");
return AbstractFramePtr();
}
inline void *maybeHookData() const;
inline void setHookData(void *data) const;
inline void setReturnValue(const Value &rval) const;
};
template <>