bug_5585.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  6. let line = 't("摩"2)';
  7. let module_name = 'temp.js';
  8. WScript.RegisterModuleSource(module_name, line);
  9. var tests = [
  10. {
  11. name: "Syntax error thrown parsing dynamic module",
  12. body: function () {
  13. let source = `import(module_name)
  14. .then(v => {
  15. assert.fail("Parsing this module should not succeed");
  16. }, e => {
  17. assert.areEqual(line, e.source, "Source line causing compile error");
  18. }).catch(e => {
  19. console.log('fail: ' + e);
  20. throw e;
  21. });`
  22. testRunner.LoadModule(source, 'samethread', true, false);
  23. }
  24. },
  25. {
  26. name: "Syntax error thrown parsing module code",
  27. body: function () {
  28. try {
  29. WScript.LoadScriptFile(module_name, 'module');
  30. assert.fail("Parsing this module should not succeed");
  31. } catch(e) {
  32. assert.areEqual(line, e.source, "Source line causing compile error");
  33. }
  34. }
  35. },
  36. {
  37. name: "Error line which contains multi-byte UTF-8 sequence which is an end-of-line character",
  38. body: function () {
  39. WScript.RegisterModuleSource('temp2.js', 't("\u2028"2)');
  40. try {
  41. WScript.LoadScriptFile('temp2.js', 'module');
  42. assert.fail("Parsing this module should not succeed");
  43. } catch(e) {
  44. assert.areEqual('t("', e.source, "Source line causing compile error");
  45. }
  46. }
  47. }
  48. ];
  49. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });