Skip to content

Commit

Permalink
Bug 1492090 - Part 9: Use UTF-8 in module ThrowResolutionError. r=nbp
Browse files Browse the repository at this point in the history
  • Loading branch information
arai-a committed May 23, 2023
1 parent f42b699 commit 5107aa4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions js/src/tests/shell/script-file-name-utf8.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ function getLcovInfoScriptName(fileName) {
return scriptFiles[0].substring(3);
}

// Return the file name from the error during module import.
function moduleResolutionError(fileName) {
const a = parseModule(`import { x } from "b";`, fileName);
const ma = registerModule("a", a);
const b = parseModule(`export var y = 10;`);
const mb = registerModule("b", b);

try {
moduleLink(ma);
} catch (e) {
return e.fileName;
}
}

// Return the file name from the profiler stack.
function geckoInterpProfilingStack(fileName) {
enableGeckoProfilingWithSlowAssertions();
Expand All @@ -191,6 +205,7 @@ const testFunctions = [
fromErrorStackAsmJS,
fromErrorStackStreamingWasm,
getBacktraceScriptName,
moduleResolutionError,
];

if (isLcovEnabled()) {
Expand Down
7 changes: 6 additions & 1 deletion js/src/vm/Modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,12 @@ static void ThrowResolutionError(JSContext* cx, Handle<ModuleObject*> module,
}

RootedString filename(cx);
filename = JS_NewStringCopyZ(cx, module->script()->filename());
if (const char* chars = module->script()->filename()) {
filename =
JS_NewStringCopyUTF8Z(cx, JS::ConstUTF8CharsZ(chars, strlen(chars)));
} else {
filename = cx->names().empty;
}
if (!filename) {
return;
}
Expand Down

0 comments on commit 5107aa4

Please sign in to comment.