Bug 500691 - Call JS_ClearScope before XPConnect tries to update our outer window's scope's concept of what {Function,Object}.prototype are so that we forward correctly to the inner window's versions. r=jst sr=bzbarsky

This commit is contained in:
Blake Kaplan 2009-07-01 16:43:50 -07:00
Родитель 27bdebeec1
Коммит b2a9ae6b91
3 изменённых файлов: 44 добавлений и 8 удалений

Просмотреть файл

@ -2416,11 +2416,6 @@ nsJSContext::ConnectToInner(nsIScriptGlobalObject *aNewInner, void *aOuterGlobal
JSObject *newInnerJSObject = (JSObject *)aNewInner->GetScriptGlobal(JAVASCRIPT);
JSObject *myobject = (JSObject *)aOuterGlobal;
// Call ClearScope to nuke any properties (e.g. Function and Object) on the
// outer object. From now on, anybody asking the outer object for these
// properties will be forwarded to the inner window.
::JS_ClearScope(mContext, myobject);
// Make the inner and outer window both share the same
// prototype. The prototype we share is the outer window's
// prototype, this way XPConnect can still find the wrapper to
@ -2520,11 +2515,23 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
NS_ENSURE_SUCCESS(rv, rv);
}
} else {
// If there's already a global object in mContext we're called
// after ::JS_ClearScope() was called. We'll have to tell
// XPConnect to re-initialize the global object to do things like
// There's already a global object. We are preparing this outer window
// object for use as a real outer window (i.e. everything needs to live on
// the inner window).
// Call ClearScope to nuke any properties (e.g. Function and Object) on the
// outer object. From now on, anybody asking the outer object for these
// properties will be forwarded to the inner window.
::JS_ClearScope(mContext, global);
// Tell XPConnect to re-initialize the global object to do things like
// define the Components object on the global again and forget all
// old prototypes in this scope.
// XXX Except that now, the global is thawed and has an inner window. So
// anything that XPConnect does to our global will be forwarded. So I
// think the only thing that this does for real is to call SetGlobal on
// our XPCWrappedNativeScope. Perhaps XPConnect should have a more
// targeted API?
rv = xpc->InitClasses(mContext, global);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -57,6 +57,7 @@ _TEST_FILES = inner.html \
test_bug478438.html \
test_bug484107.html \
test_bug484459.html \
test_bug500691.html \
$(NULL)
libs:: $(_TEST_FILES)

Просмотреть файл

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=500691
-->
<head>
<title>Test for Bug 500691</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=500691">Mozilla Bug 500691</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 500691 **/
ok(Function === alert.constructor, "alert's constructor is our Function");
ok(window.Function === alert.constructor, "window.Function is also correct");
</script>
</pre>
</body>
</html>