test_bug853709.js (1424B)
1 function setupChromeSandbox() { 2 this.chromeObj = {a: 2 }; 3 this.chromeArr = [4, 2, 1]; 4 } 5 6 function checkDefineThrows(sb, obj, prop, desc) { 7 var result = Cu.evalInSandbox('(function() { try { Object.defineProperty(' + obj + ', "' + prop + '", ' + desc.toSource() + '); return "nothrow"; } catch (e) { return e.toString(); }})();', sb); 8 Assert.notEqual(result, 'nothrow'); 9 Assert.ok(!!/denied|prohibited/.exec(result)); 10 Assert.ok(result.includes(prop)); // Make sure the prop name is in the error message. 11 } 12 13 function run_test() { 14 var chromeSB = new Cu.Sandbox(this); 15 var contentSB = new Cu.Sandbox('http://www.example.org'); 16 Cu.evalInSandbox('(' + setupChromeSandbox.toSource() + ')()', chromeSB); 17 contentSB.chromeObj = chromeSB.chromeObj; 18 contentSB.chromeArr = chromeSB.chromeArr; 19 20 Assert.equal(Cu.evalInSandbox('chromeObj.a', contentSB), undefined); 21 try { 22 Cu.evalInSandbox('chromeArr[1]', contentSB); 23 Assert.ok(false); 24 } catch (e) { Assert.ok(/denied|insecure/.test(e)); } 25 26 checkDefineThrows(contentSB, 'chromeObj', 'a', {get: function() { return 2; }}); 27 checkDefineThrows(contentSB, 'chromeObj', 'a', {configurable: true, get: function() { return 2; }}); 28 checkDefineThrows(contentSB, 'chromeObj', 'b', {configurable: true, get: function() { return 2; }, set: function() {}}); 29 checkDefineThrows(contentSB, 'chromeArr', '1', {configurable: true, get: function() { return 2; }}); 30 }