Bug 871887 - Fix marquee _setEventListener. r=bz, a=akeybl
authorBobby Holley <bobbyholley@gmail.com>
Wed, 15 May 2013 18:59:53 -0700
changeset 142697 d9a77ea591250f197e499f72fdb7c20bda8b38b4
parent 142696 c43520eb66d0c3467b8fcbada030d218294502d1
child 142698 b31b08960f75f0d517260026236d3211282a975a
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, akeybl
bugs871887
milestone23.0a2
Bug 871887 - Fix marquee _setEventListener. r=bz, a=akeybl
js/xpconnect/tests/mochitest/Makefile.in
js/xpconnect/tests/mochitest/test_bug871887.html
layout/style/xbl-marquee/xbl-marquee.xml
--- a/js/xpconnect/tests/mochitest/Makefile.in
+++ b/js/xpconnect/tests/mochitest/Makefile.in
@@ -89,16 +89,17 @@ MOCHITEST_FILES =	chrome_wrappers_helper
 		test_bug800864.html \
 		test_bug802557.html \
 		file_bug802557.html \
 		test_bug803730.html \
 		test_bug809547.html \
 		test_bug809674.html \
 		test_bug829872.html \
 		test_bug865260.html \
+		test_bug871887.html \
 		file_crosscompartment_weakmap.html \
 		test_crosscompartment_weakmap.html \
 		test_asmjs.html \
 		file_asmjs.js \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/mochitest/test_bug871887.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=871887
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 871887</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript;version=1.7">
+
+  /** Test for Bug 871887 **/
+  SimpleTest.waitForExplicitFinish();
+
+  // NB: onstart ends up getting invoked twice, for mysterious and potentially-
+  // IE6-related reasons.
+  function checkpoint(invocant) {
+    ok(true, "onstart called");
+    is(invocant, $('llama'), "this-binding is correct");
+    $('llama').loop = 1;
+    $('llama').scrollDelay = 1;
+    $('llama').scrollAmount = 500;
+  }
+
+  function done(invocant) {
+    is(invocant, $('llama'), "this-binding is correct");
+    ok(true, "onfinish called");
+    SimpleTest.finish();
+  }
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=871887">Mozilla Bug 871887</a>
+<p id="display"></p>
+<div id="content">
+<marquee id="llama" onstart="checkpoint(this);" onfinish="done(this);">Watch the Llama</marquee>
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
--- a/layout/style/xbl-marquee/xbl-marquee.xml
+++ b/layout/style/xbl-marquee/xbl-marquee.xml
@@ -254,17 +254,23 @@
             case "function":
               this["_on" + aName] = aValue;
               this.addEventListener(aName, this["_on" + aName], false);
             break;
 
             case "string":
               if (!aIgnoreNextCall) {
                 try {
-                  this["_on" + aName] = new XPCNativeWrapper.unwrap(window).Function("event", aValue);
+                  // Work around bug 872772 by wrapping the cross-compartment-
+                  // wrapped function in a function from this scope.
+                  //
+                  // NB: Make sure to wrap the constructor in parentheses to
+                  // deal with the weird precedence of |new| in JS.
+                  var contentFn = new (XPCNativeWrapper.unwrap(window).Function)("event", aValue);
+                  this["_on" + aName] = function(e) { return contentFn.call(this, e); };
                 }
                 catch(e) {
                   return false;
                 }
                 this.addEventListener(aName, this["_on" + aName], false);
               }
               else {
                 this["_on" + aName] = aValue;