OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
4 <script src="../../http/tests/inspector/console-test.js"></script> | 4 <script src="../../http/tests/inspector/console-test.js"></script> |
5 <script> | 5 <script> |
6 | 6 |
| 7 (function() { |
| 8 var _originalFunctionCall = Function.prototype.call; |
| 9 var _originalFunctionApply = Function.prototype.apply; |
| 10 |
| 11 var _overriddenFunctionCall = function() { |
| 12 original(); |
| 13 console.error("FAIL: Function.prototype.call should not be called!"); |
| 14 var result = _originalFunctionCall.apply(this, arguments); |
| 15 overridden(); |
| 16 return result; |
| 17 } |
| 18 |
| 19 var _overriddenFunctionApply = function(thisArg, argsArray) { |
| 20 original(); |
| 21 console.error("FAIL: Function.prototype.apply should not be called!"); |
| 22 var result = _originalFunctionApply.call(this, thisArg, argsArray); |
| 23 overridden(); |
| 24 return result; |
| 25 } |
| 26 |
| 27 function original() |
| 28 { |
| 29 Function.prototype.call = _originalFunctionCall; |
| 30 Function.prototype.apply = _originalFunctionApply; |
| 31 } |
| 32 |
| 33 function overridden() |
| 34 { |
| 35 Function.prototype.call = _overriddenFunctionCall; |
| 36 Function.prototype.apply = _overriddenFunctionApply; |
| 37 } |
| 38 |
| 39 overridden(); |
| 40 })(); |
| 41 |
7 function throwGetter() | 42 function throwGetter() |
8 { | 43 { |
9 console.error("FAIL: Should not be called!"); | 44 console.error("FAIL: Should not be called!"); |
10 throw new Error("FAIL"); | 45 throw new Error("FAIL"); |
11 } | 46 } |
12 | 47 |
13 function foo() | 48 function testOverriddenArrayPushAndMathMax() |
14 { | 49 { |
15 Object.defineProperty(Array.prototype, "push", { | 50 Object.defineProperty(Array.prototype, "push", { |
16 get: throwGetter | 51 get: throwGetter |
17 }); | 52 }); |
18 Object.defineProperty(Math, "max", { | 53 Object.defineProperty(Math, "max", { |
19 get: throwGetter | 54 get: throwGetter |
20 }); | 55 }); |
21 return [1, 2, 3]; | 56 return [1, 2, 3]; |
22 } | 57 } |
23 | 58 |
24 function testOverriddenConstructorName() | 59 function testOverriddenConstructorName() |
25 { | 60 { |
26 var obj = {}; | 61 var obj = {}; |
27 obj.constructor = { name: "foo" }; | 62 obj.constructor = { name: "foo" }; |
28 return obj; | 63 return obj; |
29 } | 64 } |
30 | 65 |
31 function testThrowConstructorName() | 66 function testThrowConstructorName() |
32 { | 67 { |
33 var obj = {}; | 68 var obj = {}; |
34 Object.defineProperty(obj, "constructor", { | 69 Object.defineProperty(obj, "constructor", { |
35 get: throwGetter | 70 get: throwGetter |
36 }); | 71 }); |
37 return obj; | 72 return obj; |
38 } | 73 } |
39 | 74 |
40 function test() | 75 function test() |
41 { | 76 { |
42 InspectorTest.evaluateInConsole("foo()"); | 77 InspectorTest.runTestSuite([ |
43 InspectorTest.evaluateInConsole("testOverriddenConstructorName()"); | 78 function evaluateInConsole(next) |
44 InspectorTest.evaluateInConsole("testThrowConstructorName()"); | 79 { |
45 InspectorTest.runAfterPendingDispatches(step1); | 80 InspectorTest.evaluateInConsole("testOverriddenArrayPushAndMathMax()
"); |
| 81 InspectorTest.evaluateInConsole("testOverriddenConstructorName()"); |
| 82 InspectorTest.evaluateInConsole("testThrowConstructorName()"); |
| 83 InspectorTest.runAfterPendingDispatches(next); |
| 84 }, |
46 | 85 |
47 function step1() | 86 function testRuntimeAgentCallFunctionOn(next) |
48 { | 87 { |
49 InspectorTest.dumpConsoleMessages(); | 88 RuntimeAgent.evaluate("({ a : 1, b : 2 })", step1); |
50 InspectorTest.completeTest(); | 89 |
51 } | 90 function step1(error, result, wasThrown) |
| 91 { |
| 92 function sum() |
| 93 { |
| 94 return this.a + this.b; |
| 95 } |
| 96 RuntimeAgent.callFunctionOn(result.objectId, sum.toString(), ste
p2); |
| 97 } |
| 98 |
| 99 function step2(error, result, wasThrown) |
| 100 { |
| 101 InspectorTest.assertEquals(3, result.value); |
| 102 next(); |
| 103 } |
| 104 }, |
| 105 |
| 106 function dumpConsoleMessages(next) |
| 107 { |
| 108 InspectorTest.dumpConsoleMessages(); |
| 109 next(); |
| 110 } |
| 111 ]); |
52 } | 112 } |
53 </script> | 113 </script> |
54 </head> | 114 </head> |
55 | 115 |
56 <body onload="runTest()"> | 116 <body onload="runTest()"> |
57 <p> | 117 <p> |
58 Tests that overriding global methods (like Array.prototype.push, Math.max) will
not break the inspector. | 118 Tests that overriding global methods (like Array.prototype.push, Math.max) will
not break the inspector. |
59 </p> | 119 </p> |
60 | 120 |
61 </body> | 121 </body> |
62 </html> | 122 </html> |
OLD | NEW |