Backed out 13 changesets (bug 880917) for Android and B2G test bustage on a CLOSED TREE.

Backed out changeset 71c1ce2cb0a4 (bug 880917)
Backed out changeset cd240e19560f (bug 880917)
Backed out changeset 93509a0001b5 (bug 880917)
Backed out changeset fdbba20e4647 (bug 880917)
Backed out changeset d82060172367 (bug 880917)
Backed out changeset 709f0b699489 (bug 880917)
Backed out changeset 421bdbccfa7c (bug 880917)
Backed out changeset 962c656c7452 (bug 880917)
Backed out changeset 888a5690ccdf (bug 880917)
Backed out changeset 57228f5fcd87 (bug 880917)
Backed out changeset ce8c3e14c234 (bug 880917)
Backed out changeset 08fe7b777450 (bug 880917)
Backed out changeset 5192a9233d83 (bug 880917)
This commit is contained in:
Ryan VanderMeulen 2013-06-13 15:19:50 -04:00
parent a3d61db254
commit 4bfd3df72c
42 changed files with 538 additions and 148 deletions

View File

@ -1108,6 +1108,7 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope,
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_PRIVATE_IS_NSISUPPORTS);
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, ContentScriptErrorReporter);
nsIXPConnect* xpc = nsContentUtils::XPConnect();
@ -1116,12 +1117,9 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope,
JS_SetContextPrivate(cx, aScope);
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
nsresult rv =
xpc->InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal,
flags, options, getter_AddRefs(mGlobal));
flags, JS::SystemZone, getter_AddRefs(mGlobal));
NS_ENSURE_SUCCESS(rv, false);

View File

@ -284,11 +284,9 @@ nsXBLDocGlobalObject::EnsureScriptEnvironment()
// why - see bug 339647)
JS_SetErrorReporter(cx, XBL_ProtoErrorReporter);
JS::CompartmentOptions options;
options.setZone(JS::SystemZone);
mJSObject = JS_NewGlobalObject(cx, &gSharedGlobalClass,
nsJSPrincipals::get(GetPrincipal()),
options);
JS::SystemZone);
if (!mJSObject)
return NS_OK;

View File

@ -21,6 +21,27 @@
using namespace mozilla;
// Checks that the version is not modified in a given scope.
class AutoVersionChecker
{
DebugOnly<JSContext *> const cx;
DebugOnly<JSVersion> versionBefore;
public:
explicit AutoVersionChecker(JSContext *aCx) : cx(aCx) {
#ifdef DEBUG
versionBefore = JS_GetVersion(cx);
#endif
}
~AutoVersionChecker() {
#ifdef DEBUG
JSVersion versionAfter = JS_GetVersion(cx);
NS_ABORT_IF_FALSE(versionAfter == versionBefore, "version must not change");
#endif
}
};
nsresult
nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
nsXBLBinding* aBinding)
@ -68,6 +89,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aPrototypeBinding,
AutoPushJSContext cx(context->GetNativeContext());
JSAutoCompartment ac(cx, targetClassObject);
AutoVersionChecker avc(cx);
// Walk our member list and install each one in turn.
for (nsXBLProtoImplMember* curr = mMembers;
@ -207,6 +229,8 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding)
MOZ_ASSERT(classObject);
mClassObject = classObject;
AutoVersionChecker avc(cx);
// Now that we have a class object installed, we walk our member list and compile each of our
// properties and methods in turn.
for (nsXBLProtoImplMember* curr = mMembers;
@ -275,6 +299,7 @@ nsXBLProtoImpl::FindField(const nsString& aFieldName) const
bool
nsXBLProtoImpl::ResolveAllFields(JSContext *cx, JS::Handle<JSObject*> obj) const
{
AutoVersionChecker avc(cx);
for (nsXBLProtoImplField* f = mFields; f; f = f->GetNext()) {
// Using OBJ_LOOKUP_PROPERTY is a pain, since what we have is a
// PRUnichar* for the property name. Let's just use the public API and

View File

@ -762,11 +762,9 @@ nsXULPDGlobalObject::EnsureScriptEnvironment()
// will re-fetch the global and set it up in our language globals array.
{
AutoPushJSContext cx(ctxNew->GetNativeContext());
JS::CompartmentOptions options;
options.setZone(JS::SystemZone);
JS::Rooted<JSObject*> newGlob(cx,
JS_NewGlobalObject(cx, &gSharedGlobalClass,
nsJSPrincipals::get(GetPrincipal()), options));
nsJSPrincipals::get(GetPrincipal()), JS::SystemZone));
if (!newGlob)
return NS_OK;

View File

@ -2120,10 +2120,10 @@ CreateNativeGlobalForInner(JSContext* aCx,
if (aNewInner->GetOuterWindow()) {
top = aNewInner->GetTop();
}
JS::CompartmentOptions options;
JS::ZoneSpecifier zoneSpec = JS::FreshZone;
if (top) {
if (top->GetGlobalJSObject()) {
options.zoneSpec = JS::SameZoneAs(top->GetGlobalJSObject());
zoneSpec = JS::SameZoneAs(top->GetGlobalJSObject());
}
}
@ -2139,7 +2139,7 @@ CreateNativeGlobalForInner(JSContext* aCx,
nsRefPtr<nsIXPConnectJSObjectHolder> jsholder;
nsresult rv = xpc->InitClassesWithNewWrappedGlobal(
aCx, ToSupports(aNewInner),
aPrincipal, flags, options, getter_AddRefs(jsholder));
aPrincipal, flags, zoneSpec, getter_AddRefs(jsholder));
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(jsholder);

View File

@ -829,6 +829,10 @@ CreateJSContextForWorker(WorkerPrivate* aWorkerPrivate)
JS_SetGCZeal(workerCx, settings.gcZeal, settings.gcZealFrequency);
#endif
if (aWorkerPrivate->IsChromeWorker()) {
JS_SetVersion(workerCx, JSVERSION_LATEST);
}
return workerCx;
}

View File

@ -967,12 +967,9 @@ CreateDedicatedWorkerGlobalScope(JSContext* aCx)
WorkerPrivate* worker = GetWorkerPrivateFromContext(aCx);
JS_ASSERT(worker);
JS::CompartmentOptions options;
if (worker->IsChromeWorker())
options.setVersion(JSVERSION_LATEST);
JS::Rooted<JSObject*> global(aCx,
JS_NewGlobalObject(aCx, DedicatedWorkerGlobalScope::Class(),
GetWorkerPrincipal(), options));
GetWorkerPrincipal()));
if (!global) {
return NULL;
}

View File

@ -188,6 +188,7 @@ ContextCallback(JSContext *cx,
if (contextOp == JSCONTEXT_NEW) {
JS_SetErrorReporter(cx, ScriptErrorReporter);
JS_SetVersion(cx, JSVERSION_LATEST);
}
return JS_TRUE;
}
@ -305,10 +306,10 @@ Version(JSContext *cx,
JS::Value *vp)
{
JS::Value *argv = JS_ARGV(cx, vp);
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_GetVersion(cx)));
if (argc > 0 && JSVAL_IS_INT(argv[0]))
JS_SetVersionForCompartment(js::GetContextCompartment(cx),
JSVersion(JSVAL_TO_INT(argv[0])));
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_SetVersion(cx, JSVersion(JSVAL_TO_INT(argv[0])))));
else
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_GetVersion(cx)));
return JS_TRUE;
}
@ -782,14 +783,11 @@ XPCShellEnvironment::Init()
return false;
}
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->InitClassesWithNewWrappedGlobal(cx,
static_cast<nsIGlobalObject *>(backstagePass),
principal, 0,
options,
JS::SystemZone,
getter_AddRefs(holder));
if (NS_FAILED(rv)) {
NS_ERROR("InitClassesWithNewWrappedGlobal failed!");

View File

@ -45,7 +45,7 @@ interface jsdIActivationCallback;
* Debugger service. It is not a good idea to have more than one active client
* of the debugger service.
*/
[scriptable, uuid(029b8f0a-aa84-47eb-a60f-1a4752b7ad06)]
[scriptable, uuid(9be5b327-6818-464d-9695-f33885fd8377)]
interface jsdIDebuggerService : nsISupports
{
/** Internal use only. */
@ -88,6 +88,29 @@ interface jsdIDebuggerService : nsISupports
*/
attribute jsdICallHook functionHook;
/**
* VERSION_* values must be kept in sync with the JSVersion enumeration in
* jspubtd.h.
*/
/**
* Possible values for jsdIScript::version and jsdIContext::version.
*/
const long VERSION_1_0 = 100;
const long VERSION_1_1 = 110;
const long VERSION_1_2 = 120;
const long VERSION_1_3 = 130;
const long VERSION_1_4 = 140;
const long VERSION_1_5 = 150;
const long VERSION_DEFAULT = 0;
const long VERSION_UNKNOWN = -1;
/**
* These flags need to be kept in sync with the context flags defined in
* jsdebug.h
*/
/**
* Link native frames in call stacks.
*/
@ -699,6 +722,13 @@ interface jsdIContext : jsdIEphemeral
*/
attribute unsigned long options;
/**
* Last version set on this context.
* Scripts typically select this with the "language" attribute.
* See the VERSION_* consts on jsdIDebuggerService.
*/
attribute long version;
/**
* Unique tag among all valid jsdIContext objects, useful as a hash key.
*/

View File

@ -1693,6 +1693,23 @@ jsdContext::GetTag(uint32_t *_rval)
return NS_OK;
}
NS_IMETHODIMP
jsdContext::GetVersion (int32_t *_rval)
{
ASSERT_VALID_EPHEMERAL;
*_rval = static_cast<int32_t>(JS_GetVersion(mJSCx));
return NS_OK;
}
NS_IMETHODIMP
jsdContext::SetVersion (int32_t id)
{
ASSERT_VALID_EPHEMERAL;
JSVersion ver = static_cast<JSVersion>(id);
JS_SetVersion(mJSCx, ver);
return NS_OK;
}
NS_IMETHODIMP
jsdContext::GetGlobalObject (jsdIValue **_rval)
{

View File

@ -62,14 +62,13 @@ main (int argc, const char **argv)
JS_SetNativeStackQuota(runtime, 5000000);
JSContext *cx = checkPtr(JS_NewContext(runtime, 8192));
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, reportError);
JSAutoRequest ar(cx);
/* Create the global object. */
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
RootedObject global(cx, checkPtr(JS_NewGlobalObject(cx, &global_class, NULL, options)));
RootedObject global(cx, checkPtr(JS_NewGlobalObject(cx, &global_class, NULL)));
JS_SetGlobalObject(cx, global);
JSAutoCompartment ac(cx, global);

View File

@ -64,6 +64,7 @@ CPP_SOURCES += [
'testTrap.cpp',
'testTypedArrays.cpp',
'testUTF8.cpp',
'testVersion.cpp',
'testXDR.cpp',
'tests.cpp',
]

View File

@ -0,0 +1,171 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "tests.h"
#include "jsscript.h"
#include "jscntxt.h"
#include "jscntxtinlines.h"
#include "jsobjinlines.h"
using namespace js;
struct VersionFixture;
/*
* Fast-native callbacks for use from JS.
* They set their results on the current fixture instance.
*/
static VersionFixture *callbackData = NULL;
JSBool CallSetVersion17(JSContext *cx, unsigned argc, jsval *vp);
JSBool OverrideVersion18(JSContext *cx, unsigned argc, jsval *vp);
JSBool CaptureVersion(JSContext *cx, unsigned argc, jsval *vp);
JSBool CheckOverride(JSContext *cx, unsigned argc, jsval *vp);
JSBool EvalScriptVersion16(JSContext *cx, unsigned argc, jsval *vp);
struct VersionFixture : public JSAPITest
{
JSVersion captured;
virtual bool init() {
if (!JSAPITest::init())
return false;
JS_SetOptions(cx, JS_GetOptions(cx));
callbackData = this;
captured = JSVERSION_UNKNOWN;
JS::RootedObject global(cx, JS_GetGlobalForScopeChain(cx));
return JS_DefineFunction(cx, global, "callSetVersion17", CallSetVersion17, 0, 0) &&
JS_DefineFunction(cx, global, "overrideVersion18", OverrideVersion18, 0, 0) &&
JS_DefineFunction(cx, global, "captureVersion", CaptureVersion, 0, 0) &&
JS_DefineFunction(cx, global, "checkOverride", CheckOverride, 1, 0) &&
JS_DefineFunction(cx, global, "evalScriptVersion16",
EvalScriptVersion16, 0, 0);
}
JSScript *fakeScript(const char *contents, size_t length) {
JS::RootedObject global(cx, JS_GetGlobalForScopeChain(cx));
return JS_CompileScript(cx, global, contents, length, "<test>", 1);
}
bool checkVersionIsOverridden() {
CHECK(cx->isVersionOverridden());
return true;
}
bool setVersion(JSVersion version) {
CHECK(JS_GetVersion(cx) != version);
JS_SetVersion(cx, version);
return true;
}
bool evalVersion(const jschar *chars, size_t len, JSVersion version) {
CHECK(JS_GetVersion(cx) != version);
jsval rval;
JS::RootedObject global(cx, JS_GetGlobalForScopeChain(cx));
CHECK(JS_EvaluateUCScriptForPrincipalsVersion(
cx, global, NULL, chars, len, "<test>", 0, &rval, version));
return true;
}
};
/* Callbacks to throw into JS-land. */
JSBool
CallSetVersion17(JSContext *cx, unsigned argc, jsval *vp)
{
return callbackData->setVersion(JSVERSION_1_7);
}
JSBool
OverrideVersion18(JSContext *cx, unsigned argc, jsval *vp)
{
if (!callbackData->setVersion(JSVERSION_1_8))
return false;
return callbackData->checkVersionIsOverridden();
}
JSBool
EvalScriptVersion16(JSContext *cx, unsigned argc, jsval *vp)
{
JS_ASSERT(argc == 1);
jsval *argv = JS_ARGV(cx, vp);
JS_ASSERT(JSVAL_IS_STRING(argv[0]));
JSStableString *str = JSVAL_TO_STRING(argv[0])->ensureStable(cx);
JS_ASSERT(str);
return callbackData->evalVersion(str->chars().get(), str->length(), JSVERSION_1_6);
}
JSBool
CaptureVersion(JSContext *cx, unsigned argc, jsval *vp)
{
callbackData->captured = JS_GetVersion(cx);
return true;
}
JSBool
CheckOverride(JSContext *cx, unsigned argc, jsval *vp)
{
JS_ASSERT(argc == 1);
jsval *argv = JS_ARGV(cx, vp);
JS_ASSERT(JSVAL_IS_BOOLEAN(argv[0]));
bool shouldHaveOverride = !!JSVAL_TO_BOOLEAN(argv[0]);
return shouldHaveOverride == cx->isVersionOverridden();
}
/*
* When re-entering the virtual machine through a *Version API the version
* is no longer forced -- it continues with its natural push/pop oriented
* version progression. This is maintained by the |AutoVersionAPI| class in
* jsapi.cpp.
*/
BEGIN_FIXTURE_TEST(VersionFixture, testVersion_EntryLosesOverride)
{
EXEC("overrideVersion18(); evalScriptVersion16('checkOverride(false); captureVersion()');");
CHECK_EQUAL(captured, JSVERSION_1_6);
/*
* Override gets propagated to default version as non-override when you leave the VM's execute
* call.
*/
CHECK_EQUAL(JS_GetVersion(cx), JSVERSION_1_8);
CHECK(!cx->isVersionOverridden());
return true;
}
END_FIXTURE_TEST(VersionFixture, testVersion_EntryLosesOverride)
/*
* EvalScriptVersion does not propagate overrides to its caller, it
* restores things exactly as they were before the call. This is as opposed to
* the normal (no Version suffix) API which propagates overrides
* to the caller.
*/
BEGIN_FIXTURE_TEST(VersionFixture, testVersion_ReturnLosesOverride)
{
CHECK_EQUAL(JS_GetVersion(cx), JSVERSION_ECMA_5);
EXEC(
"checkOverride(false);"
"evalScriptVersion16('overrideVersion18();');"
"checkOverride(false);"
"captureVersion();"
);
CHECK_EQUAL(captured, JSVERSION_ECMA_5);
return true;
}
END_FIXTURE_TEST(VersionFixture, testVersion_ReturnLosesOverride)
BEGIN_FIXTURE_TEST(VersionFixture, testVersion_EvalPropagatesOverride)
{
CHECK_EQUAL(JS_GetVersion(cx), JSVERSION_ECMA_5);
EXEC(
"checkOverride(false);"
"eval('overrideVersion18();');"
"checkOverride(true);"
"captureVersion();"
);
CHECK_EQUAL(captured, JSVERSION_1_8);
return true;
}
END_FIXTURE_TEST(VersionFixture, testVersion_EvalPropagatesOverride)

View File

@ -51,9 +51,7 @@ bool JSAPITest::definePrint()
JSObject * JSAPITest::createGlobal(JSPrincipals *principals)
{
/* Create the global object. */
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
global = JS_NewGlobalObject(cx, getGlobalClass(), principals, options);
global = JS_NewGlobalObject(cx, getGlobalClass(), principals);
if (!global)
return NULL;
JS_AddNamedObjectRoot(cx, &global, "test-global");

View File

@ -299,6 +299,7 @@ class JSAPITest
if (!cx)
return NULL;
JS_SetOptions(cx, JSOPTION_VAROBJFIX);
JS_SetVersion(cx, JSVERSION_LATEST);
JS_SetErrorReporter(cx, &reportError);
return cx;
}

View File

@ -122,6 +122,47 @@ JS::detail::CallMethodIfWrapped(JSContext *cx, IsAcceptableThis test, NativeImpl
return false;
}
/*
* 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.
* - The starting version state is not an override.
* - Overrides in the VM session are not propagated to the caller.
*/
class AutoVersionAPI
{
JSContext * const cx;
JSVersion oldDefaultVersion;
bool oldHasVersionOverride;
JSVersion oldVersionOverride;
JSVersion newVersion;
public:
AutoVersionAPI(JSContext *cx, JSVersion newVersion)
: cx(cx),
oldDefaultVersion(cx->getDefaultVersion()),
oldHasVersionOverride(cx->isVersionOverridden()),
oldVersionOverride(oldHasVersionOverride ? cx->findVersion() : JSVERSION_UNKNOWN)
{
this->newVersion = newVersion;
cx->clearVersionOverride();
cx->setDefaultVersion(newVersion);
}
~AutoVersionAPI() {
cx->setDefaultVersion(oldDefaultVersion);
if (oldHasVersionOverride)
cx->overrideVersion(oldVersionOverride);
else
cx->clearVersionOverride();
}
/* The version that this scoped-entity establishes. */
JSVersion version() const { return newVersion; }
};
#ifdef HAVE_VA_LIST_AS_ARRAY
#define JS_ADDRESSOF_VA_LIST(ap) ((va_list *)(ap))
#else
@ -694,7 +735,6 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
numCompartments(0),
localeCallbacks(NULL),
defaultLocale(NULL),
defaultVersion_(JSVERSION_DEFAULT),
#ifdef JS_THREADSAFE
ownerThread_(NULL),
#endif
@ -901,8 +941,7 @@ JSRuntime::init(uint32_t maxbytes)
if (!atomsZone)
return false;
JS::CompartmentOptions options;
ScopedJSDeletePtr<JSCompartment> atomsCompartment(new_<JSCompartment>(atomsZone.get(), options));
ScopedJSDeletePtr<JSCompartment> atomsCompartment(new_<JSCompartment>(atomsZone.get()));
if (!atomsCompartment || !atomsCompartment->init(NULL))
return false;
@ -1300,10 +1339,21 @@ JS_GetVersion(JSContext *cx)
return VersionNumber(cx->findVersion());
}
JS_PUBLIC_API(void)
JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version)
JS_PUBLIC_API(JSVersion)
JS_SetVersion(JSContext *cx, JSVersion newVersion)
{
compartment->options().setVersion(version);
JS_ASSERT(VersionIsKnown(newVersion));
JS_ASSERT(!VersionHasFlags(newVersion));
JSVersion newVersionNumber = newVersion;
JSVersion oldVersion = cx->findVersion();
JSVersion oldVersionNumber = VersionNumber(oldVersion);
if (oldVersionNumber == newVersionNumber)
return oldVersionNumber; /* No override actually occurs! */
VersionCopyFlags(&newVersion, oldVersion);
cx->maybeOverrideVersion(newVersion);
return oldVersionNumber;
}
static struct v2smap {
@ -3377,8 +3427,7 @@ class AutoHoldZone
};
JS_PUBLIC_API(JSObject *)
JS_NewGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals,
const JS::CompartmentOptions &options)
JS_NewGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals, JS::ZoneSpecifier zoneSpec)
{
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
@ -3387,18 +3436,18 @@ JS_NewGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals,
JSRuntime *rt = cx->runtime();
Zone *zone;
if (options.zoneSpec == JS::SystemZone)
if (zoneSpec == JS::SystemZone)
zone = rt->systemZone;
else if (options.zoneSpec == JS::FreshZone)
else if (zoneSpec == JS::FreshZone)
zone = NULL;
else
zone = ((JSObject *)options.zoneSpec)->zone();
zone = ((JSObject *)zoneSpec)->zone();
JSCompartment *compartment = NewCompartment(cx, zone, principals, options);
JSCompartment *compartment = NewCompartment(cx, zone, principals);
if (!compartment)
return NULL;
if (options.zoneSpec == JS::SystemZone) {
if (zoneSpec == JS::SystemZone) {
rt->systemZone = compartment->zone();
rt->systemZone->isSystem = true;
}
@ -5263,6 +5312,13 @@ JSScript *
JS::Compile(JSContext *cx, HandleObject obj, CompileOptions options,
const jschar *chars, size_t length)
{
Maybe<AutoVersionAPI> mava;
if (options.versionSet) {
mava.construct(cx, options.version);
// AutoVersionAPI propagates some compilation flags through.
options.version = mava.ref().version();
}
JS_THREADSAFE_ASSERT(cx->compartment() != cx->runtime()->atomsCompartment);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
@ -5415,6 +5471,13 @@ JS::CompileFunction(JSContext *cx, HandleObject obj, CompileOptions options,
const char *name, unsigned nargs, const char **argnames,
const jschar *chars, size_t length)
{
Maybe<AutoVersionAPI> mava;
if (options.versionSet) {
mava.construct(cx, options.version);
// AutoVersionAPI propagates some compilation flags through.
options.version = mava.ref().version();
}
JS_THREADSAFE_ASSERT(cx->compartment() != cx->runtime()->atomsCompartment);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
@ -5589,6 +5652,7 @@ JS_ExecuteScriptVersion(JSContext *cx, JSObject *objArg, JSScript *script, jsval
JSVersion version)
{
RootedObject obj(cx, objArg);
AutoVersionAPI ava(cx, version);
return JS_ExecuteScript(cx, obj, script, rval);
}
@ -5598,6 +5662,13 @@ extern JS_PUBLIC_API(bool)
JS::Evaluate(JSContext *cx, HandleObject obj, CompileOptions options,
const jschar *chars, size_t length, jsval *rval)
{
Maybe<AutoVersionAPI> mava;
if (options.versionSet) {
mava.construct(cx, options.version);
// AutoVersionAPI propagates some compilation flags through.
options.version = mava.ref().version();
}
JS_THREADSAFE_ASSERT(cx->compartment() != cx->runtime()->atomsCompartment);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);

View File

@ -1890,14 +1890,8 @@ JS_ContextIterator(JSRuntime *rt, JSContext **iterp);
extern JS_PUBLIC_API(JSVersion)
JS_GetVersion(JSContext *cx);
// Mutate the version on the compartment. This is generally discouraged, but
// necessary to support the version mutation in the js and xpc shell command
// set.
//
// It would be nice to put this in jsfriendapi, but the linkage requirements
// of the shells make that impossible.
JS_PUBLIC_API(void)
JS_SetVersionForCompartment(JSCompartment *compartment, JSVersion version);
extern JS_PUBLIC_API(JSVersion)
JS_SetVersion(JSContext *cx, JSVersion version);
extern JS_PUBLIC_API(const char *)
JS_VersionToString(JSVersion version);
@ -3150,25 +3144,11 @@ SameZoneAs(JSObject *obj)
return ZoneSpecifier(obj);
}
struct JS_PUBLIC_API(CompartmentOptions) {
ZoneSpecifier zoneSpec;
bool hasVersion;
JSVersion version;
explicit CompartmentOptions() : zoneSpec(JS::FreshZone)
, hasVersion(false)
, version(JSVERSION_UNKNOWN)
{}
CompartmentOptions &setZone(ZoneSpecifier spec) { zoneSpec = spec; return *this; }
CompartmentOptions &setVersion(JSVersion version_) { hasVersion = true; version = version_; return *this; }
};
} /* namespace JS */
extern JS_PUBLIC_API(JSObject *)
JS_NewGlobalObject(JSContext *cx, JSClass *clasp, JSPrincipals *principals,
const JS::CompartmentOptions &options = JS::CompartmentOptions());
JS::ZoneSpecifier zoneSpec = JS::FreshZone);
extern JS_PUBLIC_API(JSObject *)
JS_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent);

View File

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

View File

@ -719,9 +719,6 @@ 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:
@ -831,9 +828,6 @@ 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;
@ -1539,6 +1533,11 @@ struct JSContext : js::ContextFriendFields,
js::PerThreadData &mainThread() { return runtime()->mainThread; }
private:
/* See JSContext::findVersion. */
JSVersion defaultVersion; /* script compilation version */
JSVersion versionOverride; /* supercedes defaultVersion when valid */
bool hasVersionOverride;
/* 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 */
@ -1647,11 +1646,51 @@ struct JSContext : js::ContextFriendFields,
inline js::RegExpStatics *regExpStatics();
public:
/*
* The default script compilation version can be set iff there is no code running.
* This typically occurs via the JSAPI right after a context is constructed.
*/
inline bool canSetDefaultVersion() const;
/* Force a version for future script compilation. */
inline void overrideVersion(JSVersion newVersion);
/* Set the default script compilation version. */
void setDefaultVersion(JSVersion version) {
defaultVersion = version;
}
void clearVersionOverride() { hasVersionOverride = false; }
JSVersion getDefaultVersion() const { return defaultVersion; }
bool isVersionOverridden() const { return hasVersionOverride; }
JSVersion getVersionOverride() const {
JS_ASSERT(isVersionOverridden());
return versionOverride;
}
/*
* Set the default version if possible; otherwise, force the version.
* Return whether an override occurred.
*/
inline bool maybeOverrideVersion(JSVersion newVersion);
/*
* If there is no code on the stack, turn the override version into the
* default version.
*/
void maybeMigrateVersionOverride() {
JS_ASSERT(stack.empty());
if (JS_UNLIKELY(isVersionOverridden())) {
defaultVersion = versionOverride;
clearVersionOverride();
}
}
/*
* Return:
* - The override version, if there is an override version.
* - The newest scripted frame's version, if there is such a frame.
* - The version from the compartment.
* - The default version.
*
* Note: if this ever shows up in a profile, just add caching!

View File

@ -468,13 +468,38 @@ CallSetter(JSContext *cx, HandleObject obj, HandleId id, StrictPropertyOp op, un
inline JSVersion
JSContext::findVersion() const
{
if (hasVersionOverride)
return versionOverride;
if (JSScript *script = stack.currentScript(NULL, js::ContextStack::ALLOW_CROSS_COMPARTMENT))
return script->getVersion();
if (compartment() && compartment()->options().hasVersion)
return compartment()->options().version;
return defaultVersion;
}
return runtime()->defaultVersion();
inline bool
JSContext::canSetDefaultVersion() const
{
return !stack.hasfp() && !hasVersionOverride;
}
inline void
JSContext::overrideVersion(JSVersion newVersion)
{
JS_ASSERT(!canSetDefaultVersion());
versionOverride = newVersion;
hasVersionOverride = true;
}
inline bool
JSContext::maybeOverrideVersion(JSVersion newVersion)
{
if (canSetDefaultVersion()) {
setDefaultVersion(newVersion);
return false;
}
overrideVersion(newVersion);
return true;
}
inline js::LifoAlloc &

View File

@ -30,9 +30,8 @@ using namespace js::gc;
using mozilla::DebugOnly;
JSCompartment::JSCompartment(Zone *zone, const JS::CompartmentOptions &options = JS::CompartmentOptions())
JSCompartment::JSCompartment(Zone *zone)
: zone_(zone),
options_(options),
rt(zone->rt),
principals(NULL),
isSystem(false),

View File

@ -123,7 +123,6 @@ class DebugScopes;
struct JSCompartment
{
JS::Zone *zone_;
JS::CompartmentOptions options_;
JSRuntime *rt;
JSPrincipals *principals;
@ -145,8 +144,6 @@ struct JSCompartment
JS::Zone *zone() { return zone_; }
const JS::Zone *zone() const { return zone_; }
JS::CompartmentOptions &options() { return options_; }
const JS::CompartmentOptions &options() const { return options_; }
/*
* Nb: global_ might be NULL, if (a) it's the atoms compartment, or (b) the
@ -262,7 +259,7 @@ struct JSCompartment
unsigned debugModeBits; // see debugMode() below
public:
JSCompartment(JS::Zone *zone, const JS::CompartmentOptions &options);
JSCompartment(JS::Zone *zone);
~JSCompartment();
bool init(JSContext *cx);

View File

@ -827,6 +827,12 @@ JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure)
/************************************************************************/
JS_FRIEND_API(void)
js_RevertVersion(JSContext *cx)
{
cx->clearVersionOverride();
}
JS_PUBLIC_API(const JSDebugHooks *)
JS_GetGlobalDebugHooks(JSRuntime *rt)
{

View File

@ -427,6 +427,9 @@ JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);
/************************************************************************/
extern JS_FRIEND_API(void)
js_RevertVersion(JSContext *cx);
extern JS_PUBLIC_API(const JSDebugHooks *)
JS_GetGlobalDebugHooks(JSRuntime *rt);

View File

@ -4699,8 +4699,7 @@ AutoPrepareForTracing::AutoPrepareForTracing(JSRuntime *rt)
}
JSCompartment *
js::NewCompartment(JSContext *cx, Zone *zone, JSPrincipals *principals,
const JS::CompartmentOptions &options)
js::NewCompartment(JSContext *cx, Zone *zone, JSPrincipals *principals)
{
JSRuntime *rt = cx->runtime();
JS_AbortIfWrongThread(rt);
@ -4722,7 +4721,7 @@ js::NewCompartment(JSContext *cx, Zone *zone, JSPrincipals *principals,
zone->isSystem = principals && principals == trusted;
}
ScopedJSDeletePtr<JSCompartment> compartment(cx->new_<JSCompartment>(zone, options));
ScopedJSDeletePtr<JSCompartment> compartment(cx->new_<JSCompartment>(zone));
if (!compartment || !compartment->init(cx))
return NULL;

View File

@ -1201,8 +1201,7 @@ js_FinalizeStringRT(JSRuntime *rt, JSString *str);
namespace js {
JSCompartment *
NewCompartment(JSContext *cx, JS::Zone *zone, JSPrincipals *principals,
const JS::CompartmentOptions &options);
NewCompartment(JSContext *cx, JS::Zone *zone, JSPrincipals *principals);
namespace gc {

View File

@ -625,10 +625,9 @@ static JSBool
Version(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JSVersion origVersion = JS_GetVersion(cx);
if (args.length() == 0 || JSVAL_IS_VOID(args[0])) {
/* Get version. */
args.rval().setInt32(origVersion);
args.rval().setInt32(JS_GetVersion(cx));
} else {
/* Set version. */
int32_t v = -1;
@ -643,12 +642,20 @@ Version(JSContext *cx, unsigned argc, jsval *vp)
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_INVALID_ARGS, "version");
return false;
}
JS_SetVersionForCompartment(js::GetContextCompartment(cx), JSVersion(v));
args.rval().setInt32(origVersion);
args.rval().setInt32(JS_SetVersion(cx, JSVersion(v)));
}
return true;
}
static JSBool
RevertVersion(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
js_RevertVersion(cx);
args.rval().setUndefined();
return true;
}
static JSScript *
GetTopScript(JSContext *cx)
{
@ -3558,6 +3565,10 @@ static JSFunctionSpecWithHelp shell_functions[] = {
"version([number])",
" Get or force a script compilation version number."),
JS_FN_HELP("revertVersion", RevertVersion, 0, 0,
"revertVersion()",
" Revert previously set version number."),
JS_FN_HELP("options", Options, 0, 0,
"options([option ...])",
" Get or toggle JavaScript options."),
@ -4763,6 +4774,7 @@ NewContext(JSRuntime *rt)
JS_SetContextPrivate(cx, data);
JS_SetErrorReporter(cx, my_ErrorReporter);
JS_SetVersion(cx, JSVERSION_LATEST);
SetContextOptions(cx);
if (enableTypeInference)
JS_ToggleOptions(cx, JSOPTION_TYPE_INFERENCE);
@ -4787,10 +4799,8 @@ DestroyContext(JSContext *cx, bool withGC)
static JSObject *
NewGlobalObject(JSContext *cx, JSObject *sameZoneAs)
{
JS::CompartmentOptions options;
options.setZone(sameZoneAs ? JS::SameZoneAs(sameZoneAs) : JS::FreshZone)
.setVersion(JSVERSION_LATEST);
RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, NULL, options));
JS::ZoneSpecifier spec = sameZoneAs ? JS::SameZoneAs(sameZoneAs) : JS::FreshZone;
RootedObject glob(cx, JS_NewGlobalObject(cx, &global_class, NULL, spec));
if (!glob)
return NULL;

View File

@ -137,6 +137,19 @@ function test()
expect(["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"] + "",
([a + b for (a in 'abc') for (b in '123')]) + "");
/*
* Version switching
*/
if (typeof version == 'function')
{
var v = version(150);
f = new Function("return version(arguments[0])");
revertVersion();
expect(150, f());
expect(150, eval("f()"));
expect(0, eval("f(0); f()"));
revertVersion();
}
print("End of Tests");
/*

View File

@ -833,6 +833,9 @@ ContextStack::popSegment()
{
space().seg_ = seg_->prevInMemory();
seg_ = seg_->prevInContext();
if (!seg_)
cx_->maybeMigrateVersionOverride();
}
bool

View File

@ -44,7 +44,7 @@ class nsWrapperCache;
[ref] native nsCCTraversalCallbackRef(nsCycleCollectionTraversalCallback);
[ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext);
[ptr] native nsWrapperCachePtr(nsWrapperCache);
[ref] native JSCompartmentOptions(JS::CompartmentOptions);
native ZoneSpecifier(uintptr_t);
[ref] native JSCallArgsRef(const JS::CallArgs);
native JSHandleId(JS::HandleId);
@ -291,7 +291,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
%}
[uuid(bd61342d-8a88-4f23-8d2d-1782fff02d26)]
[uuid(2950bc62-ba03-4465-9685-a0eec9e188c2)]
interface nsIXPConnect : nsISupports
{
%{ C++
@ -318,15 +318,14 @@ interface nsIXPConnect : nsISupports
* compartment. Can be null if not on the main thread.
* @param aFlags one of the flags below specifying what options this
* global object wants.
* @param aOptions JSAPI-specific options for the new compartment.
*/
nsIXPConnectJSObjectHolder
initClassesWithNewWrappedGlobal(
in JSContextPtr aJSContext,
in nsISupports aCOMObj,
in nsIPrincipal aPrincipal,
in uint32_t aFlags,
in JSCompartmentOptions aOptions);
in JSContextPtr aJSContext,
in nsISupports aCOMObj,
in nsIPrincipal aPrincipal,
in uint32_t aFlags,
in ZoneSpecifier aZoneSpec);
const uint32_t INIT_JS_STANDARD_CLASSES = 1 << 0;
// Free bit here!

View File

@ -460,6 +460,9 @@ mozJSComponentLoader::ReallyInit()
if (!mContext)
return NS_ERROR_OUT_OF_MEMORY;
// Always use the latest js version
JS_SetVersion(mContext, JSVERSION_LATEST);
nsCOMPtr<nsIScriptSecurityManager> secman =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (!secman)
@ -723,14 +726,11 @@ mozJSComponentLoader::PrepareObjectForLocation(JSCLContextHelper& aCx,
rv = NS_NewBackstagePass(getter_AddRefs(backstagePass));
NS_ENSURE_SUCCESS(rv, nullptr);
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
rv = xpc->InitClassesWithNewWrappedGlobal(aCx,
static_cast<nsIGlobalObject *>(backstagePass),
mSystemPrincipal,
0,
options,
JS::SystemZone,
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, nullptr);

View File

@ -489,11 +489,10 @@ Load(JSContext *cx, unsigned argc, jsval *vp)
static JSBool
Version(JSContext *cx, unsigned argc, jsval *vp)
{
JSVersion origVersion = JS_GetVersion(cx);
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(origVersion));
if (argc > 0 && JSVAL_IS_INT(JS_ARGV(cx, vp)[0]))
JS_SetVersionForCompartment(js::GetContextCompartment(cx),
JSVersion(JSVAL_TO_INT(JS_ARGV(cx, vp)[0])));
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_SetVersion(cx, JSVersion(JSVAL_TO_INT(JS_ARGV(cx, vp)[0])))));
else
JS_SET_RVAL(cx, vp, INT_TO_JSVAL(JS_GetVersion(cx)));
return true;
}
@ -1237,8 +1236,7 @@ ProcessArgs(JSContext *cx, JS::Handle<JSObject*> obj, char **argv, int argc, XPC
if (++i == argc) {
return usage();
}
JS_SetVersionForCompartment(js::GetContextCompartment(cx),
JSVersion(atoi(argv[i])));
JS_SetVersion(cx, JSVersion(atoi(argv[i])));
break;
case 'W':
reportWarnings = false;
@ -1402,6 +1400,7 @@ ContextCallback(JSContext *cx, unsigned contextOp)
if (contextOp == JSCONTEXT_NEW) {
JS_SetErrorReporter(cx, my_ErrorReporter);
JS_SetVersion(cx, JSVERSION_LATEST);
}
return true;
}
@ -1635,15 +1634,12 @@ main(int argc, char **argv, char **envp)
return 1;
}
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = xpc->InitClassesWithNewWrappedGlobal(cx,
static_cast<nsIGlobalObject *>(backstagePass),
systemprincipal,
0,
options,
JS::SystemZone,
getter_AddRefs(holder));
if (NS_FAILED(rv))
return 1;

View File

@ -3279,12 +3279,10 @@ xpc_CreateSandboxObject(JSContext *cx, jsval *vp, nsISupports *prinOrSop, Sandbo
MOZ_ASSERT(principal);
}
JS::CompartmentOptions compartmentOptions;
compartmentOptions.setZone(options.sameZoneAs
JS::ZoneSpecifier zoneSpec = options.sameZoneAs
? JS::SameZoneAs(js::UncheckedUnwrap(options.sameZoneAs))
: JS::SystemZone);
RootedObject sandbox(cx, xpc::CreateGlobalObject(cx, &SandboxClass,
principal, compartmentOptions));
: JS::SystemZone;
RootedObject sandbox(cx, xpc::CreateGlobalObject(cx, &SandboxClass, principal, zoneSpec));
if (!sandbox)
return NS_ERROR_FAILURE;
@ -3822,13 +3820,6 @@ nsXPCComponents_Utils::EvalInSandbox(const nsAString& source,
return NS_ERROR_INVALID_ARG;
jsVersion = JS_StringToVersion(bytes.ptr());
// Explicitly check for "latest", which we support for sandboxes but
// isn't in the set of web-exposed version strings.
if (jsVersion == JSVERSION_UNKNOWN &&
!strcmp(bytes.ptr(), "latest"))
{
jsVersion = JSVERSION_LATEST;
}
if (jsVersion == JSVERSION_UNKNOWN)
return NS_ERROR_INVALID_ARG;
}
@ -3913,11 +3904,12 @@ xpc_EvalInSandbox(JSContext *cx, HandleObject sandboxArg, const nsAString& sourc
pusher.Push(sandcx);
JSAutoCompartment ac(sandcx, sandbox);
if (jsVersion != JSVERSION_DEFAULT)
JS_SetVersion(sandcx, jsVersion);
JS::CompileOptions options(sandcx);
options.setPrincipals(nsJSPrincipals::get(prin))
.setFileAndLine(filename, lineNo);
if (jsVersion != JSVERSION_DEFAULT)
options.setVersion(jsVersion);
JS::RootedObject rootedSandbox(sandcx, sandbox);
ok = JS::Evaluate(sandcx, rootedSandbox, options,
PromiseFlatString(source).get(), source.Length(),

View File

@ -167,9 +167,7 @@ XPCJSContextStack::GetSafeJSContext()
JS_SetErrorReporter(mSafeJSContext, mozJSLoaderErrorReporter);
JS::CompartmentOptions options;
options.setZone(JS::SystemZone);
glob = xpc::CreateGlobalObject(mSafeJSContext, &global_class, principal, options);
glob = xpc::CreateGlobalObject(mSafeJSContext, &global_class, principal, JS::SystemZone);
if (glob) {
// Make sure the context is associated with a proper compartment

View File

@ -285,7 +285,7 @@ FinishCreate(XPCWrappedNativeScope* Scope,
nsresult
XPCWrappedNative::WrapNewGlobal(xpcObjectHelper &nativeHelper,
nsIPrincipal *principal, bool initStandardClasses,
JS::CompartmentOptions& aOptions,
ZoneSpecifier zoneSpec,
XPCWrappedNative **wrappedGlobal)
{
AutoJSContext cx;
@ -315,7 +315,7 @@ XPCWrappedNative::WrapNewGlobal(xpcObjectHelper &nativeHelper,
MOZ_ASSERT(clasp->flags & JSCLASS_IS_GLOBAL);
// Create the global.
RootedObject global(cx, xpc::CreateGlobalObject(cx, clasp, principal, aOptions));
RootedObject global(cx, xpc::CreateGlobalObject(cx, clasp, principal, zoneSpec));
if (!global)
return NS_ERROR_FAILURE;
XPCWrappedNativeScope *scope = GetCompartmentPrivate(global)->scope;

View File

@ -981,7 +981,7 @@ namespace xpc {
JSObject*
CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal,
JS::CompartmentOptions& aOptions)
JS::ZoneSpecifier zoneSpec)
{
// Make sure that Type Inference is enabled for everything non-chrome.
// Sandboxes and compilation scopes are exceptions. See bug 744034.
@ -991,7 +991,7 @@ CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal,
MOZ_ASSERT(principal);
RootedObject global(cx,
JS_NewGlobalObject(cx, clasp, nsJSPrincipals::get(principal), aOptions));
JS_NewGlobalObject(cx, clasp, nsJSPrincipals::get(principal), zoneSpec));
if (!global)
return nullptr;
JSAutoCompartment ac(cx, global);
@ -1027,7 +1027,7 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
nsISupports *aCOMObj,
nsIPrincipal * aPrincipal,
uint32_t aFlags,
JS::CompartmentOptions& aOptions,
JS::ZoneSpecifier zoneSpec,
nsIXPConnectJSObjectHolder **_retval)
{
NS_ASSERTION(aJSContext, "bad param");
@ -1046,7 +1046,8 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
nsresult rv =
XPCWrappedNative::WrapNewGlobal(helper, aPrincipal,
aFlags & nsIXPConnect::INIT_JS_STANDARD_CLASSES,
aOptions, getter_AddRefs(wrappedGlobal));
zoneSpec,
getter_AddRefs(wrappedGlobal));
NS_ENSURE_SUCCESS(rv, rv);
// Grab a copy of the global and enter its compartment.

View File

@ -2471,7 +2471,7 @@ public:
static nsresult
WrapNewGlobal(xpcObjectHelper &nativeHelper,
nsIPrincipal *principal, bool initStandardClasses,
JS::CompartmentOptions& aOptions,
JS::ZoneSpecifier zoneSpec,
XPCWrappedNative **wrappedGlobal);
static nsresult
@ -3796,7 +3796,7 @@ struct SandboxOptions {
JSObject *
CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal,
JS::CompartmentOptions& aOptions);
JS::ZoneSpecifier zoneSpec);
}
// Helper for creating a sandbox object to use for evaluating

View File

@ -0,0 +1,3 @@
/* Some constructs that require a high default version number. */
let x = 12;
function simpleGen() { yield 12; }

View File

@ -0,0 +1,19 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
function run_test() {
var file = do_get_file("bug596580_versioned.js");
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var uri = ios.newFileURI(file);
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
scriptLoader.loadSubScript(uri.spec);
version(150)
try {
scriptLoader.loadSubScript(uri.spec);
throw new Error("Subscript should fail to load.");
} catch (e if e instanceof SyntaxError) {
// Okay.
}
}

View File

@ -5,6 +5,7 @@ tail =
[test_bogus_files.js]
[test_bug408412.js]
[test_bug451678.js]
[test_bug596580.js]
[test_bug604362.js]
[test_bug641378.js]
[test_bug677864.js]

View File

@ -536,15 +536,13 @@ private:
JSAutoRequest ar(mContext);
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
mGlobal = JS_NewGlobalObject(mContext, &sGlobalClass, nullptr, options);
mGlobal = JS_NewGlobalObject(mContext, &sGlobalClass, nullptr, JS::SystemZone);
NS_ENSURE_TRUE(mGlobal, NS_ERROR_OUT_OF_MEMORY);
JS_SetGlobalObject(mContext, mGlobal);
JS_InitStandardClasses(mContext, mGlobal);
JS_SetVersion(mContext, JSVERSION_LATEST);
JS_SetErrorReporter(mContext, PACErrorReporter);
if (!JS_DefineFunctions(mContext, mGlobal, PACGlobalFunctions))

View File

@ -2727,7 +2727,7 @@ ServerHandler.prototype =
// getting the line number where we evaluate the SJS file. Don't
// separate these two lines!
var line = new Error().lineNumber;
Cu.evalInSandbox(sis.read(file.fileSize), s, "latest");
Cu.evalInSandbox(sis.read(file.fileSize), s);
}
catch (e)
{