本文整理汇总了C++中js::CompartmentOptions类的典型用法代码示例。如果您正苦于以下问题:C++ CompartmentOptions类的具体用法?C++ CompartmentOptions怎么用?C++ CompartmentOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompartmentOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: global
JSObject *newDelegate()
{
static const JSClass delegateClass = {
"delegate",
JSCLASS_GLOBAL_FLAGS | JSCLASS_HAS_RESERVED_SLOTS(1),
JS_PropertyStub,
JS_DeletePropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
nullptr,
nullptr,
nullptr,
nullptr,
JS_GlobalObjectTraceHook
};
/* Create the global object. */
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
JS::RootedObject global(cx);
global = JS_NewGlobalObject(cx, &delegateClass, nullptr, JS::FireOnNewGlobalHook, options);
JS_SetReservedSlot(global, 0, JS::Int32Value(42));
/*
* Ensure the delegate is not in the nursery because for the purpose of this
* test we're going to put it in a private slot where it won't get updated.
*/
JS_GC(rt);
return global;
}
示例2: ShouldDiscardSystemSource
void
InitGlobalObjectOptions(JS::CompartmentOptions& aOptions,
nsIPrincipal* aPrincipal)
{
bool shouldDiscardSystemSource = ShouldDiscardSystemSource();
bool extraWarningsForSystemJS = ExtraWarningsForSystemJS();
bool isSystem = nsContentUtils::IsSystemPrincipal(aPrincipal);
if (isSystem) {
// Make sure [SecureContext] APIs are visible:
aOptions.creationOptions().setSecureContext(true);
#if 0 // TODO: Reenable in Bug 1288653
// Enable the ECMA-402 experimental formatToParts in any chrome page
aOptions.creationOptions()
.setExperimentalDateTimeFormatFormatToPartsEnabled(true);
#endif
}
if (shouldDiscardSystemSource) {
bool discardSource = isSystem;
aOptions.behaviors().setDiscardSource(discardSource);
}
if (extraWarningsForSystemJS) {
if (isSystem)
aOptions.behaviors().extraWarningsOverride().set(true);
}
}
示例3: Wrap
bool
DedicatedWorkerGlobalScope::WrapGlobalObject(JSContext* aCx,
JS::MutableHandle<JSObject*> aReflector)
{
mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerPrivate->IsSharedWorker());
JS::CompartmentOptions options;
mWorkerPrivate->CopyJSCompartmentOptions(options);
const bool usesSystemPrincipal = mWorkerPrivate->UsesSystemPrincipal();
// Note that xpc::ShouldDiscardSystemSource() and
// xpc::ExtraWarningsForSystemJS() read prefs that are cached on the main
// thread. This is benignly racey.
const bool discardSource = (usesSystemPrincipal ||
mWorkerPrivate->IsInPrivilegedApp()) &&
xpc::ShouldDiscardSystemSource();
const bool extraWarnings = usesSystemPrincipal &&
xpc::ExtraWarningsForSystemJS();
options.setDiscardSource(discardSource)
.extraWarningsOverride().set(extraWarnings);
return DedicatedWorkerGlobalScopeBinding_workers::Wrap(aCx, this, this,
options,
GetWorkerPrincipal(),
true, aReflector);
}
示例4: JS_NewGlobalObject
JSObject*
createTestGlobal(bool preserveJitCode)
{
JS::CompartmentOptions options;
options.creationOptions().setPreserveJitCode(preserveJitCode);
return JS_NewGlobalObject(cx, getGlobalClass(), nullptr, JS::FireOnNewGlobalHook, options);
}
示例5: Wrap
bool
DedicatedWorkerGlobalScope::WrapGlobalObject(JSContext* aCx,
JS::MutableHandle<JSObject*> aReflector)
{
mWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mWorkerPrivate->IsSharedWorker());
JS::CompartmentOptions options;
mWorkerPrivate->CopyJSCompartmentOptions(options);
const bool usesSystemPrincipal = mWorkerPrivate->UsesSystemPrincipal();
// Note that xpc::ShouldDiscardSystemSource() and
// xpc::ExtraWarningsForSystemJS() read prefs that are cached on the main
// thread. This is benignly racey.
const bool discardSource = usesSystemPrincipal &&
xpc::ShouldDiscardSystemSource();
const bool extraWarnings = usesSystemPrincipal &&
xpc::ExtraWarningsForSystemJS();
JS::CompartmentBehaviors& behaviors = options.behaviors();
behaviors.setDiscardSource(discardSource)
.extraWarningsOverride().set(extraWarnings);
const bool sharedMemoryEnabled = xpc::SharedMemoryEnabled();
JS::CompartmentCreationOptions& creationOptions = options.creationOptions();
creationOptions.setSharedMemoryAndAtomicsEnabled(sharedMemoryEnabled);
return DedicatedWorkerGlobalScopeBinding::Wrap(aCx, this, this,
options,
GetWorkerPrincipal(),
true, aReflector);
}
示例6: ShouldDiscardSystemSource
void
InitGlobalObjectOptions(JS::CompartmentOptions& aOptions,
nsIPrincipal* aPrincipal)
{
bool shouldDiscardSystemSource = ShouldDiscardSystemSource();
bool extraWarningsForSystemJS = ExtraWarningsForSystemJS();
bool isSystem = nsContentUtils::IsSystemPrincipal(aPrincipal);
if (isSystem) {
// Make sure [SecureContext] APIs are visible:
aOptions.creationOptions().setSecureContext(true);
}
short status = aPrincipal->GetAppStatus();
// Enable the ECMA-402 experimental formatToParts in certified apps.
if (status == nsIPrincipal::APP_STATUS_CERTIFIED) {
aOptions.creationOptions()
.setExperimentalDateTimeFormatFormatToPartsEnabled(true);
}
if (shouldDiscardSystemSource) {
bool discardSource = isSystem ||
(status == nsIPrincipal::APP_STATUS_PRIVILEGED ||
status == nsIPrincipal::APP_STATUS_CERTIFIED);
aOptions.behaviors().setDiscardSource(discardSource);
}
if (extraWarningsForSystemJS) {
if (isSystem)
aOptions.behaviors().extraWarningsOverride().set(true);
}
}
示例7: rq
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime) :
m_runtime(runtime), m_glob(runtime->m_rt), m_nativeScope(runtime->m_rt)
{
bool ok;
m_cx = JS_NewContext(m_runtime->m_rt, STACK_CHUNK_SIZE);
ENSURE(m_cx);
JS_SetParallelIonCompilationEnabled(m_runtime->m_rt, true);
// For GC debugging:
// JS_SetGCZeal(m_cx, 2);
JS_SetContextPrivate(m_cx, NULL);
JS_SetErrorReporter(m_cx, ErrorReporter);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1);
JS::ContextOptionsRef(m_cx).setExtraWarnings(1)
.setWerror(0)
.setVarObjFix(1)
.setStrictMode(1);
JS::CompartmentOptions opt;
opt.setVersion(JSVERSION_LATEST);
JSAutoRequest rq(m_cx);
JS::RootedObject globalRootedVal(m_cx, JS_NewGlobalObject(m_cx, &global_class, NULL, JS::OnNewGlobalHookOption::FireOnNewGlobalHook, opt));
m_comp = JS_EnterCompartment(m_cx, globalRootedVal);
ok = JS_InitStandardClasses(m_cx, globalRootedVal);
ENSURE(ok);
m_glob = globalRootedVal.get();
// Use the testing functions to globally enable gcPreserveCode. This brings quite a
// big performance improvement. In future SpiderMonkey versions, we should probably
// use the functions implemented here: https://bugzilla.mozilla.org/show_bug.cgi?id=1068697
JS::RootedObject testingFunctionsObj(m_cx, js::GetTestingFunctions(m_cx));
ENSURE(testingFunctionsObj);
JS::RootedValue ret(m_cx);
JS_CallFunctionName(m_cx, testingFunctionsObj, "gcPreserveCode", JS::HandleValueArray::empty(), &ret);
JS_DefineProperty(m_cx, m_glob, "global", globalRootedVal, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
m_nativeScope = JS_DefineObject(m_cx, m_glob, nativeScopeName, NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY
| JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "print", ::print, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "log", ::logmsg, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "warn", ::warn, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "error", ::error, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "deepcopy", ::deepcopy, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
Register("ProfileStart", ::ProfileStart, 1);
Register("ProfileStop", ::ProfileStop, 0);
runtime->RegisterContext(m_cx);
}
示例8: isSelfHosting
JSCompartment::JSCompartment(Zone* zone, const JS::CompartmentOptions& options = JS::CompartmentOptions())
: creationOptions_(options.creationOptions()),
behaviors_(options.behaviors()),
zone_(zone),
runtime_(zone->runtimeFromAnyThread()),
principals_(nullptr),
isSystem_(false),
isAtomsCompartment_(false),
isSelfHosting(false),
marked(true),
warnedAboutExprClosure(false),
warnedAboutStringGenericsMethods(0),
#ifdef DEBUG
firedOnNewGlobalObject(false),
#endif
global_(nullptr),
enterCompartmentDepth(0),
globalHolds(0),
performanceMonitoring(runtime_),
data(nullptr),
realmData(nullptr),
allocationMetadataBuilder(nullptr),
lastAnimationTime(0),
regExps(),
arraySpeciesLookup(),
globalWriteBarriered(0),
detachedTypedObjects(0),
objectMetadataState(ImmediateMetadata()),
selfHostingScriptSource(nullptr),
objectMetadataTable(nullptr),
innerViews(zone),
lazyArrayBuffers(nullptr),
wasm(zone),
nonSyntacticLexicalEnvironments_(nullptr),
gcIncomingGrayPointers(nullptr),
debugModeBits(0),
validAccessPtr(nullptr),
randomKeyGenerator_(runtime_->forkRandomKeyGenerator()),
scriptCountsMap(nullptr),
scriptNameMap(nullptr),
debugScriptMap(nullptr),
debugEnvs(nullptr),
enumerators(nullptr),
compartmentStats_(nullptr),
scheduledForDestruction(false),
maybeAlive(true),
jitCompartment_(nullptr),
mappedArgumentsTemplate_(nullptr),
unmappedArgumentsTemplate_(nullptr),
iterResultTemplate_(nullptr),
lcovOutput()
{
PodArrayZero(sawDeprecatedLanguageExtension);
runtime_->numCompartments++;
MOZ_ASSERT_IF(creationOptions_.mergeable(),
creationOptions_.invisibleToDebugger());
}
示例9: createContext
bool JSAudioContext::createContext()
{
if (m_JsRt != NULL) return false;
if ((m_JsRt = JS_NewRuntime(JS::DefaultHeapMaxBytes, JS::DefaultNurseryBytes))
== NULL) {
fprintf(stderr, "Failed to init JS runtime");
return false;
}
NidiumJS::SetJSRuntimeOptions(m_JsRt);
JS_SetGCParameter(m_JsRt, JSGC_MAX_BYTES, 0xffffffff);
JS_SetGCParameter(m_JsRt, JSGC_SLICE_TIME_BUDGET, 15);
if ((m_JsTcx = JS_NewContext(m_JsRt, 8192)) == NULL) {
fprintf(stderr, "Failed to init JS context");
return false;
}
NidiumLocalContext::InitJSThread(m_JsRt, m_JsTcx);
JSAutoRequest ar(m_JsTcx);
// JS_SetGCParameterForThread(this->tcx, JSGC_MAX_CODE_CACHE_BYTES, 16 *
// 1024 * 1024);
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
JS::RootedObject global(
m_JsTcx, JS_NewGlobalObject(m_JsTcx, &Global_AudioThread_class, nullptr,
JS::DontFireOnNewGlobalHook, options));
JSAutoCompartment ac(m_JsTcx, global);
m_JsGlobalObj = global;
// We don't actually needs to root a global object, but we
// need to store a reference to the global object in a
// JS::Heap and this reference needs to be traced.
NidiumLocalContext::RootObjectUntilShutdown(m_JsGlobalObj);
if (!JS_InitStandardClasses(m_JsTcx, global)) {
fprintf(stderr, "Failed to init std class");
return false;
}
JS_SetErrorReporter(m_JsRt, reportError);
JS_FireOnNewGlobalObject(m_JsTcx, global);
JSConsole::RegisterObject(m_JsTcx);
JSAudioNodeThreaded::RegisterObject(m_JsTcx);
return true;
}
示例10: ReadEvalPrintLoop
void JavaScriptInterpreter::ReadEvalPrintLoop()
{
JSAutoRequest ar(cx);
JS::CompartmentOptions compartmentOptions;
compartmentOptions.setVersion(JSVERSION_DEFAULT);
JS::RootedObject global(cx, JS_NewGlobalObject(cx, &global_class, nullptr, JS::FireOnNewGlobalHook, compartmentOptions));
if (!global)
return;
JS::RootedValue rval(cx);
JSAutoCompartment ac(cx, global);
if (!JS_InitStandardClasses(cx, global))
return;
v = JS_GetVersion(cx);
actionJSVersion->setDisabled(false);
/////////////////////////////////////////////////////////////
int lineno = 1;
int startline = lineno;
errno = 1;
u16string source = TextEdit_input->toPlainText().toStdU16String();
if (source.empty()) {
if (errno) {
char buffer[80];
strerror_s(buffer, 80, errno);
JS_ReportError(cx, buffer);
return;
}
return;
}
lineno++;
QString output = EvalAndPrint(source.c_str(), source.length(), startline);
if (output.isEmpty())
{
JS_ReportPendingException(cx);
}
if (checkBox->isChecked()) {
TextEdit_output->setPlainText(output);
}
else {
TextEdit_output->insertPlainText(output + "\n");
}
}
示例11: rq
ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime) :
m_runtime(runtime), m_glob(runtime->m_rt), m_nativeScope(runtime->m_rt)
{
bool ok;
m_cx = JS_NewContext(m_runtime->m_rt, STACK_CHUNK_SIZE);
ENSURE(m_cx);
JS_SetOffthreadIonCompilationEnabled(m_runtime->m_rt, true);
// For GC debugging:
// JS_SetGCZeal(m_cx, 2, JS_DEFAULT_ZEAL_FREQ);
JS_SetContextPrivate(m_cx, NULL);
JS_SetErrorReporter(m_runtime->m_rt, ErrorReporter);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_ION_ENABLE, 1);
JS_SetGlobalJitCompilerOption(m_runtime->m_rt, JSJITCOMPILER_BASELINE_ENABLE, 1);
JS::RuntimeOptionsRef(m_cx).setExtraWarnings(1)
.setWerror(0)
.setVarObjFix(1)
.setStrictMode(1);
JS::CompartmentOptions opt;
opt.setVersion(JSVERSION_LATEST);
// Keep JIT code during non-shrinking GCs. This brings a quite big performance improvement.
opt.setPreserveJitCode(true);
JSAutoRequest rq(m_cx);
JS::RootedObject globalRootedVal(m_cx, JS_NewGlobalObject(m_cx, &global_class, NULL, JS::OnNewGlobalHookOption::FireOnNewGlobalHook, opt));
m_comp = JS_EnterCompartment(m_cx, globalRootedVal);
ok = JS_InitStandardClasses(m_cx, globalRootedVal);
ENSURE(ok);
m_glob = globalRootedVal.get();
JS_DefineProperty(m_cx, m_glob, "global", globalRootedVal, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
m_nativeScope = JS_DefineObject(m_cx, m_glob, nativeScopeName, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "print", ::print, 0, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "log", ::logmsg, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "warn", ::warn, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "error", ::error, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(m_cx, globalRootedVal, "deepcopy", ::deepcopy, 1, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
Register("ProfileStart", ::ProfileStart, 1);
Register("ProfileStop", ::ProfileStop, 0);
Register("ProfileAttribute", ::ProfileAttribute, 1);
runtime->RegisterContext(m_cx);
}
示例12: isSelfHosting
JSCompartment::JSCompartment(Zone* zone, const JS::CompartmentOptions& options = JS::CompartmentOptions())
: creationOptions_(options.creationOptions()),
behaviors_(options.behaviors()),
zone_(zone),
runtime_(zone->runtimeFromMainThread()),
principals_(nullptr),
isSystem_(false),
isSelfHosting(false),
marked(true),
warnedAboutExprClosure(false),
#ifdef DEBUG
firedOnNewGlobalObject(false),
#endif
global_(nullptr),
enterCompartmentDepth(0),
performanceMonitoring(runtime_),
data(nullptr),
allocationMetadataBuilder(nullptr),
lastAnimationTime(0),
regExps(runtime_),
globalWriteBarriered(0),
detachedTypedObjects(0),
objectMetadataState(ImmediateMetadata()),
propertyTree(thisForCtor()),
baseShapes(zone, BaseShapeSet()),
initialShapes(zone, InitialShapeSet()),
selfHostingScriptSource(nullptr),
objectMetadataTable(nullptr),
lazyArrayBuffers(nullptr),
wasmInstances(zone, WasmInstanceObjectSet()),
nonSyntacticLexicalScopes_(nullptr),
gcIncomingGrayPointers(nullptr),
debugModeBits(0),
watchpointMap(nullptr),
scriptCountsMap(nullptr),
debugScriptMap(nullptr),
debugScopes(nullptr),
enumerators(nullptr),
compartmentStats_(nullptr),
scheduledForDestruction(false),
maybeAlive(true),
jitCompartment_(nullptr),
mappedArgumentsTemplate_(nullptr),
unmappedArgumentsTemplate_(nullptr),
lcovOutput()
{
PodArrayZero(sawDeprecatedLanguageExtension);
runtime_->numCompartments++;
MOZ_ASSERT_IF(creationOptions_.mergeable(),
creationOptions_.invisibleToDebugger());
}
示例13: isSelfHosting
JSCompartment::JSCompartment(Zone* zone, const JS::CompartmentOptions& options = JS::CompartmentOptions())
: options_(options),
zone_(zone),
runtime_(zone->runtimeFromMainThread()),
principals_(nullptr),
isSystem_(false),
isSelfHosting(false),
marked(true),
warnedAboutNoSuchMethod(false),
warnedAboutFlagsArgument(false),
addonId(options.addonIdOrNull()),
#ifdef DEBUG
firedOnNewGlobalObject(false),
#endif
global_(nullptr),
enterCompartmentDepth(0),
performanceMonitoring(runtime_),
data(nullptr),
objectMetadataCallback(nullptr),
lastAnimationTime(0),
regExps(runtime_),
globalWriteBarriered(false),
neuteredTypedObjects(0),
objectMetadataState(ImmediateMetadata()),
propertyTree(thisForCtor()),
selfHostingScriptSource(nullptr),
objectMetadataTable(nullptr),
lazyArrayBuffers(nullptr),
nonSyntacticLexicalScopes_(nullptr),
gcIncomingGrayPointers(nullptr),
gcPreserveJitCode(options.preserveJitCode()),
debugModeBits(0),
rngState(0),
watchpointMap(nullptr),
scriptCountsMap(nullptr),
debugScriptMap(nullptr),
debugScopes(nullptr),
enumerators(nullptr),
compartmentStats(nullptr),
scheduledForDestruction(false),
maybeAlive(true),
jitCompartment_(nullptr),
mappedArgumentsTemplate_(nullptr),
unmappedArgumentsTemplate_(nullptr),
lcovOutput()
{
PodArrayZero(sawDeprecatedLanguageExtension);
runtime_->numCompartments++;
MOZ_ASSERT_IF(options.mergeable(), options.invisibleToDebugger());
}
示例14: req
JSContext*
XPCJSContextStack::InitSafeJSContext()
{
MOZ_ASSERT(!mSafeJSContext);
// Start by getting the principal holder and principal for this
// context. If we can't manage that, don't bother with the rest.
nsRefPtr<nsNullPrincipal> principal = new nsNullPrincipal();
nsresult rv = principal->Init();
if (NS_FAILED(rv))
MOZ_CRASH();
nsXPConnect* xpc = nsXPConnect::XPConnect();
JSRuntime *rt = xpc->GetRuntime()->Runtime();
if (!rt)
MOZ_CRASH();
mSafeJSContext = JS_NewContext(rt, 8192);
if (!mSafeJSContext)
MOZ_CRASH();
JSAutoRequest req(mSafeJSContext);
ContextOptionsRef(mSafeJSContext).setNoDefaultCompartmentObject(true);
JS_SetErrorReporter(mSafeJSContext, xpc::SystemErrorReporter);
// Note - We intentionally avoid firing OnNewGlobalObject while
// simultaneously skipping the call to setInvisibleToDebugger(true) here.
// This lets us piggy-back on the assertions in the JS engine (which make
// sure that, for non-invisible globals, we always fire onNewGlobalObject
// before creating scripts), to assert that we never create scripts with
// the SafeJSContextGlobal. This is all happening way before anyone could be
// listening for debugger notifications anyway.
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setTrace(TraceXPCGlobal);
mSafeJSContextGlobal = CreateGlobalObject(mSafeJSContext,
&SafeJSContextGlobalClass,
principal, options);
if (!mSafeJSContextGlobal)
MOZ_CRASH();
nsRefPtr<SandboxPrivate> sp = new SandboxPrivate(principal, mSafeJSContextGlobal);
JS_SetPrivate(mSafeJSContextGlobal, sp.forget().take());
return mSafeJSContext;
}
示例15: global
static void
CreateGlobalAndRunTest(JSRuntime* rt, JSContext* cx)
{
static const JSClass GlobalClass = {
"global", JSCLASS_GLOBAL_FLAGS,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr,
JS_GlobalObjectTraceHook
};
JS::CompartmentOptions options;
options.setVersion(JSVERSION_LATEST);
JS::PersistentRootedObject global(cx);
global = JS_NewGlobalObject(cx, &GlobalClass, nullptr, JS::FireOnNewGlobalHook, options);
ASSERT_TRUE(global != nullptr);
JSCompartment *oldCompartment = JS_EnterCompartment(cx, global);
typedef Heap<JSObject*> ElementT;
{
nsTArray<ElementT>* array = new nsTArray<ElementT>(InitialElements);
RunTest(rt, cx, array);
delete array;
}
{
FallibleTArray<ElementT>* array = new FallibleTArray<ElementT>(InitialElements);
RunTest(rt, cx, array);
delete array;
}
{
nsAutoTArray<ElementT, InitialElements> array;
RunTest(rt, cx, &array);
}
{
AutoFallibleTArray<ElementT, InitialElements> array;
RunTest(rt, cx, &array);
}
JS_LeaveCompartment(cx, oldCompartment);
}