Remove JS_GetScriptedCaller (bug 732652, r=luke,mrbkap,bholley,smaug,bent).

This commit is contained in:
David Anderson 2012-03-06 15:33:12 -08:00
parent bdbd0a6430
commit a02e3e035e
17 changed files with 116 additions and 103 deletions

View File

@ -1550,17 +1550,12 @@ nsWebSocket::Init(nsIPrincipal* aPrincipal,
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
JSContext* cx = nsnull;
if (stack && NS_SUCCEEDED(stack->Peek(&cx)) && cx) {
JSStackFrame *fp = JS_GetScriptedCaller(cx, NULL);
if (fp) {
JSScript *script = JS_GetFrameScript(cx, fp);
if (script) {
mScriptFile = JS_GetScriptFilename(cx, script);
}
unsigned lineno;
JSScript *script;
jsbytecode *pc = JS_GetFramePC(cx, fp);
if (script && pc) {
mScriptLine = JS_PCToLineNumber(cx, script, pc);
}
if (JS_DescribeScriptedCaller(cx, &script, &lineno)) {
mScriptFile = JS_GetScriptFilename(cx, script);
mScriptLine = lineno;
}
mInnerWindowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx);

View File

@ -739,8 +739,11 @@ nsJSContext::DOMOperationCallback(JSContext *cx)
NS_ENSURE_TRUE(prompt, JS_FALSE);
// Check if we should offer the option to debug
JSStackFrame* fp = ::JS_GetScriptedCaller(cx, NULL);
bool debugPossible = fp && js::CanCallContextDebugHandler(cx);
JSScript *script;
unsigned lineno;
JSBool hasFrame = ::JS_DescribeScriptedCaller(cx, &script, &lineno);
bool debugPossible = hasFrame && js::CanCallContextDebugHandler(cx);
#ifdef MOZ_JSDEBUGGER
// Get the debugger service if necessary.
if (debugPossible) {
@ -805,7 +808,6 @@ nsJSContext::DOMOperationCallback(JSContext *cx)
}
// Append file and line number information, if available
JSScript *script = fp ? ::JS_GetFrameScript(cx, fp) : nsnull;
if (script) {
const char *filename = ::JS_GetScriptFilename(cx, script);
if (filename) {
@ -820,17 +822,8 @@ nsJSContext::DOMOperationCallback(JSContext *cx)
if (NS_SUCCEEDED(rv) && scriptLocation) {
msg.AppendLiteral("\n\n");
msg.Append(scriptLocation);
JSStackFrame *fp, *iterator = nsnull;
fp = ::JS_FrameIterator(cx, &iterator);
if (fp) {
jsbytecode *pc = ::JS_GetFramePC(cx, fp);
if (pc) {
PRUint32 lineno = ::JS_PCToLineNumber(cx, script, pc);
msg.Append(':');
msg.AppendInt(lineno);
}
}
msg.Append(':');
msg.AppendInt(lineno);
}
}
}
@ -867,22 +860,7 @@ nsJSContext::DOMOperationCallback(JSContext *cx)
return JS_TRUE;
}
else if ((buttonPressed == 2) && debugPossible) {
// Debug the script
jsval rval;
switch (js::CallContextDebugHandler(cx, script, JS_GetFramePC(cx, fp), &rval)) {
case JSTRAP_RETURN:
JS_SetFrameReturnValue(cx, fp, rval);
return JS_TRUE;
case JSTRAP_ERROR:
JS_ClearPendingException(cx);
return JS_FALSE;
case JSTRAP_THROW:
JS_SetPendingException(cx, rval);
return JS_FALSE;
case JSTRAP_CONTINUE:
default:
return JS_TRUE;
}
return js_CallContextDebugHandler(cx);
}
JS_ClearPendingException(cx);

View File

@ -2528,13 +2528,8 @@ WorkerPrivate::Create(JSContext* aCx, JSObject* aObj, WorkerPrivate* aParent,
// We're being created outside of a window. Need to figure out the script
// that is creating us in order for us to use relative URIs later on.
JSStackFrame* frame = JS_GetScriptedCaller(aCx, nsnull);
if (frame) {
JSScript* script = JS_GetFrameScript(aCx, frame);
if (!script) {
JS_ReportError(aCx, "Could not get frame script!");
return nsnull;
}
JSScript *script;
if (JS_DescribeScriptedCaller(aCx, &script, nsnull)) {
if (NS_FAILED(NS_NewURI(getter_AddRefs(baseURI),
JS_GetScriptFilename(aCx, script)))) {
JS_ReportError(aCx, "Failed to construct base URI!");

View File

@ -273,10 +273,10 @@ BEGIN_TEST(testDebugger_singleStepThrow)
static JSBool
setStepMode(JSContext *cx, unsigned argc, jsval *vp)
{
JSStackFrame *fp = JS_GetScriptedCaller(cx, NULL);
JS_ASSERT(fp);
JSScript *script = JS_GetFrameScript(cx, fp);
JSScript *script;
JS_DescribeScriptedCaller(cx, &script, NULL);
JS_ASSERT(script);
if (!JS_SetSingleStepMode(cx, script, true))
return false;
JS_SET_RVAL(cx, vp, JSVAL_VOID);

View File

@ -6638,6 +6638,25 @@ JS_IsIdentifier(JSContext *cx, JSString *str, JSBool *isIdentifier)
return true;
}
JS_PUBLIC_API(JSBool)
JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno)
{
if (script)
*script = NULL;
if (lineno)
*lineno = 0;
FrameRegsIter i(cx);
if (i.done())
return JS_FALSE;
if (script)
*script = i.script();
if (lineno)
*lineno = js::PCToLineNumber(i.script(), i.pc());
return JS_TRUE;
}
#ifdef JS_THREADSAFE
static PRStatus
CallOnce(void *func)

View File

@ -5426,6 +5426,14 @@ JS_IndexToId(JSContext *cx, uint32_t index, jsid *id);
extern JS_PUBLIC_API(JSBool)
JS_IsIdentifier(JSContext *cx, JSString *str, JSBool *isIdentifier);
/*
* Return the current script and line number of the most currently running
* frame. Returns true if a scripted frame was found, false otherwise.
*/
extern JS_PUBLIC_API(JSBool)
JS_DescribeScriptedCaller(JSContext *cx, JSScript **script, unsigned *lineno);
JS_END_EXTERN_C
#endif /* jsapi_h___ */

View File

@ -919,17 +919,6 @@ js_HandleExecutionInterrupt(JSContext *cx)
return result;
}
StackFrame *
js_GetScriptedCaller(JSContext *cx, StackFrame *fp)
{
if (!fp)
fp = js_GetTopStackFrame(cx, FRAME_EXPAND_ALL);
while (fp && fp->isDummyFrame())
fp = fp->prev();
JS_ASSERT_IF(fp, fp->isScriptFrame());
return fp;
}
jsbytecode*
js_GetCurrentBytecodePC(JSContext* cx)
{

View File

@ -1530,14 +1530,6 @@ js_InvokeOperationCallback(JSContext *cx);
extern JSBool
js_HandleExecutionInterrupt(JSContext *cx);
/*
* Get the topmost scripted frame in a context. Note: if the topmost frame is
* in the middle of an inline call, that call will be expanded. To avoid this,
* use cx->stack.currentScript or cx->stack.currentScriptedScopeChain.
*/
extern js::StackFrame *
js_GetScriptedCaller(JSContext *cx, js::StackFrame *fp);
extern jsbytecode*
js_GetCurrentBytecodePC(JSContext* cx);

View File

@ -518,12 +518,6 @@ JS_GetFramePC(JSContext *cx, JSStackFrame *fp)
return Valueify(fp)->pcQuadratic(cx->stack);
}
JS_PUBLIC_API(JSStackFrame *)
JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp)
{
return Jsvalify(js_GetScriptedCaller(cx, Valueify(fp)));
}
JS_PUBLIC_API(void *)
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fpArg)
{
@ -1668,3 +1662,25 @@ JS_UnwrapObject(JSObject *obj)
{
return UnwrapObject(obj);
}
JS_FRIEND_API(JSBool)
js_CallContextDebugHandler(JSContext *cx)
{
FrameRegsIter iter(cx);
JS_ASSERT(!iter.done());
jsval rval;
switch (js::CallContextDebugHandler(cx, iter.script(), iter.pc(), &rval)) {
case JSTRAP_ERROR:
JS_ClearPendingException(cx);
return JS_FALSE;
case JSTRAP_THROW:
JS_SetPendingException(cx, rval);
return JS_FALSE;
case JSTRAP_RETURN:
case JSTRAP_CONTINUE:
default:
return JS_TRUE;
}
}

View File

@ -241,12 +241,6 @@ JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(jsbytecode *)
JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
/*
* Get the closest scripted frame below fp. If fp is null, start from cx->fp.
*/
extern JS_PUBLIC_API(JSStackFrame *)
JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
extern JS_PUBLIC_API(void *)
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
@ -581,6 +575,10 @@ JS_DumpCompartmentPCCounts(JSContext *cx);
extern JS_PUBLIC_API(JSObject *)
JS_UnwrapObject(JSObject *obj);
/* Call the context debug handler on the topmost scripted frame. */
extern JS_FRIEND_API(JSBool)
js_CallContextDebugHandler(JSContext *cx);
JS_END_EXTERN_C
#endif /* jsdbgapi_h___ */

View File

@ -782,7 +782,10 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsid id, Value *vp)
if (!fp->prev())
return true;
StackFrame *frame = js_GetScriptedCaller(cx, fp->prev());
StackFrame *frame = fp->prev();
while (frame && frame->isDummyFrame())
frame = frame->prev();
if (frame && !frame->getValidCalleeObject(cx, vp))
return false;

View File

@ -2715,8 +2715,9 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
*/
uint32_t format = cs->format;
bool matchPC = false;
if (StackFrame *fp = js_GetScriptedCaller(cx, NULL)) {
jsbytecode *npc = fp->pcQuadratic(cx);
FrameRegsIter iter(cx);
if (!iter.done()) {
jsbytecode *npc = iter.pc();
if (pc == npc) {
matchPC = true;
} else if (format & JOF_DECOMPOSE) {

View File

@ -1303,11 +1303,19 @@ SetDebug(JSContext *cx, unsigned argc, jsval *vp)
return ok;
}
static JSScript *
GetTopScript(JSContext *cx)
{
JSScript *script;
JS_DescribeScriptedCaller(cx, &script, NULL);
return script;
}
static JSBool
GetScriptAndPCArgs(JSContext *cx, unsigned argc, jsval *argv, JSScript **scriptp,
int32_t *ip)
{
JSScript *script = JS_GetFrameScript(cx, JS_GetScriptedCaller(cx, NULL));
JSScript *script = GetTopScript(cx);
*ip = 0;
if (argc != 0) {
jsval v = argv[0];
@ -1339,8 +1347,12 @@ TrapHandler(JSContext *cx, JSScript *, jsbytecode *pc, jsval *rval,
jsval closure)
{
JSString *str = JSVAL_TO_STRING(closure);
JSStackFrame *caller = JS_GetScriptedCaller(cx, NULL);
JSScript *script = JS_GetFrameScript(cx, caller);
FrameRegsIter iter(cx);
JS_ASSERT(!iter.done());
JSStackFrame *caller = Jsvalify(iter.fp());
JSScript *script = iter.script();
size_t length;
const jschar *chars = JS_GetStringCharsAndLength(cx, str, &length);
@ -1455,7 +1467,7 @@ LineToPC(JSContext *cx, unsigned argc, jsval *vp)
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_LINE2PC_USAGE);
return JS_FALSE;
}
script = JS_GetFrameScript(cx, JS_GetScriptedCaller(cx, NULL));
script = GetTopScript(cx);
jsval v = JS_ARGV(cx, vp)[0];
if (!JSVAL_IS_PRIMITIVE(v) &&
JS_GetClass(JSVAL_TO_OBJECT(v)) == Jsvalify(&FunctionClass))
@ -1801,8 +1813,7 @@ DisassembleToString(JSContext *cx, unsigned argc, jsval *vp)
bool ok = true;
if (p.argc == 0) {
/* Without arguments, disassemble the current script. */
if (JSStackFrame *frame = JS_GetScriptedCaller(cx, NULL)) {
JSScript *script = JS_GetFrameScript(cx, frame);
if (JSScript *script = GetTopScript(cx)) {
if (js_Disassemble(cx, script, p.lines, &sprinter)) {
SrcNotes(cx, script, &sprinter);
TryNotes(cx, script, &sprinter);
@ -1839,8 +1850,7 @@ Disassemble(JSContext *cx, unsigned argc, jsval *vp)
bool ok = true;
if (p.argc == 0) {
/* Without arguments, disassemble the current script. */
if (JSStackFrame *frame = JS_GetScriptedCaller(cx, NULL)) {
JSScript *script = JS_GetFrameScript(cx, frame);
if (JSScript *script = GetTopScript(cx)) {
if (js_Disassemble(cx, script, p.lines, &sprinter)) {
SrcNotes(cx, script, &sprinter);
TryNotes(cx, script, &sprinter);
@ -2670,9 +2680,10 @@ EvalInContext(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
JSStackFrame *fp = JS_GetScriptedCaller(cx, NULL);
JSScript *script = JS_GetFrameScript(cx, fp);
jsbytecode *pc = JS_GetFramePC(cx, fp);
JSScript *script;
unsigned lineno;
JS_DescribeScriptedCaller(cx, &script, &lineno);
jsval rval;
{
JSAutoEnterCompartment ac;
@ -2693,7 +2704,7 @@ EvalInContext(JSContext *cx, unsigned argc, jsval *vp)
}
if (!JS_EvaluateUCScript(cx, sobj, src, srclen,
script->filename,
JS_PCToLineNumber(cx, script, pc),
lineno,
&rval)) {
return false;
}
@ -3379,9 +3390,8 @@ Snarf(JSContext *cx, unsigned argc, jsval *vp)
return JS_FALSE;
/* Get the currently executing script's name. */
JSStackFrame *fp = JS_GetScriptedCaller(cx, NULL);
JSScript *script = JS_GetFrameScript(cx, fp);
JS_ASSERT(fp && script->filename);
JSScript *script = GetTopScript(cx);
JS_ASSERT(script->filename);
const char *pathname = filename.ptr();
#ifdef XP_UNIX
FreeOnReturn pnGuard(cx);

View File

@ -1120,8 +1120,9 @@ Worker::create(JSContext *parentcx, WorkerParent *parent, JSString *scriptName,
return NULL;
}
JSStackFrame *frame = JS_GetScriptedCaller(parentcx, NULL);
const char *base = JS_GetScriptFilename(parentcx, JS_GetFrameScript(parentcx, frame));
JSScript *script;
JS_DescribeScriptedCaller(parentcx, &script, NULL);
const char *base = JS_GetScriptFilename(parentcx, script);
JSString *scriptPath = ResolveRelativePath(parentcx, base, scriptName);
if (!scriptPath)
return NULL;

View File

@ -978,6 +978,7 @@ StackIter::poisonRegs()
{
sp_ = (Value *)0xbad;
pc_ = (jsbytecode *)0xbad;
script_ = (JSScript *)0xbad;
}
void
@ -1019,6 +1020,8 @@ StackIter::popFrame()
JS_ASSERT(oldfp->isDummyFrame());
sp_ = (Value *)oldfp;
}
script_ = fp_->maybeScript();
} else {
poisonRegs();
}
@ -1044,6 +1047,8 @@ StackIter::settleOnNewSegment()
if (FrameRegs *regs = seg_->maybeRegs()) {
sp_ = regs->sp;
pc_ = regs->pc;
if (fp_)
script_ = fp_->maybeScript();
} else {
poisonRegs();
}

View File

@ -1818,6 +1818,7 @@ class StackIter
StackSegment *seg_;
Value *sp_;
jsbytecode *pc_;
JSScript *script_;
CallArgs args_;
void poisonRegs();
@ -1840,6 +1841,7 @@ class StackIter
StackFrame *fp() const { JS_ASSERT(!done() && isScript()); return fp_; }
Value *sp() const { JS_ASSERT(!done() && isScript()); return sp_; }
jsbytecode *pc() const { JS_ASSERT(!done() && isScript()); return pc_; }
JSScript *script() const { JS_ASSERT(!done() && isScript()); return script_; }
bool isNativeCall() const { JS_ASSERT(!done()); return state_ != SCRIPTED; }
CallArgs nativeArgs() const { JS_ASSERT(!done() && isNativeCall()); return args_; }
@ -1868,6 +1870,7 @@ class FrameRegsIter
StackFrame *fp() const { return iter_.fp(); }
Value *sp() const { return iter_.sp(); }
jsbytecode *pc() const { return iter_.pc(); }
JSScript *script() const { return iter_.script(); }
};
/*****************************************************************************/

View File

@ -168,8 +168,8 @@ GetLocationProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
//XXX: your platform should really implement this
return false;
#else
JSStackFrame *fp = JS_GetScriptedCaller(cx, NULL);
JSScript *script = JS_GetFrameScript(cx, fp);
JSScript *script;
JS_DescribeScriptedCaller(cx, &script, NULL);
const char *filename = JS_GetScriptFilename(cx, script);
if (filename) {