Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / unit / test_allowWaivers.js
blobb5a764e3522ae2795fb03c66434d70d2135fd017
1 function checkWaivers(from, allowed) {
2   var sb = new Cu.Sandbox('http://example.com');
3   from.test = sb.eval('var o = {prop: 2, f: function() {return 42;}}; o');
5   // Make sure that |from| has Xrays to sb.
6   Assert.equal(from.eval('test.prop'), 2);
7   Assert.equal(from.eval('test.f'), undefined);
9   // Make sure that waivability works as expected.
10   Assert.equal(from.eval('!!test.wrappedJSObject'), allowed);
11   Assert.equal(from.eval('XPCNativeWrapper.unwrap(test) !== test'), allowed);
13   // Make a sandbox with the same principal as |from|, but without any waiver
14   // restrictions, and make sure that the waiver does not transfer.
15   var friend = new Cu.Sandbox(Cu.getObjectPrincipal(from));
16   friend.test = from.test;
17   friend.eval('var waived = test.wrappedJSObject;');
18   Assert.equal(friend.eval('waived.f()'), 42);
19   friend.from = from;
20   friend.eval('from.waived = waived');
21   Assert.equal(from.eval('!!waived.f'), allowed);
24 function run_test() {
25   checkWaivers(new Cu.Sandbox('http://example.com'), true);
26   checkWaivers(new Cu.Sandbox('http://example.com', {allowWaivers: false}), false);
27   checkWaivers(new Cu.Sandbox(['http://example.com']), true);
28   checkWaivers(new Cu.Sandbox(['http://example.com'], {allowWaivers: false}), false);