diff --git a/js/src/xpconnect/src/xpcJSWeakReference.cpp b/js/src/xpconnect/src/xpcJSWeakReference.cpp index 7115f9c24e5e..d53cb5a561bc 100644 --- a/js/src/xpconnect/src/xpcJSWeakReference.cpp +++ b/js/src/xpconnect/src/xpcJSWeakReference.cpp @@ -97,29 +97,52 @@ NS_IMETHODIMP xpcJSWeakReference::Get() { nsresult rv; - + nsXPConnect* xpc = nsXPConnect::GetXPConnect(); - if (!xpc) return NS_ERROR_UNEXPECTED; - + if (!xpc) + return NS_ERROR_UNEXPECTED; + nsAXPCNativeCallContext* cc = nsnull; rv = xpc->GetCurrentNativeCallContext(&cc); NS_ENSURE_SUCCESS(rv, rv); + JSContext *cx; + cc->GetJSContext(&cx); + if (!cx) + return NS_ERROR_UNEXPECTED; + jsval *retval = nsnull; cc->GetRetValPtr(&retval); - if (!retval) return NS_ERROR_UNEXPECTED; + if (!retval) + return NS_ERROR_UNEXPECTED; *retval = JSVAL_NULL; - + nsCOMPtr wrappedObj; - + if (mWrappedJSObject && NS_SUCCEEDED(mWrappedJSObject->QueryReferent(NS_GET_IID(nsIXPConnectWrappedJS), getter_AddRefs(wrappedObj))) && wrappedObj) { JSObject *obj; wrappedObj->GetJSObject(&obj); if (obj) + { + // Most users of XPCWrappedJS don't need to worry about + // re-wrapping because things are implicitly rewrapped by + // xpcconvert. However, because we're doing this directly + // through the native call context, we need to call + // nsXPConnect::GetWrapperForObject. But it takes a lot of + // arguments! It turns out that the thisObject hook on XPConnect + // objects does the right thing though, so... + + if (obj->map->ops->thisObject && + !(obj = obj->map->ops->thisObject(cx, obj))) + { + return NS_ERROR_FAILURE; + } + *retval = OBJECT_TO_JSVAL(obj); + } } - + return NS_OK; } diff --git a/js/src/xpconnect/tests/Makefile.in b/js/src/xpconnect/tests/Makefile.in index 66289bda210e..8099956970e4 100644 --- a/js/src/xpconnect/tests/Makefile.in +++ b/js/src/xpconnect/tests/Makefile.in @@ -53,7 +53,7 @@ REQUIRES = xpconnect \ xpconnect_tests \ $(NULL) -DIRS = idl mochitest +DIRS = idl mochitest chrome ifndef MOZ_ENABLE_LIBXUL DIRS += components diff --git a/js/src/xpconnect/tests/chrome/Makefile.in b/js/src/xpconnect/tests/chrome/Makefile.in new file mode 100644 index 000000000000..6ca468c20c28 --- /dev/null +++ b/js/src/xpconnect/tests/chrome/Makefile.in @@ -0,0 +1,51 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is +# Mozilla Foundation. +# Portions created by the Initial Developer are Copyright (C) 2008 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = js/src/xpconnect/tests/chrome + +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/rules.mk + +_CHROME_FILES = \ + test_bug500931.xul \ + $(NULL) + +libs:: $(_CHROME_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir) diff --git a/js/src/xpconnect/tests/chrome/test_bug500931.xul b/js/src/xpconnect/tests/chrome/test_bug500931.xul new file mode 100644 index 000000000000..e2ff2cb6612d --- /dev/null +++ b/js/src/xpconnect/tests/chrome/test_bug500931.xul @@ -0,0 +1,43 @@ + + + + + + + + + + + Mozilla Bug 500931 + + + + + + diff --git a/js/src/xpconnect/tests/mochitest/Makefile.in b/js/src/xpconnect/tests/mochitest/Makefile.in index 592abef07ca1..8f2c18f5213d 100644 --- a/js/src/xpconnect/tests/mochitest/Makefile.in +++ b/js/src/xpconnect/tests/mochitest/Makefile.in @@ -44,7 +44,8 @@ relativesrcdir = js/src/xpconnect/tests/mochitest include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk -_TEST_FILES = inner.html \ +_TEST_FILES = bug500931_helper.html \ + inner.html \ test_bug361111.xul \ test_bug390488.html \ test_bug393269.html \ diff --git a/js/src/xpconnect/tests/mochitest/bug500931_helper.html b/js/src/xpconnect/tests/mochitest/bug500931_helper.html new file mode 100644 index 000000000000..df5a02f4daaa --- /dev/null +++ b/js/src/xpconnect/tests/mochitest/bug500931_helper.html @@ -0,0 +1,7 @@ + + + Inner frame for bug 500931 mochitest + + + +