mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 610381 part B - Report thread-usage errors to the error console directly from xpconnect, so that the error console shows them even when extension authors are using asynchronous dispatch. r=jst a=blocking2.0
--HG-- extra : rebase_source : 973d58b5d9be243f92e261ca0a2664bdbf120546
This commit is contained in:
parent
ec247769d5
commit
7f589a0fa9
@ -44,6 +44,7 @@
|
||||
#include "xpcprivate.h"
|
||||
#include "nsAtomicRefcnt.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsTextFormatter.h"
|
||||
|
||||
// NOTE: much of the fancy footwork is done in xpcstubs.cpp
|
||||
|
||||
@ -572,6 +573,17 @@ nsXPCWrappedJS::CallMethod(PRUint16 methodIndex,
|
||||
if(!IsValid())
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
if (NS_IsMainThread() != mMainThread) {
|
||||
NS_NAMED_LITERAL_STRING(kFmt, "Attempt to use JS function on a different thread calling %s.%s. JS objects may not be shared across threads.");
|
||||
PRUnichar* msg =
|
||||
nsTextFormatter::smprintf(kFmt.get(),
|
||||
GetClass()->GetInterfaceName(),
|
||||
info->name);
|
||||
nsCOMPtr<nsIConsoleService> cs =
|
||||
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
||||
if (cs)
|
||||
cs->LogStringMessage(msg);
|
||||
NS_Free(msg);
|
||||
|
||||
return NS_ERROR_NOT_SAME_THREAD;
|
||||
}
|
||||
return GetClass()->CallMethod(this, methodIndex, info, params);
|
||||
|
@ -40,6 +40,19 @@ function run_test() {
|
||||
var tm = Components.classes["@mozilla.org/thread-manager;1"].getService();
|
||||
var thr = tm.newThread(0);
|
||||
|
||||
var foundThreadError = false;
|
||||
|
||||
var listener = {
|
||||
observe: function(message) {
|
||||
if (/JS function on a different thread/.test(message.message))
|
||||
foundThreadError = true;
|
||||
}
|
||||
};
|
||||
|
||||
var cs = Components.classes["@mozilla.org/consoleservice;1"].
|
||||
getService(Components.interfaces.nsIConsoleService);
|
||||
cs.registerListener(listener);
|
||||
|
||||
thr.dispatch({
|
||||
run: function() {
|
||||
do_check_true(false);
|
||||
@ -47,5 +60,8 @@ function run_test() {
|
||||
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
|
||||
|
||||
thr.shutdown();
|
||||
|
||||
cs.unregisterListener(listener);
|
||||
do_check_true(foundThreadError);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user