зеркало из https://github.com/mozilla/pjs.git
Bug 734023 - Remove language arguments from nsIScriptGlobalObject methods, r=jst, f=ms2ger
This commit is contained in:
Родитель
13c438c06e
Коммит
ceb4fe49c5
|
@ -417,8 +417,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
|||
return false;
|
||||
}
|
||||
|
||||
nsIScriptContext *context = globalObject->GetScriptContext(
|
||||
nsIProgrammingLanguage::JAVASCRIPT);
|
||||
nsIScriptContext *context = globalObject->GetScriptContext();
|
||||
|
||||
// If scripts aren't enabled in the current context, there's no
|
||||
// point in going on.
|
||||
|
@ -890,14 +889,14 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
|
|||
PRUint32 stid = scriptContent ? scriptContent->GetScriptTypeID() :
|
||||
nsIProgrammingLanguage::JAVASCRIPT;
|
||||
// and make sure we are setup for this type of script.
|
||||
rv = globalObject->EnsureScriptEnvironment(stid);
|
||||
rv = globalObject->EnsureScriptEnvironment();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// Make sure context is a strong reference since we access it after
|
||||
// we've executed a script, which may cause all other references to
|
||||
// the context to go away.
|
||||
nsCOMPtr<nsIScriptContext> context = globalObject->GetScriptContext(stid);
|
||||
nsCOMPtr<nsIScriptContext> context = globalObject->GetScriptContext();
|
||||
if (!context) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -532,12 +532,12 @@ nsEventListenerManager::AddScriptEventListener(nsIAtom *aName,
|
|||
|
||||
// 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))) {
|
||||
if (NS_FAILED(global->EnsureScriptEnvironment())) {
|
||||
NS_WARNING("Failed to setup script environment for this language");
|
||||
// but fall through and let the inevitable failure below handle it.
|
||||
}
|
||||
|
||||
nsIScriptContext* context = global->GetScriptContext(aLanguage);
|
||||
nsIScriptContext* context = global->GetScriptContext();
|
||||
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
|
||||
|
||||
JSObject* scope = global->GetGlobalJSObject();
|
||||
|
|
|
@ -78,8 +78,8 @@ public:
|
|||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
|
||||
// nsIScriptGlobalObject methods
|
||||
virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID);
|
||||
virtual nsresult SetScriptContext(PRUint32 lang_id, nsIScriptContext *aContext);
|
||||
virtual nsresult EnsureScriptEnvironment();
|
||||
virtual nsresult SetScriptContext(nsIScriptContext *aContext);
|
||||
|
||||
virtual nsIScriptContext *GetContext();
|
||||
virtual JSObject *GetGlobalJSObject();
|
||||
|
@ -103,10 +103,10 @@ protected:
|
|||
virtual ~nsXBLDocGlobalObject();
|
||||
|
||||
void SetContext(nsIScriptContext *aContext);
|
||||
nsIScriptContext *GetScriptContext(PRUint32 language);
|
||||
nsIScriptContext *GetScriptContext();
|
||||
|
||||
nsCOMPtr<nsIScriptContext> mScriptContext;
|
||||
JSObject *mJSObject; // XXX JS language rabies bigotry badness
|
||||
JSObject *mJSObject;
|
||||
|
||||
nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // weak reference
|
||||
static JSClass gSharedGlobalClass;
|
||||
|
@ -282,28 +282,21 @@ nsXBLDocGlobalObject::SetContext(nsIScriptContext *aScriptContext)
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsXBLDocGlobalObject::SetScriptContext(PRUint32 lang_id, nsIScriptContext *aContext)
|
||||
nsXBLDocGlobalObject::SetScriptContext(nsIScriptContext *aContext)
|
||||
{
|
||||
NS_ASSERTION(lang_id == nsIProgrammingLanguage::JAVASCRIPT, "Only JS allowed!");
|
||||
SetContext(aContext);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIScriptContext *
|
||||
nsXBLDocGlobalObject::GetScriptContext(PRUint32 language)
|
||||
nsXBLDocGlobalObject::GetScriptContext()
|
||||
{
|
||||
// This impl still assumes JS
|
||||
NS_ENSURE_TRUE(language==nsIProgrammingLanguage::JAVASCRIPT, nsnull);
|
||||
return GetContext();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXBLDocGlobalObject::EnsureScriptEnvironment(PRUint32 aLangID)
|
||||
nsXBLDocGlobalObject::EnsureScriptEnvironment()
|
||||
{
|
||||
if (aLangID != nsIProgrammingLanguage::JAVASCRIPT) {
|
||||
NS_WARNING("XBL still JS only");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
if (mScriptContext)
|
||||
return NS_OK; // already initialized for this lang
|
||||
nsCOMPtr<nsIDOMScriptObjectFactory> factory = do_GetService(kDOMScriptObjectFactoryCID);
|
||||
|
@ -312,10 +305,11 @@ nsXBLDocGlobalObject::EnsureScriptEnvironment(PRUint32 aLangID)
|
|||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIScriptRuntime> scriptRuntime;
|
||||
rv = NS_GetScriptRuntimeByID(aLangID, getter_AddRefs(scriptRuntime));
|
||||
rv = NS_GetScriptRuntimeByID(nsIProgrammingLanguage::JAVASCRIPT,
|
||||
getter_AddRefs(scriptRuntime));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIScriptContext> newCtx = scriptRuntime->CreateContext();
|
||||
rv = SetScriptContext(aLangID, newCtx);
|
||||
rv = SetScriptContext(newCtx);
|
||||
|
||||
JSContext *cx = mScriptContext->GetNativeContext();
|
||||
JSAutoRequest ar(cx);
|
||||
|
@ -347,7 +341,7 @@ nsXBLDocGlobalObject::GetContext()
|
|||
// This whole fragile mess is predicated on the fact that
|
||||
// GetContext() will be called before GetScriptObject() is.
|
||||
if (! mScriptContext) {
|
||||
nsresult rv = EnsureScriptEnvironment(nsIProgrammingLanguage::JAVASCRIPT);
|
||||
nsresult rv = EnsureScriptEnvironment();
|
||||
// JS is builtin so we make noise if it fails to initialize.
|
||||
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to setup JS!?");
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
@ -563,7 +557,7 @@ nsXBLDocumentInfo::~nsXBLDocumentInfo()
|
|||
/* destructor code */
|
||||
if (mGlobalObject) {
|
||||
// remove circular reference
|
||||
mGlobalObject->SetScriptContext(nsIProgrammingLanguage::JAVASCRIPT, nsnull);
|
||||
mGlobalObject->SetScriptContext(nsnull);
|
||||
mGlobalObject->ClearGlobalObjectOwner(); // just in case
|
||||
}
|
||||
if (mBindingTable) {
|
||||
|
|
|
@ -301,8 +301,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventTarget* aTarget,
|
|||
if (!boundGlobal)
|
||||
return NS_OK;
|
||||
|
||||
nsIScriptContext *boundContext =
|
||||
boundGlobal->GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT);
|
||||
nsIScriptContext *boundContext = boundGlobal->GetScriptContext();
|
||||
if (!boundContext)
|
||||
return NS_OK;
|
||||
|
||||
|
|
|
@ -771,7 +771,7 @@ nsScriptEventHandlerOwnerTearoff::CompileEventHandler(
|
|||
nsIScriptGlobalObject* global = globalOwner->GetScriptGlobalObject();
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
|
||||
|
||||
context = global->GetScriptContext(aContext->GetScriptTypeID());
|
||||
context = global->GetScriptContext();
|
||||
// It could be possible the language has been setup on aContext but
|
||||
// not on the global - we don't demand-create language contexts on the
|
||||
// nsGlobalWindow
|
||||
|
@ -2943,8 +2943,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
|
|||
nsIScriptGlobalObject* aGlobal,
|
||||
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
||||
{
|
||||
nsIScriptContext *context = aGlobal->GetScriptContext(
|
||||
mScriptObject.mLangID);
|
||||
nsIScriptContext *context = aGlobal->GetScriptContext();
|
||||
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nsnull ||
|
||||
!mScriptObject.mObject,
|
||||
"script source still loading when serializing?!");
|
||||
|
@ -3022,8 +3021,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
|
|||
aStream->Read32(&mLineNo);
|
||||
aStream->Read32(&mLangVersion);
|
||||
|
||||
nsIScriptContext *context = aGlobal->GetScriptContext(
|
||||
mScriptObject.mLangID);
|
||||
nsIScriptContext *context = aGlobal->GetScriptContext();
|
||||
NS_ASSERTION(context != nsnull, "Have no context for deserialization");
|
||||
NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
|
||||
nsScriptObjectHolder<JSScript> newScriptObject(context);
|
||||
|
@ -3151,7 +3149,7 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
|
|||
if (! global)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
context = global->GetScriptContext(mScriptObject.mLangID);
|
||||
context = global->GetScriptContext();
|
||||
NS_ASSERTION(context != nsnull, "no context for script global");
|
||||
if (! context)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
|
|
@ -3553,9 +3553,8 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
|
||||
NS_ASSERTION(global != nsnull, "master prototype w/o global?!");
|
||||
if (global) {
|
||||
PRUint32 stid = scriptProto->mScriptObject.mLangID;
|
||||
nsIScriptContext *scriptContext = \
|
||||
global->GetScriptContext(stid);
|
||||
global->GetScriptContext();
|
||||
NS_ASSERTION(scriptContext != nsnull,
|
||||
"Failed to get script context for language");
|
||||
if (scriptContext)
|
||||
|
@ -3619,14 +3618,13 @@ nsXULDocument::ExecuteScript(nsXULPrototypeScript *aScript)
|
|||
NS_PRECONDITION(aScript != nsnull, "null ptr");
|
||||
NS_ENSURE_TRUE(aScript, NS_ERROR_NULL_POINTER);
|
||||
NS_ENSURE_TRUE(mScriptGlobalObject, NS_ERROR_NOT_INITIALIZED);
|
||||
PRUint32 stid = aScript->mScriptObject.mLangID;
|
||||
|
||||
nsresult rv;
|
||||
rv = mScriptGlobalObject->EnsureScriptEnvironment(stid);
|
||||
rv = mScriptGlobalObject->EnsureScriptEnvironment();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> context =
|
||||
mScriptGlobalObject->GetScriptContext(stid);
|
||||
mScriptGlobalObject->GetScriptContext();
|
||||
// failure getting a script context is fatal.
|
||||
NS_ENSURE_TRUE(context != nsnull, NS_ERROR_UNEXPECTED);
|
||||
|
||||
|
|
|
@ -85,10 +85,10 @@ public:
|
|||
virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts);
|
||||
|
||||
virtual JSObject* GetGlobalJSObject();
|
||||
virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID);
|
||||
virtual nsresult EnsureScriptEnvironment();
|
||||
|
||||
virtual nsIScriptContext *GetScriptContext(PRUint32 lang);
|
||||
virtual nsresult SetScriptContext(PRUint32 language, nsIScriptContext *ctx);
|
||||
virtual nsIScriptContext *GetScriptContext();
|
||||
virtual nsresult SetScriptContext(nsIScriptContext *ctx);
|
||||
|
||||
// nsIScriptObjectPrincipal methods
|
||||
virtual nsIPrincipal* GetPrincipal();
|
||||
|
@ -683,10 +683,8 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULPDGlobalObject)
|
|||
//
|
||||
|
||||
nsresult
|
||||
nsXULPDGlobalObject::SetScriptContext(PRUint32 lang_id, nsIScriptContext *aScriptContext)
|
||||
nsXULPDGlobalObject::SetScriptContext(nsIScriptContext *aScriptContext)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(lang_id == nsIProgrammingLanguage::JAVASCRIPT,
|
||||
"We don't support this language ID");
|
||||
// almost a clone of nsGlobalWindow
|
||||
if (!aScriptContext) {
|
||||
NS_WARNING("Possibly early removal of script object, see bug #41608");
|
||||
|
@ -713,10 +711,8 @@ nsXULPDGlobalObject::SetScriptContext(PRUint32 lang_id, nsIScriptContext *aScrip
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsXULPDGlobalObject::EnsureScriptEnvironment(PRUint32 lang_id)
|
||||
nsXULPDGlobalObject::EnsureScriptEnvironment()
|
||||
{
|
||||
NS_ABORT_IF_FALSE(lang_id == nsIProgrammingLanguage::JAVASCRIPT,
|
||||
"We don't support this language ID");
|
||||
if (mContext) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -752,23 +748,21 @@ nsXULPDGlobalObject::EnsureScriptEnvironment(PRUint32 lang_id)
|
|||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
rv = SetScriptContext(lang_id, ctxNew);
|
||||
rv = SetScriptContext(ctxNew);
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIScriptContext*
|
||||
nsXULPDGlobalObject::GetScriptContext(PRUint32 lang_id)
|
||||
nsXULPDGlobalObject::GetScriptContext()
|
||||
{
|
||||
NS_ABORT_IF_FALSE(lang_id == nsIProgrammingLanguage::JAVASCRIPT,
|
||||
"We don't support this language ID");
|
||||
// This global object creates a context on demand - do that now.
|
||||
nsresult rv = EnsureScriptEnvironment(nsIProgrammingLanguage::JAVASCRIPT);
|
||||
nsresult rv = EnsureScriptEnvironment();
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("Failed to setup script language");
|
||||
return NULL;
|
||||
}
|
||||
// Note that EnsureScriptEnvironment has validated lang_id
|
||||
|
||||
return mContext;
|
||||
}
|
||||
|
||||
|
|
|
@ -10850,11 +10850,9 @@ nsDocShell::EnsureScriptEnvironment()
|
|||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(mScriptGlobal));
|
||||
win->SetDocShell(static_cast<nsIDocShell *>(this));
|
||||
|
||||
// Ensure the script object is set to run javascript - other languages
|
||||
// setup on demand.
|
||||
// XXXmarkh - should this be setup to run the default language for this doc?
|
||||
// Ensure the script object is set up to run script.
|
||||
nsresult rv;
|
||||
rv = mScriptGlobal->EnsureScriptEnvironment(nsIProgrammingLanguage::JAVASCRIPT);
|
||||
rv = mScriptGlobal->EnsureScriptEnvironment();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -1572,10 +1572,8 @@ nsGlobalWindow::UnmarkGrayTimers()
|
|||
//*****************************************************************************
|
||||
|
||||
nsresult
|
||||
nsGlobalWindow::SetScriptContext(PRUint32 lang_id, nsIScriptContext *aScriptContext)
|
||||
nsGlobalWindow::SetScriptContext(nsIScriptContext *aScriptContext)
|
||||
{
|
||||
NS_ASSERTION(lang_id == nsIProgrammingLanguage::JAVASCRIPT,
|
||||
"We don't support this language ID");
|
||||
NS_ASSERTION(IsOuterWindow(), "Uh, SetScriptContext() called on inner window!");
|
||||
|
||||
NS_ASSERTION(!aScriptContext || !mContext, "Bad call to SetContext()!");
|
||||
|
@ -1601,11 +1599,9 @@ nsGlobalWindow::SetScriptContext(PRUint32 lang_id, nsIScriptContext *aScriptCont
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalWindow::EnsureScriptEnvironment(PRUint32 aLangID)
|
||||
nsGlobalWindow::EnsureScriptEnvironment()
|
||||
{
|
||||
NS_ASSERTION(aLangID == nsIProgrammingLanguage::JAVASCRIPT,
|
||||
"We don't support this language ID");
|
||||
FORWARD_TO_OUTER(EnsureScriptEnvironment, (aLangID), NS_ERROR_NOT_INITIALIZED);
|
||||
FORWARD_TO_OUTER(EnsureScriptEnvironment, (), NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
if (mJSObject)
|
||||
return NS_OK;
|
||||
|
@ -1614,20 +1610,18 @@ nsGlobalWindow::EnsureScriptEnvironment(PRUint32 aLangID)
|
|||
"mJSObject is null, but we have an inner window?");
|
||||
|
||||
nsCOMPtr<nsIScriptRuntime> scriptRuntime;
|
||||
nsresult rv = NS_GetScriptRuntimeByID(aLangID, getter_AddRefs(scriptRuntime));
|
||||
nsresult rv = NS_GetScriptRuntimeByID(nsIProgrammingLanguage::JAVASCRIPT,
|
||||
getter_AddRefs(scriptRuntime));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> context = scriptRuntime->CreateContext();
|
||||
return SetScriptContext(aLangID, context);
|
||||
return SetScriptContext(context);
|
||||
}
|
||||
|
||||
nsIScriptContext *
|
||||
nsGlobalWindow::GetScriptContext(PRUint32 lang)
|
||||
nsGlobalWindow::GetScriptContext()
|
||||
{
|
||||
NS_ASSERTION(lang == nsIProgrammingLanguage::JAVASCRIPT,
|
||||
"We don't support this language ID");
|
||||
|
||||
FORWARD_TO_OUTER(GetScriptContext, (lang), nsnull);
|
||||
FORWARD_TO_OUTER(GetScriptContext, (), nsnull);
|
||||
return mContext;
|
||||
}
|
||||
|
||||
|
@ -1637,7 +1631,7 @@ nsGlobalWindow::GetContext()
|
|||
FORWARD_TO_OUTER(GetContext, (), nsnull);
|
||||
|
||||
// check GetContext is indeed identical to GetScriptContext()
|
||||
NS_ASSERTION(mContext == GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT),
|
||||
NS_ASSERTION(mContext == GetScriptContext(),
|
||||
"GetContext confused?");
|
||||
return mContext;
|
||||
}
|
||||
|
|
|
@ -317,13 +317,13 @@ public:
|
|||
return mJSObject;
|
||||
}
|
||||
|
||||
virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID);
|
||||
virtual nsresult EnsureScriptEnvironment();
|
||||
|
||||
virtual nsIScriptContext *GetScriptContext(PRUint32 lang);
|
||||
virtual nsIScriptContext *GetScriptContext();
|
||||
|
||||
// Set a new script language context for this global. The native global
|
||||
// for the context is created by the context's GetNativeGlobal() method.
|
||||
virtual nsresult SetScriptContext(PRUint32 lang, nsIScriptContext *aContext);
|
||||
virtual nsresult SetScriptContext(nsIScriptContext *aContext);
|
||||
|
||||
virtual void OnFinalize(JSObject* aObject);
|
||||
virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts);
|
||||
|
|
|
@ -122,16 +122,16 @@ public:
|
|||
* has not been registered, as well as 'normal' errors, such as
|
||||
* out-of-memory
|
||||
*/
|
||||
virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID) = 0;
|
||||
virtual nsresult EnsureScriptEnvironment() = 0;
|
||||
/**
|
||||
* Get a script context (WITHOUT added reference) for the specified language.
|
||||
*/
|
||||
virtual nsIScriptContext *GetScriptContext(PRUint32 lang) = 0;
|
||||
virtual nsIScriptContext *GetScriptContext() = 0;
|
||||
|
||||
virtual JSObject* GetGlobalJSObject() = 0;
|
||||
|
||||
virtual nsIScriptContext *GetContext() {
|
||||
return GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT);
|
||||
return GetScriptContext();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,7 +139,7 @@ public:
|
|||
* context is created by the context's GetNativeGlobal() method.
|
||||
*/
|
||||
|
||||
virtual nsresult SetScriptContext(PRUint32 lang, nsIScriptContext *aContext) = 0;
|
||||
virtual nsresult SetScriptContext(nsIScriptContext *aContext) = 0;
|
||||
|
||||
/**
|
||||
* Called when the global script for a language is finalized, typically as
|
||||
|
|
|
@ -143,7 +143,7 @@ nsJSUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj)
|
|||
if (!nativeGlobal)
|
||||
return nsnull;
|
||||
|
||||
return nativeGlobal->GetScriptContext(nsIProgrammingLanguage::JAVASCRIPT);
|
||||
return nativeGlobal->GetScriptContext();
|
||||
}
|
||||
|
||||
nsIScriptGlobalObject *
|
||||
|
|
Загрузка…
Ссылка в новой задаче