Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit a38774d

Browse files
committed
Bug 854503 - Rename JS unwrapping functions. r=bholley
1 parent 046c5d0 commit a38774d

45 files changed

Lines changed: 135 additions & 136 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

content/base/src/nsObjectLoadingContent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3087,7 +3087,7 @@ nsObjectLoadingContent::TeardownProtoChain()
30873087
}
30883088
// Unwrap while checking the jsclass - if the prototype is a wrapper for
30893089
// an NP object, that counts too.
3090-
if (JS_GetClass(js::UnwrapObject(proto)) == &sNPObjectJSWrapperClass) {
3090+
if (JS_GetClass(js::UncheckedUnwrap(proto)) == &sNPObjectJSWrapperClass) {
30913091
// We found an NPObject on the proto chain, get its prototype...
30923092
if (!::JS_GetPrototype(cx, proto, &proto)) {
30933093
return;

content/xbl/src/nsXBLProtoImplField.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ InstallXBLField(JSContext* cx,
183183

184184
// If a separate XBL scope is being used, the callee is not same-compartment
185185
// with the xbl prototype, and the object is a cross-compartment wrapper.
186-
xblProto = js::UnwrapObject(xblProto);
186+
xblProto = js::UncheckedUnwrap(xblProto);
187187
JSAutoCompartment ac2(cx, xblProto);
188188
JS::Value slotVal = ::JS_GetReservedSlot(xblProto, 0);
189189
protoBinding = static_cast<nsXBLPrototypeBinding*>(slotVal.toPrivate());
@@ -230,7 +230,7 @@ FieldGetterImpl(JSContext *cx, JS::CallArgs args)
230230
// wrapper. In this case, we know we want to do an unsafe unwrap, and
231231
// InstallXBLField knows how to handle cross-compartment pointers.
232232
bool installed = false;
233-
JS::Rooted<JSObject*> callee(cx, js::UnwrapObject(&args.calleev().toObject()));
233+
JS::Rooted<JSObject*> callee(cx, js::UncheckedUnwrap(&args.calleev().toObject()));
234234
JS::Rooted<jsid> id(cx);
235235
if (!InstallXBLField(cx, callee, thisObj, &id, &installed)) {
236236
return false;
@@ -299,7 +299,7 @@ FieldSetterImpl(JSContext *cx, JS::CallArgs args)
299299
// wrapper. In this case, we know we want to do an unsafe unwrap, and
300300
// InstallXBLField knows how to handle cross-compartment pointers.
301301
bool installed = false;
302-
JS::Rooted<JSObject*> callee(cx, js::UnwrapObject(&args.calleev().toObject()));
302+
JS::Rooted<JSObject*> callee(cx, js::UncheckedUnwrap(&args.calleev().toObject()));
303303
JS::Rooted<jsid> id(cx);
304304
if (!InstallXBLField(cx, callee, thisObj, &id, &installed)) {
305305
return false;

dom/base/nsDOMClassInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,7 +4169,7 @@ nsDOMConstructor::HasInstance(nsIXPConnectWrappedNative *wrapper,
41694169
NS_ASSERTION(dom_obj, "nsDOMConstructor::HasInstance couldn't get object");
41704170

41714171
// This might not be the right object, if there are wrappers. Unwrap if we can.
4172-
JSObject *wrapped_obj = js::UnwrapObjectChecked(dom_obj, /* stopAtOuter = */ false);
4172+
JSObject *wrapped_obj = js::CheckedUnwrap(dom_obj, /* stopAtOuter = */ false);
41734173
if (wrapped_obj)
41744174
dom_obj = wrapped_obj;
41754175

@@ -4684,7 +4684,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
46844684
JSObject* global;
46854685
bool defineOnXray = ObjectIsNativeWrapper(cx, obj);
46864686
if (defineOnXray) {
4687-
global = js::UnwrapObjectChecked(obj, /* stopAtOuter = */ false);
4687+
global = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
46884688
if (!global) {
46894689
return NS_ERROR_DOM_SECURITY_ERR;
46904690
}
@@ -4932,7 +4932,7 @@ static nsresult
49324932
LocationSetterGuts(JSContext *cx, JSObject *obj, jsval *vp)
49334933
{
49344934
// This function duplicates some of the logic in XPC_WN_HelperSetProperty
4935-
obj = js::UnwrapObjectChecked(obj, /* stopAtOuter = */ false);
4935+
obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
49364936
if (!IS_WN_WRAPPER(obj))
49374937
return NS_ERROR_XPC_BAD_CONVERT_JS;
49384938
XPCWrappedNative *wrapper = XPCWrappedNative::Get(obj);

dom/base/nsGlobalWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6540,7 +6540,7 @@ nsGlobalWindow::CallerInnerWindow()
65406540
bool ok = JS_GetPrototype(cx, scope, &scopeProto);
65416541
NS_ENSURE_TRUE(ok, nullptr);
65426542
if (scopeProto && xpc::IsSandboxPrototypeProxy(scopeProto) &&
6543-
(scopeProto = js::UnwrapObjectChecked(scopeProto, /* stopAtOuter = */ false)))
6543+
(scopeProto = js::CheckedUnwrap(scopeProto, /* stopAtOuter = */ false)))
65446544
{
65456545
scope = scopeProto;
65466546
}

dom/bindings/BindingUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
671671
// Get the object. It might be a security wrapper, in which case we do a checked
672672
// unwrap.
673673
JSObject* origObj = JSVAL_TO_OBJECT(thisv);
674-
JSObject* obj = js::UnwrapObjectChecked(origObj);
674+
JSObject* obj = js::CheckedUnwrap(origObj);
675675
if (!obj) {
676676
JS_ReportError(cx, "Permission denied to access object");
677677
return false;
@@ -1249,7 +1249,7 @@ HasPropertyOnPrototype(JSContext* cx, JSObject* proxy, DOMProxyHandler* handler,
12491249
{
12501250
Maybe<JSAutoCompartment> ac;
12511251
if (xpc::WrapperFactory::IsXrayWrapper(proxy)) {
1252-
proxy = js::UnwrapObject(proxy);
1252+
proxy = js::UncheckedUnwrap(proxy);
12531253
ac.construct(cx, proxy);
12541254
}
12551255
MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
@@ -1592,7 +1592,7 @@ GetGlobalObject(JSContext* aCx, JSObject* aObject,
15921592
Maybe<JSAutoCompartment>& aAutoCompartment)
15931593
{
15941594
if (js::IsWrapper(aObject)) {
1595-
aObject = js::UnwrapObjectChecked(aObject, /* stopAtOuter = */ false);
1595+
aObject = js::CheckedUnwrap(aObject, /* stopAtOuter = */ false);
15961596
if (!aObject) {
15971597
Throw<mainThread>(aCx, NS_ERROR_XPC_SECURITY_MANAGER_VETO);
15981598
return nullptr;
@@ -1641,7 +1641,7 @@ InterfaceHasInstance(JSContext* cx, JSHandleObject obj, JSObject* instance,
16411641
const DOMIfaceAndProtoJSClass* clasp =
16421642
DOMIfaceAndProtoJSClass::FromJSClass(js::GetObjectClass(obj));
16431643

1644-
const DOMClass* domClass = GetDOMClass(js::UnwrapObject(instance));
1644+
const DOMClass* domClass = GetDOMClass(js::UncheckedUnwrap(instance));
16451645

16461646
MOZ_ASSERT(!domClass || clasp->mPrototypeID != prototypes::id::_ID_Count,
16471647
"Why do we have a hasInstance hook if we don't have a prototype "

dom/bindings/BindingUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ UnwrapObject(JSContext* cx, JSObject* obj, U& value)
160160
return NS_ERROR_XPC_BAD_CONVERT_JS;
161161
}
162162

163-
obj = js::UnwrapObjectChecked(obj, /* stopAtOuter = */ false);
163+
obj = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
164164
if (!obj) {
165165
return NS_ERROR_XPC_SECURITY_MANAGER_VETO;
166166
}
@@ -621,7 +621,7 @@ WrapNewBindingNonWrapperCachedObject(JSContext* cx, JSObject* scope, T* value,
621621
// before we call JS_WrapValue.
622622
Maybe<JSAutoCompartment> ac;
623623
if (js::IsWrapper(scope)) {
624-
scope = js::UnwrapObjectChecked(scope, /* stopAtOuter = */ false);
624+
scope = js::CheckedUnwrap(scope, /* stopAtOuter = */ false);
625625
if (!scope)
626626
return false;
627627
ac.construct(cx, scope);

dom/bindings/CallbackObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CallbackObject::CallSetup::CallSetup(JSObject* const aCallback,
5050
// callable.
5151

5252
// First, find the real underlying callback.
53-
JSObject* realCallback = js::UnwrapObject(aCallback);
53+
JSObject* realCallback = js::UncheckedUnwrap(aCallback);
5454

5555
// Now get the nsIScriptGlobalObject for this callback.
5656
JSContext* cx = nullptr;
@@ -106,7 +106,7 @@ CallbackObject::CallSetup::CallSetup(JSObject* const aCallback,
106106
// Make sure to unwrap aCallback before passing it in, because
107107
// getting principals from wrappers is silly.
108108
nsresult rv = nsContentUtils::GetSecurityManager()->
109-
CheckFunctionAccess(cx, js::UnwrapObject(aCallback), nullptr);
109+
CheckFunctionAccess(cx, js::UncheckedUnwrap(aCallback), nullptr);
110110

111111
// Construct a termination func holder even if we're not planning to
112112
// run any script. We need this because we're going to call

dom/bindings/CallbackObject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CallbackObject : public nsISupports
5454
// If aOwner is not null, enter the compartment of aOwner's
5555
// underlying object.
5656
if (aOwner) {
57-
aOwner = js::UnwrapObject(aOwner);
57+
aOwner = js::UncheckedUnwrap(aOwner);
5858
JSAutoCompartment ac(cx, aOwner);
5959
if (!JS_WrapObject(cx, &aCallback)) {
6060
*aInited = false;
@@ -282,9 +282,9 @@ class CallbackObjectHolder : CallbackObjectHolderBase
282282
}
283283

284284
JSObject* thisObj =
285-
js::UnwrapObject(GetWebIDLCallback()->CallbackPreserveColor());
285+
js::UncheckedUnwrap(GetWebIDLCallback()->CallbackPreserveColor());
286286
JSObject* otherObj =
287-
js::UnwrapObject(aOtherCallback->CallbackPreserveColor());
287+
js::UncheckedUnwrap(aOtherCallback->CallbackPreserveColor());
288288
return thisObj == otherObj;
289289
}
290290

dom/bindings/Codegen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,14 +1111,14 @@ def generate_code(self):
11111111
// FIXME Limit this to chrome by checking xpc::AccessCheck::isChrome(obj).
11121112
nsISupports* native =
11131113
nsContentUtils::XPConnect()->GetNativeOfWrapper(cx,
1114-
js::UnwrapObject(instance));
1114+
js::UncheckedUnwrap(instance));
11151115
nsCOMPtr<nsIDOM%s> qiResult = do_QueryInterface(native);
11161116
*bp = !!qiResult;
11171117
return true;
11181118
""" % self.descriptor.interface.identifier.name
11191119

11201120
hasInstanceCode = """
1121-
const DOMClass* domClass = GetDOMClass(js::UnwrapObject(instance));
1121+
const DOMClass* domClass = GetDOMClass(js::UncheckedUnwrap(instance));
11221122
*bp = false;
11231123
if (!domClass) {
11241124
// Not a DOM object, so certainly not an instance of this interface
@@ -6090,7 +6090,7 @@ def definition_body(self):
60906090
return """ MOZ_ASSERT(js::IsProxy(obj));
60916091
if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
60926092
MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
6093-
obj = js::UnwrapObject(obj);
6093+
obj = js::UncheckedUnwrap(obj);
60946094
}
60956095
MOZ_ASSERT(IsProxy(obj));
60966096
return static_cast<%s*>(js::GetProxyPrivate(obj).toPrivate());""" % (self.descriptor.nativeType)

dom/plugins/base/nsJSNPRuntime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ JSValToNPVariant(NPP npp, JSContext *cx, JS::Value val, NPVariant *variant)
465465
// legitimate cases where a security wrapper ends up here (for example,
466466
// Location objects, which are _always_ behind security wrappers).
467467
JSObject *obj = JSVAL_TO_OBJECT(val);
468-
obj = js::UnwrapObjectChecked(obj);
468+
obj = js::CheckedUnwrap(obj);
469469
if (!obj) {
470470
obj = JSVAL_TO_OBJECT(val);
471471
}
@@ -1127,7 +1127,7 @@ nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JSObject *obj)
11271127
static JSObject *
11281128
GetNPObjectWrapper(JSContext *cx, JSObject *obj, bool wrapResult = true)
11291129
{
1130-
while (obj && (obj = js::UnwrapObjectChecked(obj))) {
1130+
while (obj && (obj = js::CheckedUnwrap(obj))) {
11311131
if (JS_GetClass(obj) == &sNPObjectJSWrapperClass) {
11321132
if (wrapResult && !JS_WrapObject(cx, &obj)) {
11331133
return NULL;

0 commit comments

Comments
 (0)