xbintsc 0.6.12 → 0.6.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ast/expressions.d.ts +6 -0
- package/dist/src/checker/type-infer.js +1 -1
- package/dist/src/checker/type-infer.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/codegen/generator/calls/literals.js +4 -1
- package/dist/src/codegen/generator/calls/literals.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +3 -1
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/operators.js +2 -6
- package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.d.ts +9 -0
- package/dist/src/codegen/generator/expressions/primary.js +44 -7
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.js +1 -1
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/symbols.js +6 -0
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/features.d.ts +2 -0
- package/dist/src/extensions/gui/features.js +24 -0
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +39 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/node/index.js +2 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/readline/index.d.ts +12 -0
- package/dist/src/extensions/node/readline/index.js +27 -0
- package/dist/src/extensions/node/readline/index.js.map +1 -0
- package/dist/src/parser/declarations/functions.js +6 -0
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/literals.js +1 -1
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +22 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/date-parse.test.js +17 -0
- package/dist/tests/e2e/date-parse.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +61 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-coverage.test.js +39 -0
- package/dist/tests/e2e/gui-css-coverage.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-features.test.js +100 -0
- package/dist/tests/e2e/gui-css-features.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +34 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-errors.test.d.ts +11 -0
- package/dist/tests/e2e/gui-errors.test.js +68 -0
- package/dist/tests/e2e/gui-errors.test.js.map +1 -0
- package/dist/tests/e2e/gui-example-pelican3d.test.d.ts +6 -4
- package/dist/tests/e2e/gui-example-pelican3d.test.js +103 -44
- package/dist/tests/e2e/gui-example-pelican3d.test.js.map +1 -1
- package/dist/tests/e2e/gui-example-webgpu.test.d.ts +9 -0
- package/dist/tests/e2e/gui-example-webgpu.test.js +59 -0
- package/dist/tests/e2e/gui-example-webgpu.test.js.map +1 -0
- package/dist/tests/e2e/gui-helpers.d.ts +1 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js +7 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgpu.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgpu.test.js +402 -0
- package/dist/tests/e2e/gui-webgpu.test.js.map +1 -0
- package/dist/tests/e2e/harness.d.ts +4 -0
- package/dist/tests/e2e/harness.js +2 -0
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/readline.test.d.ts +7 -0
- package/dist/tests/e2e/readline.test.js +73 -0
- package/dist/tests/e2e/readline.test.js.map +1 -0
- package/dist/tests/extensions/gui-features.test.js +18 -1
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/doc/ai/extensions.md +7 -1
- package/doc/ai/zh-CN/extensions.md +6 -1
- package/doc/gui/api.md +15 -0
- package/doc/gui/dom.md +7 -2
- package/doc/gui/known-issues.md +2 -1
- package/doc/gui/layout.md +5 -1
- package/doc/gui/webgpu.md +121 -0
- package/doc/gui.md +12 -1
- package/doc/implemented/node/readline.md +34 -0
- package/doc/implemented/node.md +1 -0
- package/doc/unimplemented/node/modules.md +2 -3
- package/doc/unimplemented/node.md +2 -2
- package/doc/zh-CN/gui/api.md +11 -0
- package/doc/zh-CN/gui/dom.md +6 -2
- package/doc/zh-CN/gui/known-issues.md +2 -1
- package/doc/zh-CN/gui/layout.md +4 -1
- package/doc/zh-CN/gui/webgpu.md +111 -0
- package/doc/zh-CN/gui.md +10 -1
- package/doc/zh-CN/implemented/node/readline.md +33 -0
- package/doc/zh-CN/implemented/node.md +1 -0
- package/doc/zh-CN/unimplemented/node/modules.md +1 -2
- package/doc/zh-CN/unimplemented/node.md +2 -2
- package/llms.txt +1 -0
- package/package.json +7 -7
- package/runtime/ext_gui/browser.cpp +10 -0
- package/runtime/ext_gui/browser_abort.cpp +2 -2
- package/runtime/ext_gui/browser_loop.cpp +1 -0
- package/runtime/ext_gui/browser_media.cpp +1 -1
- package/runtime/ext_gui/dom_api_canvas.cpp +21 -0
- package/runtime/ext_gui/dom_api_canvas_extra.cpp +61 -0
- package/runtime/ext_gui/dom_api_canvas_image.cpp +2 -1
- package/runtime/ext_gui/dom_api_events.cpp +1 -1
- package/runtime/ext_gui/dom_api_internal.h +2 -0
- package/runtime/ext_gui/dom_api_node.cpp +18 -12
- package/runtime/ext_gui/dom_api_node_read.cpp +27 -0
- package/runtime/ext_gui/dom_api_proto.cpp +2 -0
- package/runtime/ext_gui/error_report.cpp +166 -0
- package/runtime/ext_gui/gpu_feature.cpp +2 -0
- package/runtime/ext_gui/gpu_shader_api.h +6 -0
- package/runtime/ext_gui/gui.cpp +16 -0
- package/runtime/ext_gui/gui_canvas.cpp +18 -0
- package/runtime/ext_gui/gui_engine.h +13 -0
- package/runtime/ext_gui/gui_events.cpp +4 -1
- package/runtime/ext_gui/layout_inline.cpp +46 -14
- package/runtime/ext_gui/paint.cpp +22 -0
- package/runtime/ext_gui/renderer_image.cpp +6 -0
- package/runtime/ext_gui/script.cpp +1 -1
- package/runtime/ext_gui/style.cpp +1 -0
- package/runtime/ext_gui/style.h +13 -0
- package/runtime/ext_gui/style_print.cpp +99 -0
- package/runtime/ext_gui/style_text.cpp +79 -0
- package/runtime/ext_gui/webgl_glsl.h +8 -0
- package/runtime/ext_gui/webgl_glsl_compile.cpp +11 -5
- package/runtime/ext_gui/webgl_msl.cpp +20 -9
- package/runtime/ext_gui/webgl_msl.h +4 -0
- package/runtime/ext_gui/webgl_texture.cpp +0 -8
- package/runtime/ext_gui/webgpu.h +371 -0
- package/runtime/ext_gui/webgpu_api.h +42 -0
- package/runtime/ext_gui/webgpu_bindings.cpp +364 -0
- package/runtime/ext_gui/webgpu_bindings.h +59 -0
- package/runtime/ext_gui/webgpu_bridge.c +21 -0
- package/runtime/ext_gui/webgpu_buffer.cpp +293 -0
- package/runtime/ext_gui/webgpu_canvas.cpp +305 -0
- package/runtime/ext_gui/webgpu_command.cpp +510 -0
- package/runtime/ext_gui/webgpu_compute_pass.cpp +138 -0
- package/runtime/ext_gui/webgpu_convert.cpp +309 -0
- package/runtime/ext_gui/webgpu_device.cpp +370 -0
- package/runtime/ext_gui/webgpu_feature.cpp +74 -0
- package/runtime/ext_gui/webgpu_objects.cpp +125 -0
- package/runtime/ext_gui/webgpu_pass.cpp +295 -0
- package/runtime/ext_gui/webgpu_pass.h +33 -0
- package/runtime/ext_gui/webgpu_pipeline.cpp +463 -0
- package/runtime/ext_gui/webgpu_queue.cpp +222 -0
- package/runtime/ext_gui/webgpu_render_pass.cpp +417 -0
- package/runtime/ext_gui/webgpu_resources.cpp +315 -0
- package/runtime/ext_gui/webgpu_shader.cpp +242 -0
- package/runtime/ext_gui/wgsl.h +99 -0
- package/runtime/ext_gui/wgsl_api.cpp +137 -0
- package/runtime/ext_gui/wgsl_ast.h +233 -0
- package/runtime/ext_gui/wgsl_emit.cpp +452 -0
- package/runtime/ext_gui/wgsl_emit.h +128 -0
- package/runtime/ext_gui/wgsl_emit_call.cpp +281 -0
- package/runtime/ext_gui/wgsl_emit_expr.cpp +192 -0
- package/runtime/ext_gui/wgsl_emit_stmt.cpp +209 -0
- package/runtime/ext_gui/wgsl_entry.cpp +189 -0
- package/runtime/ext_gui/wgsl_infer.cpp +171 -0
- package/runtime/ext_gui/wgsl_lexer.cpp +179 -0
- package/runtime/ext_gui/wgsl_lexer.h +32 -0
- package/runtime/ext_gui/wgsl_parse_expr.cpp +215 -0
- package/runtime/ext_gui/wgsl_parse_stmt.cpp +259 -0
- package/runtime/ext_gui/wgsl_parser.cpp +457 -0
- package/runtime/ext_gui/wgsl_parser.h +77 -0
- package/runtime/ext_gui/wgsl_type.cpp +232 -0
- package/runtime/ext_gui/window.cpp +22 -8
- package/runtime/ext_gui/window_emit.cpp +1 -1
- package/runtime/ext_node/fs/parts/platform.inc +2 -0
- package/runtime/ext_node/readline/readline.c +572 -0
- package/runtime/rt.h +15 -0
- package/runtime/rt_internal.h +3 -2
- package/runtime/xt_io/exception.inc +29 -6
- package/runtime/xt_loop.c +36 -1
- package/runtime/xt_promise.c +26 -2
- package/runtime/xt_stdlib2/date.inc +2 -2
- package/runtime/xt_typed_array/elements.inc +0 -9
- package/runtime/xt_url.c +0 -6
- package/runtime/xt_url_object.c +1 -1
- package/src/ast/expressions.ts +6 -0
- package/src/checker/type-infer.ts +1 -1
- package/src/codegen/generator/calls/literals.ts +4 -1
- package/src/codegen/generator/expressions/assignment.ts +3 -1
- package/src/codegen/generator/expressions/operators.ts +2 -6
- package/src/codegen/generator/expressions/primary.ts +58 -6
- package/src/driver/bundler/commonjs.ts +1 -1
- package/src/driver/bundler/symbols.ts +6 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +24 -0
- package/src/extensions/gui/index.ts +39 -0
- package/src/extensions/node/index.ts +2 -0
- package/src/extensions/node/readline/index.ts +31 -0
- package/src/parser/declarations/functions.ts +6 -0
- package/src/parser/literals.ts +1 -1
package/doc/zh-CN/gui.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> 语言 / Language:[English](../gui.md) | **简体中文**
|
|
4
4
|
|
|
5
|
-
状态:**
|
|
5
|
+
状态:**M23** —— 功能(M1–M15)已全部完成:HTML 解析、CSS 选择器匹配、层叠(cascade)、计算样式与布局(块级、行内、Flexbox 与 CSS 定位)均已就位,引擎还会**绘制**:它构建一个由矩形、图像与排版后的文本 run 组成的显示列表,并通过 SDL_GPU 渲染。输入事件会经过命中测试并投递给原生 TS 处理器,`:hover`/`:focus` 会被动态匹配,`<img>` 依据其固有尺寸确定大小并从纹理绘制——位图(PNG/JPEG/…)与 SVG 文件皆可,后者按绘制尺寸光栅化,因此矢量图保持清晰——CSS transition 会为绘制属性做动画。**M16** 让内联 `<svg>` 子树获得同样的处理:子树被序列化回 SVG 文档,并按绘制设备尺寸光栅化,因此图标不再需要单独的文件。**M8** 增加了交互式 DOM:具有稳定标识的元素句柄、变更操作(`appendChild`、`textContent`、`classList`、`style` 等)以及支持捕获/冒泡的元素级事件。**M9** 会提前编译 `<script>` 主体(内联与 `<script src>`)——参见 `gui-scripts.md`。**M10** 增加 `requestAnimationFrame` 以及若干 DOM 辅助方法。**M11** 增加 `position: relative`/`absolute`/`fixed` 及其偏移,`examples/gui/pelican-bike`(一个可玩的 2D 游戏)就构建在它之上。**M12** 明确了 DOM 节点生命周期(哪些变更释放、哪些保留),并让引擎内存有界:参见[节点生命周期](./gui/dom.md)与[内存与 GC](./gui/runtime.md)。**M13** 真正播放
|
|
6
6
|
`<video>`/`<audio>`——可选的 **`media` 链接特性**用 vendored 的最小 FFmpeg 在主线程解码,
|
|
7
7
|
视频帧走图像纹理路径、音频进入 SDL 流,DOM 媒体 API 暴露
|
|
8
8
|
`play`/`pause`/`currentTime`/… 与媒体事件。编译器会从程序里判断是否需要它
|
|
@@ -327,6 +327,15 @@
|
|
|
327
327
|
文档 CSS(`fill`/`stroke`/…)均已生效。
|
|
328
328
|
- e2e:`tests/e2e/gui-css-coverage.test.ts`。
|
|
329
329
|
|
|
330
|
+
23. **M23 — WebGPU** ✅
|
|
331
|
+
- `navigator.gpu`、`getContext("webgpu")` 与整套 `GPU…` 对象模型实现在可选的
|
|
332
|
+
**`webgpu` 链接特性**(依赖 `gpu`)中;WGSL 先翻译为 Vulkan GLSL,由内置
|
|
333
|
+
glslang 编译,Metal 上再由 SPIRV-Cross 转成 MSL。
|
|
334
|
+
- 画布后备缓冲与页面合成器共享(无回读);缓冲、纹理、采样器、bind group、
|
|
335
|
+
render/compute pipeline、命令编码器、render/compute pass、绘制、dispatch、
|
|
336
|
+
拷贝与缓冲映射均已实现;查询/原子/DOM 图像上传会记录校验错误
|
|
337
|
+
(见 [WebGPU](./gui/webgpu.md))。
|
|
338
|
+
- e2e:`tests/e2e/gui-webgpu.test.ts`;示例:`examples/gui/webgpu-triangle`。
|
|
330
339
|
## 进度日志
|
|
331
340
|
|
|
332
341
|
- **M1** ✅ 通用 `xt_loop_poll`/`xt_loop_set_main`;`gui` 扩展骨架。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# `readline`
|
|
2
|
+
|
|
3
|
+
> 属于 [Node 扩展:已实现](../node.md) · [English](../../../implemented/node/readline.md)
|
|
4
|
+
|
|
5
|
+
位置:`src/extensions/node/readline/index.ts`、`runtime/ext_node/readline/readline.c`
|
|
6
|
+
|
|
7
|
+
`createInterface(options)`(以及 `new Interface(options)`)按行读取标准输入。
|
|
8
|
+
阻塞读取运行在异步 I/O 线程池上,因此程序等待输入时事件循环仍会继续处理定时器。
|
|
9
|
+
|
|
10
|
+
| API | 说明 |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `createInterface({ input?, output?, prompt?, terminal? })` | `input`/`output` 仅作声明:实现始终读 stdin、写 stdout。`prompt` 设置初始提示符。 |
|
|
13
|
+
| `rl.on(event, fn)` / `rl.once(...)` / `rl.off(...)` / `rl.removeListener(...)` / `rl.removeAllListeners(...)` | 支持 `line`、`close`、`pause`、`resume` 事件 |
|
|
14
|
+
| `rl.question(query, callback)` | 写出 `query`,用下一行调用 `callback(answer)`;问题按顺序排队,且不触发 `line` |
|
|
15
|
+
| `rl.prompt()` / `rl.setPrompt(text)` / `rl.getPrompt()` | 写出并管理提示符(默认 `"> "`);没有行编辑 |
|
|
16
|
+
| `rl.pause()` / `rl.resume()` | 暂停期间到达的行会缓存,恢复后投递 |
|
|
17
|
+
| `rl.close()` | 触发 `close` 并停止读取;输入结束会自动关闭 |
|
|
18
|
+
| `rl.write(text)` / `rl.setRawMode(bool)` | 写到 stdout;raw mode 作为无操作接受 |
|
|
19
|
+
| `cursorTo(stream, x[, y])`、`moveCursor(stream, dx, dy)`、`clearLine(stream, dir)`、`clearScreenDown(stream)` | 写出 Node 相同的 ANSI 转义序列;stream 参数被忽略 |
|
|
20
|
+
| `emitKeypressEvents(stream[, interface])` | 作为无操作接受 |
|
|
21
|
+
|
|
22
|
+
差异:没有终端行编辑、历史、补全、`readline/promises` 或按键事件合成;
|
|
23
|
+
不会重定向自定义 `input`/`output` 流。
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createInterface } from "readline";
|
|
27
|
+
|
|
28
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
29
|
+
rl.question("name? ", (name: string) => {
|
|
30
|
+
console.log("hello " + name);
|
|
31
|
+
rl.close();
|
|
32
|
+
});
|
|
33
|
+
```
|
|
@@ -31,6 +31,7 @@ TypeScript 导出与 C 实现一一对应。新增模块不需要改动核心编
|
|
|
31
31
|
| `events` | [events](./node/events.md) | `EventEmitter`(全局与具名导出) |
|
|
32
32
|
| `util` | [util](./node/util.md) | 格式化、inspect 与类型谓词 |
|
|
33
33
|
| `querystring` | [querystring](./node/querystring.md) | parse / stringify / escape |
|
|
34
|
+
| `readline` | [readline](./node/readline.md) | 基于 stdin 的逐行/question 读取与光标辅助函数 |
|
|
34
35
|
| `assert` | [assert](./node/assert.md) | 断言函数 |
|
|
35
36
|
| `test` | [test](./node/test.md) | 最小 TAP 运行器 |
|
|
36
37
|
| `crypto` | [crypto](./node/crypto.md) | `createHash`(SHA-1 / SHA-256) |
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
> 属于[Node 扩展:未实现](../node.md) · [English](../../../unimplemented/node/modules.md)
|
|
4
4
|
|
|
5
|
-
以下 Node 内置模块没有任何对应扩展 / 内置函数(`fs` / `fs/promises` / `path` / `os` / `process` / `buffer` / `stream` / `dgram` / `http` / `events` / `util` / `querystring` / `assert` / `test` 已实现,`crypto` / `url` / `child_process` / `zlib` / `stream/promises` / `worker_threads` 部分实现,见[已实现:Node 扩展](../../implemented/node.md)):
|
|
5
|
+
以下 Node 内置模块没有任何对应扩展 / 内置函数(`fs` / `fs/promises` / `path` / `os` / `process` / `buffer` / `stream` / `dgram` / `http` / `events` / `util` / `querystring` / `readline` / `assert` / `test` 已实现,`crypto` / `url` / `child_process` / `zlib` / `stream/promises` / `worker_threads` 部分实现,见[已实现:Node 扩展](../../implemented/node.md)):
|
|
6
6
|
|
|
7
7
|
| 模块 | 说明 |
|
|
8
8
|
| --- | --- |
|
|
9
9
|
| `https` | TLS 版 HTTP |
|
|
10
|
-
| `readline` | 命令行读取 |
|
|
11
10
|
| `tls` / `cluster` / `vm` | 其余未列出的核心模块 |
|
|
12
11
|
|
|
13
12
|
> `crypto`(仅 `createHash`,现支持流式 API)、`url`(仅 `pathToFileURL` / `fileURLToPath`)、
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
> 属于[未实现语法与功能](../unimplemented.md) · [English](../../unimplemented/node.md)
|
|
4
4
|
|
|
5
|
-
Node 扩展实现了
|
|
5
|
+
Node 扩展实现了 22 个模块以及事件循环集成;已实现表面按模块记录在
|
|
6
6
|
[Node 扩展:已实现](../implemented/node.md)。本节记录缺失或与 Node 不同之处。
|
|
7
7
|
|
|
8
8
|
## 目录
|
|
9
9
|
|
|
10
10
|
- [`fs`](./node/fs.md) —— 回调式异步操作、真正的文件监听、选项回调
|
|
11
11
|
- [`fs/promises`](./node/fs-promises.md) —— `FileHandle` 追加/读取偏移、`Dir` 回调立即完成、`watch` 不触发、无取消
|
|
12
|
-
- [完全未实现的模块](./node/modules.md) —— `https`、`
|
|
12
|
+
- [完全未实现的模块](./node/modules.md) —— `https`、`tls`、`cluster`、`vm` 等
|
|
13
13
|
- [全局对象与命名空间](./node/globals.md) —— `global`、`__dirname`、`node_modules` 之外的 `require`
|
|
14
14
|
- [异步与事件循环模型](./node/async.md) —— 文件监听缺失、阻塞式 `net.connect`、无 keep-alive、固定大小线程池
|
|
15
15
|
- [Bun 扩展](./node/bun.md) —— 仅为设计示例
|
package/llms.txt
CHANGED
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
- [doc/gui/runtime.md](https://raw.githubusercontent.com/zy445566/xbintsc/main/doc/gui/runtime.md): event loop integration, the native bridge and memory
|
|
78
78
|
- [doc/gui/canvas.md](https://raw.githubusercontent.com/zy445566/xbintsc/main/doc/gui/canvas.md): `<canvas>` and the 2D context
|
|
79
79
|
- [doc/gui/webgl.md](https://raw.githubusercontent.com/zy445566/xbintsc/main/doc/gui/webgl.md): WebGL 1.0 on the GPU — GLSL ES to SPIR-V, textures, framebuffers and readback
|
|
80
|
+
- [doc/gui/webgpu.md](https://raw.githubusercontent.com/zy445566/xbintsc/main/doc/gui/webgpu.md): WebGPU — navigator.gpu, the GPU object model and WGSL shaders over SDL_GPU
|
|
80
81
|
- [doc/gui/build.md](https://raw.githubusercontent.com/zy445566/xbintsc/main/doc/gui/build.md): building `gui.a` and running the examples
|
|
81
82
|
- [doc/gui/known-issues.md](https://raw.githubusercontent.com/zy445566/xbintsc/main/doc/gui/known-issues.md): known issues and open questions
|
|
82
83
|
- [doc/gui-scripts.md](https://raw.githubusercontent.com/zy445566/xbintsc/main/doc/gui-scripts.md): the GUI scripting surface
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xbintsc",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.17",
|
|
4
4
|
"description": "xbintsc - a TypeScript binary compiler (TypeScript -> LLVM IR -> native binary)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"vitest": "^2.1.8"
|
|
73
73
|
},
|
|
74
74
|
"optionalDependencies": {
|
|
75
|
-
"@xbintsc/linux-x64": "0.6.
|
|
76
|
-
"@xbintsc/linux-arm64": "0.6.
|
|
77
|
-
"@xbintsc/darwin-x64": "0.6.
|
|
78
|
-
"@xbintsc/darwin-arm64": "0.6.
|
|
79
|
-
"@xbintsc/win32-x64": "0.6.
|
|
80
|
-
"@xbintsc/win32-arm64": "0.6.
|
|
75
|
+
"@xbintsc/linux-x64": "0.6.17",
|
|
76
|
+
"@xbintsc/linux-arm64": "0.6.17",
|
|
77
|
+
"@xbintsc/darwin-x64": "0.6.17",
|
|
78
|
+
"@xbintsc/darwin-arm64": "0.6.17",
|
|
79
|
+
"@xbintsc/win32-x64": "0.6.17",
|
|
80
|
+
"@xbintsc/win32-arm64": "0.6.17"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=22"
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
#include "gui_engine.h"
|
|
21
21
|
#include "dom_api_internal.h"
|
|
22
|
+
#include "webgpu_api.h"
|
|
22
23
|
|
|
23
24
|
#include <cstdio>
|
|
24
25
|
#include <string>
|
|
@@ -214,6 +215,11 @@ xt_value navigator_build(void) {
|
|
|
214
215
|
set_number(nav, "maxTouchPoints", 0);
|
|
215
216
|
set_prop(nav, "onLine", XT_TRUE);
|
|
216
217
|
set_prop(nav, "webdriver", XT_FALSE);
|
|
218
|
+
if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
|
|
219
|
+
set_prop(nav, "gpu", webgpu->navigator_gpu());
|
|
220
|
+
} else {
|
|
221
|
+
set_prop(nav, "gpu", XT_UNDEFINED);
|
|
222
|
+
}
|
|
217
223
|
set_method(nav, "vibrate", (void *)noop);
|
|
218
224
|
xt_value languages = xt_array_new(0, NULL);
|
|
219
225
|
xt_array_push(languages, string_of("en-US"));
|
|
@@ -533,6 +539,10 @@ xt_value xt_browser_type(int32_t argc, xt_value *argv) {
|
|
|
533
539
|
name == "DOMParser") {
|
|
534
540
|
return XT_UNDEFINED;
|
|
535
541
|
}
|
|
542
|
+
if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
|
|
543
|
+
xt_value type = webgpu->host_type(name.c_str());
|
|
544
|
+
if (!XT_IS_UNDEFINED(type)) return type;
|
|
545
|
+
}
|
|
536
546
|
return type_value(name);
|
|
537
547
|
}
|
|
538
548
|
|
|
@@ -58,14 +58,14 @@ void call_abort_listener(xt_value fn, xt_value signal) {
|
|
|
58
58
|
xt_object_set(event, xt_string_from_cstr("defaultPrevented"), XT_FALSE);
|
|
59
59
|
if (XT_IS_FUNCTION(fn)) {
|
|
60
60
|
xt_value args[1] = {event};
|
|
61
|
-
|
|
61
|
+
xt_gui_invoke(fn, signal, 1, args);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (XT_IS_OBJECT(fn)) {
|
|
65
65
|
xt_value handler = xt_object_get_cstr(fn, "handleEvent");
|
|
66
66
|
if (XT_IS_FUNCTION(handler)) {
|
|
67
67
|
xt_value args[1] = {event};
|
|
68
|
-
|
|
68
|
+
xt_gui_invoke(handler, fn, 1, args);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -75,6 +75,7 @@ xt_value browser_tick(xt_value self, xt_value env, int32_t argc, xt_value *argv)
|
|
|
75
75
|
if (record == NULL || !record->open) return XT_UNDEFINED;
|
|
76
76
|
xt_gui_pump_events();
|
|
77
77
|
xt_gui_render_window(record);
|
|
78
|
+
xt_promise_report_unhandled();
|
|
78
79
|
if (record->open && !record->animation_frames.empty()) arm_tick();
|
|
79
80
|
return XT_UNDEFINED;
|
|
80
81
|
}
|
|
@@ -54,7 +54,7 @@ void remove_listener(xt_value self, xt_value fn) {
|
|
|
54
54
|
void call_change_listener(xt_value fn, xt_value list, xt_value event) {
|
|
55
55
|
if (!XT_IS_FUNCTION(fn)) return;
|
|
56
56
|
xt_value args[1] = {event};
|
|
57
|
-
|
|
57
|
+
xt_gui_invoke(fn, list, 1, args);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
#define METHOD(name) xt_value name(xt_value self, xt_value env, int32_t argc, xt_value *argv)
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
#include "dom_api_internal.h"
|
|
12
|
+
#include "webgpu_api.h"
|
|
12
13
|
|
|
13
14
|
#include <string>
|
|
14
15
|
#include <vector>
|
|
@@ -86,11 +87,31 @@ METHOD(node_get_context) {
|
|
|
86
87
|
if (value_truthy(xt_object_get_cstr(self, "__xt_gui_offscreen"))) return XT_NULL;
|
|
87
88
|
XtGuiWindow *win = nullptr;
|
|
88
89
|
xtgui::Node *node = resolve_node(self, &win);
|
|
90
|
+
if (mode == "webgpu") {
|
|
91
|
+
const XtWebgpuApi *webgpu = xt_webgpu_api();
|
|
92
|
+
if (webgpu == nullptr) return XT_NULL;
|
|
93
|
+
if (node == nullptr) return XT_NULL;
|
|
94
|
+
if (!node->isElement() || !node->isTag("canvas")) return XT_NULL;
|
|
95
|
+
if (xt_gui_canvas_find(win, node) != nullptr) return XT_NULL;
|
|
96
|
+
if (const XtWebglApi *webgl = xt_webgl_api()) {
|
|
97
|
+
if (webgl->find(win, node) != nullptr) return XT_NULL;
|
|
98
|
+
}
|
|
99
|
+
xt_value cached = xt_object_get_cstr(self, "__xt_gui_webgpu");
|
|
100
|
+
if (XT_IS_OBJECT(cached)) return cached;
|
|
101
|
+
uint32_t context_id = 0;
|
|
102
|
+
if (!webgpu->canvas_get(win, node, &context_id)) return XT_NULL;
|
|
103
|
+
xt_value context = webgpu->handle(self, context_id);
|
|
104
|
+
xt_object_set(self, xt_string_from_cstr("__xt_gui_webgpu"), context);
|
|
105
|
+
return context;
|
|
106
|
+
}
|
|
89
107
|
if (mode == "webgl" || mode == "experimental-webgl" || mode == "webgl2") {
|
|
90
108
|
const bool webgl2 = mode == "webgl2";
|
|
91
109
|
const XtWebglApi *webgl = xt_webgl_api();
|
|
92
110
|
if (webgl == nullptr) return XT_NULL;
|
|
93
111
|
if (node == nullptr) return XT_NULL;
|
|
112
|
+
if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
|
|
113
|
+
if (XT_IS_OBJECT(xt_object_get_cstr(self, "__xt_gui_webgpu"))) return XT_NULL;
|
|
114
|
+
}
|
|
94
115
|
if (!node->isElement() || !node->isTag("canvas")) return XT_NULL;
|
|
95
116
|
if (xt_gui_canvas_find(win, node) != nullptr) return XT_NULL; // already a 2D canvas
|
|
96
117
|
xt_value cached = xt_object_get_cstr(self, "__xt_gui_gl");
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
#include "dom_api_internal.h"
|
|
11
|
+
#include "webgpu_api.h"
|
|
11
12
|
|
|
12
13
|
#include <cmath>
|
|
13
14
|
#include <string>
|
|
@@ -290,6 +291,17 @@ METHOD(node_width_get) {
|
|
|
290
291
|
xtgui::Node *node = resolve_node(self, &win);
|
|
291
292
|
if (node == nullptr || !node->isElement()) return xt_number(0);
|
|
292
293
|
if (node->isTag("canvas")) {
|
|
294
|
+
if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
|
|
295
|
+
xt_value context = xt_object_get_cstr(self, "__xt_gui_webgpu");
|
|
296
|
+
if (XT_IS_OBJECT(context)) {
|
|
297
|
+
float width = 0.0f;
|
|
298
|
+
float height = 0.0f;
|
|
299
|
+
uint64_t id = 0;
|
|
300
|
+
webgpu->info((uint32_t)xt_to_number(xt_object_get_cstr(context, "__xt_webgpu_id")),
|
|
301
|
+
&width, &height, &id);
|
|
302
|
+
return xt_number(width);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
293
305
|
if (const XtWebglApi *webgl = xt_webgl_api()) {
|
|
294
306
|
if (void *context = webgl->find(win, node)) {
|
|
295
307
|
float width = 0.0f;
|
|
@@ -316,6 +328,25 @@ METHOD(node_width_set) {
|
|
|
316
328
|
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
317
329
|
double value = canvas_number_arg(argc, argv, 0, 0.0);
|
|
318
330
|
if (node->isTag("canvas")) {
|
|
331
|
+
if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
|
|
332
|
+
xt_value context = xt_object_get_cstr(self, "__xt_gui_webgpu");
|
|
333
|
+
if (XT_IS_OBJECT(context)) {
|
|
334
|
+
uint32_t context_id =
|
|
335
|
+
(uint32_t)xt_to_number(xt_object_get_cstr(context, "__xt_webgpu_id"));
|
|
336
|
+
float width = 0.0f;
|
|
337
|
+
float height = 0.0f;
|
|
338
|
+
uint64_t canvas_id = 0;
|
|
339
|
+
webgpu->info(context_id, &width, &height, &canvas_id);
|
|
340
|
+
webgpu->resize(context_id, (int)value, (int)height);
|
|
341
|
+
mark_dirty(win);
|
|
342
|
+
if (win->document != nullptr) {
|
|
343
|
+
webgpu->info(context_id, &width, &height, &canvas_id);
|
|
344
|
+
win->document->setCanvasInfo(node, width, height, canvas_id);
|
|
345
|
+
}
|
|
346
|
+
set_attribute(win, node, "width", std::to_string((long long)value));
|
|
347
|
+
return XT_UNDEFINED;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
319
350
|
if (const XtWebglApi *webgl = xt_webgl_api()) {
|
|
320
351
|
if (void *context = webgl->find(win, node)) {
|
|
321
352
|
float width = 0.0f;
|
|
@@ -367,6 +398,17 @@ METHOD(node_height_get) {
|
|
|
367
398
|
xtgui::Node *node = resolve_node(self, &win);
|
|
368
399
|
if (node == nullptr || !node->isElement()) return xt_number(0);
|
|
369
400
|
if (node->isTag("canvas")) {
|
|
401
|
+
if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
|
|
402
|
+
xt_value context = xt_object_get_cstr(self, "__xt_gui_webgpu");
|
|
403
|
+
if (XT_IS_OBJECT(context)) {
|
|
404
|
+
float width = 0.0f;
|
|
405
|
+
float height = 0.0f;
|
|
406
|
+
uint64_t id = 0;
|
|
407
|
+
webgpu->info((uint32_t)xt_to_number(xt_object_get_cstr(context, "__xt_webgpu_id")),
|
|
408
|
+
&width, &height, &id);
|
|
409
|
+
return xt_number(height);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
370
412
|
if (const XtWebglApi *webgl = xt_webgl_api()) {
|
|
371
413
|
if (void *context = webgl->find(win, node)) {
|
|
372
414
|
float width = 0.0f;
|
|
@@ -392,6 +434,25 @@ METHOD(node_height_set) {
|
|
|
392
434
|
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
393
435
|
double value = canvas_number_arg(argc, argv, 0, 0.0);
|
|
394
436
|
if (node->isTag("canvas")) {
|
|
437
|
+
if (const XtWebgpuApi *webgpu = xt_webgpu_api()) {
|
|
438
|
+
xt_value context = xt_object_get_cstr(self, "__xt_gui_webgpu");
|
|
439
|
+
if (XT_IS_OBJECT(context)) {
|
|
440
|
+
uint32_t context_id =
|
|
441
|
+
(uint32_t)xt_to_number(xt_object_get_cstr(context, "__xt_webgpu_id"));
|
|
442
|
+
float width = 0.0f;
|
|
443
|
+
float height = 0.0f;
|
|
444
|
+
uint64_t canvas_id = 0;
|
|
445
|
+
webgpu->info(context_id, &width, &height, &canvas_id);
|
|
446
|
+
webgpu->resize(context_id, (int)width, (int)value);
|
|
447
|
+
mark_dirty(win);
|
|
448
|
+
if (win->document != nullptr) {
|
|
449
|
+
webgpu->info(context_id, &width, &height, &canvas_id);
|
|
450
|
+
win->document->setCanvasInfo(node, width, height, canvas_id);
|
|
451
|
+
}
|
|
452
|
+
set_attribute(win, node, "height", std::to_string((long long)value));
|
|
453
|
+
return XT_UNDEFINED;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
395
456
|
if (const XtWebglApi *webgl = xt_webgl_api()) {
|
|
396
457
|
if (void *context = webgl->find(win, node)) {
|
|
397
458
|
float width = 0.0f;
|
|
@@ -114,7 +114,8 @@ xt_value blob_callback(xt_value self, xt_value env, int32_t argc, xt_value *argv
|
|
|
114
114
|
xt_value fn = xt_closure_env(env, 0);
|
|
115
115
|
xt_value blob = xt_closure_env(env, 1);
|
|
116
116
|
xt_value args[1] = {blob};
|
|
117
|
-
|
|
117
|
+
xt_gui_invoke(fn, XT_UNDEFINED, 1, args);
|
|
118
|
+
return XT_UNDEFINED;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
} // namespace
|
|
@@ -117,7 +117,7 @@ static bool call_node_listeners(XtGuiWindow *win, xtgui::Node *node, const char
|
|
|
117
117
|
xt_object_set(event, xt_string_from_cstr("__xt_gui_passive"),
|
|
118
118
|
listener.passive ? XT_TRUE : XT_FALSE);
|
|
119
119
|
xt_value args[1] = {event};
|
|
120
|
-
|
|
120
|
+
xt_gui_invoke(listener.fn, self, 1, args);
|
|
121
121
|
xt_object_set(event, xt_string_from_cstr("__xt_gui_passive"), previousPassive);
|
|
122
122
|
if (value_truthy(xt_object_get_cstr(event, "__stopImmediate"))) return true;
|
|
123
123
|
if (value_truthy(xt_object_get_cstr(event, "__stop"))) return true;
|
|
@@ -176,6 +176,8 @@ METHOD(node_id_get);
|
|
|
176
176
|
METHOD(node_id_set);
|
|
177
177
|
METHOD(node_class_name_get);
|
|
178
178
|
METHOD(node_class_name_set);
|
|
179
|
+
METHOD(node_html_for_get);
|
|
180
|
+
METHOD(node_html_for_set);
|
|
179
181
|
METHOD(node_text_content_get);
|
|
180
182
|
METHOD(node_text_content_set);
|
|
181
183
|
METHOD(node_inner_html_get);
|
|
@@ -214,25 +214,31 @@ METHOD(node_get_bounding_rect) {
|
|
|
214
214
|
(void)env;
|
|
215
215
|
(void)argc;
|
|
216
216
|
(void)argv;
|
|
217
|
+
/* Like the DOM, an element with no layout box (`display: none`, a detached
|
|
218
|
+
* node, or a stale handle) still returns a rectangle, all zeroes. Returning
|
|
219
|
+
* `undefined` made every hidden-state measurement in UI code fail. */
|
|
220
|
+
auto rectangle = [](float x, float y, float width, float height) {
|
|
221
|
+
xt_value object = xt_object_new();
|
|
222
|
+
xt_object_set(object, xt_string_from_cstr("x"), xt_number(x));
|
|
223
|
+
xt_object_set(object, xt_string_from_cstr("y"), xt_number(y));
|
|
224
|
+
xt_object_set(object, xt_string_from_cstr("width"), xt_number(width));
|
|
225
|
+
xt_object_set(object, xt_string_from_cstr("height"), xt_number(height));
|
|
226
|
+
xt_object_set(object, xt_string_from_cstr("top"), xt_number(y));
|
|
227
|
+
xt_object_set(object, xt_string_from_cstr("right"), xt_number(x + width));
|
|
228
|
+
xt_object_set(object, xt_string_from_cstr("bottom"), xt_number(y + height));
|
|
229
|
+
xt_object_set(object, xt_string_from_cstr("left"), xt_number(x));
|
|
230
|
+
return object;
|
|
231
|
+
};
|
|
217
232
|
XtGuiWindow *win = nullptr;
|
|
218
233
|
xtgui::Node *node = resolve_node(self, &win);
|
|
219
|
-
if (node == nullptr || win == nullptr || win->document == nullptr) return
|
|
234
|
+
if (node == nullptr || win == nullptr || win->document == nullptr) return rectangle(0, 0, 0, 0);
|
|
220
235
|
const xtgui::LayoutBox *box = win->document->boxOf(node);
|
|
221
|
-
if (box == nullptr) return
|
|
236
|
+
if (box == nullptr) return rectangle(0, 0, 0, 0);
|
|
222
237
|
/* Like the DOM: the rectangle of the *transformed* border box. The legacy
|
|
223
238
|
* `top`/`right`/`bottom`/`left` members are the same rectangle in the other
|
|
224
239
|
* spelling; libraries read both. */
|
|
225
240
|
xtgui::LayoutRect rect = xtgui::xt_layout_transformed_bounds(box);
|
|
226
|
-
|
|
227
|
-
xt_object_set(object, xt_string_from_cstr("x"), xt_number(rect.x));
|
|
228
|
-
xt_object_set(object, xt_string_from_cstr("y"), xt_number(rect.y));
|
|
229
|
-
xt_object_set(object, xt_string_from_cstr("width"), xt_number(rect.width));
|
|
230
|
-
xt_object_set(object, xt_string_from_cstr("height"), xt_number(rect.height));
|
|
231
|
-
xt_object_set(object, xt_string_from_cstr("top"), xt_number(rect.y));
|
|
232
|
-
xt_object_set(object, xt_string_from_cstr("right"), xt_number(rect.x + rect.width));
|
|
233
|
-
xt_object_set(object, xt_string_from_cstr("bottom"), xt_number(rect.y + rect.height));
|
|
234
|
-
xt_object_set(object, xt_string_from_cstr("left"), xt_number(rect.x));
|
|
235
|
-
return object;
|
|
241
|
+
return rectangle(rect.x, rect.y, rect.width, rect.height);
|
|
236
242
|
}
|
|
237
243
|
|
|
238
244
|
METHOD(node_offset_width_get) {
|
|
@@ -102,6 +102,33 @@ METHOD(node_id_set) {
|
|
|
102
102
|
return XT_UNDEFINED;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/** `label.htmlFor` reflects the `for` attribute (`""` when absent). */
|
|
106
|
+
METHOD(node_html_for_get) {
|
|
107
|
+
(void)env;
|
|
108
|
+
(void)argc;
|
|
109
|
+
(void)argv;
|
|
110
|
+
xtgui::Node *node = resolve_node(self, nullptr);
|
|
111
|
+
if (node == nullptr || !node->isElement()) return xt_string_from_cstr("");
|
|
112
|
+
const std::string *value = node->attr("for");
|
|
113
|
+
return xt_string_from_cstr(value != nullptr ? value->c_str() : "");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
METHOD(node_html_for_set) {
|
|
117
|
+
(void)env;
|
|
118
|
+
XtGuiWindow *win = nullptr;
|
|
119
|
+
xtgui::Node *node = resolve_node(self, &win);
|
|
120
|
+
if (node == nullptr || !node->isElement()) return XT_UNDEFINED;
|
|
121
|
+
std::string value = argc >= 1 ? to_string_value(xt_arg(argc, argv, 0)) : "";
|
|
122
|
+
/* HTML reflects an empty `htmlFor` as a missing attribute. */
|
|
123
|
+
if (value.empty()) {
|
|
124
|
+
remove_attribute_raw(node, "for");
|
|
125
|
+
mark_dirty(win);
|
|
126
|
+
} else {
|
|
127
|
+
set_attribute(win, node, "for", value);
|
|
128
|
+
}
|
|
129
|
+
return XT_UNDEFINED;
|
|
130
|
+
}
|
|
131
|
+
|
|
105
132
|
METHOD(node_class_name_get) {
|
|
106
133
|
(void)env;
|
|
107
134
|
(void)argc;
|
|
@@ -32,6 +32,7 @@ xt_value node_proto() {
|
|
|
32
32
|
define_getter(proto, "prefix", (void *)node_prefix_get);
|
|
33
33
|
define_getter(proto, "id", (void *)node_id_get);
|
|
34
34
|
define_getter(proto, "className", (void *)node_class_name_get);
|
|
35
|
+
define_getter(proto, "htmlFor", (void *)node_html_for_get);
|
|
35
36
|
define_getter(proto, "textContent", (void *)node_text_content_get);
|
|
36
37
|
define_getter(proto, "innerText", (void *)node_text_content_get);
|
|
37
38
|
define_getter(proto, "innerHTML", (void *)node_inner_html_get);
|
|
@@ -92,6 +93,7 @@ xt_value node_proto() {
|
|
|
92
93
|
/* Setters. */
|
|
93
94
|
define_setter(proto, "id", (void *)node_id_set);
|
|
94
95
|
define_setter(proto, "className", (void *)node_class_name_set);
|
|
96
|
+
define_setter(proto, "htmlFor", (void *)node_html_for_set);
|
|
95
97
|
define_setter(proto, "textContent", (void *)node_text_content_set);
|
|
96
98
|
define_setter(proto, "innerText", (void *)node_text_content_set);
|
|
97
99
|
define_setter(proto, "innerHTML", (void *)node_inner_html_set);
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — page-level error reporting.
|
|
3
|
+
*
|
|
4
|
+
* A callback the engine invokes (an element listener, a window listener, a
|
|
5
|
+
* timer, an animation frame, a media event) can throw. Without a boundary that
|
|
6
|
+
* exception reaches `xt_throw` with no `try` frame, prints to stderr and calls
|
|
7
|
+
* `exit(1)`; in a GUI program the only visible effect is the window vanishing.
|
|
8
|
+
* `xt_gui_invoke` runs such callbacks under a `try` frame and hands the value
|
|
9
|
+
* to `xt_gui_report_uncaught`, which mirrors the browser surfaces:
|
|
10
|
+
*
|
|
11
|
+
* - `window.onerror(message, source, line, column, error)`
|
|
12
|
+
* - `window.addEventListener("error", handler)` (an ErrorEvent-like object)
|
|
13
|
+
* - `window.onunhandledrejection` / the `unhandledrejection` event
|
|
14
|
+
*
|
|
15
|
+
* Reporting never terminates the program, so one bad handler cannot take the
|
|
16
|
+
* page (or the other listeners) down. A throw inside the reporter itself is
|
|
17
|
+
* only logged, which also breaks the recursion an error listener could cause.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#include "dom_api_internal.h"
|
|
21
|
+
#include "gui_engine.h"
|
|
22
|
+
|
|
23
|
+
#include <setjmp.h>
|
|
24
|
+
#include <cstdio>
|
|
25
|
+
#include <string>
|
|
26
|
+
|
|
27
|
+
namespace {
|
|
28
|
+
|
|
29
|
+
/** Set while a report (and the handlers it runs) is in progress. */
|
|
30
|
+
bool g_reporting = false;
|
|
31
|
+
|
|
32
|
+
std::string to_std_string(xt_value value) {
|
|
33
|
+
const char *data = xt_string_data(xt_to_string(value));
|
|
34
|
+
return data != nullptr ? std::string(data) : std::string();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
std::string error_message(xt_value error) {
|
|
38
|
+
if (XT_IS_OBJECT(error)) {
|
|
39
|
+
xt_value message = xt_object_get_cstr(error, "message");
|
|
40
|
+
if (XT_IS_STRING(message)) {
|
|
41
|
+
const char *data = xt_string_data(message);
|
|
42
|
+
if (data != nullptr) return std::string(data);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to_std_string(error);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
xt_value set_field(xt_value object, const char *key, xt_value value) {
|
|
49
|
+
xt_object_set(object, xt_string_from_cstr(key), value);
|
|
50
|
+
return object;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Common Event fields; `event_proto` supplies `preventDefault()`. */
|
|
54
|
+
xt_value make_event(const char *type, XtGuiWindow *win) {
|
|
55
|
+
xt_value event = xt_object_new_with_proto(domapi::event_proto());
|
|
56
|
+
set_field(event, "type", xt_string_from_cstr(type));
|
|
57
|
+
set_field(event, "target", win->object);
|
|
58
|
+
set_field(event, "currentTarget", win->object);
|
|
59
|
+
set_field(event, "defaultPrevented", XT_FALSE);
|
|
60
|
+
set_field(event, "bubbles", XT_FALSE);
|
|
61
|
+
set_field(event, "cancelable", XT_TRUE);
|
|
62
|
+
set_field(event, "isTrusted", XT_TRUE);
|
|
63
|
+
set_field(event, "eventPhase", xt_number(2));
|
|
64
|
+
set_field(event, "timeStamp", xt_number(0));
|
|
65
|
+
return event;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void log_uncaught(const std::string &message) {
|
|
69
|
+
std::fprintf(stderr, "Uncaught %s\n", message.c_str());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
} // namespace
|
|
73
|
+
|
|
74
|
+
extern "C" void xt_gui_install_error_handlers(void) {
|
|
75
|
+
xt_set_uncaught_exception_handler(xt_gui_report_uncaught);
|
|
76
|
+
xt_set_unhandled_rejection_handler(xt_gui_unhandled_rejection);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
extern "C" void xt_gui_report_uncaught(xt_value error) {
|
|
80
|
+
std::string message = error_message(error);
|
|
81
|
+
if (g_reporting) {
|
|
82
|
+
log_uncaught(message);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
XtGuiWindow *win = xt_gui_primary_window();
|
|
86
|
+
if (win == nullptr) {
|
|
87
|
+
log_uncaught(message);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
g_reporting = true;
|
|
91
|
+
|
|
92
|
+
xt_value event = make_event("error", win);
|
|
93
|
+
set_field(event, "message", xt_string_from_cstr(message.c_str()));
|
|
94
|
+
set_field(event, "filename", xt_string_from_cstr(""));
|
|
95
|
+
set_field(event, "lineno", xt_number(0));
|
|
96
|
+
set_field(event, "colno", xt_number(0));
|
|
97
|
+
set_field(event, "error", error);
|
|
98
|
+
|
|
99
|
+
/* The classic `onerror` signature, then every `error` listener. Either can
|
|
100
|
+
* call the event's `preventDefault()` (or `onerror` can return true) to
|
|
101
|
+
* suppress the default log line. */
|
|
102
|
+
int prevented = 0;
|
|
103
|
+
xt_value handler = xt_object_get_cstr(win->object, "onerror");
|
|
104
|
+
if (XT_IS_FUNCTION(handler)) {
|
|
105
|
+
xt_value args[5] = {
|
|
106
|
+
xt_string_from_cstr(message.c_str()),
|
|
107
|
+
xt_string_from_cstr(""),
|
|
108
|
+
xt_number(0),
|
|
109
|
+
xt_number(0),
|
|
110
|
+
error,
|
|
111
|
+
};
|
|
112
|
+
prevented = xt_truthy(xt_call_with_this(handler, win->object, 5, args));
|
|
113
|
+
}
|
|
114
|
+
xt_gui_emit_payload(win, "error", event);
|
|
115
|
+
if (xt_truthy(xt_object_get_cstr(event, "defaultPrevented"))) prevented = 1;
|
|
116
|
+
if (!prevented) log_uncaught(message);
|
|
117
|
+
|
|
118
|
+
g_reporting = false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
extern "C" int xt_gui_unhandled_rejection(xt_value reason, xt_value promise) {
|
|
122
|
+
XtGuiWindow *win = xt_gui_primary_window();
|
|
123
|
+
if (win == nullptr) return 0;
|
|
124
|
+
std::string message = error_message(reason);
|
|
125
|
+
if (g_reporting) {
|
|
126
|
+
std::fprintf(stderr, "Unhandled promise rejection\n%s\n", message.c_str());
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
g_reporting = true;
|
|
130
|
+
|
|
131
|
+
xt_value event = make_event("unhandledrejection", win);
|
|
132
|
+
set_field(event, "reason", reason);
|
|
133
|
+
set_field(event, "promise", promise);
|
|
134
|
+
set_field(event, "message", xt_string_from_cstr(message.c_str()));
|
|
135
|
+
|
|
136
|
+
xt_value handler = xt_object_get_cstr(win->object, "onunhandledrejection");
|
|
137
|
+
if (XT_IS_FUNCTION(handler)) {
|
|
138
|
+
xt_value args[1] = {event};
|
|
139
|
+
xt_call_with_this(handler, win->object, 1, args);
|
|
140
|
+
}
|
|
141
|
+
xt_gui_emit_payload(win, "unhandledrejection", event);
|
|
142
|
+
if (!xt_truthy(xt_object_get_cstr(event, "defaultPrevented"))) {
|
|
143
|
+
std::fprintf(stderr, "Unhandled promise rejection\n%s\n", message.c_str());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
g_reporting = false;
|
|
147
|
+
/* The page owns the rejection now; never turn it into a fatal process exit. */
|
|
148
|
+
return 1;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
extern "C" int xt_gui_invoke(xt_value fn, xt_value thisValue, int32_t argc, xt_value *argv) {
|
|
152
|
+
if (!XT_IS_FUNCTION(fn)) return 1;
|
|
153
|
+
void *frame = xt_try_enter();
|
|
154
|
+
/* `xt_try_frame` starts with the setjmp buffer; the longjmp in `xt_throw`
|
|
155
|
+
* returns here and the C++ frames between the callback and this boundary
|
|
156
|
+
* hold no destructible state. */
|
|
157
|
+
if (_setjmp(*(jmp_buf *)frame) == 0) {
|
|
158
|
+
xt_call_with_this(fn, thisValue, argc, argv);
|
|
159
|
+
xt_try_leave(frame);
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
xt_value error = xt_try_exception(frame);
|
|
163
|
+
xt_try_leave(frame);
|
|
164
|
+
xt_gui_report_uncaught(error);
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
@@ -18,9 +18,11 @@ const xtgui::GpuShaderApi kGpuShaderApi = {
|
|
|
18
18
|
xtgui::scan_glsl,
|
|
19
19
|
xtgui::rewrite_glsl,
|
|
20
20
|
xtgui::compile_glsl,
|
|
21
|
+
xtgui::compile_glsl_stage,
|
|
21
22
|
xtgui::reflect_uniform_block,
|
|
22
23
|
xtgui::reflect_attributes,
|
|
23
24
|
xtgui::cross_compile_msl,
|
|
25
|
+
xtgui::cross_compile_msl_stage,
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
} // namespace
|