test_bug484107.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 type="application/javascript" 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. </div>
  16. <pre id="test">
  17. <script type="application/javascript">
  18. /** Test for Bug 484107 **/
  19. var text = "first group",
  20. xpcWin = new XPCSafeJSObjectWrapper(window);
  21. function get$1() { return RegExp.$1 };
  22. function reset() {
  23. var match = /(.*)/.exec(text);
  24. if (!reset.skipStupidTests) {
  25. reset.skipStupidTests = true;
  26. ok(match, "No match?");
  27. is(match[1], text, "Bad match?");
  28. is(text, RegExp.$1, "RegExp.$1 missing?");
  29. is(text, get$1(), "RegExp.$1 inaccessible?");
  30. }
  31. }
  32. function test_XPC_SJOW_Call() {
  33. isnot(text, xpcWin.get$1(), "Able to see RegExp.$1 from wrapped method.");
  34. is("", xpcWin.get$1(), "Saw something other than an empty string for " +
  35. "RegExp.$1 from wrapped method.");
  36. is(text, window.get$1(), "Unable to see RegExp.$1 from non-wrapped method.");
  37. }
  38. function test_XPC_SJOW_Call_foreign_obj() {
  39. var obj = {
  40. xpcGet: xpcWin.get$1,
  41. rawGet: window.get$1
  42. };
  43. isnot(text, obj.xpcGet(), "obj.xpcGet() returned matched text.");
  44. is("", obj.xpcGet(), "obj.xpcGet() returned something other than the empty string.");
  45. is(text, obj.rawGet(), "obj.rawGet() did not return matched text.");
  46. }
  47. function test_XPC_SJOW_toString() {
  48. var str = new XPCSafeJSObjectWrapper({
  49. toString: function() { return RegExp.$1 }
  50. }) + "";
  51. isnot(text, str, "toString() returned the matched text.");
  52. is("", str, "toString() returned something other than the empty string.");
  53. }
  54. function test_XPC_SJOW_GetOrSetProperty() {
  55. window.__defineGetter__("firstMatch", function() { return RegExp.$1 });
  56. isnot(text, xpcWin.firstMatch, "Getter xpcWin.firstMatch returned matched text.");
  57. is("", xpcWin.firstMatch,
  58. "Getter xpcWin.firstMatch returned something other than the empty string.");
  59. is(text, window.firstMatch, "Getter window.firstMatch did not return matched text.");
  60. }
  61. function test_XPC_SJOW_Create() {
  62. function ctor() {
  63. this.match = RegExp.$1;
  64. return this; // XXX Why is this necessary?
  65. }
  66. ctor.prototype.getMatch = function() { return this.match };
  67. var xpcCtor = new XPCSafeJSObjectWrapper(ctor),
  68. match = (new xpcCtor).getMatch();
  69. isnot(text, match, "(new xpcCtor).getMatch() was the matched text.");
  70. is("", match, "(new xpcCtor).getMatch() was not the empty string.");
  71. }
  72. var tests = [
  73. test_XPC_SJOW_Call,
  74. test_XPC_SJOW_Call_foreign_obj,
  75. test_XPC_SJOW_toString,
  76. test_XPC_SJOW_GetOrSetProperty,
  77. test_XPC_SJOW_Create
  78. ];
  79. for (var i = 0; i < tests.length; i++) {
  80. reset();
  81. tests[i]();
  82. is(text, RegExp.$1, "RegExp.$1 was clobbered.");
  83. }
  84. </script>
  85. </pre>
  86. </body>
  87. </html>