Bug 880330 - Remove the old options API; r=bholley
authorEddy Bruel <ejpbruel@mozilla.com>
Mon, 28 Oct 2013 12:59:04 +0100
changeset 166289 87e380e5b6c1e1e0563b9eae417e35af88de3434
parent 166288 88310e106cab3708136c7bcf7c754dc7204f3045
child 166290 fa845144832cbe0f14dc0a80d35a9ed5ef25ae4c
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)
reviewersbholley
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 - Remove the old options API; r=bholley
js/ipc/JavaScriptChild.cpp
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/ipc/JavaScriptChild.cpp
+++ b/js/ipc/JavaScriptChild.cpp
@@ -491,26 +491,25 @@ JavaScriptChild::AnswerCall(const Object
             RootedValue v(cx);
             if (!toValue(cx, argv[i].get_JSVariant(), &v))
                 return fail(cx, rs);
             if (!vals.append(v))
                 return fail(cx, rs);
         }
     }
 
-    uint32_t oldOpts =
-        JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_DONT_REPORT_UNCAUGHT);
+    RootedValue rval(cx);
+    {
+        AutoSaveContextOptions asco(cx);
+        ContextOptionsRef(cx).setDontReportUncaught(true);
 
-    RootedValue rval(cx);
-    bool success = JS::Call(cx, vals[1], vals[0], vals.length() - 2, vals.begin() + 2, &rval);
-
-    JS_SetOptions(cx, oldOpts);
-
-    if (!success)
-        return fail(cx, rs);
+        bool success = JS::Call(cx, vals[1], vals[0], vals.length() - 2, vals.begin() + 2, &rval);
+        if (!success)
+            return fail(cx, rs);
+    }
 
     if (!toVariant(cx, rval, result))
         return fail(cx, rs);
 
     // Prefill everything with a dummy jsval.
     for (size_t i = 0; i < outobjects.length(); i++)
         outparams->AppendElement(JSParam(void_t()));
 
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -952,99 +952,16 @@ JS_StringToVersion(const char *string)
     int i;
 
     for (i = 0; v2smap[i].string; i++)
         if (strcmp(v2smap[i].string, string) == 0)
             return v2smap[i].version;
     return JSVERSION_UNKNOWN;
 }
 
-static unsigned
-GetOptionsCommon(JSContext *cx)
-{
-    return (cx->options().extraWarnings() ? JSOPTION_EXTRA_WARNINGS : 0)
-         | (cx->options().werror() ? JSOPTION_WERROR : 0)
-         | (cx->options().varObjFix() ? JSOPTION_VAROBJFIX : 0)
-         | (cx->options().privateIsNSISupports() ? JSOPTION_PRIVATE_IS_NSISUPPORTS : 0)
-         | (cx->options().compileAndGo() ? JSOPTION_COMPILE_N_GO : 0)
-         | (cx->options().dontReportUncaught() ? JSOPTION_DONT_REPORT_UNCAUGHT : 0)
-         | (cx->options().noDefaultCompartmentObject() ? JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT : 0)
-         | (cx->options().noScriptRval() ? JSOPTION_NO_SCRIPT_RVAL : 0)
-         | (cx->options().baseline() ? JSOPTION_BASELINE : 0)
-         | (cx->options().typeInference() ? JSOPTION_TYPE_INFERENCE : 0)
-         | (cx->options().strictMode() ? JSOPTION_STRICT_MODE : 0)
-         | (cx->options().ion() ? JSOPTION_ION : 0)
-         | (cx->options().asmJS() ? JSOPTION_ASMJS : 0);
-}
-
-static unsigned
-SetOptionsCommon(JSContext *cx, unsigned newopts)
-{
-    JS_ASSERT((newopts & JSOPTION_MASK) == newopts);
-    unsigned oldopts = GetOptionsCommon(cx);
-
-    cx->options().setExtraWarnings(newopts & JSOPTION_EXTRA_WARNINGS);
-    cx->options().setWerror(newopts & JSOPTION_WERROR);
-    cx->options().setVarObjFix(newopts & JSOPTION_VAROBJFIX);
-    cx->options().setPrivateIsNSISupports(newopts & JSOPTION_PRIVATE_IS_NSISUPPORTS);
-    cx->options().setCompileAndGo(newopts & JSOPTION_COMPILE_N_GO);
-    cx->options().setDontReportUncaught(newopts & JSOPTION_DONT_REPORT_UNCAUGHT);
-    cx->options().setNoDefaultCompartmentObject(newopts & JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT);
-    cx->options().setNoScriptRval(newopts & JSOPTION_NO_SCRIPT_RVAL);
-    cx->options().setBaseline(newopts & JSOPTION_BASELINE);
-    cx->options().setTypeInference(newopts & JSOPTION_TYPE_INFERENCE);
-    cx->options().setStrictMode(newopts & JSOPTION_STRICT_MODE);
-    cx->options().setIon(newopts & JSOPTION_ION);
-    cx->options().setAsmJS(newopts & JSOPTION_ASMJS);
-
-    cx->updateJITEnabled();
-    return oldopts;
-}
-
-JS_PUBLIC_API(uint32_t)
-JS_GetOptions(JSContext *cx)
-{
-    /*
-     * Can't check option/version synchronization here.
-     * We may have been synchronized with a script version that was formerly on
-     * the stack, but has now been popped.
-     */
-    return GetOptionsCommon(cx);
-}
-
-JS_PUBLIC_API(uint32_t)
-JS_SetOptions(JSContext *cx, uint32_t options)
-{
-    return SetOptionsCommon(cx, options);
-}
-
-JS_PUBLIC_API(uint32_t)
-JS_DisableOptions(JSContext *cx, uint32_t options)
-{
-    unsigned oldopts = GetOptionsCommon(cx);
-    unsigned newopts = oldopts & ~options;
-    return SetOptionsCommon(cx, newopts);
-}
-
-JS_PUBLIC_API(uint32_t)
-JS_EnableOptions(JSContext *cx, uint32_t options)
-{
-    unsigned oldopts = GetOptionsCommon(cx);
-    unsigned newopts = oldopts | options;
-    return SetOptionsCommon(cx, newopts);
-}
-
-JS_PUBLIC_API(uint32_t)
-JS_ToggleOptions(JSContext *cx, uint32_t options)
-{
-    unsigned oldopts = GetOptionsCommon(cx);
-    unsigned newopts = oldopts ^ options;
-    return SetOptionsCommon(cx, newopts);
-}
-
 JS_PUBLIC_API(JS::ContextOptions &)
 JS::ContextOptionsRef(JSContext *cx)
 {
     return cx->options();
 }
 
 JS_PUBLIC_API(void)
 JS_SetJitHardening(JSRuntime *rt, bool enabled)
@@ -6092,29 +6009,29 @@ JS_SetGlobalJitCompilerOption(JSContext 
         if (value == uint32_t(-1))
             value = defaultValues.usesBeforeCompile;
         jit::js_IonOptions.usesBeforeCompile = value;
         if (value == 0)
             jit::js_IonOptions.setEagerCompilation();
         break;
       case JSJITCOMPILER_ION_ENABLE:
         if (value == 1) {
-            JS_EnableOptions(cx, JSOPTION_ION);
+            JS::ContextOptionsRef(cx).setIon(true);
             IonSpew(js::jit::IonSpew_Scripts, "Enable ion");
         } else if (value == 0) {
-            JS_DisableOptions(cx, JSOPTION_ION);
+            JS::ContextOptionsRef(cx).setIon(false);
             IonSpew(js::jit::IonSpew_Scripts, "Disable ion");
         }
         break;
       case JSJITCOMPILER_BASELINE_ENABLE:
         if (value == 1) {
-            JS_EnableOptions(cx, JSOPTION_BASELINE);
+            JS::ContextOptionsRef(cx).setBaseline(true);
             IonSpew(js::jit::IonSpew_BaselineScripts, "Enable baseline");
         } else if (value == 0) {
-            JS_DisableOptions(cx, JSOPTION_BASELINE);
+            JS::ContextOptionsRef(cx).setBaseline(false);
             IonSpew(js::jit::IonSpew_BaselineScripts, "Disable baseline");
         }
         break;
       default:
         break;
     }
 #endif
 }
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1463,91 +1463,16 @@ JS_PUBLIC_API(void)
 JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version);
 
 extern JS_PUBLIC_API(const char *)
 JS_VersionToString(JSVersion version);
 
 extern JS_PUBLIC_API(JSVersion)
 JS_StringToVersion(const char *string);
 
-/*
- * JS options are orthogonal to version, and may be freely composed with one
- * another as well as with version.
- *
- * JSOPTION_VAROBJFIX is recommended -- see the comments associated with the
- * prototypes for JS_ExecuteScript, JS_EvaluateScript, etc.
- */
-#define JSOPTION_EXTRA_WARNINGS JS_BIT(0)       /* warn on dubious practices */
-#define JSOPTION_WERROR         JS_BIT(1)       /* convert warning to error */
-#define JSOPTION_VAROBJFIX      JS_BIT(2)       /* make JS_EvaluateScript use
-                                                   the last object on its 'obj'
-                                                   param's scope chain as the
-                                                   ECMA 'variables object' */
-#define JSOPTION_PRIVATE_IS_NSISUPPORTS \
-                                JS_BIT(3)       /* context private data points
-                                                   to an nsISupports subclass */
-#define JSOPTION_COMPILE_N_GO   JS_BIT(4)       /* caller of JS_Compile*Script
-                                                   promises to execute compiled
-                                                   script once only; enables
-                                                   compile-time scope chain
-                                                   resolution of consts. */
-
-/* JS_BIT(5) is currently unused. */
-
-/* JS_BIT(6) is currently unused. */
-
-/* JS_BIT(7) is currently unused. */
-
-#define JSOPTION_DONT_REPORT_UNCAUGHT                                   \
-                                JS_BIT(8)       /* When returning from the
-                                                   outermost API call, prevent
-                                                   uncaught exceptions from
-                                                   being converted to error
-                                                   reports */
-
-/* JS_BIT(9) is currently unused. */
-
-/* JS_BIT(10) is currently unused. */
-
-#define JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT JS_BIT(11)     /* This JSContext does not use a
-                                                                 default compartment object. Such
-                                                                 an object will not be set implicitly,
-                                                                 and attempts to get or set it will
-                                                                 assert. */
-
-#define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12)      /* A promise to the compiler
-                                                   that a null rval out-param
-                                                   will be passed to each call
-                                                   to JS_ExecuteScript. */
-
-/* JS_BIT(13) is currently unused. */
-
-#define JSOPTION_BASELINE       JS_BIT(14)      /* Baseline compiler. */
-
-#define JSOPTION_TYPE_INFERENCE JS_BIT(16)      /* Perform type inference. */
-#define JSOPTION_STRICT_MODE    JS_BIT(17)      /* Provides a way to force
-                                                   strict mode for all code
-                                                   without requiring
-                                                   "use strict" annotations. */
-
-#define JSOPTION_ION            JS_BIT(18)      /* IonMonkey */
-
-#define JSOPTION_ASMJS          JS_BIT(19)      /* optimizingasm.js compiler */
-
-#define JSOPTION_MASK           JS_BITMASK(20)
-
-extern JS_PUBLIC_API(uint32_t)
-JS_GetOptions(JSContext *cx);
-
-extern JS_PUBLIC_API(uint32_t)
-JS_SetOptions(JSContext *cx, uint32_t options);
-
-extern JS_PUBLIC_API(uint32_t)
-JS_ToggleOptions(JSContext *cx, uint32_t options);
-
 namespace JS {
 
 class JS_PUBLIC_API(ContextOptions) {
   public:
     ContextOptions()
       : extraWarnings_(false),
         werror_(false),
         varObjFix_(false),
@@ -3566,21 +3491,19 @@ JS_DecompileFunctionBody(JSContext *cx, 
  * embeddings have several such objects.  ECMA requires that "global code" be
  * executed with the variables object equal to this global object.  But these
  * JS API entry points provide freedom to execute code against a "sub-global",
  * i.e., a parented or scoped object, in which case the variables object will
  * differ from the last object on the scope chain, resulting in confusing and
  * non-ECMA explicit vs. implicit variable creation.
  *
  * Caveat embedders: unless you already depend on this buggy variables object
- * binding behavior, you should call JS_SetOptions(cx, JSOPTION_VAROBJFIX) or
- * JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_VAROBJFIX) -- the latter if
- * someone may have set other options on cx already -- for each context in the
- * application, if you pass parented objects as the obj parameter, or may ever
- * pass such objects in the future.
+ * binding behavior, you should call ContextOptionsRef(cx).setVarObjFix(true)
+ * for each context in the application, if you pass parented objects as the obj
+ * parameter, or may ever pass such objects in the future.
  *
  * Why a runtime option?  The alternative is to add six or so new API entry
  * points with signatures matching the following six, and that doesn't seem
  * worth the code bloat cost.  Such new entry points would probably have less
  * obvious names, too, so would not tend to be used.  The JS_SetOption call,
  * OTOH, can be more easily hacked into existing code that does not depend on
  * the bug; such code can continue to use the familiar JS_EvaluateScript,
  * etc., entry points.