diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 6f27e4b1dd4..47b2d437364 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -754,20 +754,21 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject, } } - if (global) { - // This might be the first reference to this language in the global - // We must init the language before we attempt to fetch its context. - if (NS_FAILED(global->EnsureScriptEnvironment(aLanguage))) { - NS_WARNING("Failed to setup script environment for this language"); - // but fall through and let the inevitable failure below handle it. - } - - context = global->GetScriptContext(aLanguage); + if (!global) { + // This can happen; for example this document might have been + // loaded as data. + return NS_OK; + } + + // This might be the first reference to this language in the global + // We must init the language before we attempt to fetch its context. + if (NS_FAILED(global->EnsureScriptEnvironment(aLanguage))) { + NS_WARNING("Failed to setup script environment for this language"); + // but fall through and let the inevitable failure below handle it. } - NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); - NS_ASSERTION(global, "How could we possibly have a context without an " - "nsIScriptGlobalObject?"); + context = global->GetScriptContext(aLanguage); + NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); void *scope = global->GetScriptGlobal(aLanguage); nsresult rv; diff --git a/content/events/test/Makefile.in b/content/events/test/Makefile.in index e4a5a53c823..0e8d1a739c8 100644 --- a/content/events/test/Makefile.in +++ b/content/events/test/Makefile.in @@ -45,6 +45,7 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk _TEST_FILES = test_bug367781.html \ + test_bug379120.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/content/events/test/test_bug379120.html b/content/events/test/test_bug379120.html new file mode 100644 index 00000000000..fac86ac5bad --- /dev/null +++ b/content/events/test/test_bug379120.html @@ -0,0 +1,57 @@ + + + +
++ ++ + +