Skip to content

Commit

Permalink
Bug 1461292 part 1 - Rename JSAutoCompartment to JSAutoRealm. r=bz,luke
Browse files Browse the repository at this point in the history
  • Loading branch information
jandem committed May 16, 2018
1 parent 8f51a6b commit 7d2b934
Show file tree
Hide file tree
Showing 128 changed files with 471 additions and 474 deletions.
2 changes: 1 addition & 1 deletion devtools/shared/heapsnapshot/tests/gtest/DevTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct DevTools : public ::testing::Test {
if (!newGlobal)
return nullptr;

JSAutoCompartment ac(cx, newGlobal);
JSAutoRealm ar(cx, newGlobal);

/* Populate the global object with the standard globals, like Object and
Array. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DEF_TEST(DoesCrossCompartmentBoundaries, {
ASSERT_TRUE(newGlobal);
JSCompartment* newCompartment = nullptr;
{
JSAutoCompartment ac(cx, newGlobal);
JSAutoRealm ar(cx, newGlobal);
ASSERT_TRUE(JS_InitStandardClasses(cx, newGlobal));
newCompartment = js::GetContextCompartment(cx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DEF_TEST(DoesntCrossCompartmentBoundaries, {
ASSERT_TRUE(newGlobal);
JSCompartment* newCompartment = nullptr;
{
JSAutoCompartment ac(cx, newGlobal);
JSAutoRealm ar(cx, newGlobal);
ASSERT_TRUE(JS_InitStandardClasses(cx, newGlobal));
newCompartment = js::GetContextCompartment(cx);
}
Expand Down
12 changes: 6 additions & 6 deletions dom/base/ChromeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ ChromeUtils::ShallowClone(GlobalObject& aGlobal,
return;
}

JSAutoCompartment ac(cx, obj);
JSAutoRealm ar(cx, obj);

if (!JS_Enumerate(cx, obj, &ids) ||
!values.reserve(ids.length())) {
Expand All @@ -238,14 +238,14 @@ ChromeUtils::ShallowClone(GlobalObject& aGlobal,

JS::RootedObject obj(cx);
{
Maybe<JSAutoCompartment> ac;
Maybe<JSAutoRealm> ar;
if (aTarget) {
JS::RootedObject target(cx, js::CheckedUnwrap(aTarget));
if (!target) {
js::ReportAccessDenied(cx);
return;
}
ac.emplace(cx, target);
ar.emplace(cx, target);
}

obj = JS_NewPlainObject(cx);
Expand Down Expand Up @@ -481,7 +481,7 @@ namespace module_getter {

JS::RootedValue value(aCx);
{
JSAutoCompartment ac(aCx, moduleExports);
JSAutoRealm ar(aCx, moduleExports);

if (!JS_GetPropertyById(aCx, moduleExports, id, &value)) {
return false;
Expand Down Expand Up @@ -728,11 +728,11 @@ ChromeUtils::CreateError(const GlobalObject& aGlobal, const nsAString& aMessage,
uint32_t line = 0;
uint32_t column = 0;

Maybe<JSAutoCompartment> ac;
Maybe<JSAutoRealm> ar;
JS::RootedObject stack(cx);
if (aStack) {
stack = UncheckedUnwrap(aStack);
ac.emplace(cx, stack);
ar.emplace(cx, stack);

if (JS::GetSavedFrameLine(cx, stack, &line) != JS::SavedFrameResult::Ok ||
JS::GetSavedFrameColumn(cx, stack, &column) != JS::SavedFrameResult::Ok ||
Expand Down
14 changes: 7 additions & 7 deletions dom/base/CustomElementRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,11 @@ CustomElementRegistry::Define(const nsAString& aName,
*/
AutoSetRunningFlag as(this);

{ // Enter constructor's compartment.
{ // Enter constructor's realm.
/**
* 10.1. Let prototype be Get(constructor, "prototype"). Rethrow any exceptions.
*/
JSAutoCompartment ac(cx, constructor);
JSAutoRealm ar(cx, constructor);
// The .prototype on the constructor passed could be an "expando" of a
// wrapper. So we should get it from wrapper instead of the underlying
// object.
Expand All @@ -794,7 +794,7 @@ CustomElementRegistry::Define(const nsAString& aName,
aRv.ThrowTypeError<MSG_NOT_OBJECT>(NS_LITERAL_STRING("constructor.prototype"));
return;
}
} // Leave constructor's compartment.
} // Leave constructor's realm.

JS::Rooted<JSObject*> constructorProtoUnwrapped(
cx, js::CheckedUnwrap(&constructorPrototype.toObject()));
Expand All @@ -806,7 +806,7 @@ CustomElementRegistry::Define(const nsAString& aName,
}

{ // Enter constructorProtoUnwrapped's compartment
JSAutoCompartment ac(cx, constructorProtoUnwrapped);
JSAutoRealm ar(cx, constructorProtoUnwrapped);

/**
* 10.3. Let lifecycleCallbacks be a map with the four keys
Expand Down Expand Up @@ -847,8 +847,8 @@ CustomElementRegistry::Define(const nsAString& aName,
* any exceptions from the conversion.
*/
if (callbacksHolder->mAttributeChangedCallback.WasPassed()) {
// Enter constructor's compartment.
JSAutoCompartment ac(cx, constructor);
// Enter constructor's realm.
JSAutoRealm ar(cx, constructor);
JS::Rooted<JS::Value> observedAttributesIterable(cx);

if (!JS_GetProperty(cx, constructor, "observedAttributes",
Expand Down Expand Up @@ -897,7 +897,7 @@ CustomElementRegistry::Define(const nsAString& aName,
}
}
}
} // Leave constructor's compartment.
} // Leave constructor's realm.
} // Leave constructorProtoUnwrapped's compartment.
} // Unset mIsCustomDefinitionRunning

Expand Down
6 changes: 3 additions & 3 deletions dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3684,11 +3684,11 @@ Element::Animate(const Nullable<ElementOrCSSPseudoElement>& aTarget,
}

// Animation constructor follows the standard Xray calling convention and
// needs to be called in the target element's compartment.
Maybe<JSAutoCompartment> ac;
// needs to be called in the target element's realm.
Maybe<JSAutoRealm> ar;
if (js::GetContextCompartment(aContext) !=
js::GetObjectCompartment(ownerGlobal->GetGlobalJSObject())) {
ac.emplace(aContext, ownerGlobal->GetGlobalJSObject());
ar.emplace(aContext, ownerGlobal->GetGlobalJSObject());
}

AnimationTimeline* timeline = referenceElement->OwnerDoc()->Timeline();
Expand Down
4 changes: 2 additions & 2 deletions dom/base/IntlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ IntlUtils::GetDisplayNames(const Sequence<nsString>& aLocales,
}

// Return the result as DisplayNameResult.
JSAutoCompartment ac(cx, &retVal.toObject());
JSAutoRealm ar(cx, &retVal.toObject());
if (!aResult.Init(cx, retVal)) {
aError.Throw(NS_ERROR_FAILURE);
}
Expand Down Expand Up @@ -135,7 +135,7 @@ IntlUtils::GetLocaleInfo(const Sequence<nsString>& aLocales,
}

// Return the result as LocaleInfo.
JSAutoCompartment ac(cx, &retVal.toObject());
JSAutoRealm ar(cx, &retVal.toObject());
if (!aResult.Init(cx, retVal)) {
aError.Throw(NS_ERROR_FAILURE);
}
Expand Down
2 changes: 1 addition & 1 deletion dom/base/PostMessageEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ PostMessageEvent::Run()
targetWindow->IsDying())
return NS_OK;

JSAutoCompartment ac(cx, targetWindow->GetWrapper());
JSAutoRealm ar(cx, targetWindow->GetWrapper());

// Ensure that any origin which might have been provided is the origin of this
// window's document. Note that we do this *now* instead of when postMessage
Expand Down
8 changes: 4 additions & 4 deletions dom/base/StructuredCloneBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ StructuredCloneBlob::Constructor(GlobalObject& aGlobal, JS::HandleValue aValue,

RefPtr<StructuredCloneBlob> holder = StructuredCloneBlob::Create();

Maybe<JSAutoCompartment> ac;
Maybe<JSAutoRealm> ar;
JS::RootedValue value(cx, aValue);

if (aTargetGlobal) {
Expand All @@ -49,7 +49,7 @@ StructuredCloneBlob::Constructor(GlobalObject& aGlobal, JS::HandleValue aValue,
return nullptr;
}

ac.emplace(cx, targetGlobal);
ar.emplace(cx, targetGlobal);

if (!JS_WrapValue(cx, &value)) {
aRv.NoteJSContextException(cx);
Expand All @@ -63,7 +63,7 @@ StructuredCloneBlob::Constructor(GlobalObject& aGlobal, JS::HandleValue aValue,
return nullptr;
}

ac.emplace(cx, obj);
ar.emplace(cx, obj);
value = JS::ObjectValue(*obj);
}

Expand All @@ -87,7 +87,7 @@ StructuredCloneBlob::Deserialize(JSContext* aCx, JS::HandleObject aTargetScope,
}

{
JSAutoCompartment ac(aCx, scope);
JSAutoRealm ar(aCx, scope);

Read(xpc::NativeGlobal(scope), aCx, aResult, aRv);
if (aRv.Failed()) {
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentPermissionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ nsContentPermissionRequestProxy::Allow(JS::HandleValue aChoices)

JSContext* cx = jsapi.cx();
JS::Rooted<JSObject*> obj(cx, &aChoices.toObject());
JSAutoCompartment ac(cx, obj);
JSAutoRealm ar(cx, obj);

JS::Rooted<JS::Value> val(cx);

Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ nsContentUtils::SubjectPrincipal()
JSCompartment *compartment = js::GetContextCompartment(cx);

// When an AutoJSAPI is instantiated, we are in a null compartment until the
// first JSAutoCompartment, which is kind of a purgatory as far as permissions
// first JSAutoRealm, which is kind of a purgatory as far as permissions
// go. It would be nice to just hard-abort if somebody does a security check
// in this purgatory zone, but that would be too fragile, since it could be
// triggered by random IsCallerChrome() checks 20-levels deep.
Expand Down Expand Up @@ -7071,7 +7071,7 @@ nsContentUtils::IsPatternMatching(nsAString& aValue, nsAString& aPattern,

// We can use the junk scope here, because we're just using it for
// regexp evaluation, not actual script execution.
JSAutoCompartment ac(cx, xpc::UnprivilegedJunkScope());
JSAutoRealm ar(cx, xpc::UnprivilegedJunkScope());

// The pattern has to match the entire value.
aPattern.InsertLiteral(u"^(?:", 0);
Expand Down
6 changes: 3 additions & 3 deletions dom/base/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,7 @@ nsDocument::IsShadowDOMEnabled(JSContext* aCx, JSObject* aObject)
{
JS::Rooted<JSObject*> obj(aCx, aObject);

JSAutoCompartment ac(aCx, obj);
JSAutoRealm ar(aCx, obj);
JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, obj));
nsCOMPtr<nsPIDOMWindowInner> window =
do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global));
Expand Down Expand Up @@ -7092,7 +7092,7 @@ nsIDocument::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv)
// It's kind of irrelevant, given that we're passing aAllowWrapping =
// false, and documents should always insist on being wrapped in an
// canonical scope. But we try to pass something sane anyway.
JSAutoCompartment ac(cx, GetScopeObject()->GetGlobalJSObject());
JSAutoRealm ar(cx, GetScopeObject()->GetGlobalJSObject());
JS::Rooted<JS::Value> v(cx);
rv = nsContentUtils::WrapNative(cx, this, this, &v,
/* aAllowWrapping = */ false);
Expand Down Expand Up @@ -9647,7 +9647,7 @@ nsIDocument::GetStateObject(nsIVariant** aState)
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
JS::Rooted<JSObject*> global(cx, sgo->GetGlobalJSObject());
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
JSAutoCompartment ac(cx, global);
JSAutoRealm ar(cx, global);

mStateObjectContainer->
DeserializeToVariant(cx, getter_AddRefs(mStateObjectCached));
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsFrameLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ nsFrameLoader::SetOwnerContent(Element* aContent)

JS::RootedObject wrapper(jsapi.cx(), GetWrapper());
if (wrapper) {
JSAutoCompartment ac(jsapi.cx(), wrapper);
JSAutoRealm ar(jsapi.cx(), wrapper);
IgnoredErrorResult rv;
ReparentWrapper(jsapi.cx(), wrapper, rv);
Unused << NS_WARN_IF(rv.Failed());
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,9 @@ nsFrameMessageManager::GetInitialProcessData(JSContext* aCx,
JS::RootedValue init(aCx, mInitialProcessData);
if (mChrome && init.isUndefined()) {
// We create the initial object in the junk scope. If we created it in a
// normal compartment, that compartment would leak until shutdown.
// normal realm, that realm would leak until shutdown.
JS::RootedObject global(aCx, xpc::PrivilegedJunkScope());
JSAutoCompartment ac(aCx, global);
JSAutoRealm ar(aCx, global);

JS::RootedObject obj(aCx, JS_NewPlainObject(aCx));
if (!obj) {
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4130,7 +4130,7 @@ nsGlobalWindowInner::CallerInnerWindow()
// sandboxPrototype. This used to work incidentally for unrelated reasons, but
// now we need to do some special handling to support it.
if (xpc::IsSandbox(scope)) {
JSAutoCompartment ac(cx, scope);
JSAutoRealm ar(cx, scope);
JS::Rooted<JSObject*> scopeProto(cx);
bool ok = JS_GetPrototype(cx, scope, &scopeProto);
NS_ENSURE_TRUE(ok, nullptr);
Expand Down
16 changes: 8 additions & 8 deletions dom/base/nsGlobalWindowOuter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ nsChromeOuterWindowProxy::singleton;
static JSObject*
NewOuterWindowProxy(JSContext *cx, JS::Handle<JSObject*> global, bool isChrome)
{
JSAutoCompartment ac(cx, global);
JSAutoRealm ar(cx, global);
MOZ_ASSERT(js::GetGlobalForObjectCrossCompartment(global) == global);

js::WrapperOptions options;
Expand Down Expand Up @@ -1535,7 +1535,7 @@ static const JSFunctionSpec EnablePrivilegeSpec[] = {
static bool
InitializeLegacyNetscapeObject(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
{
JSAutoCompartment ac(aCx, aGlobal);
JSAutoRealm ar(aCx, aGlobal);

// Note: MathJax depends on window.netscape being exposed. See bug 791526.
JS::Rooted<JSObject*> obj(aCx);
Expand Down Expand Up @@ -1872,8 +1872,8 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument,
mContext->SetWindowProxy(outerObject);
}

// Enter the new global's compartment.
JSAutoCompartment ac(cx, GetWrapperPreserveColor());
// Enter the new global's realm.
JSAutoRealm ar(cx, GetWrapperPreserveColor());

{
JS::Rooted<JSObject*> outer(cx, GetWrapperPreserveColor());
Expand Down Expand Up @@ -1905,7 +1905,7 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument,
}
}

JSAutoCompartment ac(cx, GetWrapperPreserveColor());
JSAutoRealm ar(cx, GetWrapperPreserveColor());

if (!aState && !reUseInnerWindow) {
// Loading a new page and creating a new inner window, *not*
Expand Down Expand Up @@ -3808,7 +3808,7 @@ nsGlobalWindowOuter::DispatchResizeEvent(const CSSIntSize& aSize)
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
JSAutoCompartment ac(cx, GetWrapperPreserveColor());
JSAutoRealm ar(cx, GetWrapperPreserveColor());

DOMWindowResizeEventDetail detail;
detail.mWidth = aSize.width;
Expand Down Expand Up @@ -5604,7 +5604,7 @@ nsGlobalWindowOuter::CallerInnerWindow()
// sandboxPrototype. This used to work incidentally for unrelated reasons, but
// now we need to do some special handling to support it.
if (xpc::IsSandbox(scope)) {
JSAutoCompartment ac(cx, scope);
JSAutoRealm ar(cx, scope);
JS::Rooted<JSObject*> scopeProto(cx);
bool ok = JS_GetPrototype(cx, scope, &scopeProto);
NS_ENSURE_TRUE(ok, nullptr);
Expand Down Expand Up @@ -7152,7 +7152,7 @@ nsGlobalWindowOuter::SecurityCheckURL(const char *aURL)
}
AutoJSContext cx;
nsGlobalWindowInner* sourceWin = nsGlobalWindowInner::Cast(sourceWindow);
JSAutoCompartment ac(cx, sourceWin->GetGlobalJSObject());
JSAutoRealm ar(cx, sourceWin->GetGlobalJSObject());

// Resolve the baseURI, which could be relative to the calling window.
//
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsINode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ CheckForOutdatedParent(nsINode* aParent, nsINode* aNode, ErrorResult& aError)

if (js::GetGlobalForObjectCrossCompartment(existingObj) !=
global->GetGlobalJSObject()) {
JSAutoCompartment ac(cx, existingObj);
JSAutoRealm ar(cx, existingObj);
ReparentWrapper(cx, existingObj, aError);
}
}
Expand Down
6 changes: 3 additions & 3 deletions dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports* aArgs,
NS_ASSERTION(prim == nullptr,
"Don't pass nsISupportsPrimitives - use nsIVariant!");
#endif
JSAutoCompartment ac(cx, aScope);
JSAutoRealm ar(cx, aScope);
rv = nsContentUtils::WrapNative(cx, arg, thisVal);
}
}
Expand Down Expand Up @@ -984,7 +984,7 @@ nsJSContext::AddSupportsPrimitiveTojsvals(nsISupports *aArg, JS::Value *aArgv)

JS::Rooted<JSObject*> scope(cx, GetWindowProxy());
JS::Rooted<JS::Value> v(cx);
JSAutoCompartment ac(cx, scope);
JSAutoRealm ar(cx, scope);
nsresult rv = nsContentUtils::WrapNative(cx, data, iid, &v);
NS_ENSURE_SUCCESS(rv, rv);

Expand Down Expand Up @@ -1119,7 +1119,7 @@ nsJSContext::InitClasses(JS::Handle<JSObject*> aGlobalObj)
AutoJSAPI jsapi;
jsapi.Init();
JSContext* cx = jsapi.cx();
JSAutoCompartment ac(cx, aGlobalObj);
JSAutoRealm ar(cx, aGlobalObj);

// Attempt to initialize profiling functions
::JS_DefineProfilingFunctions(cx, aGlobalObj);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsJSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ nsJSUtils::ExecutionContext::ExecutionContext(JSContext* aCx,
__LINE__, js::ProfileEntry::Category::JS),
#endif
mCx(aCx)
, mCompartment(aCx, aGlobal)
, mRealm(aCx, aGlobal)
, mRetValue(aCx)
, mScopeChain(aCx)
, mRv(NS_OK)
Expand Down
Loading

0 comments on commit 7d2b934

Please sign in to comment.