2007-08-07 19:12:31 -07:00
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head>
|
2008-04-13 18:18:30 -07:00
|
|
|
<title>Tests XPConnect Wrappers</title>
|
2007-08-07 19:12:31 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script class="testbody" type="text/javascript;version=1.7">
|
|
|
|
var answer = [];
|
|
|
|
for (let i in location)
|
|
|
|
answer.push(i);
|
|
|
|
var expected = [
|
|
|
|
"hash",
|
|
|
|
"host",
|
|
|
|
"hostname",
|
|
|
|
"href",
|
|
|
|
"pathname",
|
|
|
|
"port",
|
|
|
|
"protocol",
|
|
|
|
"search",
|
|
|
|
"reload",
|
|
|
|
"replace",
|
|
|
|
"assign"
|
|
|
|
];
|
|
|
|
|
|
|
|
is(answer.sort().toString(),
|
|
|
|
expected.sort().toString(),
|
2007-12-29 15:40:50 -08:00
|
|
|
'enumeration over XOWs walks the prototype chain');
|
|
|
|
|
|
|
|
answer = [];
|
|
|
|
let (obj = { a: 3 }) {
|
|
|
|
for (let i in XPCSafeJSObjectWrapper({ __proto__: obj}))
|
|
|
|
answer.push(i);
|
|
|
|
is(answer.toString(), 'a',
|
|
|
|
'enumeration over SJOWs walks the prototype chain');
|
|
|
|
}
|
|
|
|
|
|
|
|
answer = [];
|
|
|
|
for (let i in XPCSafeJSObjectWrapper(location))
|
|
|
|
answer.push(i);
|
|
|
|
|
|
|
|
is(answer.sort().toString(),
|
|
|
|
expected.sort().toString(),
|
|
|
|
'enumeration over SJOWs walks the prototype chain and works over XOWs');
|
2007-08-07 19:12:31 -07:00
|
|
|
|
2009-02-26 17:01:42 -08:00
|
|
|
for (let i in XPCSafeJSObjectWrapper({ 0: 0, "hi": "there" })) {
|
|
|
|
is(typeof i, "string", "enumeration on wrappers only returns strings");
|
|
|
|
}
|
|
|
|
|
2008-01-29 18:06:17 -08:00
|
|
|
ok(!(new XPCSafeJSObjectWrapper({}) == new XPCSafeJSObjectWrapper({})),
|
|
|
|
'SJOWs equality hook returns false correctly');
|
|
|
|
|
|
|
|
let (obj = {}) {
|
|
|
|
ok(new XPCSafeJSObjectWrapper(obj) == new XPCSafeJSObjectWrapper(obj),
|
|
|
|
'SJOWs equality hook returns true correctly');
|
|
|
|
}
|
|
|
|
|
2009-01-16 18:05:14 -08:00
|
|
|
ok(new XPCSafeJSObjectWrapper(window) == new XPCNativeWrapper(window),
|
|
|
|
'SJOWs equality hook returns true correctly against XPCNW');
|
2008-01-29 18:06:17 -08:00
|
|
|
ok(new XPCSafeJSObjectWrapper(window) == window,
|
|
|
|
'SJOWs equality hook returns true correctly against XOW');
|
|
|
|
|
2008-04-13 18:18:30 -07:00
|
|
|
is(typeof(new XPCSafeJSObjectWrapper(function(){})), 'function',
|
|
|
|
'SJOWs look like functions when they wrap functions');
|
|
|
|
is(typeof(new XPCSafeJSObjectWrapper({})), 'object',
|
|
|
|
'SJOWs look like objects when they wrap objects');
|
|
|
|
|
2007-08-07 19:12:31 -07:00
|
|
|
var origProto = window.__proto__;
|
|
|
|
try {
|
|
|
|
window.__proto__ = window;
|
|
|
|
ok(false, 'cyclic proto value allowed');
|
|
|
|
window.__proto__ = origProto;
|
|
|
|
} catch (e) {
|
2007-09-22 14:42:36 -07:00
|
|
|
is(e.toString(),
|
2007-12-20 15:46:08 -08:00
|
|
|
'Error: cyclic __proto__ value',
|
2007-08-07 19:12:31 -07:00
|
|
|
'throw the right exception for a cyclic proto');
|
|
|
|
is(window.__proto__, origProto, 'reset __proto__ after a cyclic proto');
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
is('PASS', window.eval("'PASS'"), 'window.eval throws an exception');
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, 'window.eval does not throw an exception');
|
|
|
|
}
|
2007-08-07 19:18:05 -07:00
|
|
|
|
2007-09-22 14:42:36 -07:00
|
|
|
try {
|
|
|
|
window.__proto__ = null;
|
|
|
|
is(window.__proto__, null,
|
|
|
|
"allowed to update window.__proto__ to null");
|
|
|
|
} catch (e) {
|
|
|
|
ok(false, "some crazy exception was thrown");
|
|
|
|
}
|
2007-12-24 11:28:21 -08:00
|
|
|
|
|
|
|
// Some tests for SJOWs too.
|
|
|
|
is(new XPCSafeJSObjectWrapper(document.body) === document.body, true,
|
|
|
|
"triple equals ignores wrappers");
|
|
|
|
is(XPCSafeJSObjectWrapper.prototype + '',
|
|
|
|
"[object XPCSafeJSObjectWrapper]",
|
|
|
|
"able to convert XPCSafeJSObjectWrapper.prototype to string");
|
2007-08-07 19:12:31 -07:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|