test_asyncLoadSubScriptError.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. const Cc = Components.classes;
  5. const Ci = Components.interfaces;
  6. var srvScope = {};
  7. function success(result) {
  8. ok(false, "script should not have loaded successfully");
  9. do_test_finished();
  10. }
  11. function error(err) {
  12. ok(err instanceof SyntaxError, "loading script with early error asynchronously resulted in error");
  13. do_test_finished();
  14. }
  15. function run_test() {
  16. do_test_pending();
  17. var file = do_get_file("subScriptWithEarlyError.js");
  18. var ios = Cc["@mozilla.org/network/io-service;1"]
  19. .getService(Ci.nsIIOService);
  20. var uri = ios.newFileURI(file);
  21. var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
  22. .getService(Ci.mozIJSSubScriptLoader);
  23. var p = scriptLoader.loadSubScriptWithOptions(uri.spec,
  24. { target: srvScope,
  25. async: true });
  26. p.then(success, error);
  27. }