Bug 880330 - Refactor dom to use the new options API (1/2); r=khuey

This commit is contained in:
Eddy Bruel 2013-10-28 12:48:23 +01:00
parent cbefd67b93
commit 7f0f636fdf
2 changed files with 19 additions and 28 deletions

View File

@ -724,17 +724,16 @@ int
nsJSContext::JSOptionChangedCallback(const char *pref, void *data)
{
nsJSContext *context = reinterpret_cast<nsJSContext *>(data);
uint32_t oldDefaultJSOptions = context->mDefaultJSOptions;
uint32_t newDefaultJSOptions = oldDefaultJSOptions;
uint32_t options = JS_GetOptions(context->mContext);
sPostGCEventsToConsole = Preferences::GetBool(js_memlog_option_str);
sPostGCEventsToObserver = Preferences::GetBool(js_memnotify_option_str);
bool strict = Preferences::GetBool(js_strict_option_str);
if (strict)
newDefaultJSOptions |= JSOPTION_EXTRA_WARNINGS;
options |= JSOPTION_EXTRA_WARNINGS;
else
newDefaultJSOptions &= ~JSOPTION_EXTRA_WARNINGS;
options &= ~JSOPTION_EXTRA_WARNINGS;
// 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,
@ -777,42 +776,42 @@ nsJSContext::JSOptionChangedCallback(const char *pref, void *data)
}
if (useTypeInference)
newDefaultJSOptions |= JSOPTION_TYPE_INFERENCE;
options |= JSOPTION_TYPE_INFERENCE;
else
newDefaultJSOptions &= ~JSOPTION_TYPE_INFERENCE;
options &= ~JSOPTION_TYPE_INFERENCE;
if (useBaselineJIT)
newDefaultJSOptions |= JSOPTION_BASELINE;
options |= JSOPTION_BASELINE;
else
newDefaultJSOptions &= ~JSOPTION_BASELINE;
options &= ~JSOPTION_BASELINE;
if (useIon)
newDefaultJSOptions |= JSOPTION_ION;
options |= JSOPTION_ION;
else
newDefaultJSOptions &= ~JSOPTION_ION;
options &= ~JSOPTION_ION;
if (useAsmJS)
newDefaultJSOptions |= JSOPTION_ASMJS;
options |= JSOPTION_ASMJS;
else
newDefaultJSOptions &= ~JSOPTION_ASMJS;
options &= ~JSOPTION_ASMJS;
#ifdef DEBUG
// In debug builds, warnings are enabled in chrome context if
// javascript.options.strict.debug is true
bool strictDebug = Preferences::GetBool(js_strict_debug_option_str);
if (strictDebug && (newDefaultJSOptions & JSOPTION_EXTRA_WARNINGS) == 0) {
if (strictDebug && (options & JSOPTION_EXTRA_WARNINGS) == 0) {
if (chromeWindow || !contentWindow)
newDefaultJSOptions |= JSOPTION_EXTRA_WARNINGS;
options |= JSOPTION_EXTRA_WARNINGS;
}
#endif
bool werror = Preferences::GetBool(js_werror_option_str);
if (werror)
newDefaultJSOptions |= JSOPTION_WERROR;
options |= JSOPTION_WERROR;
else
newDefaultJSOptions &= ~JSOPTION_WERROR;
options &= ~JSOPTION_WERROR;
::JS_SetOptions(context->mContext, newDefaultJSOptions & JSOPTION_MASK);
::JS_SetOptions(context->mContext, options & JSOPTION_MASK);
::JS_SetParallelParsingEnabled(context->mContext, parallelParsing);
::JS_SetParallelIonCompilationEnabled(context->mContext, parallelIonCompilation);
@ -823,9 +822,6 @@ nsJSContext::JSOptionChangedCallback(const char *pref, void *data)
::JS_SetGlobalJitCompilerOption(context->mContext, JSJITCOMPILER_ION_USECOUNT_TRIGGER,
(useIonEager ? 0 : -1));
// Save the new defaults for the next page load (InitContext).
context->mDefaultJSOptions = newDefaultJSOptions;
JSRuntime *rt = JS_GetRuntime(context->mContext);
JS_SetJitHardening(rt, useHardening);
@ -856,18 +852,14 @@ nsJSContext::nsJSContext(bool aGCOnDestruction,
++sContextCount;
mDefaultJSOptions = JSOPTION_PRIVATE_IS_NSISUPPORTS |
JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT;
mContext = ::JS_NewContext(sRuntime, gStackSize);
if (mContext) {
::JS_SetContextPrivate(mContext, static_cast<nsIScriptContext *>(this));
// Preserve any flags the context callback might have set.
mDefaultJSOptions |= ::JS_GetOptions(mContext);
// Make sure the new context gets the default context options
::JS_SetOptions(mContext, mDefaultJSOptions);
::JS_SetOptions(mContext, ::JS_GetOptions(mContext) |
JSOPTION_PRIVATE_IS_NSISUPPORTS |
JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT);
// Watch for the JS boolean options
Preferences::RegisterCallback(JSOptionChangedCallback,

View File

@ -170,7 +170,6 @@ private:
bool mGCOnDestruction;
bool mProcessingScriptTag;
uint32_t mDefaultJSOptions;
PRTime mOperationCallbackTime;
PRTime mModalStateTime;