5 <script src="../resources/js-test-pre.js"></script>
8 <pre id='console'></pre>
14 const log = console.log.bind(console);
15 const canvas = document.querySelector("canvas");
16 const ctx = canvas.getContext("2d");
19 function makeValue(x) {
21 valueOf() { ++callCount; return x; }
25 let array = [makeValue(1), makeValue(2), makeValue(3)];
26 ctx.setLineDash(array);
27 let a = ctx.getLineDash();
28 log("Using an array but with objects with valueOf()");
31 ctx.setLineDash([1,2,3]);
32 let b = ctx.getLineDash();
35 if (a.toString() !== b.toString())
36 throw new Error("Bad result. They should be equal.");
38 log(`callCount: ${callCount}`);
40 throw new Error("Bad result. callCount should be 3.");
43 let iter = [][Symbol.iterator]();
44 let iterProto = Object.getPrototypeOf(iter);
45 let oldNext = iterProto.next;
48 function hackedNext() {
51 let val = oldNext.call(this);
59 iterProto.next = hackedNext;
64 ctx.setLineDash(array);
65 b = ctx.getLineDash();
68 iterProto.next = oldNext;
69 ctx.setLineDash([1,2,3]);
70 a = ctx.getLineDash();
72 if (a.toString() !== b.toString())
73 throw new Error("Bad result. They should be equal.");
75 log(`callCount: ${callCount}`);
77 throw new Error("Bad result. callCount should be 0.");
81 <script src="../resources/js-test-post.js"></script>