|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=923904 |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for Bug 923904</title> |
|
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 <script type="application/javascript"> |
|
12 |
|
13 /** Test for cloning of |any| and |object| for JS-Implemented WebIDL. **/ |
|
14 SimpleTest.waitForExplicitFinish(); |
|
15 SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]}, go); |
|
16 |
|
17 function go() { |
|
18 var someAny = { a: 11 }; |
|
19 var someObj = { b: 22, c: "str" }; |
|
20 var t = new TestInterfaceJS(someAny, someObj); |
|
21 is(Object.getPrototypeOf(t), TestInterfaceJS.prototype, "Prototype setup works correctly"); |
|
22 is(t.anyArg.toSource(), someAny.toSource(), "anyArg comes back looking like what we sent"); |
|
23 is(t.objectArg.toSource(), someObj.toSource(), "objectArg comes back looking like what we sent"); |
|
24 isnot(t.anyArg, t.anyArg, "get a new anyArg each time"); |
|
25 isnot(t.objectArg, t.objectArg, "get a new objectArg each time"); |
|
26 |
|
27 t.anyAttr = 2; |
|
28 is(t.anyAttr, 2, "ping-pong works"); |
|
29 testObjectCloned(t, 'anyAttr'); |
|
30 testObjectCloned(t, 'objectAttr'); |
|
31 |
|
32 is(someAny.toSource(), t.pingPongAny(someAny).toSource(), "ping-pong works with any"); |
|
33 is(someObj.toSource(), t.pingPongObject(someObj).toSource(), "ping-pong works with obj"); |
|
34 isnot(someAny, t.pingPongAny(someAny), "Clone works for ping-pong any"); |
|
35 isnot(someObj, t.pingPongObject(someObj), "Clone works for ping-pong obj"); |
|
36 |
|
37 SimpleTest.finish(); |
|
38 } |
|
39 |
|
40 function testObjectCloned(iface, propname) { |
|
41 var obj = { prop: 42 }; |
|
42 iface[propname] = obj; |
|
43 is(iface[propname].prop, 42, "objects come back as well"); |
|
44 is(iface[propname].__proto__, Object.prototype, "vanilla object"); |
|
45 isnot(iface[propname], obj, "Should not be the original object"); |
|
46 isnot(iface[propname], iface[propname], "Should get cloned each time"); |
|
47 try { |
|
48 iface[propname] = { stringProp: "hi", reflectorProp: document }; |
|
49 ok(false, "Should throw when trying to clone reflector"); |
|
50 } catch (e) { |
|
51 ok(/cloned/.test(e), "Should throw clone error: " + e); |
|
52 } |
|
53 } |
|
54 |
|
55 </script> |
|
56 </head> |
|
57 <body> |
|
58 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=923904">Mozilla Bug 923904</a> |
|
59 <p id="display"></p> |
|
60 <div id="content" style="display: none"> |
|
61 |
|
62 </div> |
|
63 <pre id="test"> |
|
64 </pre> |
|
65 </body> |
|
66 </html> |