Bug 484459. Give SandboxClass a convert method so it doesn't end up delegating that to the prototype. r+sr=mrbkap
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 03 Jun 2009 18:49:53 -0400
changeset 28927 206ce59bf935f87a457363d7619f090576e0930b
parent 28926 054daaef53c938aff9fa7208f514495c51a6c6dd
child 28928 ad31c4f614079cb4cf31f922774db67411b47a43
push id7331
push userbzbarsky@mozilla.com
push dateWed, 03 Jun 2009 22:50:51 +0000
treeherderautoland@206ce59bf935 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs484459
milestone1.9.2a1pre
Bug 484459. Give SandboxClass a convert method so it doesn't end up delegating that to the prototype. r+sr=mrbkap
js/src/xpconnect/src/xpccomponents.cpp
js/src/xpconnect/tests/mochitest/Makefile.in
js/src/xpconnect/tests/mochitest/test_bug484459.html
--- a/js/src/xpconnect/src/xpccomponents.cpp
+++ b/js/src/xpconnect/src/xpccomponents.cpp
@@ -3133,21 +3133,32 @@ sandbox_resolve(JSContext *cx, JSObject 
 static void
 sandbox_finalize(JSContext *cx, JSObject *obj)
 {
     nsIScriptObjectPrincipal *sop =
         (nsIScriptObjectPrincipal *)xpc_GetJSPrivate(obj);
     NS_IF_RELEASE(sop);
 }
 
+static JSBool
+sandbox_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
+{
+    if (type == JSTYPE_OBJECT) {
+        *vp = OBJECT_TO_JSVAL(obj);
+        return JS_TRUE;
+    }
+
+    return JS_ConvertStub(cx, obj, type, vp);
+}
+
 static JSClass SandboxClass = {
     "Sandbox",
     JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS | JSCLASS_GLOBAL_FLAGS,
     JS_PropertyStub,   JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
-    sandbox_enumerate, sandbox_resolve, JS_ConvertStub,  sandbox_finalize,
+    sandbox_enumerate, sandbox_resolve, sandbox_convert,  sandbox_finalize,
     JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
 static JSFunctionSpec SandboxFunctions[] = {
     {"dump",    SandboxDump,    1,0,0},
     {"debug",   SandboxDebug,   1,0,0},
     {"importFunction", SandboxImport, 1,0,0},
     {nsnull,nsnull,0,0,0}
--- a/js/src/xpconnect/tests/mochitest/Makefile.in
+++ b/js/src/xpconnect/tests/mochitest/Makefile.in
@@ -51,12 +51,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug396851.html \
 		test_bug428021.html \
 		test_bug448587.html \
 		test_wrappers.html \
 		test_bug446584.html \
 		test_bug462428.html \
 		test_bug478438.html \
 		test_bug484107.html \
+		test_bug484459.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/js/src/xpconnect/tests/mochitest/test_bug484459.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=484459
+-->
+<head>
+  <title>Test for Bug 484459</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=484459">Mozilla Bug 484459</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 484459 **/
+var x = 3;
+var w = new XPCSafeJSObjectWrapper(window);
+netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+var sandbox = new Components.utils.Sandbox(w);
+sandbox.__proto__ = w;
+is(Components.utils.evalInSandbox("x * 4", sandbox), 12,
+   "Unexpected return from the sandbox");
+
+
+
+
+</script>
+</pre>
+</body>
+</html>