зеркало из https://github.com/mozilla/gecko-dev.git
Bug 811784: Account for subscripts when figuring out what object to stick properties on. r=mrbkap
--HG-- extra : rebase_source : 6da8a33c512b2e5758094f4a2108e5c342c7c28c
This commit is contained in:
Родитель
59d3bd6ffb
Коммит
c728f95e75
|
@ -625,6 +625,16 @@ mozJSComponentLoader::FindTargetObject(JSContext* aCx,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mozJSComponentLoader::NoteSubScript(JSScript* aScript, JSObject* aThisObject)
|
||||||
|
{
|
||||||
|
if (!mInitialized && NS_FAILED(ReallyInit())) {
|
||||||
|
MOZ_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
mThisObjects.Put(aScript, aThisObject);
|
||||||
|
}
|
||||||
|
|
||||||
// Some stack based classes for cleaning up on early return
|
// Some stack based classes for cleaning up on early return
|
||||||
#ifdef HAVE_PR_MEMMAP
|
#ifdef HAVE_PR_MEMMAP
|
||||||
class FileAutoCloser
|
class FileAutoCloser
|
||||||
|
|
|
@ -54,6 +54,8 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
|
||||||
|
|
||||||
static mozJSComponentLoader* Get() { return sSelf; }
|
static mozJSComponentLoader* Get() { return sSelf; }
|
||||||
|
|
||||||
|
void NoteSubScript(JSScript* aScript, JSObject* aThisObject);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static mozJSComponentLoader* sSelf;
|
static mozJSComponentLoader* sSelf;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include "mozilla/scache/StartupCache.h"
|
#include "mozilla/scache/StartupCache.h"
|
||||||
#include "mozilla/scache/StartupCacheUtils.h"
|
#include "mozilla/scache/StartupCacheUtils.h"
|
||||||
|
#include "mozilla/Preferences.h"
|
||||||
|
|
||||||
using namespace mozilla::scache;
|
using namespace mozilla::scache;
|
||||||
|
|
||||||
|
@ -57,6 +58,7 @@ mozJSSubScriptLoader::mozJSSubScriptLoader() : mSystemPrincipal(nullptr)
|
||||||
// Force construction of the JS component loader. We may need it later.
|
// Force construction of the JS component loader. We may need it later.
|
||||||
nsCOMPtr<xpcIJSModuleLoader> componentLoader =
|
nsCOMPtr<xpcIJSModuleLoader> componentLoader =
|
||||||
do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
|
do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
|
||||||
|
mReuseLoaderGlobal = mozilla::Preferences::GetBool("jsloader.reuseGlobal");
|
||||||
}
|
}
|
||||||
|
|
||||||
mozJSSubScriptLoader::~mozJSSubScriptLoader()
|
mozJSSubScriptLoader::~mozJSSubScriptLoader()
|
||||||
|
@ -77,12 +79,15 @@ nsresult
|
||||||
mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_obj,
|
mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_obj,
|
||||||
const nsAString& charset, const char *uriStr,
|
const nsAString& charset, const char *uriStr,
|
||||||
nsIIOService *serv, nsIPrincipal *principal,
|
nsIIOService *serv, nsIPrincipal *principal,
|
||||||
JSScript **scriptp)
|
JSScript **scriptp, JSFunction **functionp)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIChannel> chan;
|
nsCOMPtr<nsIChannel> chan;
|
||||||
nsCOMPtr<nsIInputStream> instream;
|
nsCOMPtr<nsIInputStream> instream;
|
||||||
JSErrorReporter er;
|
JSErrorReporter er;
|
||||||
|
|
||||||
|
*scriptp = nullptr;
|
||||||
|
*functionp = nullptr;
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
// Instead of calling NS_OpenURI, we create the channel ourselves and call
|
// Instead of calling NS_OpenURI, we create the channel ourselves and call
|
||||||
// SetContentType, to avoid expensive MIME type lookups (bug 632490).
|
// SetContentType, to avoid expensive MIME type lookups (bug 632490).
|
||||||
|
@ -120,7 +125,9 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_ob
|
||||||
JS::CompileOptions options(cx);
|
JS::CompileOptions options(cx);
|
||||||
options.setPrincipals(nsJSPrincipals::get(principal))
|
options.setPrincipals(nsJSPrincipals::get(principal))
|
||||||
.setFileAndLine(uriStr, 1)
|
.setFileAndLine(uriStr, 1)
|
||||||
.setSourcePolicy(JS::CompileOptions::LAZY_SOURCE);
|
.setSourcePolicy(mReuseLoaderGlobal ?
|
||||||
|
JS::CompileOptions::NO_SOURCE :
|
||||||
|
JS::CompileOptions::LAZY_SOURCE);
|
||||||
js::RootedObject target_obj_root(cx, target_obj);
|
js::RootedObject target_obj_root(cx, target_obj);
|
||||||
if (!charset.IsVoid()) {
|
if (!charset.IsVoid()) {
|
||||||
nsString script;
|
nsString script;
|
||||||
|
@ -131,10 +138,24 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_ob
|
||||||
return ReportError(cx, LOAD_ERROR_BADCHARSET);
|
return ReportError(cx, LOAD_ERROR_BADCHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
*scriptp = JS::Compile(cx, target_obj_root, options,
|
if (!mReuseLoaderGlobal) {
|
||||||
reinterpret_cast<const jschar*>(script.get()), script.Length());
|
*scriptp = JS::Compile(cx, target_obj_root, options,
|
||||||
|
reinterpret_cast<const jschar*>(script.get()),
|
||||||
|
script.Length());
|
||||||
|
} else {
|
||||||
|
*functionp = JS::CompileFunction(cx, target_obj_root, options,
|
||||||
|
nullptr, 0, nullptr,
|
||||||
|
reinterpret_cast<const jschar*>(script.get()),
|
||||||
|
script.Length());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
*scriptp = JS::Compile(cx, target_obj_root, options, buf.get(), len);
|
if (!mReuseLoaderGlobal) {
|
||||||
|
*scriptp = JS::Compile(cx, target_obj_root, options, buf.get(), len);
|
||||||
|
} else {
|
||||||
|
*functionp = JS::CompileFunction(cx, target_obj_root, options,
|
||||||
|
nullptr, 0, nullptr, buf.get(),
|
||||||
|
len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* repent for our evil deeds */
|
/* repent for our evil deeds */
|
||||||
|
@ -181,10 +202,9 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
|
||||||
if (!JS_ValueToObject(cx, target, &targetObj))
|
if (!JS_ValueToObject(cx, target, &targetObj))
|
||||||
return NS_ERROR_ILLEGAL_VALUE;
|
return NS_ERROR_ILLEGAL_VALUE;
|
||||||
|
|
||||||
|
mozJSComponentLoader* loader = mozJSComponentLoader::Get();
|
||||||
if (!targetObj) {
|
if (!targetObj) {
|
||||||
// If the user didn't provide an object to eval onto, find one.
|
// If the user didn't provide an object to eval onto, find one.
|
||||||
mozJSComponentLoader* loader = mozJSComponentLoader::Get();
|
|
||||||
rv = loader->FindTargetObject(cx, &targetObj);
|
rv = loader->FindTargetObject(cx, &targetObj);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
@ -272,20 +292,32 @@ mozJSSubScriptLoader::LoadSubScript(const nsAString& url,
|
||||||
cachePath.AppendPrintf("jssubloader/%d", version);
|
cachePath.AppendPrintf("jssubloader/%d", version);
|
||||||
PathifyURI(uri, cachePath);
|
PathifyURI(uri, cachePath);
|
||||||
|
|
||||||
|
JSFunction* function = nullptr;
|
||||||
script = nullptr;
|
script = nullptr;
|
||||||
if (cache)
|
if (cache)
|
||||||
rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
|
rv = ReadCachedScript(cache, cachePath, cx, mSystemPrincipal, &script);
|
||||||
if (!script) {
|
if (!script) {
|
||||||
rv = ReadScript(uri, cx, targetObj, charset,
|
rv = ReadScript(uri, cx, targetObj, charset,
|
||||||
static_cast<const char*>(uriStr.get()), serv,
|
static_cast<const char*>(uriStr.get()), serv,
|
||||||
principal, &script);
|
principal, &script, &function);
|
||||||
writeScript = true;
|
writeScript = !!script;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_FAILED(rv) || !script)
|
if (NS_FAILED(rv) || (!script && !function))
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
bool ok = JS_ExecuteScriptVersion(cx, targetObj, script, retval, version);
|
if (function) {
|
||||||
|
script = JS_GetFunctionScript(cx, function);
|
||||||
|
}
|
||||||
|
|
||||||
|
loader->NoteSubScript(script, targetObj);
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
if (function) {
|
||||||
|
ok = JS_CallFunction(cx, targetObj, function, 0, nullptr, retval);
|
||||||
|
} else {
|
||||||
|
ok = JS_ExecuteScriptVersion(cx, targetObj, script, retval, version);
|
||||||
|
}
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
JSAutoCompartment rac(cx, result_obj);
|
JSAutoCompartment rac(cx, result_obj);
|
||||||
|
|
|
@ -33,7 +33,8 @@ private:
|
||||||
nsresult ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_obj,
|
nsresult ReadScript(nsIURI *uri, JSContext *cx, JSObject *target_obj,
|
||||||
const nsAString& charset, const char *uriStr,
|
const nsAString& charset, const char *uriStr,
|
||||||
nsIIOService *serv, nsIPrincipal *principal,
|
nsIIOService *serv, nsIPrincipal *principal,
|
||||||
JSScript **scriptp);
|
JSScript **scriptp, JSFunction **functionp);
|
||||||
|
|
||||||
|
bool mReuseLoaderGlobal;
|
||||||
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
nsCOMPtr<nsIPrincipal> mSystemPrincipal;
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче