xbintsc 0.7.0 → 0.7.7

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.
Files changed (351) hide show
  1. package/dist/src/ast/common.d.ts +10 -0
  2. package/dist/src/binder/references.js +13 -7
  3. package/dist/src/binder/references.js.map +1 -1
  4. package/dist/src/checker/source.js +4 -0
  5. package/dist/src/checker/source.js.map +1 -1
  6. package/dist/src/cli/help.d.ts +1 -1
  7. package/dist/src/cli/main.js +15 -3
  8. package/dist/src/cli/main.js.map +1 -1
  9. package/dist/src/codegen/generator/calls/access.js +4 -11
  10. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  11. package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
  12. package/dist/src/codegen/generator/calls/element-inline.js +388 -0
  13. package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
  14. package/dist/src/codegen/generator/calls/invocation.js +82 -1
  15. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  16. package/dist/src/codegen/generator/calls.d.ts +3 -1
  17. package/dist/src/codegen/generator/calls.js +3 -1
  18. package/dist/src/codegen/generator/calls.js.map +1 -1
  19. package/dist/src/codegen/generator/debug.js +20 -3
  20. package/dist/src/codegen/generator/debug.js.map +1 -1
  21. package/dist/src/codegen/generator/expressions/assignment.js +10 -2
  22. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  23. package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
  24. package/dist/src/codegen/generator/expressions/global-values.js +49 -0
  25. package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
  26. package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
  27. package/dist/src/codegen/generator/expressions/primary.js +4 -24
  28. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  29. package/dist/src/codegen/generator/expressions.d.ts +2 -1
  30. package/dist/src/codegen/generator/expressions.js +2 -1
  31. package/dist/src/codegen/generator/expressions.js.map +1 -1
  32. package/dist/src/codegen/generator/layout.d.ts +65 -0
  33. package/dist/src/codegen/generator/layout.js +50 -0
  34. package/dist/src/codegen/generator/layout.js.map +1 -0
  35. package/dist/src/codegen/generator/state.js +4 -0
  36. package/dist/src/codegen/generator/state.js.map +1 -1
  37. package/dist/src/diagnostics/diagnostic.js +1 -1
  38. package/dist/src/diagnostics/diagnostic.js.map +1 -1
  39. package/dist/src/diagnostics/source-text.d.ts +37 -9
  40. package/dist/src/diagnostics/source-text.js +124 -23
  41. package/dist/src/diagnostics/source-text.js.map +1 -1
  42. package/dist/src/diagnostics/source.d.ts +16 -6
  43. package/dist/src/diagnostics/source.js +25 -4
  44. package/dist/src/diagnostics/source.js.map +1 -1
  45. package/dist/src/driver/build-key.d.ts +14 -0
  46. package/dist/src/driver/build-key.js +6 -1
  47. package/dist/src/driver/build-key.js.map +1 -1
  48. package/dist/src/driver/bundler/concatenate.js +11 -4
  49. package/dist/src/driver/bundler/concatenate.js.map +1 -1
  50. package/dist/src/driver/bundler/graph.js +2 -2
  51. package/dist/src/driver/bundler/graph.js.map +1 -1
  52. package/dist/src/driver/bundler/merge.js +11 -5
  53. package/dist/src/driver/bundler/merge.js.map +1 -1
  54. package/dist/src/driver/bundler/reexport-resolution.js +3 -0
  55. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
  56. package/dist/src/driver/compiler.js +13 -3
  57. package/dist/src/driver/compiler.js.map +1 -1
  58. package/dist/src/driver/frontend.js +3 -4
  59. package/dist/src/driver/frontend.js.map +1 -1
  60. package/dist/src/driver/runtime-objects.d.ts +1 -1
  61. package/dist/src/driver/runtime-objects.js +4 -0
  62. package/dist/src/driver/runtime-objects.js.map +1 -1
  63. package/dist/src/driver/toolchain.js +28 -5
  64. package/dist/src/driver/toolchain.js.map +1 -1
  65. package/dist/src/driver/version.d.ts +1 -1
  66. package/dist/src/driver/version.js +1 -1
  67. package/dist/src/extensions/gui/html.js +42 -10
  68. package/dist/src/extensions/gui/html.js.map +1 -1
  69. package/dist/src/extensions/gui/index.js +53 -0
  70. package/dist/src/extensions/gui/index.js.map +1 -1
  71. package/dist/src/extensions/registry.d.ts +20 -0
  72. package/dist/src/extensions/registry.js.map +1 -1
  73. package/dist/src/parser/expressions.js +2 -2
  74. package/dist/src/parser/expressions.js.map +1 -1
  75. package/dist/src/parser/helpers.d.ts +8 -0
  76. package/dist/src/parser/helpers.js +21 -0
  77. package/dist/src/parser/helpers.js.map +1 -1
  78. package/dist/tests/binder/binder.test.js +26 -4
  79. package/dist/tests/binder/binder.test.js.map +1 -1
  80. package/dist/tests/checker/checker.test.js +16 -0
  81. package/dist/tests/checker/checker.test.js.map +1 -1
  82. package/dist/tests/cli/main.test.js +9 -0
  83. package/dist/tests/cli/main.test.js.map +1 -1
  84. package/dist/tests/codegen/element-layout.test.d.ts +19 -0
  85. package/dist/tests/codegen/element-layout.test.js +80 -0
  86. package/dist/tests/codegen/element-layout.test.js.map +1 -0
  87. package/dist/tests/codegen/expressions.test.js +25 -0
  88. package/dist/tests/codegen/expressions.test.js.map +1 -1
  89. package/dist/tests/codegen/llvm.test.js +13 -0
  90. package/dist/tests/codegen/llvm.test.js.map +1 -1
  91. package/dist/tests/diagnostics/diagnostic.test.js +9 -0
  92. package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
  93. package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
  94. package/dist/tests/diagnostics/source-text.test.js +50 -0
  95. package/dist/tests/diagnostics/source-text.test.js.map +1 -0
  96. package/dist/tests/diagnostics/source.test.js +17 -0
  97. package/dist/tests/diagnostics/source.test.js.map +1 -1
  98. package/dist/tests/driver/build-key.test.d.ts +1 -0
  99. package/dist/tests/driver/build-key.test.js +49 -0
  100. package/dist/tests/driver/build-key.test.js.map +1 -0
  101. package/dist/tests/driver/toolchain.test.js +8 -1
  102. package/dist/tests/driver/toolchain.test.js.map +1 -1
  103. package/dist/tests/driver/usage.test.js +2 -1
  104. package/dist/tests/driver/usage.test.js.map +1 -1
  105. package/dist/tests/e2e/async-await.test.js +16 -0
  106. package/dist/tests/e2e/async-await.test.js.map +1 -1
  107. package/dist/tests/e2e/compile-builtins.test.js +29 -0
  108. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  109. package/dist/tests/e2e/compile-modules.test.js +13 -0
  110. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  111. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  112. package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
  113. package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
  114. package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
  115. package/dist/tests/e2e/differential-language.test.js +25 -0
  116. package/dist/tests/e2e/differential-language.test.js.map +1 -1
  117. package/dist/tests/e2e/differential-values.test.js +59 -0
  118. package/dist/tests/e2e/differential-values.test.js.map +1 -1
  119. package/dist/tests/e2e/gc.test.js +22 -0
  120. package/dist/tests/e2e/gc.test.js.map +1 -1
  121. package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
  122. package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
  123. package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
  124. package/dist/tests/e2e/gui-browser.test.js +66 -2
  125. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  126. package/dist/tests/e2e/gui-dom.test.js +88 -0
  127. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  128. package/dist/tests/e2e/gui-events.test.js +89 -0
  129. package/dist/tests/e2e/gui-events.test.js.map +1 -1
  130. package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
  131. package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
  132. package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
  133. package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
  134. package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
  135. package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
  136. package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
  137. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
  138. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
  139. package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
  140. package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
  141. package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
  142. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
  143. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
  144. package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
  145. package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
  146. package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
  147. package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
  148. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
  149. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
  150. package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
  151. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
  152. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
  153. package/dist/tests/e2e/gui-webgl2.test.js +59 -1
  154. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
  155. package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
  156. package/dist/tests/e2e/hang-watchdog.test.js +50 -0
  157. package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
  158. package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
  159. package/dist/tests/e2e/method-call-cache.test.js +65 -0
  160. package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
  161. package/dist/tests/e2e/performance-now.test.d.ts +9 -0
  162. package/dist/tests/e2e/performance-now.test.js +36 -0
  163. package/dist/tests/e2e/performance-now.test.js.map +1 -0
  164. package/dist/tests/e2e/property-ic.test.js +33 -0
  165. package/dist/tests/e2e/property-ic.test.js.map +1 -1
  166. package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
  167. package/dist/tests/e2e/shape-interning.test.js +55 -0
  168. package/dist/tests/e2e/shape-interning.test.js.map +1 -0
  169. package/dist/tests/e2e/string-utf16.test.js +9 -0
  170. package/dist/tests/e2e/string-utf16.test.js.map +1 -1
  171. package/dist/tests/e2e/typed-array-views.test.js +26 -0
  172. package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
  173. package/dist/tests/e2e/url-search-params.test.js +19 -0
  174. package/dist/tests/e2e/url-search-params.test.js.map +1 -1
  175. package/dist/tests/extensions/gui.test.js +16 -1
  176. package/dist/tests/extensions/gui.test.js.map +1 -1
  177. package/dist/tests/helpers.js +1 -0
  178. package/dist/tests/helpers.js.map +1 -1
  179. package/dist/tests/parser/expressions.test.js +36 -0
  180. package/dist/tests/parser/expressions.test.js.map +1 -1
  181. package/doc/ai/contributing.md +8 -5
  182. package/doc/ai/extensions.md +12 -3
  183. package/doc/ai/language-support.md +2 -1
  184. package/doc/ai/troubleshooting.md +14 -0
  185. package/doc/ai/zh-CN/contributing.md +6 -3
  186. package/doc/ai/zh-CN/extensions.md +10 -2
  187. package/doc/ai/zh-CN/language-support.md +2 -1
  188. package/doc/ai/zh-CN/troubleshooting.md +12 -0
  189. package/doc/gui/api.md +35 -4
  190. package/doc/gui/dom.md +8 -0
  191. package/doc/gui/input.md +8 -0
  192. package/doc/gui/known-issues.md +43 -6
  193. package/doc/gui/runtime.md +16 -1
  194. package/doc/gui/webgl.md +97 -26
  195. package/doc/gui-scripts.md +2 -1
  196. package/doc/gui.md +8 -5
  197. package/doc/implemented/binder.md +1 -1
  198. package/doc/implemented/checker.md +9 -0
  199. package/doc/implemented/codegen.md +7 -0
  200. package/doc/implemented/parser.md +2 -1
  201. package/doc/implemented/runtime-core.md +9 -2
  202. package/doc/implemented/stdlib.md +10 -2
  203. package/doc/implemented/typed-arrays.md +18 -2
  204. package/doc/zh-CN/gui/api.md +27 -5
  205. package/doc/zh-CN/gui/dom.md +6 -0
  206. package/doc/zh-CN/gui/input.md +7 -0
  207. package/doc/zh-CN/gui/known-issues.md +30 -5
  208. package/doc/zh-CN/gui/runtime.md +13 -1
  209. package/doc/zh-CN/gui/webgl.md +20 -7
  210. package/doc/zh-CN/gui-scripts.md +2 -1
  211. package/doc/zh-CN/gui.md +4 -1
  212. package/doc/zh-CN/implemented/binder.md +1 -1
  213. package/doc/zh-CN/implemented/checker.md +7 -0
  214. package/doc/zh-CN/implemented/codegen.md +7 -0
  215. package/doc/zh-CN/implemented/parser.md +2 -1
  216. package/doc/zh-CN/implemented/runtime-core.md +9 -2
  217. package/doc/zh-CN/implemented/stdlib.md +6 -2
  218. package/doc/zh-CN/implemented/typed-arrays.md +14 -2
  219. package/package.json +7 -7
  220. package/runtime/ext_gui/audio.cpp +39 -3
  221. package/runtime/ext_gui/audio_extra.cpp +353 -0
  222. package/runtime/ext_gui/audio_extra.h +47 -0
  223. package/runtime/ext_gui/audio_fft.h +76 -0
  224. package/runtime/ext_gui/audio_internal.h +21 -0
  225. package/runtime/ext_gui/audio_mixer.cpp +46 -1
  226. package/runtime/ext_gui/audio_mixer.h +89 -1
  227. package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
  228. package/runtime/ext_gui/audio_nodes.cpp +242 -0
  229. package/runtime/ext_gui/audio_nodes_internal.h +81 -0
  230. package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
  231. package/runtime/ext_gui/browser.cpp +11 -0
  232. package/runtime/ext_gui/browser_screen.cpp +73 -0
  233. package/runtime/ext_gui/dom_api.cpp +4 -0
  234. package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
  235. package/runtime/ext_gui/dom_api_events.cpp +2 -1
  236. package/runtime/ext_gui/dom_api_internal.h +11 -0
  237. package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
  238. package/runtime/ext_gui/dom_api_node.cpp +21 -0
  239. package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
  240. package/runtime/ext_gui/dom_api_proto.cpp +6 -0
  241. package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
  242. package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
  243. package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
  244. package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
  245. package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
  246. package/runtime/ext_gui/dom_api_webgl_state.cpp +11 -2
  247. package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
  248. package/runtime/ext_gui/gui.cpp +8 -1
  249. package/runtime/ext_gui/gui_engine.h +20 -2
  250. package/runtime/ext_gui/gui_events.cpp +31 -126
  251. package/runtime/ext_gui/gui_input.cpp +148 -0
  252. package/runtime/ext_gui/gui_webgl.cpp +3 -2
  253. package/runtime/ext_gui/pointer_lock.cpp +137 -0
  254. package/runtime/ext_gui/style_ua.cpp +4 -0
  255. package/runtime/ext_gui/warnings.cpp +1 -1
  256. package/runtime/ext_gui/webgl.h +102 -7
  257. package/runtime/ext_gui/webgl_api.h +3 -2
  258. package/runtime/ext_gui/webgl_blit.cpp +109 -15
  259. package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
  260. package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
  261. package/runtime/ext_gui/webgl_buffer.cpp +26 -170
  262. package/runtime/ext_gui/webgl_context.cpp +119 -169
  263. package/runtime/ext_gui/webgl_draw.cpp +116 -5
  264. package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
  265. package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
  266. package/runtime/ext_gui/webgl_draw_state.h +2 -0
  267. package/runtime/ext_gui/webgl_feature.cpp +2 -2
  268. package/runtime/ext_gui/webgl_feature.h +4 -3
  269. package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
  270. package/runtime/ext_gui/webgl_glsl.h +4 -0
  271. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
  272. package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
  273. package/runtime/ext_gui/webgl_objects.h +18 -2
  274. package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
  275. package/runtime/ext_gui/webgl_shader.cpp +1 -1
  276. package/runtime/ext_gui/webgl_state.cpp +45 -36
  277. package/runtime/ext_gui/webgl_targets.cpp +440 -0
  278. package/runtime/ext_gui/webgl_texture.cpp +81 -25
  279. package/runtime/ext_gui/window.cpp +11 -83
  280. package/runtime/ext_gui/window_diagnostics.cpp +94 -1
  281. package/runtime/rt.h +27 -27
  282. package/runtime/rt_binary.h +44 -0
  283. package/runtime/rt_internal.h +52 -60
  284. package/runtime/rt_object.h +83 -0
  285. package/runtime/rt_profile.h +45 -0
  286. package/runtime/xt_alloc.c +88 -133
  287. package/runtime/xt_array_buffer.c +99 -71
  288. package/runtime/xt_builtins.c +3 -1
  289. package/runtime/xt_constructors.c +1 -0
  290. package/runtime/xt_containers/access.inc +96 -11
  291. package/runtime/xt_containers/arrays.inc +2 -1
  292. package/runtime/xt_containers/cstr_cache.inc +56 -0
  293. package/runtime/xt_containers/method_cache.inc +121 -0
  294. package/runtime/xt_containers/object_keys.inc +58 -0
  295. package/runtime/xt_containers/objects.inc +47 -79
  296. package/runtime/xt_containers/shapes.inc +153 -8
  297. package/runtime/xt_containers.c +4 -0
  298. package/runtime/xt_gc_release.c +70 -0
  299. package/runtime/xt_gc_stack.c +83 -0
  300. package/runtime/xt_gc_verify.c +1 -0
  301. package/runtime/xt_io/console.inc +66 -0
  302. package/runtime/xt_io/exception.inc +32 -6
  303. package/runtime/xt_io/watchdog.inc +101 -0
  304. package/runtime/xt_io.c +1 -0
  305. package/runtime/xt_loop.c +23 -3
  306. package/runtime/xt_pool.c +151 -0
  307. package/runtime/xt_profile.c +126 -0
  308. package/runtime/xt_stdlib/dispatch.inc +7 -1
  309. package/runtime/xt_stdlib/math.inc +272 -57
  310. package/runtime/xt_stdlib2/json_stringify.inc +1 -2
  311. package/runtime/xt_stdlib2/regexp-match.inc +17 -0
  312. package/runtime/xt_storage/indexed_db.c +4 -1
  313. package/runtime/xt_structured_clone.c +2 -1
  314. package/runtime/xt_typed_array/construction.inc +10 -0
  315. package/runtime/xt_typed_array/elements.inc +43 -23
  316. package/runtime/xt_url.c +50 -0
  317. package/runtime/xt_values/constructors.inc +4 -1
  318. package/runtime/xt_values/strings.inc +3 -1
  319. package/src/ast/common.ts +10 -0
  320. package/src/binder/references.ts +13 -7
  321. package/src/checker/source.ts +3 -0
  322. package/src/cli/main.ts +14 -3
  323. package/src/codegen/generator/calls/access.ts +5 -10
  324. package/src/codegen/generator/calls/element-inline.ts +433 -0
  325. package/src/codegen/generator/calls/invocation.ts +87 -1
  326. package/src/codegen/generator/calls.ts +5 -0
  327. package/src/codegen/generator/debug.ts +21 -3
  328. package/src/codegen/generator/expressions/assignment.ts +11 -2
  329. package/src/codegen/generator/expressions/global-values.ts +57 -0
  330. package/src/codegen/generator/expressions/primary.ts +4 -27
  331. package/src/codegen/generator/expressions.ts +3 -0
  332. package/src/codegen/generator/layout.ts +54 -0
  333. package/src/codegen/generator/state.ts +5 -0
  334. package/src/diagnostics/diagnostic.ts +1 -1
  335. package/src/diagnostics/source-text.ts +118 -22
  336. package/src/diagnostics/source.ts +29 -7
  337. package/src/driver/build-key.ts +21 -1
  338. package/src/driver/bundler/concatenate.ts +12 -5
  339. package/src/driver/bundler/graph.ts +2 -2
  340. package/src/driver/bundler/merge.ts +11 -4
  341. package/src/driver/bundler/reexport-resolution.ts +2 -0
  342. package/src/driver/compiler.ts +14 -3
  343. package/src/driver/frontend.ts +3 -4
  344. package/src/driver/runtime-objects.ts +4 -0
  345. package/src/driver/toolchain.ts +28 -5
  346. package/src/driver/version.ts +1 -1
  347. package/src/extensions/gui/html.ts +41 -11
  348. package/src/extensions/gui/index.ts +55 -1
  349. package/src/extensions/registry.ts +20 -0
  350. package/src/parser/expressions.ts +2 -2
  351. package/src/parser/helpers.ts +22 -0
@@ -2,74 +2,289 @@
2
2
  /* Math */
3
3
  /* ------------------------------------------------------------------------- */
4
4
 
5
+ /*
6
+ * `Math.cbrt` uses fdlibm's cbrt instead of the host libm. The host result is
7
+ * not portable: glibc's algorithm has ~1 ulp of error and computes
8
+ * `cbrt(27) = 3.0000000000000004`, while macOS/Windows libm and Node return
9
+ * `3`. The differential suite caught that on Linux. V8 (and therefore Node)
10
+ * ships this exact fdlibm version in `src/base/ieee754.cc`, so borrowing it
11
+ * makes `Math.cbrt` bit-identical with Node on every host.
12
+ *
13
+ * The following is adapted from fdlibm (http://www.netlib.org/fdlibm).
14
+ *
15
+ * ====================================================
16
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
17
+ *
18
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
19
+ * Permission to use, copy, modify, and distribute this
20
+ * software is freely granted, provided that this notice
21
+ * is preserved.
22
+ * ====================================================
23
+ *
24
+ * V8 compiles its ieee754 code with `-ffp-contract=off`; the pragma keeps a
25
+ * compiler from fusing the polynomial's multiply-adds on FMA targets, which
26
+ * would change the low bits.
27
+ */
28
+ #pragma STDC FP_CONTRACT OFF
29
+ static double xt_math_cbrt(double x) {
30
+ /* |1/cbrt(x) - p(x)| < 2**-23.5 (~[-7.93e-8, 7.929e-8]). */
31
+ static const uint32_t B1 = 715094163u; /* (1023-1023/3-0.03306235651)*2**20 */
32
+ static const uint32_t B2 = 696219795u; /* (1023-1023/3-54/3-0.03306235651)*2**20 */
33
+ static const double P0 = 1.87595182427177009643;
34
+ static const double P1 = -1.88497979543377169875;
35
+ static const double P2 = 1.621429720105354466140;
36
+ static const double P3 = -0.758397934778766047437;
37
+ static const double P4 = 0.145996192886612446982;
38
+
39
+ uint64_t bits;
40
+ uint32_t hx, low, sign, high;
41
+ double r, s, t, w;
42
+
43
+ memcpy(&bits, &x, sizeof(bits));
44
+ hx = (uint32_t)(bits >> 32);
45
+ low = (uint32_t)bits;
46
+ sign = hx & 0x80000000u; /* sign= sign(x) */
47
+ hx ^= sign;
48
+ if (hx >= 0x7FF00000u) return x + x; /* cbrt(NaN,INF) is itself */
49
+
50
+ if (hx < 0x00100000u) { /* zero or subnormal? */
51
+ if ((hx | low) == 0) return x; /* cbrt(0) is itself */
52
+ t = 0x1p54 * x; /* scale the subnormal into the normal range */
53
+ memcpy(&bits, &t, sizeof(bits));
54
+ high = (uint32_t)(bits >> 32);
55
+ bits = (uint64_t)(sign | ((high & 0x7FFFFFFFu) / 3u + B2)) << 32;
56
+ } else {
57
+ bits = (uint64_t)(sign | (hx / 3u + B1)) << 32;
58
+ }
59
+ memcpy(&t, &bits, sizeof(t));
60
+
61
+ /* New cbrt to 23 bits: cbrt(x) ~= t*P(t**3/x), then one Newton step. */
62
+ r = (t * t) * (t / x);
63
+ t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));
64
+
65
+ /* Round t away from zero to 23 bits so it is slightly above |cbrt(x)|. */
66
+ memcpy(&bits, &t, sizeof(bits));
67
+ bits = (bits + 0x80000000ull) & 0xFFFFFFFFC0000000ull;
68
+ memcpy(&t, &bits, sizeof(t));
69
+
70
+ /* One Newton iteration to 53 bits with error < 0.667 ulps. */
71
+ s = t * t; /* t*t is exact */
72
+ r = x / s; /* error <= 0.5 ulps; |r| < |t| */
73
+ w = t + t; /* t+t is exact */
74
+ r = (r - t) / (w + r); /* r-t is exact; w+r ~= 3*t */
75
+ t = t + t * r; /* error <= 0.5 + 0.5/3 + epsilon */
76
+ return t;
77
+ }
78
+ #pragma STDC FP_CONTRACT ON
79
+
5
80
  xt_value xt_math_call(xt_value name, int32_t argc, xt_value *argv) {
81
+ XT_PROFILE_TICK(XT_PROFILE_MATH);
6
82
  const char *fn = xt_string_data(name);
83
+ if (!fn) return xt_number(NAN);
7
84
  double a = xt_to_number(xt_arg_at(argc, argv, 0));
8
85
  double b = xt_to_number(xt_arg_at(argc, argv, 1));
9
- if (!fn) return xt_number(NAN);
10
- if (strcmp(fn, "abs") == 0) return xt_number(fabs(a));
11
- if (strcmp(fn, "floor") == 0) return xt_number(floor(a));
12
- if (strcmp(fn, "ceil") == 0) return xt_number(ceil(a));
13
- if (strcmp(fn, "round") == 0) return xt_number(floor(a + 0.5));
14
- if (strcmp(fn, "trunc") == 0) return xt_number(trunc(a));
15
- if (strcmp(fn, "sqrt") == 0) return xt_number(sqrt(a));
16
- if (strcmp(fn, "cbrt") == 0) return xt_number(cbrt(a));
17
- if (strcmp(fn, "pow") == 0) return xt_number(pow(a, b));
18
- if (strcmp(fn, "exp") == 0) return xt_number(exp(a));
19
- if (strcmp(fn, "log") == 0) return xt_number(log(a));
20
- if (strcmp(fn, "log2") == 0) return xt_number(log2(a));
21
- if (strcmp(fn, "log10") == 0) return xt_number(log10(a));
22
- if (strcmp(fn, "log1p") == 0) return xt_number(log1p(a));
23
- if (strcmp(fn, "expm1") == 0) return xt_number(expm1(a));
24
- if (strcmp(fn, "sinh") == 0) return xt_number(sinh(a));
25
- if (strcmp(fn, "cosh") == 0) return xt_number(cosh(a));
26
- if (strcmp(fn, "tanh") == 0) return xt_number(tanh(a));
27
- if (strcmp(fn, "asinh") == 0) return xt_number(asinh(a));
28
- if (strcmp(fn, "acosh") == 0) return xt_number(acosh(a));
29
- if (strcmp(fn, "atanh") == 0) return xt_number(atanh(a));
30
- if (strcmp(fn, "fround") == 0) return xt_number((double)(float)a);
31
- if (strcmp(fn, "imul") == 0) return xt_number((double)((int32_t)xt_to_int32(xt_arg_at(argc, argv, 0)) * (int32_t)xt_to_int32(xt_arg_at(argc, argv, 1))));
32
- if (strcmp(fn, "clz32") == 0) {
33
- uint32_t v = (uint32_t)xt_to_int32(xt_arg_at(argc, argv, 0));
34
- int count = 0;
35
- if (v == 0) count = 32;
36
- else { while (!(v & 0x80000000u)) { v <<= 1; count++; } }
37
- return xt_number((double)count);
86
+ /* Dispatch on the first byte before comparing names. A flat chain over ~35
87
+ * names paid up to 35 `strcmp`s per call, and numeric code calls
88
+ * `Math.imul`/`floor`/`exp` hundreds of millions of times (procedural noise,
89
+ * geometry), so the difference is seconds of startup on a large page. */
90
+ switch (fn[0]) {
91
+ case 'a':
92
+ if (strcmp(fn, "abs") == 0) return xt_number(fabs(a));
93
+ if (strcmp(fn, "acos") == 0) return xt_number(acos(a));
94
+ if (strcmp(fn, "acosh") == 0) return xt_number(acosh(a));
95
+ if (strcmp(fn, "asin") == 0) return xt_number(asin(a));
96
+ if (strcmp(fn, "asinh") == 0) return xt_number(asinh(a));
97
+ if (strcmp(fn, "atan") == 0) return xt_number(atan(a));
98
+ if (strcmp(fn, "atan2") == 0) return xt_number(atan2(a, b));
99
+ if (strcmp(fn, "atanh") == 0) return xt_number(atanh(a));
100
+ break;
101
+ case 'c':
102
+ if (strcmp(fn, "cbrt") == 0) return xt_number(xt_math_cbrt(a));
103
+ if (strcmp(fn, "ceil") == 0) return xt_number(ceil(a));
104
+ if (strcmp(fn, "clz32") == 0) {
105
+ uint32_t v = (uint32_t)xt_to_int32(xt_arg_at(argc, argv, 0));
106
+ int count = 0;
107
+ if (v == 0) count = 32;
108
+ else { while (!(v & 0x80000000u)) { v <<= 1; count++; } }
109
+ return xt_number((double)count);
110
+ }
111
+ if (strcmp(fn, "cos") == 0) return xt_number(cos(a));
112
+ if (strcmp(fn, "cosh") == 0) return xt_number(cosh(a));
113
+ break;
114
+ case 'e':
115
+ if (strcmp(fn, "exp") == 0) return xt_number(exp(a));
116
+ if (strcmp(fn, "expm1") == 0) return xt_number(expm1(a));
117
+ break;
118
+ case 'f':
119
+ if (strcmp(fn, "floor") == 0) return xt_number(floor(a));
120
+ if (strcmp(fn, "fround") == 0) return xt_number((double)(float)a);
121
+ break;
122
+ case 'h':
123
+ if (strcmp(fn, "hypot") == 0) {
124
+ /* `Math.hypot(...values)` takes any number of arguments (ECMA-262
125
+ * 21.3.2.18): every argument participates, NaN wins, and the sum is
126
+ * scaled by the largest magnitude so `hypot(1e308, 1e308)` does not
127
+ * overflow. */
128
+ double scale = 0.0;
129
+ for (int32_t i = 0; i < argc; i++) {
130
+ double v = fabs(xt_to_number(argv[i]));
131
+ if (isnan(v)) return xt_number(NAN);
132
+ if (v > scale) scale = v;
133
+ }
134
+ if (scale == INFINITY) return xt_number(INFINITY);
135
+ if (scale == 0.0) return xt_number(0.0);
136
+ double sum = 0.0;
137
+ for (int32_t i = 0; i < argc; i++) {
138
+ double v = xt_to_number(argv[i]) / scale;
139
+ sum += v * v;
140
+ }
141
+ return xt_number(scale * sqrt(sum));
142
+ }
143
+ break;
144
+ case 'i':
145
+ if (strcmp(fn, "imul") == 0)
146
+ return xt_number((double)((int32_t)xt_to_int32(xt_arg_at(argc, argv, 0)) *
147
+ (int32_t)xt_to_int32(xt_arg_at(argc, argv, 1))));
148
+ break;
149
+ case 'l':
150
+ if (strcmp(fn, "log") == 0) return xt_number(log(a));
151
+ if (strcmp(fn, "log10") == 0) return xt_number(log10(a));
152
+ if (strcmp(fn, "log1p") == 0) return xt_number(log1p(a));
153
+ if (strcmp(fn, "log2") == 0) return xt_number(log2(a));
154
+ break;
155
+ case 'm':
156
+ if (strcmp(fn, "max") == 0) {
157
+ double result = -INFINITY;
158
+ for (int32_t i = 0; i < argc; i++) {
159
+ double v = xt_to_number(argv[i]);
160
+ if (isnan(v)) return xt_number(NAN);
161
+ if (v > result) result = v;
162
+ }
163
+ return xt_number(result);
164
+ }
165
+ if (strcmp(fn, "min") == 0) {
166
+ double result = INFINITY;
167
+ for (int32_t i = 0; i < argc; i++) {
168
+ double v = xt_to_number(argv[i]);
169
+ if (isnan(v)) return xt_number(NAN);
170
+ if (v < result) result = v;
171
+ }
172
+ return xt_number(result);
173
+ }
174
+ break;
175
+ case 'p':
176
+ if (strcmp(fn, "pow") == 0) return xt_number(pow(a, b));
177
+ break;
178
+ case 'r':
179
+ if (strcmp(fn, "random") == 0) return xt_number(xt_random_double());
180
+ if (strcmp(fn, "round") == 0) return xt_number(floor(a + 0.5));
181
+ break;
182
+ case 's':
183
+ if (strcmp(fn, "sign") == 0) {
184
+ if (isnan(a)) return xt_number(NAN);
185
+ return xt_number(a > 0 ? 1.0 : a < 0 ? -1.0 : a);
186
+ }
187
+ if (strcmp(fn, "sin") == 0) return xt_number(sin(a));
188
+ if (strcmp(fn, "sinh") == 0) return xt_number(sinh(a));
189
+ if (strcmp(fn, "sqrt") == 0) return xt_number(sqrt(a));
190
+ break;
191
+ case 't':
192
+ if (strcmp(fn, "tan") == 0) return xt_number(tan(a));
193
+ if (strcmp(fn, "tanh") == 0) return xt_number(tanh(a));
194
+ if (strcmp(fn, "trunc") == 0) return xt_number(trunc(a));
195
+ break;
196
+ default:
197
+ break;
38
198
  }
39
- if (strcmp(fn, "sin") == 0) return xt_number(sin(a));
40
- if (strcmp(fn, "cos") == 0) return xt_number(cos(a));
41
- if (strcmp(fn, "tan") == 0) return xt_number(tan(a));
42
- if (strcmp(fn, "asin") == 0) return xt_number(asin(a));
43
- if (strcmp(fn, "acos") == 0) return xt_number(acos(a));
44
- if (strcmp(fn, "atan") == 0) return xt_number(atan(a));
45
- if (strcmp(fn, "atan2") == 0) return xt_number(atan2(a, b));
46
- if (strcmp(fn, "hypot") == 0) return xt_number(hypot(a, b));
47
- if (strcmp(fn, "sign") == 0) {
48
- if (isnan(a)) return xt_number(NAN);
49
- return xt_number(a > 0 ? 1.0 : a < 0 ? -1.0 : a);
199
+ return xt_number(NAN);
200
+ }
201
+
202
+
203
+ /* -- direct call forms ----------------------------------------------------- */
204
+
205
+ /*
206
+ * `Math.floor(x)` used to lower to `xt_math_call("floor", 1, &x)`: a name
207
+ * dispatch plus an argument array for a call whose arity and name the compiler
208
+ * already knows. A numeric kernel calls these hundreds of times per pixel, so
209
+ * codegen emits the fixed-arity form below instead — the arguments arrive in
210
+ * registers and there is no name to resolve. `min`/`max` stay variadic and keep
211
+ * `xt_math_call`. Semantics are identical: ToNumber first, then the platform
212
+ * operation.
213
+ */
214
+ #define XT_MATH_UNARY(name, expression) \
215
+ xt_value xt_math1_##name(xt_value arg) { \
216
+ double x = xt_to_number(arg); \
217
+ return xt_number(expression); \
50
218
  }
51
- if (strcmp(fn, "random") == 0) return xt_number(xt_random_double());
52
- if (strcmp(fn, "min") == 0) {
53
- double result = INFINITY;
54
- for (int32_t i = 0; i < argc; i++) {
55
- double v = xt_to_number(argv[i]);
56
- if (isnan(v)) return xt_number(NAN);
57
- if (v < result) result = v;
58
- }
59
- return xt_number(result);
219
+
220
+ #define XT_MATH_BINARY(name, expression) \
221
+ xt_value xt_math2_##name(xt_value left, xt_value right) { \
222
+ double x = xt_to_number(left); \
223
+ double y = xt_to_number(right); \
224
+ return xt_number(expression); \
60
225
  }
61
- if (strcmp(fn, "max") == 0) {
62
- double result = -INFINITY;
63
- for (int32_t i = 0; i < argc; i++) {
64
- double v = xt_to_number(argv[i]);
65
- if (isnan(v)) return xt_number(NAN);
66
- if (v > result) result = v;
226
+
227
+ XT_MATH_UNARY(abs, fabs(x))
228
+ XT_MATH_UNARY(floor, floor(x))
229
+ XT_MATH_UNARY(ceil, ceil(x))
230
+ XT_MATH_UNARY(round, floor(x + 0.5))
231
+ XT_MATH_UNARY(trunc, trunc(x))
232
+ XT_MATH_UNARY(sqrt, sqrt(x))
233
+ XT_MATH_UNARY(cbrt, xt_math_cbrt(x))
234
+ XT_MATH_UNARY(exp, exp(x))
235
+ XT_MATH_UNARY(log, log(x))
236
+ XT_MATH_UNARY(log2, log2(x))
237
+ XT_MATH_UNARY(log10, log10(x))
238
+ XT_MATH_UNARY(log1p, log1p(x))
239
+ XT_MATH_UNARY(expm1, expm1(x))
240
+ XT_MATH_UNARY(sinh, sinh(x))
241
+ XT_MATH_UNARY(cosh, cosh(x))
242
+ XT_MATH_UNARY(tanh, tanh(x))
243
+ XT_MATH_UNARY(asinh, asinh(x))
244
+ XT_MATH_UNARY(acosh, acosh(x))
245
+ XT_MATH_UNARY(atanh, atanh(x))
246
+ XT_MATH_UNARY(fround, (double)(float)x)
247
+ XT_MATH_UNARY(sin, sin(x))
248
+ XT_MATH_UNARY(cos, cos(x))
249
+ XT_MATH_UNARY(tan, tan(x))
250
+ XT_MATH_UNARY(asin, asin(x))
251
+ XT_MATH_UNARY(acos, acos(x))
252
+ XT_MATH_UNARY(atan, atan(x))
253
+
254
+ XT_MATH_BINARY(pow, pow(x, y))
255
+ XT_MATH_BINARY(atan2, atan2(x, y))
256
+ XT_MATH_BINARY(hypot, hypot(x, y))
257
+
258
+ #undef XT_MATH_UNARY
259
+ #undef XT_MATH_BINARY
260
+
261
+ xt_value xt_math1_clz32(xt_value arg) {
262
+ uint32_t v = (uint32_t)xt_to_int32(arg);
263
+ int count = 0;
264
+ if (v == 0) {
265
+ count = 32;
266
+ } else {
267
+ while (!(v & 0x80000000u)) {
268
+ v <<= 1;
269
+ count++;
67
270
  }
68
- return xt_number(result);
69
271
  }
70
- return xt_number(NAN);
272
+ return xt_number((double)count);
273
+ }
274
+
275
+ xt_value xt_math1_sign(xt_value arg) {
276
+ double x = xt_to_number(arg);
277
+ if (isnan(x)) return xt_number(NAN);
278
+ return xt_number(x > 0 ? 1.0 : x < 0 ? -1.0 : x);
71
279
  }
72
280
 
281
+ xt_value xt_math0_random(void) { return xt_number(xt_random_double()); }
282
+
283
+ xt_value xt_math2_imul(xt_value left, xt_value right) {
284
+ int32_t a = (int32_t)xt_to_int32(left);
285
+ int32_t b = (int32_t)xt_to_int32(right);
286
+ return xt_number((double)(a * b));
287
+ }
73
288
 
74
289
  /* -- first-class Math ------------------------------------------------------ */
75
290
 
@@ -330,8 +330,7 @@ static int xt_json_replacer_write(xt_json_replacer_context *ctx, xt_value holder
330
330
  value = xt_call_method(value, xt_string_from_cstr("toJSON"), 1, &key);
331
331
  } else if (XT_IS_ARRAY(value) ||
332
332
  (XT_IS_OBJECT(value) &&
333
- (((xt_object *)XT_GET_PTR(value))->header.kind == XT_OBJECT_KIND_OBJECT ||
334
- ((xt_object *)XT_GET_PTR(value))->header.kind == XT_OBJECT_KIND_ERROR))) {
333
+ xt_kind_is_object(((xt_object *)XT_GET_PTR(value))->header.kind))) {
335
334
  xt_value toJSON = XT_IS_ARRAY(value) ? xt_get(value, xt_string_from_cstr("toJSON"))
336
335
  : xt_object_get(value, xt_string_from_cstr("toJSON"));
337
336
  if (XT_IS_FUNCTION(toJSON)) {
@@ -75,6 +75,23 @@ static char *xt_regexp_translate_js(const char *pattern, int *jsGroups, int *gro
75
75
  default: break;
76
76
  }
77
77
  }
78
+ if (!replacement && !literal && !consume) {
79
+ /* Any other escape is a literal (`\[`, `\]`, `\(`, `\.`, …). Copy the
80
+ * pair verbatim and skip the escaped character, so `\[` does not open a
81
+ * bracket expression and `\(` does not count as a group: the matcher
82
+ * reads `\[` as "a literal `[`", which is what the JavaScript pattern
83
+ * means. Dropping the backslash here used to turn `\[\s*i\s*\]` into a
84
+ * bracket expression and made three.js's unroll regex match nothing. */
85
+ if (written + 3 > capacity) {
86
+ capacity = capacity * 2 + 16;
87
+ out = (char *)realloc(out, capacity);
88
+ if (!out) abort();
89
+ }
90
+ out[written++] = '\\';
91
+ if (next != '\0') out[written++] = next;
92
+ i += next != '\0' ? 1 : 0;
93
+ continue;
94
+ }
78
95
  } else if (c == '[') {
79
96
  inClass = 1;
80
97
  } else if (c == ']') {
@@ -399,10 +399,13 @@ xt_value xt_storage_indexed_db(int32_t argc, xt_value *argv) {
399
399
  (void)argc;
400
400
  (void)argv;
401
401
  if (!XT_IS_OBJECT(g_indexed_db)) {
402
+ /* Root the slot before allocating: `xt_storage_method` allocates, and a
403
+ * collection in between would sweep the object still reachable only from
404
+ * this static. */
405
+ xt_gc_add_root(&g_indexed_db);
402
406
  g_indexed_db = xt_object_new();
403
407
  xt_storage_method(g_indexed_db, "open", (void *)idb_open);
404
408
  xt_storage_method(g_indexed_db, "deleteDatabase", (void *)idb_delete_database);
405
- xt_gc_add_root(&g_indexed_db);
406
409
  }
407
410
  return g_indexed_db;
408
411
  }
@@ -136,7 +136,7 @@ static xt_value xt_clone_value(xt_clone_context *context, xt_value value) {
136
136
  /* Plain objects and Errors are cloned as data: own enumerable string keys,
137
137
  * no prototype. That is what the platform algorithm does for ordinary
138
138
  * objects and class instances. */
139
- if (object->header.kind != XT_OBJECT_KIND_OBJECT && object->header.kind != XT_OBJECT_KIND_ERROR) {
139
+ if (!xt_kind_is_object(object->header.kind)) {
140
140
  xt_clone_fail("value");
141
141
  }
142
142
  xt_value clone = xt_object_new();
@@ -157,3 +157,4 @@ xt_value xt_structured_clone(int32_t argc, xt_value *argv) {
157
157
  free(context.entries);
158
158
  return clone;
159
159
  }
160
+
@@ -58,6 +58,16 @@ static xt_value xt_ta_view(int kind, xt_value buffer, uint32_t byteOffset, uint3
58
58
  xt_object_set(array, xt_string_from_cstr("byteOffset"), xt_number((double)byteOffset));
59
59
  xt_object_set(array, xt_ta_buffer_key(), buffer);
60
60
  xt_object_set(array, xt_ta_offset_key(), xt_number((double)byteOffset));
61
+ /* Resolve the storage once for the per-element path (`xt_typed_array_read`).
62
+ * A buffer's byte block never moves while the buffer is alive and this view
63
+ * keeps the buffer reachable, so the pointer needs no invalidation. */
64
+ uint32_t buffer_length = 0;
65
+ uint8_t *bytes = xt_array_buffer_bytes(buffer, &buffer_length);
66
+ if (bytes != NULL && byteOffset <= buffer_length) {
67
+ xt_object *object = (xt_object *)XT_GET_PTR(array);
68
+ object->view_bytes = bytes + byteOffset;
69
+ object->view_length = buffer_length - byteOffset;
70
+ }
61
71
  return array;
62
72
  }
63
73
 
@@ -47,8 +47,15 @@ int xt_typed_array_kind_of(xt_value value) {
47
47
  if (!XT_IS_OBJECT(value)) return -1;
48
48
  xt_object *object = (xt_object *)XT_GET_PTR(value);
49
49
  if (object->header.kind != XT_OBJECT_KIND_OBJECT) return -1;
50
+ /* The prototype lookup is memoized in `reserved2` (kind + 1): a typed array's
51
+ * kind never changes, and this is on the per-element path. `Object.setPrototypeOf`
52
+ * clears the slot, so a re-prototyped view falls back to the scan. */
53
+ if (object->reserved2 != 0) return (int)object->reserved2 - 1;
50
54
  for (int kind = 0; kind < XT_TA_KIND_COUNT; kind++) {
51
- if (xt_ta_protos[kind] && object->prototype == xt_ta_protos[kind]) return kind;
55
+ if (xt_ta_protos[kind] && object->prototype == xt_ta_protos[kind]) {
56
+ object->reserved2 = (uint16_t)(kind + 1);
57
+ return kind;
58
+ }
52
59
  }
53
60
  return -1;
54
61
  }
@@ -105,20 +112,36 @@ uint32_t xt_typed_array_byte_offset_of(xt_value array) {
105
112
  return (uint32_t)xt_to_number(xt_object_get(array, xt_ta_offset_key()));
106
113
  }
107
114
 
115
+ /* Views with no resolved byte block: a view over a zero-length buffer (reads are
116
+ * out of range) or a view built without a real ArrayBuffer, which keeps its
117
+ * elements as ordinary properties. */
118
+ static xt_value xt_ta_read_unbacked(xt_value array, int kind, uint32_t index) {
119
+ (void)kind;
120
+ if (xt_is_array_buffer(xt_typed_array_buffer_of(array))) return XT_UNDEFINED;
121
+ char key[24];
122
+ snprintf(key, sizeof(key), "%u", index);
123
+ return xt_object_get_cstr(array, key);
124
+ }
125
+
126
+ static void xt_ta_write_unbacked(xt_value array, int kind, uint32_t index, xt_value value) {
127
+ if (xt_is_array_buffer(xt_typed_array_buffer_of(array))) return;
128
+ char key[24];
129
+ snprintf(key, sizeof(key), "%u", index);
130
+ xt_object_set(array, xt_string_from_cstr(key),
131
+ xt_number(xt_typed_array_coerce(kind, xt_to_number(value))));
132
+ }
133
+
108
134
  xt_value xt_typed_array_read(xt_value array, uint32_t index) {
135
+ XT_PROFILE_TICK(XT_PROFILE_TYPED_READ);
109
136
  int kind = xt_typed_array_kind_of(array);
110
137
  if (kind < 0) return XT_UNDEFINED;
111
- xt_value buffer = xt_typed_array_buffer_of(array);
112
- if (!xt_is_array_buffer(buffer)) {
113
- char key[24];
114
- snprintf(key, sizeof(key), "%u", index);
115
- return xt_object_get_cstr(array, key);
116
- }
117
138
  uint32_t width = (uint32_t)xt_ta_bytes[kind];
118
- uint32_t offset = xt_typed_array_byte_offset_of(array) + index * width;
119
- if (offset + width > xt_array_buffer_byte_length(buffer)) return XT_UNDEFINED;
120
- uint8_t raw[8];
121
- for (uint32_t i = 0; i < width; i++) raw[i] = xt_array_buffer_get_byte(buffer, offset + i);
139
+ xt_object *object = (xt_object *)XT_GET_PTR(array);
140
+ uint8_t *base = object->view_bytes;
141
+ if (base == NULL) return xt_ta_read_unbacked(array, kind, index);
142
+ uint32_t offset = index * width;
143
+ if (offset + width > object->view_length) return XT_UNDEFINED;
144
+ const uint8_t *raw = base + offset;
122
145
  switch (kind) {
123
146
  case XT_TA_U8:
124
147
  return xt_number((double)raw[0]);
@@ -160,22 +183,20 @@ xt_value xt_typed_array_read(xt_value array, uint32_t index) {
160
183
  }
161
184
 
162
185
  void xt_typed_array_write(xt_value array, uint32_t index, xt_value value) {
186
+ XT_PROFILE_TICK(XT_PROFILE_TYPED_WRITE);
163
187
  int kind = xt_typed_array_kind_of(array);
164
188
  if (kind < 0) return;
165
- xt_value buffer = xt_typed_array_buffer_of(array);
166
- if (!xt_is_array_buffer(buffer)) {
167
- char key[24];
168
- snprintf(key, sizeof(key), "%u", index);
169
- xt_object_set(array, xt_string_from_cstr(key),
170
- xt_number(xt_typed_array_coerce(kind, xt_to_number(value))));
189
+ uint32_t width = (uint32_t)xt_ta_bytes[kind];
190
+ xt_object *object = (xt_object *)XT_GET_PTR(array);
191
+ uint8_t *base = object->view_bytes;
192
+ if (base == NULL) {
193
+ xt_ta_write_unbacked(array, kind, index, value);
171
194
  return;
172
195
  }
173
- uint32_t width = (uint32_t)xt_ta_bytes[kind];
174
- uint32_t offset = xt_typed_array_byte_offset_of(array) + index * width;
175
- if (offset + width > xt_array_buffer_byte_length(buffer)) return;
196
+ uint32_t offset = index * width;
197
+ if (offset + width > object->view_length) return;
176
198
  double coerced = xt_typed_array_coerce(kind, xt_to_number(value));
177
- uint8_t raw[8];
178
- memset(raw, 0, sizeof(raw));
199
+ uint8_t *raw = base + offset;
179
200
  switch (kind) {
180
201
  case XT_TA_U8:
181
202
  case XT_TA_U8C:
@@ -215,7 +236,6 @@ void xt_typed_array_write(xt_value array, uint32_t index, xt_value value) {
215
236
  break;
216
237
  }
217
238
  }
218
- for (uint32_t i = 0; i < width; i++) xt_array_buffer_set_byte(buffer, offset + i, raw[i]);
219
239
  }
220
240
 
221
241
  /* -- element storage ------------------------------------------------------ */
package/runtime/xt_url.c CHANGED
@@ -344,6 +344,52 @@ static xt_value xt_url_method_entries(xt_value thisValue, xt_value env, int32_t
344
344
  return result;
345
345
  }
346
346
 
347
+ static xt_value xt_url_iterator_self(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
348
+ (void)env;
349
+ (void)argc;
350
+ (void)argv;
351
+ return self;
352
+ }
353
+
354
+ /** One step of the `[Symbol.iterator]` walk: `{ value: [key, value], done }`. */
355
+ static xt_value xt_url_iterator_next(xt_value self, xt_value env, int32_t argc,
356
+ xt_value *argv) {
357
+ (void)self;
358
+ (void)argc;
359
+ (void)argv;
360
+ xt_array *entries = xt_as_array(xt_closure_env(env, 0));
361
+ xt_value indexBox = xt_closure_env(env, 1);
362
+ int32_t index = (int32_t)xt_to_number(xt_get(indexBox, xt_number(0)));
363
+ xt_value result = xt_object_new();
364
+ if (entries == NULL || index < 0 || (uint32_t)index >= entries->length) {
365
+ xt_object_set(result, xt_string_from_cstr("value"), XT_UNDEFINED);
366
+ xt_object_set(result, xt_string_from_cstr("done"), XT_TRUE);
367
+ return result;
368
+ }
369
+ xt_object_set(result, xt_string_from_cstr("value"), entries->items[index]);
370
+ xt_object_set(result, xt_string_from_cstr("done"), XT_FALSE);
371
+ xt_set(indexBox, xt_number(0), xt_number(index + 1));
372
+ return result;
373
+ }
374
+
375
+ /* `URLSearchParams` is iterable — `[...params]`, `for (const [k, v] of params)`
376
+ * and `Object.fromEntries(params)` all rely on it. The iterator is itself
377
+ * iterable, as the iteration protocol requires. */
378
+ static xt_value xt_url_iterator(xt_value thisValue, xt_value env, int32_t argc,
379
+ xt_value *argv) {
380
+ (void)env;
381
+ (void)argc;
382
+ (void)argv;
383
+ xt_value captured[2] = {xt_url_entries(thisValue), xt_array_new(0, NULL)};
384
+ xt_array_push(captured[1], xt_number(0));
385
+ xt_value iterator = xt_object_new();
386
+ xt_object_set(iterator, xt_string_from_cstr("next"),
387
+ xt_closure_new((void *)xt_url_iterator_next, 2, captured));
388
+ xt_object_set(iterator, xt_symbol_well_known("iterator"),
389
+ xt_closure_new((void *)xt_url_iterator_self, 0, NULL));
390
+ return iterator;
391
+ }
392
+
347
393
  static void xt_url_install(xt_value params, const char *name, void *fn) {
348
394
  xt_object_set(params, xt_string_from_cstr(name), xt_closure_new(fn, 0, NULL));
349
395
  }
@@ -364,6 +410,10 @@ xt_value xt_url_search_params_ctor(int32_t argc, xt_value *argv) {
364
410
  xt_url_install(params, "keys", (void *)xt_url_method_keys);
365
411
  xt_url_install(params, "values", (void *)xt_url_method_values);
366
412
  xt_url_install(params, "entries", (void *)xt_url_method_entries);
413
+ xt_url_install(params, "keys", (void *)xt_url_method_keys);
414
+ xt_url_install(params, "values", (void *)xt_url_method_values);
415
+ xt_object_set(params, xt_symbol_well_known("iterator"),
416
+ xt_closure_new((void *)xt_url_iterator, 0, NULL));
367
417
  xt_url_ctor_from_value(params, xt_arg_at(argc, argv, 0));
368
418
  return params;
369
419
  }
@@ -32,7 +32,10 @@ xt_value xt_string_new(const char *data, size_t len) {
32
32
  return XT_FROM_PTR(XT_TAG_STRING, s);
33
33
  }
34
34
 
35
- xt_value xt_string_from_cstr(const char *data) { return xt_string_new(data, strlen(data)); }
35
+ xt_value xt_string_from_cstr(const char *data) {
36
+ XT_PROFILE_TICK(XT_PROFILE_STRING_CSTR);
37
+ return xt_string_new(data, strlen(data));
38
+ }
36
39
 
37
40
  xt_string *xt_as_string(xt_value v);
38
41
 
@@ -105,8 +105,10 @@ int xt_string_equals(xt_string *a, xt_string *b) {
105
105
  /* Interned literals (property names above all) are shared, so identity is the
106
106
  * common case and skips the length, flattening and byte comparison entirely. */
107
107
  if (a == b) return 1;
108
+ /* Length first: a property scan compares many different keys, and a cons
109
+ * string only materialises its bytes on the first `xt_string_bytes` call. */
110
+ if (a->length != b->length) return 0;
108
111
  const char *aBytes = xt_string_bytes(a);
109
112
  const char *bBytes = xt_string_bytes(b);
110
- if (a->length != b->length) return 0;
111
113
  return memcmp(aBytes, bBytes, a->length) == 0;
112
114
  }
package/src/ast/common.ts CHANGED
@@ -234,4 +234,14 @@ export interface SourceFileNode extends Node {
234
234
  * `fail`, not `m1_fail`.
235
235
  */
236
236
  readonly modulePrefixes?: readonly string[];
237
+ /**
238
+ * For a bundled program: nodes whose source is plain JavaScript even though
239
+ * their origin file is not a `.js` file.
240
+ *
241
+ * An inline `<script>` body in an HTML page is JavaScript by default — only a
242
+ * `lang="ts"` / `type="text/typescript"` tag opts into TypeScript semantics —
243
+ * so the checker must treat its nodes the way it treats an external `.js`
244
+ * script rather than inferring types from unannotated code.
245
+ */
246
+ readonly untypedNodes?: ReadonlySet<object>;
237
247
  }