Bug 940305 - Move extraWarnings to RuntimeOptions with a per-compartment override. r=jandem,r=khuey

This commit is contained in:
Bobby Holley 2014-07-29 21:00:37 -07:00
parent 5116dd5ac7
commit 9f2d788107
18 changed files with 108 additions and 144 deletions

View File

@ -710,10 +710,6 @@ DumpString(const nsAString &str)
#define JS_OPTIONS_DOT_STR "javascript.options."
static const char js_options_dot_str[] = JS_OPTIONS_DOT_STR;
static const char js_strict_option_str[] = JS_OPTIONS_DOT_STR "strict";
#ifdef DEBUG
static const char js_strict_debug_option_str[] = JS_OPTIONS_DOT_STR "strict.debug";
#endif
#ifdef JS_GC_ZEAL
static const char js_zeal_option_str[] = JS_OPTIONS_DOT_STR "gczeal";
static const char js_zeal_frequency_str[] = JS_OPTIONS_DOT_STR "gczeal.frequency";
@ -724,34 +720,11 @@ static const char js_memnotify_option_str[] = JS_OPTIONS_DOT_STR "mem.notify";
void
nsJSContext::JSOptionChangedCallback(const char *pref, void *data)
{
nsJSContext *context = reinterpret_cast<nsJSContext *>(data);
JSContext *cx = context->mContext;
sPostGCEventsToConsole = Preferences::GetBool(js_memlog_option_str);
sPostGCEventsToObserver = Preferences::GetBool(js_memnotify_option_str);
JS::ContextOptionsRef(cx).setExtraWarnings(Preferences::GetBool(js_strict_option_str));
// The vanilla GetGlobalObject returns null if a global isn't set up on
// the context yet. We can sometimes be call midway through context init,
// So ask for the member directly instead.
nsIScriptGlobalObject *global = context->GetGlobalObjectRef();
// XXX should we check for sysprin instead of a chrome window, to make
// XXX components be covered by the chrome pref instead of the content one?
nsCOMPtr<nsIDOMWindow> contentWindow(do_QueryInterface(global));
nsCOMPtr<nsIDOMChromeWindow> chromeWindow(do_QueryInterface(global));
#ifdef DEBUG
// In debug builds, warnings are enabled in chrome context if
// javascript.options.strict.debug is true
if (Preferences::GetBool(js_strict_debug_option_str) &&
(chromeWindow || !contentWindow)) {
JS::ContextOptionsRef(cx).setExtraWarnings(true);
}
#endif
#ifdef JS_GC_ZEAL
nsJSContext *context = reinterpret_cast<nsJSContext *>(data);
int32_t zeal = Preferences::GetInt(js_zeal_option_str, -1);
int32_t frequency = Preferences::GetInt(js_zeal_frequency_str, JS_DEFAULT_ZEAL_FREQ);
if (zeal >= 0)

View File

@ -317,7 +317,7 @@ GenerateSharedWorkerKey(const nsACString& aScriptSpec, const nsACString& aName,
}
void
LoadRuntimeAndContextOptions(const char* aPrefName, void* /* aClosure */)
LoadRuntimeOptions(const char* aPrefName, void* /* aClosure */)
{
AssertIsOnMainThread();
@ -365,29 +365,14 @@ LoadRuntimeAndContextOptions(const char* aPrefName, void* /* aClosure */)
runtimeOptions.setWerror(true);
}
// Common options.
JS::ContextOptions commonContextOptions = kRequiredContextOptions;
if (GetWorkerPref<bool>(NS_LITERAL_CSTRING("strict"))) {
commonContextOptions.setExtraWarnings(true);
runtimeOptions.setExtraWarnings(true);
}
// Content options.
JS::ContextOptions contentContextOptions = commonContextOptions;
// Chrome options.
JS::ContextOptions chromeContextOptions = commonContextOptions;
#ifdef DEBUG
if (GetWorkerPref<bool>(NS_LITERAL_CSTRING("strict.debug"))) {
chromeContextOptions.setExtraWarnings(true);
}
#endif
RuntimeService::SetDefaultRuntimeAndContextOptions(runtimeOptions,
contentContextOptions,
chromeContextOptions);
RuntimeService::SetDefaultRuntimeOptions(runtimeOptions);
if (rts) {
rts->UpdateAllWorkerRuntimeAndContextOptions();
rts->UpdateAllWorkerRuntimeOptions();
}
}
@ -847,9 +832,7 @@ CreateJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
js::SetCTypesActivityCallback(aRuntime, CTypesActivityCallback);
JS::ContextOptionsRef(workerCx) =
aWorkerPrivate->IsChromeWorker() ? settings.chrome.contextOptions
: settings.content.contextOptions;
JS::ContextOptionsRef(workerCx) = kRequiredContextOptions;
#ifdef JS_GC_ZEAL
JS_SetGCZeal(workerCx, settings.gcZeal, settings.gcZealFrequency);
@ -1699,10 +1682,8 @@ RuntimeService::Init()
// Initialize JSSettings.
if (!sDefaultJSSettings.gcSettings[0].IsSet()) {
sDefaultJSSettings.runtimeOptions = JS::RuntimeOptions();
sDefaultJSSettings.chrome.contextOptions = kRequiredContextOptions;
sDefaultJSSettings.chrome.maxScriptRuntime = -1;
sDefaultJSSettings.chrome.compartmentOptions.setVersion(JSVERSION_LATEST);
sDefaultJSSettings.content.contextOptions = kRequiredContextOptions;
sDefaultJSSettings.content.maxScriptRuntime = MAX_SCRIPT_RUN_TIME_SEC;
#ifdef JS_GC_ZEAL
sDefaultJSSettings.gcZealFrequency = JS_DEFAULT_ZEAL_FREQ;
@ -1781,11 +1762,11 @@ RuntimeService::Init()
WorkerPrefChanged,
PREF_DOM_FETCH_ENABLED,
reinterpret_cast<void *>(WORKERPREF_DOM_FETCH))) ||
NS_FAILED(Preferences::RegisterCallback(LoadRuntimeAndContextOptions,
NS_FAILED(Preferences::RegisterCallback(LoadRuntimeOptions,
PREF_JS_OPTIONS_PREFIX,
nullptr)) ||
NS_FAILED(Preferences::RegisterCallbackAndCall(
LoadRuntimeAndContextOptions,
LoadRuntimeOptions,
PREF_WORKERS_OPTIONS_PREFIX,
nullptr)) ||
NS_FAILED(Preferences::RegisterCallbackAndCall(
@ -1934,10 +1915,10 @@ RuntimeService::Cleanup()
if (NS_FAILED(Preferences::UnregisterCallback(JSVersionChanged,
PREF_WORKERS_LATEST_JS_VERSION,
nullptr)) ||
NS_FAILED(Preferences::UnregisterCallback(LoadRuntimeAndContextOptions,
NS_FAILED(Preferences::UnregisterCallback(LoadRuntimeOptions,
PREF_JS_OPTIONS_PREFIX,
nullptr)) ||
NS_FAILED(Preferences::UnregisterCallback(LoadRuntimeAndContextOptions,
NS_FAILED(Preferences::UnregisterCallback(LoadRuntimeOptions,
PREF_WORKERS_OPTIONS_PREFIX,
nullptr)) ||
NS_FAILED(Preferences::UnregisterCallback(
@ -2389,12 +2370,9 @@ RuntimeService::NoteIdleThread(WorkerThread* aThread)
}
void
RuntimeService::UpdateAllWorkerRuntimeAndContextOptions()
RuntimeService::UpdateAllWorkerRuntimeOptions()
{
BROADCAST_ALL_WORKERS(UpdateRuntimeAndContextOptions,
sDefaultJSSettings.runtimeOptions,
sDefaultJSSettings.content.contextOptions,
sDefaultJSSettings.chrome.contextOptions);
BROADCAST_ALL_WORKERS(UpdateRuntimeOptions, sDefaultJSSettings.runtimeOptions);
}
void

View File

@ -193,19 +193,14 @@ public:
}
static void
SetDefaultRuntimeAndContextOptions(
const JS::RuntimeOptions& aRuntimeOptions,
const JS::ContextOptions& aContentCxOptions,
const JS::ContextOptions& aChromeCxOptions)
SetDefaultRuntimeOptions(const JS::RuntimeOptions& aRuntimeOptions)
{
AssertIsOnMainThread();
sDefaultJSSettings.runtimeOptions = aRuntimeOptions;
sDefaultJSSettings.content.contextOptions = aContentCxOptions;
sDefaultJSSettings.chrome.contextOptions = aChromeCxOptions;
}
void
UpdateAllWorkerRuntimeAndContextOptions();
UpdateAllWorkerRuntimeOptions();
void
UpdateAllWorkerPreference(WorkerPreference aPref, bool aValue);

View File

@ -724,6 +724,11 @@ ScriptExecutorRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
JS::CompartmentOptionsRef(global).setDiscardSource(discard);
}
// Similar to the above.
if (xpc::ExtraWarningsForSystemJS() && aWorkerPrivate->UsesSystemPrincipal()) {
JS::CompartmentOptionsRef(global).extraWarningsOverride().set(true);
}
for (uint32_t index = mFirstIndex; index <= mLastIndex; index++) {
ScriptLoadInfo& loadInfo = loadInfos.ElementAt(index);

View File

@ -1547,32 +1547,23 @@ private:
}
};
class UpdateRuntimeAndContextOptionsRunnable MOZ_FINAL : public WorkerControlRunnable
class UpdateRuntimeOptionsRunnable MOZ_FINAL : public WorkerControlRunnable
{
JS::RuntimeOptions mRuntimeOptions;
JS::ContextOptions mContentCxOptions;
JS::ContextOptions mChromeCxOptions;
public:
UpdateRuntimeAndContextOptionsRunnable(
UpdateRuntimeOptionsRunnable(
WorkerPrivate* aWorkerPrivate,
const JS::RuntimeOptions& aRuntimeOptions,
const JS::ContextOptions& aContentCxOptions,
const JS::ContextOptions& aChromeCxOptions)
const JS::RuntimeOptions& aRuntimeOptions)
: WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount),
mRuntimeOptions(aRuntimeOptions),
mContentCxOptions(aContentCxOptions),
mChromeCxOptions(aChromeCxOptions)
mRuntimeOptions(aRuntimeOptions)
{ }
private:
virtual bool
WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) MOZ_OVERRIDE
{
aWorkerPrivate->UpdateRuntimeAndContextOptionsInternal(aCx,
mRuntimeOptions,
mContentCxOptions,
mChromeCxOptions);
aWorkerPrivate->UpdateRuntimeOptionsInternal(aCx, mRuntimeOptions);
return true;
}
};
@ -2881,26 +2872,19 @@ WorkerPrivateParent<Derived>::GetInnerWindowId()
template <class Derived>
void
WorkerPrivateParent<Derived>::UpdateRuntimeAndContextOptions(
WorkerPrivateParent<Derived>::UpdateRuntimeOptions(
JSContext* aCx,
const JS::RuntimeOptions& aRuntimeOptions,
const JS::ContextOptions& aContentCxOptions,
const JS::ContextOptions& aChromeCxOptions)
const JS::RuntimeOptions& aRuntimeOptions)
{
AssertIsOnParentThread();
{
MutexAutoLock lock(mMutex);
mJSSettings.runtimeOptions = aRuntimeOptions;
mJSSettings.content.contextOptions = aContentCxOptions;
mJSSettings.chrome.contextOptions = aChromeCxOptions;
}
nsRefPtr<UpdateRuntimeAndContextOptionsRunnable> runnable =
new UpdateRuntimeAndContextOptionsRunnable(ParentAsWorkerPrivate(),
aRuntimeOptions,
aContentCxOptions,
aChromeCxOptions);
nsRefPtr<UpdateRuntimeOptionsRunnable> runnable =
new UpdateRuntimeOptionsRunnable(ParentAsWorkerPrivate(), aRuntimeOptions);
if (!runnable->Dispatch(aCx)) {
NS_WARNING("Failed to update worker context options!");
JS_ClearPendingException(aCx);
@ -5534,21 +5518,16 @@ WorkerPrivate::RescheduleTimeoutTimer(JSContext* aCx)
}
void
WorkerPrivate::UpdateRuntimeAndContextOptionsInternal(
WorkerPrivate::UpdateRuntimeOptionsInternal(
JSContext* aCx,
const JS::RuntimeOptions& aRuntimeOptions,
const JS::ContextOptions& aContentCxOptions,
const JS::ContextOptions& aChromeCxOptions)
const JS::RuntimeOptions& aRuntimeOptions)
{
AssertIsOnWorkerThread();
JS::RuntimeOptionsRef(aCx) = aRuntimeOptions;
JS::ContextOptionsRef(aCx) = IsChromeWorker() ? aChromeCxOptions : aContentCxOptions;
for (uint32_t index = 0; index < mChildWorkers.Length(); index++) {
mChildWorkers[index]->UpdateRuntimeAndContextOptions(aCx, aRuntimeOptions,
aContentCxOptions,
aChromeCxOptions);
mChildWorkers[index]->UpdateRuntimeOptions(aCx, aRuntimeOptions);
}
}

View File

@ -393,10 +393,8 @@ public:
GetInnerWindowId();
void
UpdateRuntimeAndContextOptions(JSContext* aCx,
const JS::RuntimeOptions& aRuntimeOptions,
const JS::ContextOptions& aContentCxOptions,
const JS::ContextOptions& aChromeCxOptions);
UpdateRuntimeOptions(JSContext* aCx,
const JS::RuntimeOptions& aRuntimeOptions);
void
UpdatePreference(JSContext* aCx, WorkerPreference aPref, bool aValue);
@ -929,11 +927,7 @@ public:
}
void
UpdateRuntimeAndContextOptionsInternal(
JSContext* aCx,
const JS::RuntimeOptions& aRuntimeOptions,
const JS::ContextOptions& aContentCxOptions,
const JS::ContextOptions& aChromeCxOptions);
UpdateRuntimeOptionsInternal(JSContext* aCx, const JS::RuntimeOptions& aRuntimeOptions);
void
UpdatePreferenceInternal(JSContext* aCx, WorkerPreference aPref, bool aValue);

View File

@ -95,12 +95,11 @@ struct JSSettings
// Settings that change based on chrome/content context.
struct JSContentChromeSettings
{
JS::ContextOptions contextOptions;
JS::CompartmentOptions compartmentOptions;
int32_t maxScriptRuntime;
JSContentChromeSettings()
: contextOptions(), compartmentOptions(), maxScriptRuntime(0)
: compartmentOptions(), maxScriptRuntime(0)
{ }
};

View File

@ -2358,6 +2358,18 @@ class AutoCompartmentRooter : private JS::CustomAutoRooter
} /* anonymous namespace */
bool
JS::CompartmentOptions::extraWarnings(JSRuntime *rt) const
{
return extraWarningsOverride_.get(rt->options().extraWarnings());
}
bool
JS::CompartmentOptions::extraWarnings(JSContext *cx) const
{
return extraWarnings(cx->runtime());
}
JS::CompartmentOptions &
JS::CompartmentOptions::setZone(ZoneSpecifier spec)
{
@ -4421,7 +4433,7 @@ JS::CompileOptions::CompileOptions(JSContext *cx, JSVersion version)
compileAndGo = false;
noScriptRval = cx->options().noScriptRval();
strictOption = cx->runtime()->options().strictMode();
extraWarningsOption = cx->options().extraWarnings();
extraWarningsOption = cx->compartment()->options().extraWarnings(cx);
werrorOption = cx->runtime()->options().werror();
asmJSOption = cx->runtime()->options().asmJS();
}

View File

@ -1424,6 +1424,7 @@ class JS_PUBLIC_API(RuntimeOptions) {
nativeRegExp_(false),
werror_(false),
strictMode_(false),
extraWarnings_(false),
varObjFix_(false)
{
}
@ -1484,6 +1485,16 @@ class JS_PUBLIC_API(RuntimeOptions) {
return *this;
}
bool extraWarnings() const { return extraWarnings_; }
RuntimeOptions &setExtraWarnings(bool flag) {
extraWarnings_ = flag;
return *this;
}
RuntimeOptions &toggleExtraWarnings() {
extraWarnings_ = !extraWarnings_;
return *this;
}
bool varObjFix() const { return varObjFix_; }
RuntimeOptions &setVarObjFix(bool flag) {
varObjFix_ = flag;
@ -1501,6 +1512,7 @@ class JS_PUBLIC_API(RuntimeOptions) {
bool nativeRegExp_ : 1;
bool werror_ : 1;
bool strictMode_ : 1;
bool extraWarnings_ : 1;
bool varObjFix_ : 1;
};
@ -1513,24 +1525,13 @@ RuntimeOptionsRef(JSContext *cx);
class JS_PUBLIC_API(ContextOptions) {
public:
ContextOptions()
: extraWarnings_(false),
privateIsNSISupports_(false),
: privateIsNSISupports_(false),
dontReportUncaught_(false),
noDefaultCompartmentObject_(false),
noScriptRval_(false)
{
}
bool extraWarnings() const { return extraWarnings_; }
ContextOptions &setExtraWarnings(bool flag) {
extraWarnings_ = flag;
return *this;
}
ContextOptions &toggleExtraWarnings() {
extraWarnings_ = !extraWarnings_;
return *this;
}
bool privateIsNSISupports() const { return privateIsNSISupports_; }
ContextOptions &setPrivateIsNSISupports(bool flag) {
privateIsNSISupports_ = flag;
@ -1572,7 +1573,6 @@ class JS_PUBLIC_API(ContextOptions) {
}
private:
bool extraWarnings_ : 1;
bool privateIsNSISupports_ : 1;
bool dontReportUncaught_ : 1;
bool noDefaultCompartmentObject_ : 1;
@ -2618,6 +2618,10 @@ class JS_PUBLIC_API(CompartmentOptions)
return *this;
}
bool extraWarnings(JSRuntime *rt) const;
bool extraWarnings(JSContext *cx) const;
Override &extraWarningsOverride() { return extraWarningsOverride_; }
void *zonePointer() const {
JS_ASSERT(uintptr_t(zone_.pointer) > uintptr_t(JS::SystemZone));
return zone_.pointer;
@ -2655,6 +2659,7 @@ class JS_PUBLIC_API(CompartmentOptions)
bool mergeable_;
bool discardSource_;
bool cloneSingletons_;
Override extraWarningsOverride_;
union {
ZoneSpecifier spec;
void *pointer; // js::Zone* is not exposed in the API.

View File

@ -777,7 +777,7 @@ js::WouldDefinePastNonwritableLength(ThreadSafeContext *cx,
JSContext *ncx = cx->asJSContext();
if (!strict && !ncx->options().extraWarnings())
if (!strict && !ncx->compartment()->options().extraWarnings(ncx))
return true;
// XXX include the index and maybe array length in the error message

View File

@ -460,13 +460,13 @@ checkReportFlags(JSContext *cx, unsigned *flags)
JSScript *script = cx->currentScript();
if (script && script->strict())
*flags &= ~JSREPORT_WARNING;
else if (cx->options().extraWarnings())
else if (cx->compartment()->options().extraWarnings(cx))
*flags |= JSREPORT_WARNING;
else
return true;
} else if (JSREPORT_IS_STRICT(*flags)) {
/* Warning/error only when JSOPTION_STRICT is set. */
if (!cx->options().extraWarnings())
if (!cx->compartment()->options().extraWarnings(cx))
return true;
}

View File

@ -4742,7 +4742,7 @@ GetPropertyHelperInline(JSContext *cx,
}
/* Don't warn if extra warnings not enabled or for random getprop operations. */
if (!cx->options().extraWarnings() || (op != JSOP_GETPROP && op != JSOP_GETELEM))
if (!cx->compartment()->options().extraWarnings(cx) || (op != JSOP_GETPROP && op != JSOP_GETELEM))
return true;
/* Don't warn repeatedly for the same script. */
@ -5010,7 +5010,7 @@ MaybeReportUndeclaredVarAssignment(JSContext *cx, JSString *propname)
// If the code is not strict and extra warnings aren't enabled, then no
// check is needed.
if (!script->strict() && !cx->options().extraWarnings())
if (!script->strict() && !cx->compartment()->options().extraWarnings(cx))
return true;
}
@ -5129,7 +5129,7 @@ baseops::SetPropertyHelper(typename ExecutionModeTraits<mode>::ContextType cxArg
if (pd.isReadonly()) {
if (strict)
return JSObject::reportReadOnly(cx, id, JSREPORT_ERROR);
if (cx->options().extraWarnings())
if (cx->compartment()->options().extraWarnings(cx))
return JSObject::reportReadOnly(cx, id, JSREPORT_STRICT | JSREPORT_WARNING);
return true;
}
@ -5189,7 +5189,7 @@ baseops::SetPropertyHelper(typename ExecutionModeTraits<mode>::ContextType cxArg
JSContext *cx = cxArg->asJSContext();
if (strict)
return JSObject::reportReadOnly(cx, id, JSREPORT_ERROR);
if (cx->options().extraWarnings())
if (cx->compartment()->options().extraWarnings(cx))
return JSObject::reportReadOnly(cx, id, JSREPORT_STRICT | JSREPORT_WARNING);
return true;
}
@ -5299,8 +5299,11 @@ baseops::SetPropertyHelper(typename ExecutionModeTraits<mode>::ContextType cxArg
/* Error in strict mode code, warn with extra warnings option, otherwise do nothing. */
if (strict)
return obj->reportNotExtensible(cxArg);
if (mode == SequentialExecution && cxArg->asJSContext()->options().extraWarnings())
if (mode == SequentialExecution &&
cxArg->asJSContext()->compartment()->options().extraWarnings(cxArg->asJSContext()))
{
return obj->reportNotExtensible(cxArg, JSREPORT_STRICT | JSREPORT_WARNING);
}
return true;
}

View File

@ -764,7 +764,6 @@ Options(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JS::ContextOptions oldContextOptions = JS::ContextOptionsRef(cx);
JS::RuntimeOptions oldRuntimeOptions = JS::RuntimeOptionsRef(cx);
for (unsigned i = 0; i < args.length(); i++) {
JSString *str = JS::ToString(cx, args[i]);
@ -777,7 +776,7 @@ Options(JSContext *cx, unsigned argc, jsval *vp)
return false;
if (strcmp(opt.ptr(), "strict") == 0)
JS::ContextOptionsRef(cx).toggleExtraWarnings();
JS::RuntimeOptionsRef(cx).toggleExtraWarnings();
else if (strcmp(opt.ptr(), "werror") == 0)
JS::RuntimeOptionsRef(cx).toggleWerror();
else if (strcmp(opt.ptr(), "strict_mode") == 0)
@ -794,7 +793,7 @@ Options(JSContext *cx, unsigned argc, jsval *vp)
char *names = strdup("");
bool found = false;
if (names && oldContextOptions.extraWarnings()) {
if (names && oldRuntimeOptions.extraWarnings()) {
names = JS_sprintf_append(names, "%s%s", found ? "," : "", "strict");
found = true;
}
@ -5675,7 +5674,7 @@ ProcessArgs(JSContext *cx, JSObject *obj_, OptionParser *op)
RootedObject obj(cx, obj_);
if (op->getBoolOption('s'))
JS::ContextOptionsRef(cx).toggleExtraWarnings();
JS::RuntimeOptionsRef(cx).toggleExtraWarnings();
if (op->getBoolOption('d')) {
JS_SetRuntimeDebugMode(JS_GetRuntime(cx), true);

View File

@ -3239,7 +3239,7 @@ nsXPCComponents_Utils::Dispatch(HandleValue runnableArg, HandleValue scope,
return NS_OK; \
}
GENERATE_JSCONTEXTOPTION_GETTER_SETTER(Strict, extraWarnings, setExtraWarnings)
GENERATE_JSRUNTIMEOPTION_GETTER_SETTER(Strict, extraWarnings, setExtraWarnings)
GENERATE_JSRUNTIMEOPTION_GETTER_SETTER(Werror, werror, setWerror)
GENERATE_JSRUNTIMEOPTION_GETTER_SETTER(Strict_mode, strictMode, setStrictMode)
GENERATE_JSRUNTIMEOPTION_GETTER_SETTER(Ion, ion, setIon)

View File

@ -101,6 +101,13 @@ static mozilla::Atomic<bool> sDiscardSystemSource(false);
bool
xpc::ShouldDiscardSystemSource() { return sDiscardSystemSource; }
#ifdef DEBUG
static mozilla::Atomic<bool> sExtraWarningsForSystemJS(false);
bool xpc::ExtraWarningsForSystemJS() { return sExtraWarningsForSystemJS; }
#else
bool xpc::ExtraWarningsForSystemJS() { return false; }
#endif
static void * const UNMARK_ONLY = nullptr;
static void * const UNMARK_AND_SWEEP = (void *)1;
@ -1538,11 +1545,17 @@ ReloadPrefsCallback(const char *pref, void *data)
bool werror = Preferences::GetBool(JS_OPTIONS_DOT_STR "werror");
bool extraWarnings = Preferences::GetBool(JS_OPTIONS_DOT_STR "strict");
#ifdef DEBUG
sExtraWarningsForSystemJS = Preferences::GetBool(JS_OPTIONS_DOT_STR "strict.debug");
#endif
JS::RuntimeOptionsRef(rt).setBaseline(useBaseline)
.setIon(useIon)
.setAsmJS(useAsmJS)
.setNativeRegExp(useNativeRegExp)
.setWerror(werror);
.setWerror(werror)
.setExtraWarnings(extraWarnings);
JS_SetParallelParsingEnabled(rt, parallelParsing);
JS_SetOffthreadIonCompilationEnabled(rt, offthreadIonCompilation);

View File

@ -470,7 +470,6 @@ static bool
Options(JSContext *cx, unsigned argc, jsval *vp)
{
JS::CallArgs args = CallArgsFromVp(argc, vp);
ContextOptions oldContextOptions = ContextOptionsRef(cx);
RuntimeOptions oldRuntimeOptions = RuntimeOptionsRef(cx);
for (unsigned i = 0; i < args.length(); ++i) {
@ -483,7 +482,7 @@ Options(JSContext *cx, unsigned argc, jsval *vp)
return false;
if (strcmp(opt.ptr(), "strict") == 0)
ContextOptionsRef(cx).toggleExtraWarnings();
RuntimeOptionsRef(cx).toggleExtraWarnings();
else if (strcmp(opt.ptr(), "werror") == 0)
RuntimeOptionsRef(cx).toggleWerror();
else if (strcmp(opt.ptr(), "strict_mode") == 0)
@ -496,7 +495,7 @@ Options(JSContext *cx, unsigned argc, jsval *vp)
}
char *names = nullptr;
if (oldContextOptions.extraWarnings()) {
if (oldRuntimeOptions.extraWarnings()) {
names = JS_sprintf_append(names, "%s", "strict");
if (!names) {
JS_ReportOutOfMemory(cx);
@ -1026,7 +1025,7 @@ ProcessArgsForCompartment(JSContext *cx, char **argv, int argc)
case 'S':
RuntimeOptionsRef(cx).toggleWerror();
case 's':
ContextOptionsRef(cx).toggleExtraWarnings();
RuntimeOptionsRef(cx).toggleExtraWarnings();
break;
case 'I':
RuntimeOptionsRef(cx).toggleIon()

View File

@ -383,6 +383,13 @@ InitGlobalObject(JSContext* aJSContext, JS::Handle<JSObject*> aGlobal, uint32_t
JS::CompartmentOptionsRef(aGlobal).setDiscardSource(isSystem);
}
if (ExtraWarningsForSystemJS()) {
nsIPrincipal *prin = GetObjectPrincipal(aGlobal);
bool isSystem = nsContentUtils::IsSystemPrincipal(prin);
if (isSystem)
JS::CompartmentOptionsRef(aGlobal).extraWarningsOverride().set(true);
}
// Stuff coming through this path always ends up as a DOM global.
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL);

View File

@ -508,6 +508,9 @@ ShouldDiscardSystemSource();
bool
SetAddonInterposition(const nsACString &addonId, nsIAddonInterposition *interposition);
bool
ExtraWarningsForSystemJS();
} // namespace xpc
namespace mozilla {