mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 19:47:17 +02:00
LibJS: Allow anonymous functions as default exports
This requires a special case with names as the default function is
supposed to have a unique name ("*default*" in our case) but when
checked should have name "default".
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 07:34:10 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/9f661d20f7 Pull-request: https://github.com/SerenityOS/serenity/pull/15100 Reviewed-by: https://github.com/linusg
@@ -0,0 +1,26 @@
|
||||
try {
|
||||
f();
|
||||
} catch (e) {
|
||||
if (!(e instanceof ReferenceError)) throw e;
|
||||
if (!e.message.includes("bindingUsedInFunction")) throw e;
|
||||
}
|
||||
|
||||
let bindingUsedInFunction = 0;
|
||||
|
||||
const immediateResult = f();
|
||||
const immediateName = f.name + "";
|
||||
|
||||
import f from "./anon-func-decl-default-export.mjs";
|
||||
export default function () {
|
||||
return bindingUsedInFunction++;
|
||||
}
|
||||
|
||||
const postImportResult = f();
|
||||
const postImportName = f.name + "";
|
||||
|
||||
export const passed =
|
||||
immediateResult === 0 &&
|
||||
postImportResult === 1 &&
|
||||
bindingUsedInFunction === 2 &&
|
||||
immediateName === "default" &&
|
||||
postImportName === "default";
|
||||
Reference in New Issue
Block a user