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