Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jsc/bindings/ImportMetaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ extern "C" JSC::EncodedJSValue functionImportMeta__resolveSyncPrivate(JSC::JSGlo

JSC::JSValue moduleName = callFrame->argument(0);
JSValue from = callFrame->argument(1);
bool isESM = callFrame->argument(2).asBoolean();
bool isESM = callFrame->argument(2).isTrue();
bool isRequireDotResolve = callFrame->argument(3).isTrue();
JSValue userPathList = callFrame->argument(4);
JSValue parentModule = callFrame->argument(5);
Expand Down
27 changes: 27 additions & 0 deletions test/js/bun/glob/scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,33 @@ test("scan handles a cwd with redundant trailing separators when following symli
expect(exitCode).toBe(0);
});

// With `this === globalThis`, the private `@resolveSync` that scanSync calls is
// the module resolver's internal entry point, called with a single argument.
// The private `@pull` that scan calls does not exist on globalThis at all.
test("scanSync and scan called with globalThis as this throw instead of crashing", async () => {
const script = `
for (const fn of ["scanSync", "scan"]) {
try {
Bun.Glob.prototype[fn].call(globalThis, 4096);
console.log(fn + ": no error");
} catch (e) {
console.log(fn + ": " + (e.code ?? e.name));
}
}
`;

await using proc = Bun.spawn({
cmd: [bunExe(), "-e", script],
env: bunEnv,
stderr: "pipe",
});

const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);

expect(stdout.trim()).toBe("scanSync: ERR_INVALID_ARG_TYPE\nscan: TypeError");
expect(exitCode).toBe(0);
});

// A pattern segment that spells out a leading `.` is an explicit request for
// that dotfile/dot-directory, so the `dot: false` default must not hide it.
// This matches bash, picomatch, minimatch and fast-glob.
Expand Down