3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../../http/tests/inspector/console-test.js"></script>
7 var originalError
= window
.Error
;
10 var originalFunctionCall
= Function
.prototype.call
;
11 var originalFunctionApply
= Function
.prototype.apply
;
13 var overriddenFunctionCall = function() {
15 console
.error("FAIL: Function.prototype.call should not be called!");
16 var result
= originalFunctionCall
.apply(this, arguments
);
21 var overriddenFunctionApply = function(thisArg
, argsArray
) {
23 console
.error("FAIL: Function.prototype.apply should not be called!");
24 var result
= originalFunctionApply
.call(this, thisArg
, argsArray
);
31 Function
.prototype.call
= originalFunctionCall
;
32 Function
.prototype.apply
= originalFunctionApply
;
37 Function
.prototype.call
= overriddenFunctionCall
;
38 Function
.prototype.apply
= overriddenFunctionApply
;
44 function throwGetter()
46 console
.error("FAIL: Should not be called!");
47 throw new Error("FAIL");
50 function testOverriddenArrayPushAndMathMax()
52 Object
.defineProperty(Array
.prototype, "push", {
55 Object
.defineProperty(Math
, "max", {
61 function testOverriddenConstructorName()
64 obj
.constructor = { name
: "foo" };
68 function testThrowConstructorName()
71 Object
.defineProperty(obj
, "constructor", {
77 function testOverriddenIsFinite()
79 window
.isFinite
= throwGetter
;
87 function testOverriddenError()
90 return { result
: "PASS" };
93 function restoreError()
95 window
.Error
= originalError
;
96 return { result
: "PASS" };
99 function testOverriddenToString(obj
, overrideThrow
)
102 var func = function() { throw new Error
; }
104 var func = function() { return [1]; }
106 Object
.defineProperty(obj
, "toString", { value
: func
, enumerable
: false });
107 Object
.defineProperty(obj
, "valueOf", { value
: func
, enumerable
: false });
109 // Now the ("" + obj) expression should throw.
111 var dummy
= "" + obj
;
112 console
.error("FAIL: Expected to throw but got: " + dummy
);
121 InspectorTest
.runTestSuite([
122 function evaluateInConsole(next
)
125 "testOverriddenArrayPushAndMathMax()",
126 "testOverriddenConstructorName()",
127 "testThrowConstructorName()",
128 "testOverriddenIsFinite()",
129 "testOverriddenError()",
131 "testOverriddenToString(function func() {}, true)",
132 "testOverriddenToString(function func() {}, false)",
133 "testOverriddenToString(new Function, true)",
134 "testOverriddenToString(new Function, false)",
135 "testOverriddenToString(/^regex$/, true)",
136 "testOverriddenToString(/^regex$/, false)",
137 "testOverriddenToString(new Date, true)",
138 "testOverriddenToString(new Date, false)",
139 "testOverriddenToString({}, true)",
140 "testOverriddenToString({}, false)",
141 "testOverriddenToString(new Number(1), true)",
142 "testOverriddenToString(new Number(1), false)",
147 var expr
= expressions
.shift();
149 InspectorTest
.runAfterPendingDispatches(next
);
152 InspectorTest
.evaluateInConsole(expr
, iterate
);
157 function testRuntimeAgentCallFunctionOn(next
)
159 InspectorTest
.RuntimeAgent
.evaluate("({ a : 1, b : 2 })", step1
);
161 function step1(error
, result
, wasThrown
)
165 return this.a
+ this.b
;
167 InspectorTest
.RuntimeAgent
.callFunctionOn(result
.objectId
, sum
.toString(), step2
);
170 function step2(error
, result
, wasThrown
)
172 InspectorTest
.assertEquals(3, result
.value
);
177 function dumpConsoleMessages(next
)
179 InspectorTest
.dumpConsoleMessages();
187 <body onload=
"runTest()">
189 Tests that overriding global methods (like Array.prototype.push, Math.max) will not break the inspector.