зеркало из https://github.com/mozilla/gecko-dev.git
Bug 901106 - Be more direct in nsXULPrototypeScript::Compile. r=smaug
Given that this is just the phony compilation global we're dealing with, the only thing relevant about this script context is that it defaults to the right compartment. But we can do that manually with the SafeJSContext. The CanExecuteScripts check was something I added to address review comments in bug 901162 comment 8. I now realize that it's effectively a no-op, because the nsIScriptContext here corresponds to the compilation scope, not the document, so it will never have script disabled.
This commit is contained in:
Родитель
9ccecb62c8
Коммит
31ddf22a6f
|
@ -2594,7 +2594,7 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
|
|||
nsIURI* aURI,
|
||||
uint32_t aLineNo,
|
||||
nsIDocument* aDocument,
|
||||
nsIScriptGlobalObject* aGlobal,
|
||||
nsXULPrototypeDocument* aProtoDoc,
|
||||
nsIOffThreadScriptReceiver *aOffThreadReceiver /* = nullptr */)
|
||||
{
|
||||
// We'll compile the script using the prototype document's special
|
||||
|
@ -2607,33 +2607,16 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
|
|||
// our script object would reference the first document, and the
|
||||
// first document would indirectly reference the prototype document
|
||||
// because it keeps the prototype cache alive. Circularity!
|
||||
NS_ASSERTION(aGlobal, "prototype doc has no script global");
|
||||
if (!aGlobal) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
// Use the prototype document's special context
|
||||
nsIScriptContext *context = aGlobal->GetScriptContext();
|
||||
NS_ASSERTION(context, "no context for script global");
|
||||
if (! context) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
MOZ_ASSERT(aProtoDoc);
|
||||
NS_ENSURE_TRUE(aProtoDoc->GetCompilationGlobal(), NS_ERROR_UNEXPECTED);
|
||||
AutoSafeJSContext cx;
|
||||
JSAutoCompartment ac(cx, aProtoDoc->GetCompilationGlobal());
|
||||
|
||||
nsAutoCString urlspec;
|
||||
nsContentUtils::GetWrapperSafeScriptFilename(aDocument, aURI, urlspec);
|
||||
|
||||
// Ok, compile it to create a prototype script object!
|
||||
|
||||
JSContext* cx = context->GetNativeContext();
|
||||
AutoCxPusher pusher(cx);
|
||||
|
||||
bool ok = false;
|
||||
nsresult rv = nsContentUtils::GetSecurityManager()->
|
||||
CanExecuteScripts(cx, aDocument->NodePrincipal(), &ok);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(ok, NS_OK);
|
||||
NS_ENSURE_TRUE(JSVersion(mLangVersion) != JSVERSION_UNKNOWN, NS_OK);
|
||||
|
||||
JS::CompileOptions options(cx);
|
||||
options.setPrincipals(nsJSPrincipals::get(aDocument->NodePrincipal()))
|
||||
.setFileAndLine(urlspec.get(), aLineNo)
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
class nsIDocument;
|
||||
class nsString;
|
||||
class nsIDocShell;
|
||||
class nsXULPrototypeDocument;
|
||||
|
||||
class nsIObjectInputStream;
|
||||
class nsIObjectOutputStream;
|
||||
|
@ -231,7 +232,7 @@ public:
|
|||
nsresult Compile(const PRUnichar* aText, int32_t aTextLength,
|
||||
nsIURI* aURI, uint32_t aLineNo,
|
||||
nsIDocument* aDocument,
|
||||
nsIScriptGlobalObject* aGlobal,
|
||||
nsXULPrototypeDocument* aProtoDoc,
|
||||
nsIOffThreadScriptReceiver *aOffThreadReceiver = nullptr);
|
||||
|
||||
void UnlinkJSObjects();
|
||||
|
|
|
@ -3525,7 +3525,7 @@ XULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
rv = mCurrentScriptProto->Compile(mOffThreadCompileString.get(),
|
||||
mOffThreadCompileString.Length(),
|
||||
uri, 1, this,
|
||||
mCurrentPrototype->GetScriptGlobalObject(),
|
||||
mCurrentPrototype,
|
||||
this);
|
||||
if (NS_SUCCEEDED(rv) && !mCurrentScriptProto->GetScriptObject()) {
|
||||
// We will be notified via OnOffThreadCompileComplete when the
|
||||
|
|
|
@ -567,8 +567,7 @@ XULContentSinkImpl::HandleEndElement(const PRUnichar *aName)
|
|||
script->mOutOfLine = false;
|
||||
if (doc)
|
||||
script->Compile(mText, mTextLength, mDocumentURL,
|
||||
script->mLineNo, doc,
|
||||
mPrototype->GetScriptGlobalObject());
|
||||
script->mLineNo, doc, mPrototype);
|
||||
}
|
||||
|
||||
FlushText(false);
|
||||
|
|
|
@ -629,6 +629,13 @@ nsXULPrototypeDocument::SetDocumentPrincipal(nsIPrincipal* aPrincipal)
|
|||
mNodeInfoManager->SetDocumentPrincipal(aPrincipal);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
nsXULPrototypeDocument::GetCompilationGlobal()
|
||||
{
|
||||
GetScriptGlobalObject()->EnsureScriptEnvironment();
|
||||
return GetScriptGlobalObject()->GetGlobalJSObject();
|
||||
}
|
||||
|
||||
nsNodeInfoManager*
|
||||
nsXULPrototypeDocument::GetNodeInfoManager()
|
||||
{
|
||||
|
|
|
@ -114,6 +114,8 @@ public:
|
|||
|
||||
nsNodeInfoManager *GetNodeInfoManager();
|
||||
|
||||
JSObject* GetCompilationGlobal();
|
||||
|
||||
// nsIScriptGlobalObjectOwner methods
|
||||
virtual nsIScriptGlobalObject* GetScriptGlobalObject() MOZ_OVERRIDE;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче