test_object_actor.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf8">
  5. <title>Test for the object actor</title>
  6. <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  7. <script type="text/javascript;version=1.8" src="common.js"></script>
  8. <!-- Any copyright is dedicated to the Public Domain.
  9. - http://creativecommons.org/publicdomain/zero/1.0/ -->
  10. </head>
  11. <body>
  12. <p>Test for the object actor</p>
  13. <script class="testbody" type="text/javascript;version=1.8">
  14. SimpleTest.waitForExplicitFinish();
  15. let expectedProps = [];
  16. function startTest()
  17. {
  18. removeEventListener("load", startTest);
  19. attachConsoleToTab(["ConsoleAPI"], onAttach);
  20. }
  21. function onAttach(aState, aResponse)
  22. {
  23. onConsoleCall = onConsoleCall.bind(null, aState);
  24. aState.dbgClient.addListener("consoleAPICall", onConsoleCall);
  25. let longString = (new Array(DebuggerServer.LONG_STRING_LENGTH + 3)).join("\u0629");
  26. // Here we put the objects in the correct window, to avoid having them all
  27. // wrapped by proxies for cross-compartment access.
  28. let foobarObject = top.Object.create(null);
  29. foobarObject.tamarbuta = longString;
  30. foobarObject.foo = 1;
  31. foobarObject.foobar = "hello";
  32. foobarObject.omg = null;
  33. foobarObject.testfoo = false;
  34. foobarObject.notInspectable = top.Object.create(null);
  35. foobarObject.omgfn = new top.Function("return 'myResult'");
  36. foobarObject.abArray = new top.Array("a", "b");
  37. foobarObject.foobaz = top.document;
  38. top.Object.defineProperty(foobarObject, "getterAndSetter", {
  39. enumerable: true,
  40. get: new top.Function("return 'foo';"),
  41. set: new top.Function("1+2"),
  42. });
  43. foobarObject.longStringObj = top.Object.create(null);
  44. foobarObject.longStringObj.toSource = new top.Function("'" + longString + "'");
  45. foobarObject.longStringObj.toString = new top.Function("'" + longString + "'");
  46. foobarObject.longStringObj.boom = "explode";
  47. top.wrappedJSObject.foobarObject = foobarObject;
  48. top.console.log("hello", top.wrappedJSObject.foobarObject);
  49. expectedProps = {
  50. "abArray": {
  51. value: {
  52. type: "object",
  53. class: "Array",
  54. actor: /[a-z]/,
  55. },
  56. },
  57. "foo": {
  58. configurable: true,
  59. enumerable: true,
  60. writable: true,
  61. value: 1,
  62. },
  63. "foobar": {
  64. value: "hello",
  65. },
  66. "foobaz": {
  67. value: {
  68. type: "object",
  69. class: "XULDocument",
  70. actor: /[a-z]/,
  71. },
  72. },
  73. "getterAndSetter": {
  74. get: {
  75. type: "object",
  76. class: "Function",
  77. actor: /[a-z]/,
  78. },
  79. set: {
  80. type: "object",
  81. class: "Function",
  82. actor: /[a-z]/,
  83. },
  84. },
  85. "longStringObj": {
  86. value: {
  87. type: "object",
  88. class: "Object",
  89. actor: /[a-z]/,
  90. },
  91. },
  92. "notInspectable": {
  93. value: {
  94. type: "object",
  95. class: "Object",
  96. actor: /[a-z]/,
  97. },
  98. },
  99. "omg": {
  100. value: { type: "null" },
  101. },
  102. "omgfn": {
  103. value: {
  104. type: "object",
  105. class: "Function",
  106. actor: /[a-z]/,
  107. },
  108. },
  109. "tamarbuta": {
  110. value: {
  111. type: "longString",
  112. initial: longString.substring(0,
  113. DebuggerServer.LONG_STRING_INITIAL_LENGTH),
  114. length: longString.length,
  115. },
  116. },
  117. "testfoo": {
  118. value: false,
  119. },
  120. };
  121. }
  122. function onConsoleCall(aState, aType, aPacket)
  123. {
  124. is(aPacket.from, aState.actor, "console API call actor");
  125. info("checking the console API call packet");
  126. checkConsoleAPICall(aPacket.message, {
  127. level: "log",
  128. filename: /test_object_actor/,
  129. functionName: "onAttach",
  130. arguments: ["hello", {
  131. type: "object",
  132. actor: /[a-z]/,
  133. }],
  134. });
  135. aState.dbgClient.removeListener("consoleAPICall", onConsoleCall);
  136. info("inspecting object properties");
  137. let args = aPacket.message.arguments;
  138. onProperties = onProperties.bind(null, aState);
  139. let client = new ObjectClient(aState.dbgClient, args[1]);
  140. client.getPrototypeAndProperties(onProperties);
  141. }
  142. function onProperties(aState, aResponse)
  143. {
  144. let props = aResponse.ownProperties;
  145. is(Object.keys(props).length, Object.keys(expectedProps).length,
  146. "number of enumerable properties");
  147. checkObject(props, expectedProps);
  148. expectedProps = [];
  149. closeDebugger(aState, function() {
  150. SimpleTest.finish();
  151. });
  152. }
  153. addEventListener("load", startTest);
  154. </script>
  155. </body>
  156. </html>