test_bug813901.js 949 B

1234567891011121314151617181920212223242526
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /* See https://bugzilla.mozilla.org/show_bug.cgi?id=813901 */
  5. const Cu = Components.utils;
  6. // Make sure that we can't inject __exposedProps__ via the proto of a COW-ed object.
  7. function checkThrows(expression, sb, regexp) {
  8. var result = Cu.evalInSandbox('(function() { try { ' + expression + '; return "allowed"; } catch (e) { return e.toString(); }})();', sb);
  9. dump('result: ' + result + '\n\n\n');
  10. do_check_true(!!regexp.exec(result));
  11. }
  12. function run_test() {
  13. var sb = new Cu.Sandbox('http://www.example.org');
  14. sb.obj = {foo: 2};
  15. checkThrows('obj.foo = 3;', sb, /denied/);
  16. Cu.evalInSandbox("var p = {__exposedProps__: {foo: 'rw'}};", sb);
  17. sb.obj.__proto__ = sb.p;
  18. checkThrows('obj.foo = 4;', sb, /__exposedProps__/);
  19. }