Bug 880330 - Refactor jsd to use the new options API; r=sphink
authorEddy Bruel <ejpbruel@mozilla.com>
Mon, 28 Oct 2013 12:52:27 +0100
changeset 166287 5b7dbe16ff211e21c191f57eacbdf585cf80ec58
parent 166286 99a97151f20d55ef0237553f367eeab2c08d3c60
child 166288 88310e106cab3708136c7bcf7c754dc7204f3045
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)
reviewerssphink
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 jsd to use the new options API; r=sphink
js/jsd/jsd_xpc.cpp
--- a/js/jsd/jsd_xpc.cpp
+++ b/js/jsd/jsd_xpc.cpp
@@ -1569,17 +1569,17 @@ jsdContext::FromPtr (JSDContext *aJSDCx,
         jsds_FindEphemeral (&gLiveContexts, static_cast<void *>(aJSCx));
     if (eph)
     {
         jsdicx = do_QueryInterface(eph);
     }
     else
     {
         nsCOMPtr<nsISupports> iscx;
-        if (JS_GetOptions(aJSCx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)
+        if (JS::ContextOptionsRef(aJSCx).privateIsNSISupports())
             iscx = static_cast<nsISupports *>(JS_GetContextPrivate(aJSCx));
         jsdicx = new jsdContext (aJSDCx, aJSCx, iscx);
     }
 
     jsdIContext *ctx = nullptr;
     jsdicx.swap(ctx);
     return ctx;
 }
@@ -1631,57 +1631,97 @@ jsdContext::InvalidateAll()
 NS_IMETHODIMP
 jsdContext::GetJSContext(JSContext **_rval)
 {
     ASSERT_VALID_EPHEMERAL;
     *_rval = mJSCx;
     return NS_OK;
 }
 
+/* Simulate the old options API in terms of the new one for backwards
+ * compatibility */
+
+#define JSOPTION_EXTRA_WARNINGS                 JS_BIT(0)
+#define JSOPTION_WERROR                         JS_BIT(1)
+#define JSOPTION_VAROBJFIX                      JS_BIT(2)
+#define JSOPTION_PRIVATE_IS_NSISUPPORTS         JS_BIT(3)
+#define JSOPTION_COMPILE_N_GO                   JS_BIT(4)
+#define JSOPTION_DONT_REPORT_UNCAUGHT           JS_BIT(8)
+#define JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT  JS_BIT(11)
+#define JSOPTION_NO_SCRIPT_RVAL                 JS_BIT(12)
+#define JSOPTION_BASELINE                       JS_BIT(14)
+#define JSOPTION_TYPE_INFERENCE                 JS_BIT(16)
+#define JSOPTION_STRICT_MODE                    JS_BIT(17)
+#define JSOPTION_ION                            JS_BIT(18)
+#define JSOPTION_ASMJS                          JS_BIT(19)
+#define JSOPTION_MASK                           JS_BITMASK(20)
+
 NS_IMETHODIMP
 jsdContext::GetOptions(uint32_t *_rval)
 {
     ASSERT_VALID_EPHEMERAL;
-    *_rval = JS_GetOptions(mJSCx);
+    *_rval = (JS::ContextOptionsRef(mJSCx).extraWarnings() ? JSOPTION_EXTRA_WARNINGS : 0)
+           | (JS::ContextOptionsRef(mJSCx).werror() ? JSOPTION_WERROR : 0)
+           | (JS::ContextOptionsRef(mJSCx).varObjFix() ? JSOPTION_VAROBJFIX : 0)
+           | (JS::ContextOptionsRef(mJSCx).privateIsNSISupports() ? JSOPTION_PRIVATE_IS_NSISUPPORTS : 0)
+           | (JS::ContextOptionsRef(mJSCx).compileAndGo() ? JSOPTION_COMPILE_N_GO : 0)
+           | (JS::ContextOptionsRef(mJSCx).dontReportUncaught() ? JSOPTION_DONT_REPORT_UNCAUGHT : 0)
+           | (JS::ContextOptionsRef(mJSCx).noDefaultCompartmentObject() ? JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT : 0)
+           | (JS::ContextOptionsRef(mJSCx).noScriptRval() ? JSOPTION_NO_SCRIPT_RVAL : 0)
+           | (JS::ContextOptionsRef(mJSCx).baseline() ? JSOPTION_BASELINE : 0)
+           | (JS::ContextOptionsRef(mJSCx).typeInference() ? JSOPTION_TYPE_INFERENCE : 0)
+           | (JS::ContextOptionsRef(mJSCx).strictMode() ? JSOPTION_STRICT_MODE : 0)
+           | (JS::ContextOptionsRef(mJSCx).ion() ? JSOPTION_ION : 0)
+           | (JS::ContextOptionsRef(mJSCx).asmJS() ? JSOPTION_ASMJS : 0);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 jsdContext::SetOptions(uint32_t options)
 {
     ASSERT_VALID_EPHEMERAL;
-    uint32_t lastOptions = JS_GetOptions(mJSCx);
 
     /* don't let users change this option, they'd just be shooting themselves
      * in the foot. */
-    if ((options ^ lastOptions) & JSOPTION_PRIVATE_IS_NSISUPPORTS)
+    if (JS::ContextOptionsRef(mJSCx).privateIsNSISupports() !=
+        (options & JSOPTION_PRIVATE_IS_NSISUPPORTS))
         return NS_ERROR_ILLEGAL_VALUE;
 
-    JS_SetOptions(mJSCx, options);
+    JS::ContextOptionsRef(mJSCx).setExtraWarnings(options & JSOPTION_EXTRA_WARNINGS)
+                                .setWerror(options & JSOPTION_WERROR)
+                                .setVarObjFix(options & JSOPTION_VAROBJFIX)
+                                .setCompileAndGo(options & JSOPTION_COMPILE_N_GO)
+                                .setDontReportUncaught(options & JSOPTION_DONT_REPORT_UNCAUGHT)
+                                .setNoDefaultCompartmentObject(options & JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT)
+                                .setNoScriptRval(options & JSOPTION_NO_SCRIPT_RVAL)
+                                .setBaseline(options & JSOPTION_BASELINE)
+                                .setTypeInference(options & JSOPTION_TYPE_INFERENCE)
+                                .setStrictMode(options & JSOPTION_STRICT_MODE)
+                                .setIon(options & JSOPTION_ION)
+                                .setAsmJS(options & JSOPTION_ASMJS);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 jsdContext::GetPrivateData(nsISupports **_rval)
 {
     ASSERT_VALID_EPHEMERAL;
-    uint32_t options = JS_GetOptions(mJSCx);
-    if (options & JSOPTION_PRIVATE_IS_NSISUPPORTS)
+    if (JS::ContextOptionsRef(mJSCx).privateIsNSISupports()) 
     {
         *_rval = static_cast<nsISupports*>(JS_GetContextPrivate(mJSCx));
         NS_IF_ADDREF(*_rval);
     }
     else
     {
         *_rval = nullptr;
     }
-    
+
     return NS_OK;
 }
-        
+
 NS_IMETHODIMP
 jsdContext::GetWrappedContext(nsISupports **_rval)
 {
     ASSERT_VALID_EPHEMERAL;
     NS_IF_ADDREF(*_rval = mISCx);
     return NS_OK;
 }