Bug 880330 - Refactor dom to use the new options API (1/2); r=khuey
authorEddy Bruel <ejpbruel@mozilla.com>
Mon, 28 Oct 2013 12:48:23 +0100
changeset 166285 e18d850abc31c031958ce55401d4fad30a8429fb
parent 166284 f03299c9d48a8bfe361391bccd33c7771f149d11
child 166286 99a97151f20d55ef0237553f367eeab2c08d3c60
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs880330
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 880330 - Refactor dom to use the new options API (1/2); r=khuey
dom/base/nsJSEnvironment.cpp
dom/base/nsJSEnvironment.h
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -719,27 +719,26 @@ static const char js_ion_chrome_str[]   
 static const char js_ion_eager_str[]          = JS_OPTIONS_DOT_STR "ion.unsafe_eager_compilation";
 static const char js_parallel_parsing_str[]   = JS_OPTIONS_DOT_STR "parallel_parsing";
 static const char js_ion_parallel_compilation_str[] = JS_OPTIONS_DOT_STR "ion.parallel_compilation";
 
 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,
   // 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?
@@ -772,65 +771,62 @@ nsJSContext::JSOptionChangedCallback(con
       useBaselineJITEager = false;
       useIon = false;
       useIonEager = false;
       useAsmJS = false;
     }
   }
 
   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;
-
-  ::JS_SetOptions(context->mContext, newDefaultJSOptions & JSOPTION_MASK);
+    options &= ~JSOPTION_WERROR;
+
+  ::JS_SetOptions(context->mContext, options & JSOPTION_MASK);
 
   ::JS_SetParallelParsingEnabled(context->mContext, parallelParsing);
   ::JS_SetParallelIonCompilationEnabled(context->mContext, parallelIonCompilation);
 
   ::JS_SetGlobalJitCompilerOption(context->mContext, JSJITCOMPILER_BASELINE_USECOUNT_TRIGGER,
                                   (useBaselineJITEager ? 0 : -1));
 
   ::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);
 
 #ifdef JS_GC_ZEAL
   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)
     ::JS_SetGCZeal(context->mContext, (uint8_t)zeal, frequency);
@@ -851,28 +847,24 @@ nsJSContext::nsJSContext(bool aGCOnDestr
   mPrev = &sContextList;
   if (sContextList) {
     sContextList->mPrev = &mNext;
   }
   sContextList = this;
 
   ++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,
                                   js_options_dot_str, this);
   }
   mIsInitialized = false;
   mScriptsEnabled = true;
   mProcessingScriptTag = false;
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -165,17 +165,16 @@ private:
   JSContext *mContext;
   JS::Heap<JSObject*> mWindowProxy;
 
   bool mIsInitialized;
   bool mScriptsEnabled;
   bool mGCOnDestruction;
   bool mProcessingScriptTag;
 
-  uint32_t mDefaultJSOptions;
   PRTime mOperationCallbackTime;
 
   PRTime mModalStateTime;
   uint32_t mModalStateDepth;
 
   nsJSContext *mNext;
   nsJSContext **mPrev;