|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
|
4 type="text/css"?> |
|
5 <!-- |
|
6 https://bugzilla.mozilla.org/show_bug.cgi?id=634156 |
|
7 --> |
|
8 <window title="Testing API exposing capabilities" |
|
9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
10 <script type="application/javascript" |
|
11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
12 |
|
13 <!-- test results are displayed in the html:body --> |
|
14 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=634156" |
|
16 target="_blank">Mozilla Bug 634156</a> |
|
17 </body> |
|
18 |
|
19 <!-- test code goes here --> |
|
20 <script type="application/javascript"><![CDATA[ |
|
21 const Cu = Components.utils; |
|
22 |
|
23 var sandbox = new Cu.Sandbox("about:blank"); |
|
24 sandbox.ok = ok; |
|
25 sandbox.is = is; |
|
26 Cu.evalInSandbox("Object.defineProperty(Object.prototype, 'getProp', { get: function() { throw 'FAIL: called getter' }, set: function() { throw 'FAIL: called setter'; } })", sandbox); |
|
27 |
|
28 var obj = Cu.createObjectIn(sandbox); |
|
29 is(obj, Cu.waiveXrays(obj), "createObjectIn waives"); |
|
30 is(Object.getPrototypeOf(obj), Cu.waiveXrays(Cu.evalInSandbox("Object.prototype", sandbox)), |
|
31 "Object is a sandbox object"); |
|
32 |
|
33 function genPropDesc(value) { |
|
34 return { enumerable: true, configurable: true, writable: true, |
|
35 value: value }; |
|
36 } |
|
37 const props = { |
|
38 'getProp': genPropDesc(function() { ok(true, "called prop that shadowed a getter"); }), |
|
39 'argument': genPropDesc(function(arg) { is(arg, 42, "can pass arguments through"); }), |
|
40 'returnval': genPropDesc(function() { return 42; }) |
|
41 }; |
|
42 Object.defineProperties(obj, props); |
|
43 Cu.makeObjectPropsNormal(obj); |
|
44 |
|
45 sandbox.api = obj; |
|
46 Cu.evalInSandbox("ok(Object.getPrototypeOf(api) === Object.prototype, 'we have the object we expected'); \ |
|
47 api.getProp(); api.argument(42); is(api.returnval(), 42, 'return value was correct');\ |
|
48 ok(typeof api.getProp === 'function', 'functions are functions');\ |
|
49 ok(Object.getPrototypeOf(api.getProp) === Function.prototype, 'functions come from our scope');", sandbox); |
|
50 ]]></script> |
|
51 </window> |