зеркало из https://github.com/mozilla/gecko-dev.git
Follow-up fix for bug 595243. Don't try to place non-main thread scripts in debug mode, and don't attempt to set debug mode from a non-main thread. r=gal
This commit is contained in:
Родитель
7b6b35d47a
Коммит
223d2052ea
|
@ -789,6 +789,7 @@ jsd_GetScriptForValue(JSDContext* jsdc, JSDValue* jsdval)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
exceptionState = JS_SaveExceptionState(cx);
|
||||
fun = JS_ValueToFunction(cx, val);
|
||||
JS_RestoreExceptionState(cx, exceptionState);
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "jsdbgapi.h"
|
||||
#include "jslock.h"
|
||||
#include "jsd_xpc.h"
|
||||
|
||||
#include "nsIXPConnect.h"
|
||||
|
@ -2424,11 +2425,17 @@ jsdService::AsyncOn (jsdIActivationCallback *activationCallback)
|
|||
|
||||
NS_IMETHODIMP
|
||||
jsdService::RecompileForDebugMode (JSRuntime *rt, JSBool mode) {
|
||||
NS_ASSERTION(NS_IsMainThread(), "wrong thread");
|
||||
|
||||
JSContext *cx;
|
||||
JSContext *iter = NULL;
|
||||
|
||||
jsword currentThreadId = reinterpret_cast<jsword>(js_CurrentThreadId());
|
||||
|
||||
while ((cx = JS_ContextIterator (rt, &iter))) {
|
||||
if (JS_GetContextThread(cx) == currentThreadId) {
|
||||
JS_SetDebugMode(cx, mode);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -48,6 +48,7 @@ MODULE = jsdebug
|
|||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = test_bug507448.html \
|
||||
bug507448.js \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
function f() {}
|
||||
function g(a,b) {}
|
||||
function h(me, too, here) { var x = 1; }
|
||||
function annoying(a, b, a, b, b, a) {}
|
||||
function manyLocals(a, b, c, d, e, f, g, h, i, j, k, l, m) {
|
||||
var n, o, p, q, r, s, t, u, v, w, x, y, z;
|
||||
}
|
||||
|
||||
assertArraysEqual(jsd.wrapValue(f).script.getParameterNames(), []);
|
||||
assertArraysEqual(jsd.wrapValue(g).script.getParameterNames(), ["a", "b"]);
|
||||
assertArraysEqual(jsd.wrapValue(h).script.getParameterNames(), ["me", "too", "here"]);
|
||||
assertArraysEqual(jsd.wrapValue(annoying).script.getParameterNames(),
|
||||
["a", "b", "a", "b", "b", "a"]);
|
||||
assertArraysEqual(jsd.wrapValue(manyLocals).script.getParameterNames(),
|
||||
"abcdefghijklm".split(""));
|
||||
|
||||
if (!jsdOnAtStart) {
|
||||
// turn JSD off if it wasn't on when this test started
|
||||
jsd.off();
|
||||
ok(!jsd.isOn, "JSD shouldn't be running at the end of this test.");
|
||||
}
|
||||
|
||||
SimpleTest.finish();
|
|
@ -16,39 +16,48 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=507448
|
|||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script>
|
||||
function f() {}
|
||||
function g(a,b) {}
|
||||
function h(me, too, here) { var x = 1; }
|
||||
function annoying(a, b, a, b, b, a) {}
|
||||
function manyLocals(a, b, c, d, e, f, g, h, i, j, k, l, m) {
|
||||
var n, o, p, q, r, s, t, u, v, w, x, y, z;
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function testJSD() {
|
||||
ok(jsd.isOn, "JSD needs to be running for this test.");
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
assertArraysEqual(jsd.wrapValue(f).script.getParameterNames(), []);
|
||||
assertArraysEqual(jsd.wrapValue(g).script.getParameterNames(), ["a", "b"]);
|
||||
assertArraysEqual(jsd.wrapValue(h).script.getParameterNames(), ["me", "too", "here"]);
|
||||
assertArraysEqual(jsd.wrapValue(annoying).script.getParameterNames(),
|
||||
["a", "b", "a", "b", "b", "a"]);
|
||||
assertArraysEqual(jsd.wrapValue(manyLocals).script.getParameterNames(),
|
||||
"abcdefghijklm".split(""));
|
||||
|
||||
if (!jsdOnAtStart) {
|
||||
// turn JSD off if it wasn't on when this test started
|
||||
jsd.off();
|
||||
ok(!jsd.isOn, "JSD shouldn't be running at the end of this test.");
|
||||
}
|
||||
SimpleTest.finish();
|
||||
<script type="application/javascript">
|
||||
function f() {}
|
||||
function g(a,b) {}
|
||||
function h(me, too, here) { var x = 1; }
|
||||
function annoying(a, b, a, b, b, a) {}
|
||||
function manyLocals(a, b, c, d, e, f, g, h, i, j, k, l, m) {
|
||||
var n, o, p, q, r, s, t, u, v, w, x, y, z;
|
||||
}
|
||||
</script>
|
||||
<script type="application/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function loadScript(url) {
|
||||
var d = new MochiKit.Async.Deferred();
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
var script = MochiKit.DOM.createDOM("script", { type: "text/javascript", src: url });
|
||||
script.onload = function() {
|
||||
script.onload = null;
|
||||
script.onerror = null;
|
||||
script.onreadystatechange = null;
|
||||
d.callback();
|
||||
};
|
||||
script.onerror = function(msg) {
|
||||
script.onload = null;
|
||||
script.onerror = null;
|
||||
script.onreadystatechange = null;
|
||||
msg = "Failed to load script at " + url + ": " + msg;
|
||||
d.errback(new URIError(msg, url));
|
||||
}
|
||||
script.onreadystatechange = function() {
|
||||
if (script.readyState == "loaded" || script.readyState == "complete") {
|
||||
script.onload();
|
||||
} else {
|
||||
// IE doesn't bother to report errors...
|
||||
MochiKit.Async.callLater(10, script.onerror, "Script loading timed out")
|
||||
}
|
||||
};
|
||||
head.appendChild(script);
|
||||
return d;
|
||||
}
|
||||
|
||||
/** Test for Bug 507448 **/
|
||||
function assertArraysEqual(arr1, arr2) {
|
||||
is(arr1.length, arr2.length, "Lengths not equal");
|
||||
|
@ -57,28 +66,44 @@ function assertArraysEqual(arr1, arr2) {
|
|||
}
|
||||
}
|
||||
|
||||
// This is somewhat unfortunate: jsd only deals with scripts that have a
|
||||
// nonzero line number, so we can't just createElement a script here.
|
||||
// So break the test up into three <script>s, of which the middle one has our test functions.
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
|
||||
var jsd = Components.classes['@mozilla.org/js/jsd/debugger-service;1']
|
||||
.getService(jsdIDebuggerService);
|
||||
var jsdOnAtStart = false;
|
||||
|
||||
var jsdOnAtStart = jsd.isOn;
|
||||
if (jsdOnAtStart) {
|
||||
testJSD();
|
||||
} else {
|
||||
jsd.asyncOn(
|
||||
{
|
||||
debuggerActivated: function() {
|
||||
testJSD();
|
||||
}
|
||||
}
|
||||
);
|
||||
function setupJSD() {
|
||||
// This is somewhat unfortunate: jsd only deals with scripts that have a
|
||||
// nonzero line number, so we can't just createElement a script here.
|
||||
// So break the test up into three <script>s, of which the middle one has our test functions.
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
jsdOnAtStart = jsd.isOn;
|
||||
if (jsdOnAtStart) {
|
||||
testJSD();
|
||||
} else {
|
||||
jsd.asyncOn(
|
||||
{
|
||||
onDebuggerActivated: function() {
|
||||
testJSD();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
addLoadEvent(setupJSD);
|
||||
|
||||
</script>
|
||||
<script>
|
||||
function testJSD() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
ok(jsd.isOn, "JSD needs to be running for this test.");
|
||||
|
||||
var deferred = loadScript("bug507448.js");
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
|
@ -2414,6 +2414,12 @@ nsXPConnect::Peek(JSContext * *_retval)
|
|||
void
|
||||
nsXPConnect::CheckForDebugMode(JSRuntime *rt) {
|
||||
if (gDebugMode != gDesiredDebugMode) {
|
||||
// This can happen if a Worker is running, but we don't have the ability
|
||||
// to debug workers right now, so just return.
|
||||
if (!NS_IsMainThread()) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
const char jsdServiceCtrID[] = "@mozilla.org/js/jsd/debugger-service;1";
|
||||
nsCOMPtr<jsdIDebuggerService> jsds = do_GetService(jsdServiceCtrID, &rv);
|
||||
|
|
Загрузка…
Ссылка в новой задаче