test_bug484107.html (3160B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=484107 5 --> 6 <head> 7 <title>Test for Bug 484107</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484107">Mozilla Bug 484107</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <pre id="test"> 18 <script type="application/javascript"> 19 20 /** Test for Bug 484107 **/ 21 22 var text = "first group", 23 xpcWin = new XPCSafeJSObjectWrapper(window); 24 function get$1() { return RegExp.$1 }; 25 26 function reset() { 27 var match = /(.*)/.exec(text); 28 if (!reset.skipStupidTests) { 29 reset.skipStupidTests = true; 30 ok(match, "No match?"); 31 is(match[1], text, "Bad match?"); 32 is(text, RegExp.$1, "RegExp.$1 missing?"); 33 is(text, get$1(), "RegExp.$1 inaccessible?"); 34 } 35 } 36 37 function test_XPC_SJOW_Call() { 38 isnot(text, xpcWin.get$1(), "Able to see RegExp.$1 from wrapped method."); 39 is("", xpcWin.get$1(), "Saw something other than an empty string for " + 40 "RegExp.$1 from wrapped method."); 41 is(text, window.get$1(), "Unable to see RegExp.$1 from non-wrapped method."); 42 } 43 44 function test_XPC_SJOW_Call_foreign_obj() { 45 var obj = { 46 xpcGet: xpcWin.get$1, 47 rawGet: window.get$1 48 }; 49 isnot(text, obj.xpcGet(), "obj.xpcGet() returned matched text."); 50 is("", obj.xpcGet(), "obj.xpcGet() returned something other than the empty string."); 51 is(text, obj.rawGet(), "obj.rawGet() did not return matched text."); 52 } 53 54 function test_XPC_SJOW_toString() { 55 var str = new XPCSafeJSObjectWrapper({ 56 toString: function() { return RegExp.$1 } 57 }) + ""; 58 isnot(text, str, "toString() returned the matched text."); 59 is("", str, "toString() returned something other than the empty string."); 60 } 61 62 function test_XPC_SJOW_GetOrSetProperty() { 63 window.__defineGetter__("firstMatch", function() { return RegExp.$1 }); 64 isnot(text, xpcWin.firstMatch, "Getter xpcWin.firstMatch returned matched text."); 65 is("", xpcWin.firstMatch, 66 "Getter xpcWin.firstMatch returned something other than the empty string."); 67 is(text, window.firstMatch, "Getter window.firstMatch did not return matched text."); 68 } 69 70 function test_XPC_SJOW_Create() { 71 function ctor() { 72 this.match = RegExp.$1; 73 return this; // XXX Why is this necessary? 74 } 75 ctor.prototype.getMatch = function() { return this.match }; 76 var xpcCtor = new XPCSafeJSObjectWrapper(ctor), 77 match = (new xpcCtor).getMatch(); 78 isnot(text, match, "(new xpcCtor).getMatch() was the matched text."); 79 is("", match, "(new xpcCtor).getMatch() was not the empty string."); 80 } 81 82 var tests = [ 83 test_XPC_SJOW_Call, 84 test_XPC_SJOW_Call_foreign_obj, 85 test_XPC_SJOW_toString, 86 test_XPC_SJOW_GetOrSetProperty, 87 test_XPC_SJOW_Create 88 ]; 89 90 for (var i = 0; i < tests.length; i++) { 91 reset(); 92 tests[i](); 93 is(text, RegExp.$1, "RegExp.$1 was clobbered."); 94 } 95 96 </script> 97 </pre> 98 </body> 99 </html>