Files
sausage/userland/qjs/source/tests/callsite-isconstructor.js
T
surma d44f1d9677 Build separate native and WASI pipelines with shared multicall names
Checkpoint before integration and package validation.

Assisted-by: SurmAgent:unknown [read] [edit] [bash]
2026-11-12 09:36:27 +00:00

31 lines
867 B
JavaScript

import { assert } from "./assert.js";
/* CallSite.prototype.isConstructor reports whether the frame was invoked as a
constructor (via `new`). */
let frames;
Error.prepareStackTrace = (_, f) => { frames = f; return f; };
function Thing() { void new Error(""); }
new Thing();
function plain() { void new Error(""); }
plain();
Error.prepareStackTrace = undefined;
// after plain(): frame 0 is plain (not a constructor)
assert(frames[0].getFunctionName(), "plain");
assert(!frames[0].isConstructor());
// re-run for the constructor case
Error.prepareStackTrace = (_, f) => { frames = f; return f; };
new Thing();
Error.prepareStackTrace = undefined;
// frame 0 is Thing, invoked via `new`
assert(frames[0].getFunctionName(), "Thing");
assert(frames[0].isConstructor());
// its caller (module top level) is not a constructor
assert(!frames[1].isConstructor());