diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 466fc2d4a014..dc8b43dde5d3 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -126,25 +126,25 @@ JS::detail::CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl /* * This class is a version-establishing barrier at the head of a VM entry or * re-entry. It ensures that |newVersion| is the starting (default) version - * used for the context. + * used for the runtime. */ class AutoVersionAPI { - JSContext * const cx; + JSRuntime * const rt; JSVersion oldDefaultVersion; JSVersion newVersion; public: - AutoVersionAPI(JSContext *cx, JSVersion newVersion) - : cx(cx), - oldDefaultVersion(cx->getDefaultVersion()) + AutoVersionAPI(JSRuntime *rt, JSVersion newVersion) + : rt(rt), + oldDefaultVersion(rt->defaultVersion()) { this->newVersion = newVersion; - cx->setDefaultVersion(newVersion); + rt->setDefaultVersion(newVersion); } ~AutoVersionAPI() { - cx->setDefaultVersion(oldDefaultVersion); + rt->setDefaultVersion(oldDefaultVersion); } /* The version that this scoped-entity establishes. */ @@ -740,6 +740,7 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads) numCompartments(0), localeCallbacks(NULL), defaultLocale(NULL), + defaultVersion_(JSVERSION_DEFAULT), #ifdef JS_THREADSAFE ownerThread_(NULL), #endif @@ -5173,7 +5174,7 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options, { Maybe mava; if (options.versionSet) { - mava.construct(cx, options.version); + mava.construct(cx->runtime(), options.version); // AutoVersionAPI propagates some compilation flags through. options.version = mava.ref().version(); } @@ -5332,7 +5333,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options, { Maybe mava; if (options.versionSet) { - mava.construct(cx, options.version); + mava.construct(cx->runtime(), options.version); // AutoVersionAPI propagates some compilation flags through. options.version = mava.ref().version(); } @@ -5512,7 +5513,7 @@ JS_ExecuteScriptVersion(JSContext *cx, JSObject *objArg, JSScript *script, jsval JSVersion version) { RootedObject obj(cx, objArg); - AutoVersionAPI ava(cx, version); + AutoVersionAPI ava(cx->runtime(), version); return JS_ExecuteScript(cx, obj, script, rval); } @@ -5524,7 +5525,7 @@ JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options, { Maybe mava; if (options.versionSet) { - mava.construct(cx, options.version); + mava.construct(cx->runtime(), options.version); // AutoVersionAPI propagates some compilation flags through. options.version = mava.ref().version(); } diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 4aeb66c19d7e..6f6b9d491eb0 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -296,8 +296,6 @@ js::NewContext(JSRuntime *rt, size_t stackChunkSize) if (!cx) return NULL; - JS_ASSERT(cx->findVersion() == JSVERSION_DEFAULT); - if (!cx->cycleDetectorSet.init()) { js_delete(cx); return NULL; @@ -1177,7 +1175,6 @@ ThreadSafeContext::asForkJoinSlice() JSContext::JSContext(JSRuntime *rt) : ThreadSafeContext(rt, &rt->mainThread, Context_JS), - defaultVersion(JSVERSION_DEFAULT), throwing(false), exception(UndefinedValue()), options_(0), @@ -1535,7 +1532,7 @@ JSContext::findVersion() const if (compartment() && compartment()->options().hasVersion) return compartment()->options().version; - return defaultVersion; + return runtime()->defaultVersion(); } #if defined JS_THREADSAFE && defined DEBUG diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index f4c5c9b0abe3..fd17d3b4d7a3 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -740,6 +740,9 @@ struct JSRuntime : public JS::shadow::Runtime, /* Default locale for Internationalization API */ char *defaultLocale; + /* Default JSVersion. */ + JSVersion defaultVersion_; + /* See comment for JS_AbortIfWrongThread in jsapi.h. */ #ifdef JS_THREADSAFE public: @@ -852,6 +855,9 @@ struct JSRuntime : public JS::shadow::Runtime, /* Gets current default locale. String remains owned by context. */ const char *getDefaultLocale(); + JSVersion defaultVersion() { return defaultVersion_; } + void setDefaultVersion(JSVersion v) { defaultVersion_ = v; } + /* Base address of the native stack for the current thread. */ uintptr_t nativeStackBase; @@ -1655,9 +1661,6 @@ struct JSContext : js::ThreadSafeContext, js::PerThreadData &mainThread() const { return runtime()->mainThread; } private: - /* See JSContext::findVersion. */ - JSVersion defaultVersion; /* script compilation version */ - /* Exception state -- the exception member is a GC root by definition. */ bool throwing; /* is there a pending exception? */ js::Value exception; /* most-recently-thrown exception */ @@ -1756,12 +1759,6 @@ struct JSContext : js::ThreadSafeContext, inline js::RegExpStatics *regExpStatics(); public: - /* Set the default script compilation version. */ - void setDefaultVersion(JSVersion version) { - defaultVersion = version; - } - - JSVersion getDefaultVersion() const { return defaultVersion; } /* * Return: