fune/js/xpconnect/tests/unit/test_bug853709.js
Andrew McCreight 2b68b38709 Bug 1377587, part 1 - Always act like __exposedProps__ is missing. r=krizsa
This patch gently removes support for __exposedProps__ by changing
ExposedPropertiesOnly::check() to always return false, while still
failing silently in deny for some kinds of access.

The tests that I changed all involve testing the behavior with
__exposedProps__. I adjusted them to expect it to fail, or to adjust
the error message they get when they fail. That seemed better than
deleting them entirely.

Note that test_bug1065185.html had a bug, so that it never executed
the first case. I fixed that, and then fixed up the test to work when
__exposedProps__ is not supported.

This also removes various bits of the test framework that use
__exposedProps__, but don't actually need to.

MozReview-Commit-ID: 8fvkAmITmXY

--HG--
extra : rebase_source : ef7e2c55adc12511f17f3865ebb46c343875f0b3
2017-08-22 14:24:11 -07:00

32 lines
1.5 KiB
JavaScript

const Cu = Components.utils;
function setupChromeSandbox() {
this.chromeObj = {a: 2, __exposedProps__: {a: "rw", b: "rw"} };
this.chromeArr = [4, 2, 1];
}
function checkDefineThrows(sb, obj, prop, desc) {
var result = Cu.evalInSandbox('(function() { try { Object.defineProperty(' + obj + ', "' + prop + '", ' + desc.toSource() + '); return "nothrow"; } catch (e) { return e.toString(); }})();', sb);
do_check_neq(result, 'nothrow');
do_check_true(!!/denied|prohibited/.exec(result));
do_check_true(result.indexOf(prop) != -1); // Make sure the prop name is in the error message.
}
function run_test() {
var chromeSB = new Cu.Sandbox(this);
var contentSB = new Cu.Sandbox('http://www.example.org');
Cu.evalInSandbox('(' + setupChromeSandbox.toSource() + ')()', chromeSB);
contentSB.chromeObj = chromeSB.chromeObj;
contentSB.chromeArr = chromeSB.chromeArr;
do_check_eq(Cu.evalInSandbox('chromeObj.a', contentSB), undefined);
try {
Cu.evalInSandbox('chromeArr[1]', contentSB);
do_check_true(false);
} catch (e) { do_check_true(/denied|insecure/.test(e)); }
checkDefineThrows(contentSB, 'chromeObj', 'a', {get: function() { return 2; }});
checkDefineThrows(contentSB, 'chromeObj', 'a', {configurable: true, get: function() { return 2; }});
checkDefineThrows(contentSB, 'chromeObj', 'b', {configurable: true, get: function() { return 2; }, set: function() {}});
checkDefineThrows(contentSB, 'chromeArr', '1', {configurable: true, get: function() { return 2; }});
}