Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / js / script-tests / cross-frame-really-bad-time-with-__proto__.js
blob151ef8f8188a840af377eeb6b3e45e1ffaef3fd9
1 description(
2 "Tests that having a bad time has correct cross frame behavior, if an instance object is created in a different global object than the affected prototype, and the prototype is assigned using __proto__."
3 );
5 if (window.testRunner)
6 testRunner.waitUntilDone();
8 var ouches = 0;
10 var array;
12 function foo(thePrototype) {
13 array = {};
14 array.__proto__ = thePrototype;
15 array.length = 10;
16 for (var i = 0; i < 10; i+=2)
17 array[i] = 42;
20 function evil(thePrototype) {
21 for (var i = 0; i < 10; i+=2)
22 thePrototype.__defineSetter__(i + 1, function() { ouches++; });
25 function bar() {
26 for (var i = 0; i < 10; i+=2)
27 array[i + 1] = 63;
30 function done() {
31 var string = Array.prototype.join.apply(array, [","]);
32 debug("Array is: " + string);
33 if (string == "42,,42,,42,,42,,42,")
34 testPassed("Array has holes in odd numbered entries.");
35 else
36 testFailed("Array does not have the required holes.");
38 if (ouches == 5)
39 testPassed("Got 5 ouches.");
40 else
41 testFailed("Did not get 5 ouches. Got " + ouches + " + instead.");
43 if (testRunner)
44 testRunner.notifyDone();
47 var frame = document.getElementById("myframe");
49 frame.contentDocument.open();
50 frame.contentDocument.write(
51 "<!DOCTYPE html>\n<html><body><script type=\"text/javascript\">\n" +
52 "var thePrototype = {};\n" +
53 "window.parent.foo(thePrototype);\n" +
54 "window.parent.evil(thePrototype);\n" +
55 "window.parent.bar();\n" +
56 "window.parent.done();\n" +
57 "</script></body></html>");
58 frame.contentDocument.close();