Bug 1095145: Remove compileAndGoGlobal argument to Debugger::onNewScript, and simplify accordingly. r=shu

--HG--
extra : rebase_source : d07242d14f9bf46584ebefbdf94c9856f632adad
extra : amend_source : f05f1a446818d95d9117b0c3e24b693a3503494e
This commit is contained in:
Jim Blandy 2015-01-26 11:48:35 -06:00
parent c097b35626
commit c29779df0f
7 changed files with 27 additions and 60 deletions

View File

@ -509,8 +509,7 @@ js::ExecuteInGlobalAndReturnScope(JSContext *cx, HandleObject global, HandleScri
if (!script)
return false;
Rooted<GlobalObject *> global(cx, script->compileAndGo() ? &script->global() : nullptr);
Debugger::onNewScript(cx, script, global);
Debugger::onNewScript(cx, script);
}
RootedObject scope(cx, JS_NewPlainObject(cx));

View File

@ -2197,10 +2197,7 @@ BytecodeEmitter::tellDebuggerAboutCompiledScript(ExclusiveContext *cx)
// Lazy scripts are never top level (despite always being invoked with a
// nullptr parent), and so the hook should never be fired.
if (emitterMode != LazyFunction && !parent) {
GlobalObject *compileAndGoGlobal = nullptr;
if (script->compileAndGo())
compileAndGoGlobal = &script->global();
Debugger::onNewScript(cx->asJSContext(), script, compileAndGoGlobal);
Debugger::onNewScript(cx->asJSContext(), script);
}
}

View File

@ -4273,8 +4273,7 @@ JS::CloneAndExecuteScript(JSContext *cx, HandleObject obj, HandleScript scriptAr
if (!script)
return false;
Rooted<GlobalObject *> global(cx, script->compileAndGo() ? &script->global() : nullptr);
js::Debugger::onNewScript(cx, script, global);
js::Debugger::onNewScript(cx, script);
}
return ExecuteScript(cx, obj, script, nullptr);
}

View File

@ -1090,10 +1090,8 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
scriptp.set(script);
/* see BytecodeEmitter::tellDebuggerAboutCompiledScript */
if (!fun) {
RootedGlobalObject global(cx, script->compileAndGo() ? &script->global() : nullptr);
Debugger::onNewScript(cx, script, global);
}
if (!fun)
Debugger::onNewScript(cx, script);
}
return true;
@ -3191,8 +3189,7 @@ js::CloneFunctionScript(JSContext *cx, HandleFunction original, HandleFunction c
cscript->setFunction(clone);
script = clone->nonLazyScript();
RootedGlobalObject global(cx, script->compileAndGo() ? &script->global() : nullptr);
Debugger::onNewScript(cx, script, global);
Debugger::onNewScript(cx, script);
return true;
}

View File

@ -1302,47 +1302,27 @@ Debugger::dispatchHook(JSContext *cx, MutableHandleValue vp, Hook which, HandleO
return JSTRAP_CONTINUE;
}
static bool
AddNewScriptRecipients(GlobalObject::DebuggerVector *src, HandleScript script,
AutoValueVector *dest)
{
bool wasEmpty = dest->length() == 0;
for (Debugger **p = src->begin(); p != src->end(); p++) {
Debugger *dbg = *p;
Value v = ObjectValue(*dbg->toJSObject());
if (dbg->observesScript(script) && dbg->observesNewScript() &&
(wasEmpty || Find(dest->begin(), dest->end(), v) == dest->end()) &&
!dest->append(v))
{
return false;
}
}
return true;
}
void
Debugger::slowPathOnNewScript(JSContext *cx, HandleScript script, GlobalObject *compileAndGoGlobal_)
Debugger::slowPathOnNewScript(JSContext *cx, HandleScript script)
{
Rooted<GlobalObject*> compileAndGoGlobal(cx, compileAndGoGlobal_);
MOZ_ASSERT(script->compileAndGo() == !!compileAndGoGlobal);
Rooted<GlobalObject*> global(cx, &script->global());
/*
* Build the list of recipients based on the debuggers observing the
* script's compartment.
*
* TODO bug 1064079 will simplify this logic. The meaning of
* compile-and-go has changed over the years and is no longer relevant to
* Debugger.
*/
AutoValueVector triggered(cx);
GlobalObject::DebuggerVector *debuggers =
(script->compileAndGo()
? compileAndGoGlobal->getDebuggers()
: script->compartment()->maybeGlobal()->getDebuggers());
GlobalObject::DebuggerVector *debuggers = global->getDebuggers();
if (debuggers) {
if (!AddNewScriptRecipients(debuggers, script, &triggered))
return;
for (Debugger **p = debuggers->begin(); p != debuggers->end(); p++) {
Debugger *dbg = *p;
if (dbg->observesNewScript() && dbg->observesScript(script)) {
if (!triggered.append(ObjectValue(*dbg->toJSObject()))) {
js_ReportOutOfMemory(cx);
return;
}
}
}
}
/*
@ -1351,8 +1331,10 @@ Debugger::slowPathOnNewScript(JSContext *cx, HandleScript script, GlobalObject *
*/
for (Value *p = triggered.begin(); p != triggered.end(); p++) {
Debugger *dbg = Debugger::fromJSObject(&p->toObject());
if ((!compileAndGoGlobal || dbg->debuggees.has(compileAndGoGlobal)) &&
dbg->enabled && dbg->getHook(OnNewScript)) {
if (dbg->debuggees.has(global) &&
dbg->enabled &&
dbg->getHook(OnNewScript))
{
dbg->fireNewScript(cx, script);
}
}

View File

@ -454,8 +454,7 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
static bool slowPathOnLeaveFrame(JSContext *cx, AbstractFramePtr frame, bool ok);
static JSTrapStatus slowPathOnDebuggerStatement(JSContext *cx, AbstractFramePtr frame);
static JSTrapStatus slowPathOnExceptionUnwind(JSContext *cx, AbstractFramePtr frame);
static void slowPathOnNewScript(JSContext *cx, HandleScript script,
GlobalObject *compileAndGoGlobal);
static void slowPathOnNewScript(JSContext *cx, HandleScript script);
static void slowPathOnNewGlobalObject(JSContext *cx, Handle<GlobalObject *> global);
static bool slowPathOnLogAllocationSite(JSContext *cx, HandleSavedFrame frame,
int64_t when, GlobalObject::DebuggerVector &dbgs);
@ -600,7 +599,7 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
*/
static inline bool onLeaveFrame(JSContext *cx, AbstractFramePtr frame, bool ok);
static inline void onNewScript(JSContext *cx, HandleScript script, GlobalObject *compileAndGoGlobal);
static inline void onNewScript(JSContext *cx, HandleScript script);
static inline void onNewGlobalObject(JSContext *cx, Handle<GlobalObject *> global);
static inline bool onLogAllocationSite(JSContext *cx, HandleSavedFrame frame, int64_t when);
static JSTrapStatus onTrap(JSContext *cx, MutableHandleValue vp);
@ -878,18 +877,15 @@ Debugger::observesGlobal(GlobalObject *global) const
}
/* static */ void
Debugger::onNewScript(JSContext *cx, HandleScript script, GlobalObject *compileAndGoGlobal)
Debugger::onNewScript(JSContext *cx, HandleScript script)
{
MOZ_ASSERT_IF(script->compileAndGo(), compileAndGoGlobal);
MOZ_ASSERT_IF(script->compileAndGo(), compileAndGoGlobal == &script->uninlinedGlobal());
// We early return in slowPathOnNewScript for self-hosted scripts, so we can
// ignore those in our assertion here.
MOZ_ASSERT_IF(!script->compartment()->options().invisibleToDebugger() &&
!script->selfHosted(),
script->compartment()->firedOnNewGlobalObject);
MOZ_ASSERT_IF(!script->compileAndGo(), !compileAndGoGlobal);
if (script->compartment()->isDebuggee())
slowPathOnNewScript(cx, script, compileAndGoGlobal);
slowPathOnNewScript(cx, script);
}
/* static */ void

View File

@ -932,10 +932,7 @@ GlobalHelperThreadState::finishParseTask(JSContext *maybecx, JSRuntime *rt, void
if (script) {
// The Debugger only needs to be told about the topmost script that was compiled.
GlobalObject *compileAndGoGlobal = nullptr;
if (script->compileAndGo())
compileAndGoGlobal = &script->global();
Debugger::onNewScript(cx, script, compileAndGoGlobal);
Debugger::onNewScript(cx, script);
// Update the compressed source table with the result. This is normally
// called by setCompressedSource when compilation occurs on the main thread.