/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
// static
JSObject* SimpleGlobalObject::Create(GlobalType globalType,
JS::Handle<JS::Value> proto) { // We can't root our return value with our AutoJSAPI because the rooting // analysis thinks ~AutoJSAPI can GC. So we need to root in a scope outside // the lifetime of the AutoJSAPI.
JS::Rooted<JSObject*> global(RootingCx());
{ // Scope to ensure the AutoJSAPI destructor runs before we end up returning
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
JS::RealmOptions options;
options.creationOptions()
.setInvisibleToDebugger(true) // Put our SimpleGlobalObjects in the system zone, so we won't create // lots of zones for what are probably very short-lived // compartments. This should help them be GCed quicker and take up // less memory before they're GCed.
.setNewCompartmentInSystemZone();
if (NS_IsMainThread()) {
nsCOMPtr<nsIPrincipal> principal =
NullPrincipal::CreateWithoutOriginAttributes();
options.creationOptions().setTrace(xpc::TraceXPCGlobal);
global = xpc::CreateGlobalObject(cx, &SimpleGlobalClass,
nsJSPrincipals::get(principal), options);
} else {
global = JS_NewGlobalObject(cx, &SimpleGlobalClass, nullptr,
JS::DontFireOnNewGlobalHook, options);
}
if (!global) {
jsapi.ClearException(); return nullptr;
}
JSAutoRealm ar(cx, global);
// It's important to create the nsIGlobalObject for our new global before we // start trying to wrap things like the prototype into its compartment, // because the wrap operation relies on the global having its // nsIGlobalObject already.
RefPtr<SimpleGlobalObject> globalObject = new SimpleGlobalObject(global, globalType);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.