Skip to content

Commit d89b8a4

Browse files
committed
bump quickjs version to get setStackFrameMapper
1 parent 0e56074 commit d89b8a4

7 files changed

Lines changed: 192 additions & 13 deletions

File tree

meta/generated-docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ For convenience, two of the builtin modules from QuickJS are also available as g
289289
[`TypeValidator`]: /meta/generated-docs/types.md#typevalidator-type
290290
[`JSX.pragma`]: /meta/generated-docs/jsx.md#jsxpragma-exported-string
291291
[`setMainModule`]: /meta/generated-docs/engine.md#quickjsenginesetmainmodule-exported-function
292+
[`setStackFrameMapper`]: /meta/generated-docs/engine.md#quickjsenginesetstackframemapper-exported-function
292293
[`setExitCode`]: /meta/generated-docs/cmdline.md#quickjsstdsetexitcode-exported-function
293294
[`FILE.seek`]: /meta/generated-docs/std.md#fileseek-method
294295
[`FILE.setvbuf`]: /meta/generated-docs/std.md#filesetvbuf-method

meta/generated-docs/bytecode.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ cycles, pass `preserveReferences: false`.
6666
To serialize Error instances (including `TypeError`, `RangeError`,
6767
`SyntaxError`, `ReferenceError`, `URIError`, `EvalError`,
6868
`AggregateError`, and `InternalError`), pass `serializeErrors: true`.
69-
Without it, attempting to serialize any Error instance throws
70-
"unsupported object class".
69+
Without it, attempting to serialize any Error instance throws.
7170

7271
```ts
7372
export function fromValue(

meta/generated-docs/engine.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
- ["quickjs:engine".defineBuiltinModule (exported function)](#quickjsenginedefinebuiltinmodule-exported-function)
1111
- ["quickjs:engine".ModuleDelegate (exported ModuleDelegate)](#quickjsenginemoduledelegate-exported-moduledelegate)
1212
- ["quickjs:engine".gc (exported function)](#quickjsenginegc-exported-function)
13+
- ["quickjs:engine".StackFrameMapper (exported type)](#quickjsenginestackframemapper-exported-type)
14+
- ["quickjs:engine".setStackFrameMapper (exported function)](#quickjsenginesetstackframemapper-exported-function)
15+
- ["quickjs:engine".getStackFrameMapper (exported function)](#quickjsenginegetstackframemapper-exported-function)
1316
- ["quickjs:engine".formatValue (exported function)](#quickjsengineformatvalue-exported-function)
1417
- ["quickjs:engine".\_\_printObject (exported function)](#quickjsengine__printobject-exported-function)
1518

@@ -54,6 +57,22 @@ declare module "quickjs:engine" {
5457
): void;
5558
export const ModuleDelegate: ModuleDelegate;
5659
export function gc(): void;
60+
export type StackFrameMapper = (
61+
filename: string,
62+
line: number,
63+
column: number,
64+
) =>
65+
| {
66+
filename: string;
67+
line: number;
68+
column: number;
69+
}
70+
| null
71+
| undefined;
72+
export function setStackFrameMapper(
73+
mapper: StackFrameMapper | null | undefined,
74+
): void;
75+
export function getStackFrameMapper(): StackFrameMapper | null;
5776
export function formatValue(
5877
value: any,
5978
options?: {
@@ -221,6 +240,94 @@ function is useful in case of specific memory constraints or for testing.
221240
export function gc(): void;
222241
```
223242

243+
## "quickjs:engine".StackFrameMapper (exported type)
244+
245+
A callback that translates the location of a stack frame as an error's
246+
backtrace is built. See [setStackFrameMapper](/meta/generated-docs/engine.md#quickjsenginesetstackframemapper-exported-function) for details.
247+
248+
`line` and `column` are 1-based, both for the values passed in and for the
249+
values returned. To change the frame's location, return an object
250+
containing all three of `filename`, `line`, and `column`. Return `null` or
251+
`undefined` (or an object missing any field) to leave the location
252+
unchanged.
253+
254+
```ts
255+
type StackFrameMapper = (
256+
filename: string,
257+
line: number,
258+
column: number,
259+
) =>
260+
| {
261+
filename: string;
262+
line: number;
263+
column: number;
264+
}
265+
| null
266+
| undefined;
267+
```
268+
269+
## "quickjs:engine".setStackFrameMapper (exported function)
270+
271+
Register a callback that translates the location of each stack frame as an
272+
error's backtrace is built. This is the hook to use for source-map support:
273+
the engine itself knows nothing about source maps, so the callback is where
274+
you map a compiled `(filename, line, column)` back to its original source
275+
location.
276+
277+
The callback is invoked once per frame while the backtrace string is being
278+
assembled. The location it returns is used both in the human-readable
279+
`error.stack` string AND in the `fileName` / `lineNumber` / `columnNumber`
280+
own properties set on the error object, so they stay consistent.
281+
282+
`line` and `column` are 1-based, both for the values passed to the callback
283+
and for the values it returns.
284+
285+
To take effect, the callback must return an object containing all three of
286+
`filename`, `line`, and `column`. If it instead returns `null` or
287+
`undefined`, returns an object missing any of those fields, returns a
288+
non-object, or throws, the frame's original location is kept unchanged (a
289+
thrown error is swallowed rather than propagated into backtrace
290+
construction).
291+
292+
Only one mapper can be registered at a time; registering a new one replaces
293+
the previous one. Pass `null` or `undefined` to unregister, restoring the
294+
default behavior of reporting compiled locations.
295+
296+
While the mapper is running, it is temporarily disabled for any error thrown
297+
from within it, so an error thrown inside the mapper will not recurse
298+
infinitely; that nested error's backtrace simply reports its original
299+
(unmapped) locations.
300+
301+
- `@param` _mapper_ — The translation callback, or `null`/`undefined` to unregister.
302+
303+
```ts
304+
export function setStackFrameMapper(
305+
mapper: StackFrameMapper | null | undefined,
306+
): void;
307+
```
308+
309+
## "quickjs:engine".getStackFrameMapper (exported function)
310+
311+
Return the stack frame mapper currently registered via
312+
[setStackFrameMapper](/meta/generated-docs/engine.md#quickjsenginesetstackframemapper-exported-function), or `null` if none is registered.
313+
314+
This is useful for composing mappers: read the existing one, then register
315+
a new mapper that adds your own behavior and delegates to the previous one.
316+
317+
```js
318+
const previous = getStackFrameMapper();
319+
setStackFrameMapper((filename, line, column) => {
320+
const mapped = previous ? previous(filename, line, column) : null;
321+
const location = mapped ?? { filename, line, column };
322+
// ...apply your own additional adjustments to `location`...
323+
return location;
324+
});
325+
```
326+
327+
```ts
328+
export function getStackFrameMapper(): StackFrameMapper | null;
329+
```
330+
224331
## "quickjs:engine".formatValue (exported function)
225332

226333
Format a value for debugging using QuickJS's built-in C-level printer.

meta/scripts/lib/generated-doc-links.json5

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
TypeValidator: "/meta/generated-docs/types.md#typevalidator-type",
144144
"JSX.pragma": "/meta/generated-docs/jsx.md#jsxpragma-exported-string",
145145
setMainModule: "/meta/generated-docs/engine.md#quickjsenginesetmainmodule-exported-function",
146+
setStackFrameMapper: "/meta/generated-docs/engine.md#quickjsenginesetstackframemapper-exported-function",
146147
setExitCode: "/meta/generated-docs/cmdline.md#quickjsstdsetexitcode-exported-function",
147148
"FILE.seek": "/meta/generated-docs/std.md#fileseek-method",
148149
"FILE.setvbuf": "/meta/generated-docs/std.md#filesetvbuf-method",
@@ -194,7 +195,7 @@
194195
'"quickjs:os"': "/meta/generated-docs/os.md#quickjsos-namespace",
195196
'"quickjs:bytecode"': "/meta/generated-docs/bytecode.md#quickjsbytecode-namespace",
196197
'"quickjs:context"': "/meta/generated-docs/quickjs-context.md#quickjscontext-namespace",
197-
"import(\"quickjs:context\")": "/meta/generated-docs/quickjs-context.md#quickjscontext-namespace",
198+
'import("quickjs:context")': "/meta/generated-docs/quickjs-context.md#quickjscontext-namespace",
198199
'"quickjs:encoding"': "/meta/generated-docs/encoding.md#quickjsencoding-namespace",
199200
'"quickjs:engine"': "/meta/generated-docs/engine.md#quickjsengine-namespace",
200201
'"quickjs:cmdline"': "/meta/generated-docs/cmdline.md#quickjscmdline-namespace",

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@suchipi/dtsmd": "^1.4.0",
1111
"@suchipi/macaroni": "^0.3.0",
1212
"@suchipi/print": "^2.5.0",
13-
"@suchipi/quickjs": "^0.16.0",
13+
"@suchipi/quickjs": "^0.16.1",
1414
"@suchipi/shinobi": "^3.0.0",
1515
"@types/coffeescript": "^2.5.7",
1616
"@types/minimatch": "^5.1.2",

yavascript.d.ts

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6508,6 +6508,78 @@ declare module "quickjs:engine" {
65086508
*/
65096509
export function gc(): void;
65106510

6511+
/**
6512+
* A callback that translates the location of a stack frame as an error's
6513+
* backtrace is built. See {@link setStackFrameMapper} for details.
6514+
*
6515+
* `line` and `column` are 1-based, both for the values passed in and for the
6516+
* values returned. To change the frame's location, return an object
6517+
* containing all three of `filename`, `line`, and `column`. Return `null` or
6518+
* `undefined` (or an object missing any field) to leave the location
6519+
* unchanged.
6520+
*/
6521+
export type StackFrameMapper = (
6522+
filename: string,
6523+
line: number,
6524+
column: number
6525+
) => { filename: string; line: number; column: number } | null | undefined;
6526+
6527+
/**
6528+
* Register a callback that translates the location of each stack frame as an
6529+
* error's backtrace is built. This is the hook to use for source-map support:
6530+
* the engine itself knows nothing about source maps, so the callback is where
6531+
* you map a compiled `(filename, line, column)` back to its original source
6532+
* location.
6533+
*
6534+
* The callback is invoked once per frame while the backtrace string is being
6535+
* assembled. The location it returns is used both in the human-readable
6536+
* `error.stack` string AND in the `fileName` / `lineNumber` / `columnNumber`
6537+
* own properties set on the error object, so they stay consistent.
6538+
*
6539+
* `line` and `column` are 1-based, both for the values passed to the callback
6540+
* and for the values it returns.
6541+
*
6542+
* To take effect, the callback must return an object containing all three of
6543+
* `filename`, `line`, and `column`. If it instead returns `null` or
6544+
* `undefined`, returns an object missing any of those fields, returns a
6545+
* non-object, or throws, the frame's original location is kept unchanged (a
6546+
* thrown error is swallowed rather than propagated into backtrace
6547+
* construction).
6548+
*
6549+
* Only one mapper can be registered at a time; registering a new one replaces
6550+
* the previous one. Pass `null` or `undefined` to unregister, restoring the
6551+
* default behavior of reporting compiled locations.
6552+
*
6553+
* While the mapper is running, it is temporarily disabled for any error thrown
6554+
* from within it, so an error thrown inside the mapper will not recurse
6555+
* infinitely; that nested error's backtrace simply reports its original
6556+
* (unmapped) locations.
6557+
*
6558+
* @param mapper - The translation callback, or `null`/`undefined` to unregister.
6559+
*/
6560+
export function setStackFrameMapper(
6561+
mapper: StackFrameMapper | null | undefined
6562+
): void;
6563+
6564+
/**
6565+
* Return the stack frame mapper currently registered via
6566+
* {@link setStackFrameMapper}, or `null` if none is registered.
6567+
*
6568+
* This is useful for composing mappers: read the existing one, then register
6569+
* a new mapper that adds your own behavior and delegates to the previous one.
6570+
*
6571+
* ```js
6572+
* const previous = getStackFrameMapper();
6573+
* setStackFrameMapper((filename, line, column) => {
6574+
* const mapped = previous ? previous(filename, line, column) : null;
6575+
* const location = mapped ?? { filename, line, column };
6576+
* // ...apply your own additional adjustments to `location`...
6577+
* return location;
6578+
* });
6579+
* ```
6580+
*/
6581+
export function getStackFrameMapper(): StackFrameMapper | null;
6582+
65116583
/**
65126584
* Format a value for debugging using QuickJS's built-in C-level printer.
65136585
*
@@ -6609,8 +6681,7 @@ declare module "quickjs:bytecode" {
66096681
* To serialize Error instances (including `TypeError`, `RangeError`,
66106682
* `SyntaxError`, `ReferenceError`, `URIError`, `EvalError`,
66116683
* `AggregateError`, and `InternalError`), pass `serializeErrors: true`.
6612-
* Without it, attempting to serialize any Error instance throws
6613-
* "unsupported object class".
6684+
* Without it, attempting to serialize any Error instance throws.
66146685
*/
66156686
export function fromValue(
66166687
value: any,

0 commit comments

Comments
 (0)