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

Commit acac520

Browse files
committed
Bug 865260 - Use IsXrayWrapper rather than ObjectIsNativeWrapper in nsWindowSH. r=bz
There are some other uses of ObjectIsNativeWrapper in other scriptable helpers that are tempting to remove as well, but it's probably just better to wait for that stuff to just go away. Given that the issue we're running into here is Window-specific, there's not a pressing need to fix the other stuff.
1 parent 2c84e2d commit acac520

3 files changed

Lines changed: 48 additions & 27 deletions

File tree

dom/base/nsDOMClassInfo.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ NS_IMETHODIMP
34073407
nsWindowSH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
34083408
JSObject *obj, bool *_retval)
34093409
{
3410-
if (!ObjectIsNativeWrapper(cx, obj)) {
3410+
if (!xpc::WrapperFactory::IsXrayWrapper(obj)) {
34113411
*_retval = JS_EnumerateStandardClasses(cx, obj);
34123412
if (!*_retval) {
34133413
return NS_OK;
@@ -4505,7 +4505,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
45054505

45064506
Maybe<JSAutoCompartment> ac;
45074507
JSObject* global;
4508-
bool defineOnXray = ObjectIsNativeWrapper(cx, obj);
4508+
bool defineOnXray = xpc::WrapperFactory::IsXrayWrapper(obj);
45094509
if (defineOnXray) {
45104510
global = js::CheckedUnwrap(obj, /* stopAtOuter = */ false);
45114511
if (!global) {
@@ -4939,37 +4939,24 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
49394939

49404940
nsIScriptContext *my_context = win->GetContextInternal();
49414941

4942-
// Resolve standard classes on my_context's JSContext (or on cx,
4943-
// if we don't have a my_context yet), in case the two contexts
4944-
// have different origins. We want lazy standard class
4945-
// initialization to behave as if it were done eagerly, on each
4946-
// window's own context (not on some other window-caller's
4947-
// context).
4948-
if (!ObjectIsNativeWrapper(cx, obj)) {
4942+
// Don't resolve standard classes on XrayWrappers, only resolve them if we're
4943+
// resolving on the real global object.
4944+
if (!xpc::WrapperFactory::IsXrayWrapper(obj)) {
49494945
JSBool did_resolve = JS_FALSE;
49504946
JSBool ok = JS_TRUE;
49514947
JS::Value exn = JSVAL_VOID;
49524948

49534949
{
4954-
nsCxPusher pusher;
4955-
Maybe<JSAutoCompartment> ac;
4956-
4957-
JSContext* my_cx;
4958-
if (!my_context) {
4959-
my_cx = cx;
4960-
} else {
4961-
my_cx = my_context->GetNativeContext();
4962-
4963-
if (my_cx != cx) {
4964-
pusher.Push(my_cx);
4965-
ac.construct(my_cx, obj);
4966-
}
4967-
}
4968-
4969-
JSAutoRequest transfer(my_cx);
4950+
// Resolve standard classes on my_context's JSContext (or on cx,
4951+
// if we don't have a my_context yet), in case the two contexts
4952+
// have different origins. We want lazy standard class
4953+
// initialization to behave as if it were done eagerly, on each
4954+
// window's own context (not on some other window-caller's
4955+
// context).
4956+
AutoPushJSContext my_cx(my_context ? my_context->GetNativeContext() : cx);
4957+
JSAutoRequest ar(my_cx);
4958+
JSAutoCompartment ac(my_cx, obj);
49704959

4971-
// Don't resolve standard classes on XPCNativeWrapper etc, only
4972-
// resolve them if we're resolving on the real global object.
49734960
ok = JS_ResolveStandardClass(my_cx, obj, id, &did_resolve);
49744961

49754962
if (!ok) {

js/xpconnect/tests/mochitest/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ MOCHITEST_FILES = chrome_wrappers_helper.html \
9292
test_bug803730.html \
9393
test_bug809547.html \
9494
test_bug809674.html \
95+
test_bug865260.html \
9596
file_crosscompartment_weakmap.html \
9697
test_crosscompartment_weakmap.html \
9798
$(NULL)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<!--
4+
https://bugzilla.mozilla.org/show_bug.cgi?id=865260
5+
-->
6+
<head>
7+
<meta charset="utf-8">
8+
<title>Test for Bug 865260</title>
9+
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10+
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11+
<script type="application/javascript">
12+
13+
/** Test for Bug 865260 **/
14+
SimpleTest.waitForExplicitFinish();
15+
function go() {
16+
var exn = "nothrow";
17+
try { $('ifr').contentWindow['Date']; } catch (e) { exn = e; };
18+
ok(!!/denied/.exec(exn), "Threw instead of crashing");
19+
SimpleTest.finish();
20+
}
21+
22+
</script>
23+
</head>
24+
<body>
25+
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=865260">Mozilla Bug 865260</a>
26+
<p id="display"></p>
27+
<div id="content">
28+
<iframe id="ifr" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>
29+
</div>
30+
<pre id="test">
31+
</pre>
32+
</body>
33+
</html>

0 commit comments

Comments
 (0)