Bug 880917 - Hoist defaultVersion into the runtime and remove it from the JSContext. r=luke

This commit is contained in:
Bobby Holley 2013-06-13 10:09:27 -07:00
Родитель fa60cdc4b6
Коммит 0d5781f0c9
4 изменённых файлов: 19 добавлений и 24 удалений

Просмотреть файл

@ -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. */
@ -723,6 +723,7 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
numCompartments(0),
localeCallbacks(NULL),
defaultLocale(NULL),
defaultVersion_(JSVERSION_DEFAULT),
#ifdef JS_THREADSAFE
ownerThread_(NULL),
#endif
@ -5293,7 +5294,7 @@ JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
{
Maybe<AutoVersionAPI> 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();
}
@ -5452,7 +5453,7 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
{
Maybe<AutoVersionAPI> 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();
}
@ -5631,7 +5632,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);
}
@ -5643,7 +5644,7 @@ JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options,
{
Maybe<AutoVersionAPI> 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();
}

Просмотреть файл

@ -280,8 +280,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;
@ -1120,7 +1118,6 @@ js_HandleExecutionInterrupt(JSContext *cx)
JSContext::JSContext(JSRuntime *rt)
: ContextFriendFields(rt),
defaultVersion(JSVERSION_DEFAULT),
throwing(false),
exception(UndefinedValue()),
options_(0),

Просмотреть файл

@ -719,6 +719,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:
@ -828,6 +831,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;
@ -1533,9 +1539,6 @@ struct JSContext : js::ContextFriendFields,
js::PerThreadData &mainThread() { 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 */
@ -1644,12 +1647,6 @@ struct JSContext : js::ContextFriendFields,
inline js::RegExpStatics *regExpStatics();
public:
/* Set the default script compilation version. */
void setDefaultVersion(JSVersion version) {
defaultVersion = version;
}
JSVersion getDefaultVersion() const { return defaultVersion; }
/*
* Return:

Просмотреть файл

@ -474,7 +474,7 @@ JSContext::findVersion() const
if (compartment() && compartment()->options().hasVersion)
return compartment()->options().version;
return defaultVersion;
return runtime()->defaultVersion();
}
inline js::LifoAlloc &