@loopdive/js2 0.57.0

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 (233) hide show
  1. package/CHANGELOG.md +1425 -0
  2. package/LICENSE +189 -0
  3. package/README.md +451 -0
  4. package/dist/checker/index.d.ts +117 -0
  5. package/dist/checker/language-service.d.ts +39 -0
  6. package/dist/checker/node-capability-map.d.ts +63 -0
  7. package/dist/checker/type-mapper.d.ts +84 -0
  8. package/dist/cjs-rewrite.d.ts +19 -0
  9. package/dist/cli.d.ts +2 -0
  10. package/dist/cli.js +363 -0
  11. package/dist/codegen/accessor-driver.d.ts +97 -0
  12. package/dist/codegen/any-helpers.d.ts +72 -0
  13. package/dist/codegen/array-element-typing.d.ts +46 -0
  14. package/dist/codegen/array-holes.d.ts +69 -0
  15. package/dist/codegen/array-methods.d.ts +68 -0
  16. package/dist/codegen/array-object-proto.d.ts +64 -0
  17. package/dist/codegen/array-reduce-fusion.d.ts +31 -0
  18. package/dist/codegen/array-to-primitive.d.ts +28 -0
  19. package/dist/codegen/async-cps.d.ts +239 -0
  20. package/dist/codegen/async-scheduler.d.ts +349 -0
  21. package/dist/codegen/binary-ops.d.ts +78 -0
  22. package/dist/codegen/binding-info.d.ts +31 -0
  23. package/dist/codegen/builtin-scaffold.d.ts +98 -0
  24. package/dist/codegen/builtin-static-globals.d.ts +8 -0
  25. package/dist/codegen/builtin-tags.d.ts +189 -0
  26. package/dist/codegen/case-convert-native.d.ts +12 -0
  27. package/dist/codegen/case-tables.d.ts +4 -0
  28. package/dist/codegen/class-bodies.d.ts +41 -0
  29. package/dist/codegen/class-member-keys.d.ts +33 -0
  30. package/dist/codegen/class-to-primitive.d.ts +39 -0
  31. package/dist/codegen/closed-method-dispatch.d.ts +42 -0
  32. package/dist/codegen/closures.d.ts +285 -0
  33. package/dist/codegen/coercion-engine.d.ts +154 -0
  34. package/dist/codegen/coercion-plan.d.ts +29 -0
  35. package/dist/codegen/context/bodies.d.ts +4 -0
  36. package/dist/codegen/context/create-context.d.ts +4 -0
  37. package/dist/codegen/context/errors.d.ts +39 -0
  38. package/dist/codegen/context/locals.d.ts +69 -0
  39. package/dist/codegen/context/source-pos.d.ts +5 -0
  40. package/dist/codegen/context/speculative.d.ts +95 -0
  41. package/dist/codegen/context/types.d.ts +1936 -0
  42. package/dist/codegen/custom-iterable.d.ts +34 -0
  43. package/dist/codegen/dataview-native.d.ts +51 -0
  44. package/dist/codegen/date-parse-native.d.ts +13 -0
  45. package/dist/codegen/dead-elimination.d.ts +26 -0
  46. package/dist/codegen/declarations.d.ts +147 -0
  47. package/dist/codegen/deno-api.d.ts +11 -0
  48. package/dist/codegen/destructuring-params.d.ts +102 -0
  49. package/dist/codegen/dyn-read.d.ts +26 -0
  50. package/dist/codegen/eval-tiering.d.ts +19 -0
  51. package/dist/codegen/expressions/assignment.d.ts +61 -0
  52. package/dist/codegen/expressions/builtins.d.ts +26 -0
  53. package/dist/codegen/expressions/calls-closures.d.ts +54 -0
  54. package/dist/codegen/expressions/calls-guards.d.ts +49 -0
  55. package/dist/codegen/expressions/calls-optional.d.ts +4 -0
  56. package/dist/codegen/expressions/calls.d.ts +83 -0
  57. package/dist/codegen/expressions/eval-inline.d.ts +24 -0
  58. package/dist/codegen/expressions/extern.d.ts +67 -0
  59. package/dist/codegen/expressions/fnctor-prototype.d.ts +52 -0
  60. package/dist/codegen/expressions/helpers.d.ts +212 -0
  61. package/dist/codegen/expressions/identifiers.d.ts +57 -0
  62. package/dist/codegen/expressions/late-imports.d.ts +81 -0
  63. package/dist/codegen/expressions/logical-ops.d.ts +18 -0
  64. package/dist/codegen/expressions/misc.d.ts +27 -0
  65. package/dist/codegen/expressions/new-super.d.ts +25 -0
  66. package/dist/codegen/expressions/promise-subclass.d.ts +38 -0
  67. package/dist/codegen/expressions/proto-override.d.ts +63 -0
  68. package/dist/codegen/expressions/unary-updates.d.ts +21 -0
  69. package/dist/codegen/expressions/unary.d.ts +6 -0
  70. package/dist/codegen/expressions.d.ts +31 -0
  71. package/dist/codegen/fallback-telemetry.d.ts +53 -0
  72. package/dist/codegen/fixups.d.ts +80 -0
  73. package/dist/codegen/fmod.d.ts +10 -0
  74. package/dist/codegen/fnctor-escape-gate.d.ts +92 -0
  75. package/dist/codegen/function-body.d.ts +52 -0
  76. package/dist/codegen/generators-native.d.ts +92 -0
  77. package/dist/codegen/helpers/body-references-own-this.d.ts +22 -0
  78. package/dist/codegen/helpers/body-uses-arguments.d.ts +12 -0
  79. package/dist/codegen/helpers/is-strict-function.d.ts +52 -0
  80. package/dist/codegen/host-import-allowlist.d.ts +140 -0
  81. package/dist/codegen/index.d.ts +500 -0
  82. package/dist/codegen/ir-tail-call.d.ts +8 -0
  83. package/dist/codegen/iterator-native.d.ts +44 -0
  84. package/dist/codegen/json-codec-native.d.ts +78 -0
  85. package/dist/codegen/json-runtime.d.ts +35 -0
  86. package/dist/codegen/json-standalone.d.ts +25 -0
  87. package/dist/codegen/linear-uint8-analysis.d.ts +46 -0
  88. package/dist/codegen/linear-uint8-arena.d.ts +7 -0
  89. package/dist/codegen/linear-uint8-codegen.d.ts +103 -0
  90. package/dist/codegen/linear-uint8-signatures.d.ts +26 -0
  91. package/dist/codegen/literals.d.ts +115 -0
  92. package/dist/codegen/map-runtime.d.ts +142 -0
  93. package/dist/codegen/math-helpers.d.ts +7 -0
  94. package/dist/codegen/member-get-dispatch.d.ts +42 -0
  95. package/dist/codegen/member-set-dispatch.d.ts +28 -0
  96. package/dist/codegen/native-proto.d.ts +98 -0
  97. package/dist/codegen/native-regex.d.ts +158 -0
  98. package/dist/codegen/native-strings.d.ts +146 -0
  99. package/dist/codegen/new-target.d.ts +30 -0
  100. package/dist/codegen/node-fs-api.d.ts +47 -0
  101. package/dist/codegen/number-format-native.d.ts +9 -0
  102. package/dist/codegen/number-ryu.d.ts +27 -0
  103. package/dist/codegen/object-ops.d.ts +94 -0
  104. package/dist/codegen/object-runtime.d.ts +171 -0
  105. package/dist/codegen/parse-number-native.d.ts +10 -0
  106. package/dist/codegen/peephole.d.ts +6 -0
  107. package/dist/codegen/property-access.d.ts +294 -0
  108. package/dist/codegen/raw-wasi-api.d.ts +13 -0
  109. package/dist/codegen/regex/bytecode.d.ts +140 -0
  110. package/dist/codegen/regex/casefold.d.ts +41 -0
  111. package/dist/codegen/regex/compile.d.ts +51 -0
  112. package/dist/codegen/regex/parse.d.ts +76 -0
  113. package/dist/codegen/regex/unicode.d.ts +42 -0
  114. package/dist/codegen/regex/vm.d.ts +24 -0
  115. package/dist/codegen/regexp-standalone.d.ts +350 -0
  116. package/dist/codegen/registry/error-types.d.ts +38 -0
  117. package/dist/codegen/registry/imports.d.ts +46 -0
  118. package/dist/codegen/registry/types.d.ts +59 -0
  119. package/dist/codegen/set-algebra.d.ts +17 -0
  120. package/dist/codegen/set-runtime.d.ts +74 -0
  121. package/dist/codegen/shared.d.ts +111 -0
  122. package/dist/codegen/stack-balance.d.ts +43 -0
  123. package/dist/codegen/statements/control-flow.d.ts +25 -0
  124. package/dist/codegen/statements/destructuring.d.ts +177 -0
  125. package/dist/codegen/statements/exceptions.d.ts +11 -0
  126. package/dist/codegen/statements/functions.d.ts +1 -0
  127. package/dist/codegen/statements/index.d.ts +1 -0
  128. package/dist/codegen/statements/loops.d.ts +7 -0
  129. package/dist/codegen/statements/nested-declarations.d.ts +78 -0
  130. package/dist/codegen/statements/shared.d.ts +38 -0
  131. package/dist/codegen/statements/tdz.d.ts +43 -0
  132. package/dist/codegen/statements/variables.d.ts +3 -0
  133. package/dist/codegen/statements.d.ts +9 -0
  134. package/dist/codegen/string-builder.d.ts +131 -0
  135. package/dist/codegen/string-ops.d.ts +87 -0
  136. package/dist/codegen/struct-accessor-closure.d.ts +36 -0
  137. package/dist/codegen/symbol-native.d.ts +55 -0
  138. package/dist/codegen/temporal-native.d.ts +8 -0
  139. package/dist/codegen/timsort.d.ts +2 -0
  140. package/dist/codegen/type-coercion.d.ts +123 -0
  141. package/dist/codegen/typeof-delete.d.ts +38 -0
  142. package/dist/codegen/uri-encoding-native.d.ts +33 -0
  143. package/dist/codegen/value-tags.d.ts +74 -0
  144. package/dist/codegen/walk-instructions.d.ts +20 -0
  145. package/dist/codegen/weak-collections-runtime.d.ts +16 -0
  146. package/dist/codegen/with-scope.d.ts +106 -0
  147. package/dist/codegen-linear/c-abi.d.ts +74 -0
  148. package/dist/codegen-linear/context.d.ts +86 -0
  149. package/dist/codegen-linear/index.d.ts +28 -0
  150. package/dist/codegen-linear/layout.d.ts +39 -0
  151. package/dist/codegen-linear/runtime.d.ts +161 -0
  152. package/dist/codegen-linear/simd.d.ts +7 -0
  153. package/dist/compiler/define-substitution.d.ts +27 -0
  154. package/dist/compiler/early-errors/assignment.d.ts +26 -0
  155. package/dist/compiler/early-errors/context.d.ts +17 -0
  156. package/dist/compiler/early-errors/duplicates.d.ts +20 -0
  157. package/dist/compiler/early-errors/index.d.ts +11 -0
  158. package/dist/compiler/early-errors/labels.d.ts +13 -0
  159. package/dist/compiler/early-errors/module-rules.d.ts +36 -0
  160. package/dist/compiler/early-errors/node-checks.d.ts +7 -0
  161. package/dist/compiler/early-errors/predicates.d.ts +140 -0
  162. package/dist/compiler/early-errors/tdz.d.ts +17 -0
  163. package/dist/compiler/import-manifest.d.ts +18 -0
  164. package/dist/compiler/output.d.ts +46 -0
  165. package/dist/compiler/validation.d.ts +45 -0
  166. package/dist/compiler.d.ts +48 -0
  167. package/dist/define-substitution-BcUeKC2A.js +109 -0
  168. package/dist/emit/binary.d.ts +50 -0
  169. package/dist/emit/c-header.d.ts +23 -0
  170. package/dist/emit/canonical-recgroup.d.ts +86 -0
  171. package/dist/emit/encoder.d.ts +28 -0
  172. package/dist/emit/object.d.ts +14 -0
  173. package/dist/emit/opcodes.d.ts +464 -0
  174. package/dist/emit/sourcemap.d.ts +33 -0
  175. package/dist/emit/wat.d.ts +6 -0
  176. package/dist/env.d.ts +46 -0
  177. package/dist/import-resolver.d.ts +68 -0
  178. package/dist/index.d.ts +486 -0
  179. package/dist/index.js +755 -0
  180. package/dist/ir/alloc-registry.d.ts +75 -0
  181. package/dist/ir/analysis/encoding.d.ts +38 -0
  182. package/dist/ir/analysis/escape.d.ts +32 -0
  183. package/dist/ir/analysis/lattice.d.ts +72 -0
  184. package/dist/ir/analysis/ownership.d.ts +31 -0
  185. package/dist/ir/analysis/stack-alloc.d.ts +20 -0
  186. package/dist/ir/backend/bytecode-emitter.d.ts +237 -0
  187. package/dist/ir/backend/bytecode-vm.d.ts +74 -0
  188. package/dist/ir/backend/emitter.d.ts +121 -0
  189. package/dist/ir/backend/handles.d.ts +133 -0
  190. package/dist/ir/backend/legality.d.ts +9 -0
  191. package/dist/ir/backend/linear-emitter.d.ts +41 -0
  192. package/dist/ir/backend/wasmgc-emitter.d.ts +43 -0
  193. package/dist/ir/builder.d.ts +401 -0
  194. package/dist/ir/from-ast.d.ts +192 -0
  195. package/dist/ir/index.d.ts +16 -0
  196. package/dist/ir/integration.d.ts +27 -0
  197. package/dist/ir/lower.d.ts +203 -0
  198. package/dist/ir/nodes.d.ts +1452 -0
  199. package/dist/ir/passes/alloc-discipline.d.ts +19 -0
  200. package/dist/ir/passes/constant-fold.d.ts +7 -0
  201. package/dist/ir/passes/dead-code.d.ts +18 -0
  202. package/dist/ir/passes/inline-small.d.ts +7 -0
  203. package/dist/ir/passes/monomorphize.d.ts +21 -0
  204. package/dist/ir/passes/simplify-cfg.d.ts +19 -0
  205. package/dist/ir/passes/tagged-union-types.d.ts +45 -0
  206. package/dist/ir/passes/tagged-unions.d.ts +22 -0
  207. package/dist/ir/propagate.d.ts +135 -0
  208. package/dist/ir/select.d.ts +81 -0
  209. package/dist/ir/types.d.ts +832 -0
  210. package/dist/ir/verify-alloc.d.ts +18 -0
  211. package/dist/ir/verify.d.ts +7 -0
  212. package/dist/link/index.d.ts +11 -0
  213. package/dist/link/isolation.d.ts +24 -0
  214. package/dist/link/linker.d.ts +37 -0
  215. package/dist/link/reader.d.ts +158 -0
  216. package/dist/link/resolver.d.ts +19 -0
  217. package/dist/optimize.d.ts +54 -0
  218. package/dist/optimize.js +262 -0
  219. package/dist/position-map.d.ts +64 -0
  220. package/dist/process-stdin-prelude.d.ts +16 -0
  221. package/dist/resolve.d.ts +82 -0
  222. package/dist/runtime/builtins.d.ts +1 -0
  223. package/dist/runtime-C-4q_KwU.js +164438 -0
  224. package/dist/runtime-containment.d.ts +6 -0
  225. package/dist/runtime-eval.d.ts +132 -0
  226. package/dist/runtime-instantiate.d.ts +16 -0
  227. package/dist/runtime.d.ts +128 -0
  228. package/dist/runtime.js +12 -0
  229. package/dist/shape-inference.d.ts +20 -0
  230. package/dist/treeshake.d.ts +17 -0
  231. package/dist/ts-api.d.ts +30 -0
  232. package/dist/wit-generator.d.ts +18 -0
  233. package/package.json +187 -0
@@ -0,0 +1,98 @@
1
+ import { Instr, ValType } from '../ir/types.js';
2
+ import { CodegenContext, FunctionContext } from './context/types.js';
3
+ /**
4
+ * Resolve (and lazily seed) the builtin brand id for `name`. Asserts the brand
5
+ * band stays disjoint from every registered class tag — a collision would
6
+ * silently mis-dispatch (#2175 Risk 2). Returns `undefined` for an unbranded
7
+ * name (caller falls through to the refusal).
8
+ */
9
+ export declare function getBuiltinBrand(ctx: CodegenContext, name: string): number | undefined;
10
+ export declare const NATIVE_PROTO_FIELD_BRAND = 0;
11
+ export declare const NATIVE_PROTO_FIELD_IS_CLASS = 1;
12
+ export declare const NATIVE_PROTO_FIELD_CTOR = 2;
13
+ export declare const NATIVE_PROTO_FIELD_PARENT = 3;
14
+ export declare const NATIVE_PROTO_FIELD_MEMBER_CSV = 4;
15
+ export declare const NATIVE_PROTO_FIELD_NAME = 5;
16
+ /**
17
+ * Register the single `$NativeProto` struct type once and stash its idx on
18
+ * `ctx.nativeProtoTypeIdx`. Mirrors the lazy one-time registration of
19
+ * `ensureStandaloneRegExpStruct`. There is exactly one `$NativeProto` heap type,
20
+ * so iso-recursive canonicalization is a non-issue for the metadata itself —
21
+ * identity rides the `$brand` *value*, not the type.
22
+ */
23
+ export declare function registerNativeProtoType(ctx: CodegenContext): number;
24
+ /**
25
+ * The per-builtin contract consumed by the shared core. A builtin registers one
26
+ * descriptor; the core uses it to populate the `$NativeProto` and to drive
27
+ * method/getter closure bodies. Registered lazily (the builtin calls
28
+ * `registerNativeProtoBuiltin` from its own module on first reflective demand)
29
+ * so the core has no import dependency on any specific builtin.
30
+ */
31
+ export interface NativeProtoBuiltinGlue {
32
+ /** Stable brand id (from BUILTIN_BRAND_TABLE). */
33
+ brand: number;
34
+ /** The proto's [[class]]/brand name (for `$name`, e.g. "RegExp"). */
35
+ name: string;
36
+ /** Own member-name CSV for the proto object (string-named members; `@@<id>`
37
+ * sentinels for well-known-symbol members — see spec §"Symbol cell"). */
38
+ memberCsv: string;
39
+ /** Which members are accessor getters (`kind:"getter"`) vs data methods
40
+ * (`kind:"method"`). `@@<id>` symbol members are always `"method"`. */
41
+ memberKind: (member: string) => "getter" | "method";
42
+ /** Static arity advertised by a member's closure value (`fn.length`). */
43
+ memberLength: (member: string) => number;
44
+ /**
45
+ * Emit a method/getter closure BODY into `fctx`, given the externref `this`
46
+ * already bound to closure-param index 1 and any further args at indices
47
+ * 2.. . The implementation runs the brand-recovery prologue (externref `this`
48
+ * → backing struct, or a catchable TypeError on a wrong `this`) and then the
49
+ * member body. Returns the closure's result ValType, or `null` on a refusal.
50
+ */
51
+ emitMemberBody: (ctx: CodegenContext, fctx: FunctionContext, member: string, kind: "getter" | "method") => ValType | null;
52
+ }
53
+ /** A builtin registers its glue once (idempotent). */
54
+ export declare function registerNativeProtoBuiltin(ctx: CodegenContext, glue: NativeProtoBuiltinGlue): void;
55
+ /** Look up a registered builtin's glue by brand. */
56
+ export declare function getNativeProtoBuiltinGlue(ctx: CodegenContext, brand: number): NativeProtoBuiltinGlue | undefined;
57
+ /**
58
+ * Emit a lazy-initialized `$NativeProto` object read for a *builtin* brand. On
59
+ * first access, builds the struct (brand, isClass=0, ctor=null, parent=null,
60
+ * memberCsv=<native string>, name=<native string>), boxes it via
61
+ * `extern.convert_any`, and stashes it in a module global; subsequent reads
62
+ * return the same externref (reference identity for `RegExp.prototype ===
63
+ * RegExp.prototype`). Pure Wasm — NO host import (the contrast with
64
+ * `emitLazyProtoGet`, which calls `__register_prototype`). Leaves an externref
65
+ * on the stack. Returns `false` if the brand has no registered glue.
66
+ */
67
+ export declare function emitLazyNativeProtoGet(ctx: CodegenContext, fctx: FunctionContext, brand: number): boolean;
68
+ /**
69
+ * (#2175) Brand-keyed native-method-closure factory. `kind`:
70
+ * - `"method"` — `(ref $wrap, externref this, ...externref args) -> result`;
71
+ * first emits the brand-recovery prologue then the member body.
72
+ * - `"getter"` — `(ref $wrap, externref this) -> result` accessor getter,
73
+ * returned as a descriptor's `.get`.
74
+ *
75
+ * The closure is a `__fn_wrap`-style struct produced by
76
+ * `getOrCreateFuncRefWrapperTypes`, so it is `call_ref`-dispatchable through the
77
+ * existing closure call path. Keyed in `ctx.funcMap` as
78
+ * `__proto_method_<brand>_<member>` / `__proto_method_<brand>_get_<member>`.
79
+ * Tags the funcIdx with `{name,length}` in `ctx.nativeClosureMeta` so the
80
+ * existing `.length`/`.name`-on-function reads resolve the closure's arity/name.
81
+ *
82
+ * Returns the `{ type, funcIdx }` for `ref.func` + `struct.new`, or `null` if
83
+ * the brand has no glue / the member body refuses.
84
+ */
85
+ export declare function ensureStandaloneNativeMethodClosure(ctx: CodegenContext, brand: number, member: string, kind: "method" | "getter"): {
86
+ type: {
87
+ kind: "ref";
88
+ typeIdx: number;
89
+ };
90
+ funcIdx: number;
91
+ } | null;
92
+ /**
93
+ * Emit the catchable-TypeError throw used by a brand-recovery prologue on a
94
+ * wrong `this`. Shared so per-builtin glue can reuse the exact shape (a real
95
+ * TypeError instance via the in-module `__new_TypeError`, then `throw $exc`),
96
+ * never a `ref.cast` trap (#2100 M2 / §22.2.6.4.1 step 2).
97
+ */
98
+ export declare function emitBrandCheckTypeError(ctx: CodegenContext, body: Instr[], message: string): void;
@@ -0,0 +1,158 @@
1
+ import { Instr } from '../ir/types.js';
2
+ import { CodegenContext } from './context/types.js';
3
+ /** i32 array type used for program, class table, and capture slots. */
4
+ export declare function regexI32ArrayType(ctx: CodegenContext): number;
5
+ /**
6
+ * Emit the backtracking VM `__regex_run` and its dependencies. Returns the
7
+ * `__regex_run` function index.
8
+ *
9
+ * Signature:
10
+ * __regex_run(prog: ref array<i32>, classTable: ref array<i32>,
11
+ * nSlots: i32, strData: ref array<i16>, strOff: i32, strLen: i32,
12
+ * startIdx: i32, caps: ref array<i32>,
13
+ * entryPc: i32, dir: i32) -> i32
14
+ *
15
+ * `caps` is caller-allocated, length `nSlots`, pre-filled with -1. On a match
16
+ * (1 returned) the slots hold `[g0s,g0e,g1s,g1e,…]`; -1 = unset. This is one
17
+ * anchored attempt at `startIdx`; the start-position scan lives in the
18
+ * higher-level helpers (`__regex_search`).
19
+ *
20
+ * #1911: `entryPc` selects the (sub-)program, `dir` the scan direction (+1
21
+ * forward, -1 for lookbehind sub-programs — consuming ops read the unit at
22
+ * sp-1 and decrement). LOOKAROUND recursively calls this function on its
23
+ * sub-program at the current position; the recursion is what makes
24
+ * lookarounds atomic (no backtrack entries leak into the outer attempt).
25
+ */
26
+ export declare function ensureRegexRun(ctx: CodegenContext): number;
27
+ /**
28
+ * Emit `__regex_search(prog, classTable, nSlots, strData, strOff, strLen,
29
+ * startIdx, sticky, caps) -> i32`.
30
+ *
31
+ * Drives the start-position scan: tries `__regex_run` at each position from
32
+ * `startIdx` to `strLen`; returns 1 with `caps` filled on the first match, 0
33
+ * otherwise. When `sticky` is non-zero (the `y` flag) only `startIdx` is tried.
34
+ * Mirrors `search` in regex/vm.ts. `caps` must be re-initialised to -1 before
35
+ * each attempt — done inside the loop via `array.fill`.
36
+ */
37
+ export declare function ensureRegexSearch(ctx: CodegenContext): number;
38
+ /**
39
+ * Emit `__regex_replace(prog, classTable, nGroups, strData, strOff, strLen,
40
+ * subject, replacement, global) -> ref $NativeString` (#1539 Phase 2c).
41
+ *
42
+ * Implements `String.prototype.replace` / `replaceAll` for a backend-created
43
+ * RegExp with a **literal** (non-`$`-pattern, non-function) replacement string
44
+ * (ECMA-262 §22.1.3.19 / §22.2.6.11 with the `$`-substitution and function
45
+ * replacer paths refused at the call site). Walks the subject with
46
+ * `__regex_search`, accumulating `result = … + slice[lastEnd, matchStart) +
47
+ * replacement` for each match and appending `slice[lastEnd, len)` at the end.
48
+ * `global != 0` replaces every match (advancing past empty matches by 1 per
49
+ * §22.2.6.11 AdvanceStringIndex); otherwise only the first.
50
+ *
51
+ * Returns a `$NativeString` — no array boundary, so no `__make_iterable` /
52
+ * host import is pulled in standalone.
53
+ */
54
+ export declare function ensureRegexReplace(ctx: CodegenContext): number;
55
+ /** Struct name for the match-result vec subtype (#1914). */
56
+ export declare const REGEXP_MATCH_VEC_STRUCT = "__regexp_match_vec";
57
+ /** Field indices of `$__regexp_match_vec` (base vec prefix + result fields). */
58
+ export declare const MATCH_VEC_FIELD_INDEX = 2;
59
+ export declare const MATCH_VEC_FIELD_INPUT = 3;
60
+ export declare const MATCH_VEC_FIELD_GROUPS = 4;
61
+ export declare const MATCH_VEC_FIELD_INDICES = 5;
62
+ /**
63
+ * Ensure the `$__regexp_match_vec` struct type (#1914) — the match-result
64
+ * shape for standalone `exec`/`match`.
65
+ *
66
+ * A WasmGC **subtype** of the nullable-native-string vec (`__vec_ref_<anyStr>`,
67
+ * fields `{length, data}`), extended with the spec result fields of
68
+ * §22.2.7.2 RegExpBuiltinExec ("index" = match start, "input" = the subject
69
+ * string). Subtyping (not a sibling struct) is load-bearing: every existing
70
+ * vec consumer (element access, `.length`, iteration) keeps working on the
71
+ * result via subsumption, and only `.index`/`.input` property reads need the
72
+ * subtype's extra fields. Mirrors the `__template_vec_externref` precedent in
73
+ * registry/types.ts (the base vec is flipped to a non-final root on demand).
74
+ */
75
+ export declare function ensureRegexMatchVecType(ctx: CodegenContext): number;
76
+ /**
77
+ * Emit `__regex_capture_array(nGroups, subject, caps) -> ref $__regexp_match_vec`
78
+ * (#1539 Phase 2b, result shape per #1914).
79
+ *
80
+ * Materializes capture slots from a populated caps array as a native string
81
+ * vec: element 0 is the full match, element N is capture N, and unmatched
82
+ * captures are null `(ref null $AnyString)`, which the standalone compiler
83
+ * already treats as `undefined` for native-string values. The returned struct
84
+ * is the match-vec subtype carrying `index` (= caps[0], the match start) and
85
+ * `input` (the flattened subject) per §22.2.7.2 RegExpBuiltinExec.
86
+ */
87
+ export declare function ensureRegexCaptureArray(ctx: CodegenContext): number;
88
+ /**
89
+ * Emit `__regex_split(prog, classTable, nGroups, strData, strOff, strLen,
90
+ * subject, lim) -> ref $vec_nstr` (#1913, full §22.2.6.14 semantics).
91
+ *
92
+ * Implements the SplitMatch walk: split points where the separator matches,
93
+ * capture values (incl. unmatched → undefined elements) interleaved after
94
+ * each split slice, every append capped at `lim` (ToUint32 of the limit
95
+ * argument; compare unsigned so the spec default 2^32-1 is just -1), and the
96
+ * empty-separator rule — a match whose END equals the last split point makes
97
+ * no split and the scan resumes one unit further (this also covers the
98
+ * empty-pattern "split into chars" behaviour without looping forever).
99
+ * Empty subject: a separator match on "" yields `[]`, otherwise `[subject]`.
100
+ */
101
+ export declare function ensureRegexSplit(ctx: CodegenContext): number;
102
+ /**
103
+ * Emit `__regex_match_all(prog, classTable, nGroups, strData, strOff, strLen,
104
+ * subject) -> ref null $__regexp_match_vec` (#1913).
105
+ *
106
+ * `String.prototype.match` with a GLOBAL regex (§22.2.6.8 step 6): collect
107
+ * every match's [0] substring, advancing past empty matches per
108
+ * AdvanceStringIndex; null when there were no matches. The result reuses the
109
+ * match-vec subtype for type uniformity with the non-global path —
110
+ * `index`/`input` carry the FIRST match (a documented narrow deviation: per
111
+ * spec a global match result is a plain Array without those properties).
112
+ */
113
+ export declare function ensureRegexMatchAll(ctx: CodegenContext): number;
114
+ /** The matchAll outer-vec type idx (`$vec<$__regexp_match_vec>`). Consumers use
115
+ * it as the result ValType of `__regex_match_all_arrays`. (#2161) */
116
+ export declare function ensureRegexMatchAllVecType(ctx: CodegenContext): number;
117
+ /**
118
+ * Emit `__regex_match_all_arrays(prog, classTable, nGroups, strData, strOff,
119
+ * strLen, subject, nScratch) -> ref $vec<$__regexp_match_vec>` (#2161).
120
+ *
121
+ * `String.prototype.matchAll` (§22.2.6.9 / RegExpStringIterator §22.2.9.2) must
122
+ * yield the **full match array** for every match — each with [0], capture
123
+ * groups, `.index`, `.input` — i.e. a sequence of capture-ARRAYS, not the [0]
124
+ * substrings that `__regex_match_all` (the global `match` path) collects.
125
+ *
126
+ * This clones the eager `__regex_match_all` AdvanceStringIndex loop verbatim,
127
+ * but per match calls `__regex_capture_array(nGroups, subject, caps)` (the same
128
+ * builder `exec`/non-global `match` use) and pushes that match-vec ref into a
129
+ * growable vec-of-(match-vec-refs). The result is ALWAYS a non-null vec (empty
130
+ * when there are no matches — matchAll returns an empty iterator, never null),
131
+ * which the native-vec for-of / spread consumers (#2169) iterate directly,
132
+ * yielding each indexable match array.
133
+ */
134
+ export declare function ensureRegexMatchAllArrays(ctx: CodegenContext): number;
135
+ /** Build inline instructions that materialize a `number[]` as a fixed
136
+ * `array i32` on the stack (used for prog + classTable literals). */
137
+ export declare function i32ArrayLiteralInstrs(ctx: CodegenContext, values: number[]): Instr[];
138
+ /**
139
+ * Emit `__regex_get_substitution(subject, slen, nGroups, caps, repl)
140
+ * -> ref $AnyString` (#1913).
141
+ *
142
+ * GetSubstitution (ECMA-262 §22.2.6.11): expand `$$`, `$&`, `` $` ``, `$'`,
143
+ * and `$n`/`$nn` in the (flattened) replacement string against the populated
144
+ * caps array. Out-of-range `$n` and `$<` (no named groups in the standalone
145
+ * engine) pass through literally per spec. Unmatched captures expand to the
146
+ * empty string. Builds the result with `__str_concat` over O(1)
147
+ * `__str_substring` views.
148
+ */
149
+ export declare function ensureRegexGetSubstitution(ctx: CodegenContext): number;
150
+ /**
151
+ * Emit `__regex_flags_str(flags: i32) -> ref $NativeString` (#1914).
152
+ *
153
+ * Builds the `RegExp.prototype.flags` string from the `$NativeRegExp` flags
154
+ * bitfield per ECMA-262 §22.2.6.4: append one code unit per set flag in the
155
+ * fixed spec order d, g, i, m, s, u, v, y. The 8-slot i16 buffer is the exact
156
+ * maximum (one slot per possible flag); `len` counts only appended units.
157
+ */
158
+ export declare function ensureRegexFlagsStr(ctx: CodegenContext): number;
@@ -0,0 +1,146 @@
1
+ import { Instr, ValType } from '../ir/types.js';
2
+ import { CodegenContext, FunctionContext } from './context/types.js';
3
+ export declare function nativeStringType(ctx: CodegenContext): ValType;
4
+ /**
5
+ * Build the inline instruction sequence that materializes a string literal as
6
+ * a NativeString (FlatString) struct ref. Mirrors `compileNativeStringLiteral`
7
+ * but returns an `Instr[]` for callers that build instruction streams without
8
+ * a `FunctionContext` (e.g. throw-instr builders that return `Instr[]`).
9
+ */
10
+ export declare function nativeStringLiteralInstrs(ctx: CodegenContext, value: string, encoding?: StringEncoding): Instr[];
11
+ /** #1588 PR-B: encoding annotation values the lowering sites consume. Mirrors
12
+ * `Encoding` in `src/ir/analysis/encoding.ts` (kept as a local string-union to
13
+ * avoid a codegen→ir import cycle). */
14
+ export type StringEncoding = "ascii" | "utf8-guaranteed" | "wtf16";
15
+ /**
16
+ * Build inline instructions that push a string constant onto the stack as an
17
+ * externref (the type expected by the throw tag and by host imports). In
18
+ * nativeStrings mode, materializes the FlatString struct inline and converts
19
+ * to externref. In legacy mode, emits a plain `global.get` of the
20
+ * `string_constants` import. Both branches require the value to be present
21
+ * in `ctx.stringGlobalMap` — call `addStringConstantGlobal(ctx, value)` first.
22
+ */
23
+ export declare function stringConstantExternrefInstrs(ctx: CodegenContext, value: string): Instr[];
24
+ /**
25
+ * Get the nullable ValType for a string reference (ref null $AnyString).
26
+ */
27
+ export declare function nativeStringTypeNullable(ctx: CodegenContext): ValType;
28
+ /**
29
+ * Get the ValType for a flat string reference (ref $NativeString).
30
+ */
31
+ export declare function flatStringType(ctx: CodegenContext): ValType;
32
+ /**
33
+ * Emit native string helper functions into the module.
34
+ * Called lazily when string operations are first encountered in fast mode.
35
+ *
36
+ * IMPORTANT: All imports must be registered BEFORE any module functions,
37
+ * because wasm function indices are: imports first, then module functions.
38
+ */
39
+ export declare function ensureNativeStringHelpers(ctx: CodegenContext): void;
40
+ export declare function ensureTextEncodingHelpers(ctx: CodegenContext): {
41
+ encodeIdx: number;
42
+ decodeU8Idx: number;
43
+ vecTypeIdx: number;
44
+ resultTypeIdx: number;
45
+ };
46
+ /**
47
+ * (#1780) Register `__textencoder_encode_into_<destElemKey>`: writes UTF-8 bytes
48
+ * of `source` into the `dest` Uint8Array backing array, never splitting a code
49
+ * point, and returns a `{ read, written }` result struct. `read` counts UTF-16
50
+ * code units consumed for fully-written code points; `written` counts bytes
51
+ * written. Shares the surrogate-decode + UTF-8 emit shape of
52
+ * `__textencoder_encode`, but writes into a caller-supplied bounded buffer.
53
+ *
54
+ * The destination vec storage differs by target: WASI/standalone back
55
+ * `Uint8Array` with a packed `i8_byte` array (`{ kind: "i8" }`), other targets
56
+ * with an `f64` array (see `typedArrayVecStorage`). The caller passes the
57
+ * matching `destElemKey` so the bytes land in the right element representation.
58
+ */
59
+ export declare function ensureEncodeIntoHelper(ctx: CodegenContext, destElemKey: "f64" | "i8_byte"): {
60
+ encodeIntoIdx: number;
61
+ destVecTypeIdx: number;
62
+ resultTypeIdx: number;
63
+ };
64
+ /**
65
+ * #1470 — Emit `$__any_to_string(v: anyref) -> ref $AnyString`, the standalone
66
+ * (no-JS-host) replacement for the `__extern_toString` host import. Dispatches
67
+ * on the concrete WasmGC type of `v`:
68
+ * - ref $AnyString → returned as-is (already a native string)
69
+ * - ref $AnyValue → switch on the boxed tag:
70
+ * 0 null → "null"
71
+ * 1 undefined → "undefined"
72
+ * 2 i32 num → number_toString(f64.convert_i32_s(i32val))
73
+ * 3 f64 num → number_toString(f64val)
74
+ * 4 bool → "true" / "false"
75
+ * 5 string → externval → any.convert_extern → ref.cast $AnyString
76
+ * 6 ref / else→ "[object Object]"
77
+ * - anything else → "[object Object]"
78
+ *
79
+ * Spec-correct dispatch for ordinary objects (walking @@toPrimitive / toString
80
+ * via the object's vtable) lands with #1472; the Phase-1 fallback here is the
81
+ * canonical `"[object Object]"` so a standalone module never traps on a string
82
+ * coercion of an arbitrary value.
83
+ *
84
+ * Idempotent — caches the function index under `nativeStrHelpers["__any_to_string"]`.
85
+ */
86
+ export declare function ensureAnyToStringHelper(ctx: CodegenContext): number;
87
+ /**
88
+ * #2007 — call-site entry point for the standalone `+`/template concat path.
89
+ * When a concat operand is a statically-known WasmGC vec (array) ref, emit the
90
+ * Array.prototype.join lowering **inline into `fctx.body`** and leave a
91
+ * `ref $AnyString` on the stack. Returns true if it handled the operand.
92
+ *
93
+ * The operand value is assumed already on the stack with the given
94
+ * `vecValType` (a `ref`/`ref_null` to a registered vec struct).
95
+ *
96
+ * **Why inline, not a cached helper (#1448).** Emitting into the current
97
+ * function body is the proven-safe pattern (cf. `compileArrayJoinNative`):
98
+ * `number_toString` / `__str_concat` indices are read here and the resulting
99
+ * `call`s live in `fctx.body`, which the late-import `shiftFuncIndices` pass
100
+ * always walks — so a closure-method operand (`[...].map(fn)`, whose late
101
+ * import registration desyncs a *separate cached helper's* baked indices) can
102
+ * no longer produce an invalid module. Nested-array elements (a ref to another
103
+ * registered vec, common in `[[1,2],[3]]` literals which are closure-free)
104
+ * recurse into the cached per-vec join helper, which is consistent there.
105
+ */
106
+ export declare function tryCompileNativeVecConcatOperand(ctx: CodegenContext, fctx: FunctionContext, vecValType: ValType): boolean;
107
+ /**
108
+ * #1470 — Emit `$__str_to_char_vec(s: ref $AnyString) -> ref $vec_nstr`: the
109
+ * pure-Wasm String-iterator materializer. Splits the string into single
110
+ * **code point** strings per §22.1.5.1 (the String Iteration protocol that
111
+ * `[...s]`, `Array.from(s)` and for-of observe): a well-formed surrogate
112
+ * pair yields one 2-code-unit string; everything else (BMP scalars and lone
113
+ * surrogates) yields a 1-code-unit string.
114
+ *
115
+ * The result reuses the `ref_<anyStr>` vec registration that `__str_split`
116
+ * established, so callers get the exact vec shape `string[]` lowers to
117
+ * (`.length`, indexing, spreads compose without conversion). The backing
118
+ * array is sized `len` (the code-unit count — an upper bound on the code
119
+ * point count); the vec's `len` field carries the actual element count, so
120
+ * trailing unused slots are never observed.
121
+ *
122
+ * Returns both the helper funcIdx (current at call time — late-import shifts
123
+ * keep `nativeStrHelpers` patched, #1839) and the nstr vec type index.
124
+ */
125
+ export declare function ensureStrToCharVecHelper(ctx: CodegenContext): {
126
+ funcIdx: number;
127
+ vecTypeIdx: number;
128
+ };
129
+ export declare function ensureNativeStringExternBridge(ctx: CodegenContext): void;
130
+ /**
131
+ * Emit `__test_str_from_externref` and `__test_str_to_externref` exported
132
+ * helpers (#1187). These are the test-runtime bridge that lets vitest tests
133
+ * pass JS strings into Wasm exports whose native-string params have type
134
+ * `(ref $AnyString)`, and read native-string results back as JS strings.
135
+ *
136
+ * Gated on `ctx.testRuntime && ctx.nativeStrings`. Production builds (with
137
+ * `testRuntime` unset) never reach this code, so the helpers are absent
138
+ * from the module entirely — zero runtime overhead.
139
+ *
140
+ * Preconditions (set up by the pre-pass in `generateModule`):
141
+ * - `addStringImports` has been called → `length`, `charCodeAt`, `concat`,
142
+ * `substring` are registered as `wasm:js-string` imports.
143
+ * - `String_fromCharCode` is registered as an `env` host import.
144
+ * - `ensureNativeStringHelpers` has been called → `__str_flatten` exists.
145
+ */
146
+ export declare function emitTestRuntimeStringHelpers(ctx: CodegenContext): void;
@@ -0,0 +1,30 @@
1
+ import { ts } from '../ts-api.js';
2
+ import { CodegenContext } from './context/types.js';
3
+ import { Instr } from '../ir/types.js';
4
+ /**
5
+ * Pre-scan the source for any `new.target` meta-property. Sets
6
+ * `ctx.usesNewTarget`. Cheap structural walk; runs once before body compilation.
7
+ */
8
+ export declare function scanForNewTarget(ctx: CodegenContext, root: ts.Node): void;
9
+ /**
10
+ * Assign (or look up) the stable 1-based class-id for a local class. Ids start
11
+ * at 1 so the global's `0` initial value never matches a real class — which
12
+ * keeps `new.target === SomeClass` false when read outside any construction.
13
+ */
14
+ export declare function getOrAssignClassNewTargetId(ctx: CodegenContext, className: string): number;
15
+ /**
16
+ * Allocate the mutable i32 `new.target` class-id global if not already present.
17
+ * Returns its absolute Wasm global index. Only call when `ctx.usesNewTarget`.
18
+ */
19
+ export declare function ensureNewTargetGlobal(ctx: CodegenContext): number;
20
+ /**
21
+ * Emit the load of the current `new.target` class-id (an i32). Only meaningful
22
+ * inside a constructor.
23
+ */
24
+ export declare function emitNewTargetClassId(ctx: CodegenContext, body: Instr[]): void;
25
+ /**
26
+ * Emit `i32.const <classId>; global.set __new_target_classid`. Call this right
27
+ * before pushing the constructor `call` instruction (args already on the
28
+ * stack). No-op when `new.target` is unused.
29
+ */
30
+ export declare function emitSetNewTargetBeforeCall(ctx: CodegenContext, body: Instr[], className: string): void;
@@ -0,0 +1,47 @@
1
+ import { ts } from '../ts-api.js';
2
+ import { CodegenContext, FunctionContext } from './context/types.js';
3
+ import { InnerResult } from './shared.js';
4
+ export declare function tryCompileNodeProcessCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
5
+ /**
6
+ * Recognize + lower an imported node:fs `readSync(fd, buf, …)` /
7
+ * `writeSync(fd, buf, …)` call. Returns the result (a byte count, f64), or
8
+ * `undefined` when this isn't a node-fs fd-based call we handle (the generic
9
+ * compiler then proceeds — path-based fs is handled / rejected elsewhere).
10
+ */
11
+ export declare function tryCompileNodeFsCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
12
+ /**
13
+ * #2655 — emit the per-`fd` "read `len` bytes from `fd` into linear `ptrLocal`,
14
+ * leaving the byte count on the stack as i32". Two modes:
15
+ * - shim (`direct=false`): `read_sync(fd, ptr, len)` — the imported shim owns
16
+ * the iovec + syscall over the shared memory; it returns the byte count.
17
+ * - direct (`direct=true`): build a `{ base=ptr, len }` iovec at
18
+ * `WASI_READSYNC_IOV_OFFSET`, call the BLOCKING
19
+ * `fd_read(fd, iovs, 1, nread=WASI_READSYNC_NREAD_OFFSET)`, then load nread.
20
+ * An errno != 0 yields 0 bytes (read loops treat `r <= 0` as EOF/stop).
21
+ *
22
+ * `ptrLocal`/`lenLocal` are i32 locals already holding the destination linear
23
+ * pointer and the requested length; `fdLocal` holds the fd.
24
+ */
25
+ export declare function emitFdReadRuntime(fctx: FunctionContext, fdLocal: number, ptrLocal: number, lenLocal: number, sinkIdx: number, direct: boolean): void;
26
+ /**
27
+ * #2655 — emit the per-`fd` "write `len` bytes from linear `ptrLocal` to `fd`,
28
+ * leaving the byte count on the stack as i32". Two modes:
29
+ * - shim (`direct=false`): `write_sync(fd, ptr, len)` returns the byte count.
30
+ * - direct (`direct=true`): build a `{ base=ptr, len }` iovec at memory[0..7],
31
+ * call `fd_write(fd, iovs=0, 1, nwritten=8)`, then load nwritten. An
32
+ * errno != 0 yields 0 bytes (write loops treat `w <= 0` as stop). The
33
+ * memory[0..11] iovec/nwritten scratch matches `emitWasiWriteTail`; a single
34
+ * writeSync call never interleaves with another write over it.
35
+ */
36
+ export declare function emitFdWriteRuntime(ctx: CodegenContext, fctx: FunctionContext, fdLocal: number, ptrLocal: number, lenLocal: number, sinkIdx: number, direct: boolean): void;
37
+ export declare function emitNodeFsResolveGcU8(ctx: CodegenContext, fctx: FunctionContext, bufExpr: ts.Expression): {
38
+ arrLocal: number;
39
+ arrTypeIdx: number;
40
+ lenLocal: number;
41
+ } | null;
42
+ /** Grow linear memory so [scratchStart, scratchStart + lenLocal) is addressable. */
43
+ export declare function ensureScratchPages(fctx: FunctionContext, scratchStart: number, lenLocal: number): void;
44
+ /** for j in [0, countLocal): dest[off + j] = scratch[scratchStart + j] (i8 array). */
45
+ export declare function emitScratchToArrayCopy(fctx: FunctionContext, arrTypeIdx: number, arrLocal: number, offLocal: number, scratchStart: number, countLocal: number): void;
46
+ /** for j in [0, countLocal): scratch[scratchStart + j] = src[off + j] (i8 array). */
47
+ export declare function emitArrayToScratchCopy(fctx: FunctionContext, arrTypeIdx: number, arrLocal: number, offLocal: number, scratchStart: number, countLocal: number): void;
@@ -0,0 +1,9 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ /**
3
+ * Emit native number-format functions and register them in `ctx.funcMap`.
4
+ * `which` is a subset of {number_toString, number_toString_radix,
5
+ * number_toFixed, number_toPrecision, number_toExponential}. Must run before
6
+ * any function bodies that call them, and (via ensureNativeStringHelpers) sets
7
+ * up the NativeString types.
8
+ */
9
+ export declare function emitNativeNumberFormat(ctx: CodegenContext, which: Set<string>): void;
@@ -0,0 +1,27 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ /**
3
+ * `__num_ryu_digits(value: f64) -> (digits: i64, exp: i32)`
4
+ *
5
+ * The Ryū `d2d` shortest-decimal core. `value` is assumed finite and non-zero.
6
+ * Returns `(digits, exp)` such that `value == ±digits × 10^exp`, where `digits`
7
+ * is the shortest decimal mantissa (sign dropped — caller tracks it). A faithful
8
+ * translation of the validated BigInt reference; comments mark each step against
9
+ * the Adams / dtolnay reference.
10
+ */
11
+ export declare function emitRyuDigits(ctx: CodegenContext): number;
12
+ /**
13
+ * `__num_ryu_to_buf(value: f64, neg: i32, buf: ref $strData, pos: i32) -> i32`
14
+ *
15
+ * Formats the shortest-roundtrip decimal of a finite, non-zero `value` into the
16
+ * caller's i16 string buffer at `pos`, writing a leading '-' when `neg`. Returns
17
+ * the new write position. Implements ECMA-262 §6.1.6.1.13 framing on top of the
18
+ * `(digits, exp)` produced by `__num_ryu_digits`:
19
+ * let k = #digits(digits), n = exp + k.
20
+ * - k <= n <= 21 → digits followed by (n-k) zeros (integer)
21
+ * - 0 < n <= 21 → digits[0..n] '.' digits[n..] (fixed)
22
+ * - -6 < n <= 0 → "0." (-n zeros) digits (fixed)
23
+ * - otherwise → digits[0] ['.' digits[1..]] 'e' sign |n-1| (exp)
24
+ *
25
+ * `strDataTypeIdx` is the native-string i16 array type (caller's buffer type).
26
+ */
27
+ export declare function emitRyuToBuf(ctx: CodegenContext, strDataTypeIdx: number): number;
@@ -0,0 +1,94 @@
1
+ import { ts } from '../ts-api.js';
2
+ import { ValType } from '../ir/types.js';
3
+ import { CodegenContext, FunctionContext } from './context/types.js';
4
+ import { InnerResult } from './shared.js';
5
+ /**
6
+ * Try to constant-fold `ToBoolean(<expr>)` at compile time. Returns:
7
+ * - `true`/`false` if the expression has a statically-known truthiness
8
+ * - `undefined` if the value cannot be determined at compile time (caller
9
+ * must evaluate at runtime or fall back to the dynamic path).
10
+ *
11
+ * Per ES spec §6.2.5.6 step 5.b, every descriptor attribute (writable,
12
+ * enumerable, configurable) is run through `ToBoolean` before being stored.
13
+ * Previously the codegen only accepted the `true`/`false` keyword literals
14
+ * and silently dropped the entire attribute when any other expression
15
+ * appeared (so `{ configurable: -12345 }` resulted in `configurable: false`
16
+ * — a silent spec violation triggering 1,000+ test262 failures).
17
+ */
18
+ export declare function tryConstantFoldToBoolean(init: ts.Expression): boolean | undefined;
19
+ export declare function emitDefinePropertyDescRuntime(ctx: CodegenContext, fctx: FunctionContext, objArg: ts.Expression, propArg: ts.Expression, descArg: ts.Expression, undefinedFields: readonly string[]): ValType | null;
20
+ /**
21
+ * Check if the first argument to Object.defineProperty / defineProperties
22
+ * is statically known to be a non-object type (undefined, null, boolean,
23
+ * number, string). If so, emit `throw TypeError` and return true.
24
+ *
25
+ * Per ES spec (19.1.2.4 step 1): "If Type(O) is not Object, throw a TypeError."
26
+ */
27
+ export declare function emitNonObjectArgGuard(ctx: CodegenContext, fctx: FunctionContext, argExpr: ts.Expression, methodName: string): boolean;
28
+ /**
29
+ * Property descriptor flag encoding for the __pf_ side-table:
30
+ * bit 0: writable
31
+ * bit 1: enumerable
32
+ * bit 2: configurable
33
+ * bit 3: "defined" marker (always 1 when a descriptor has been stored)
34
+ * bit 4: is accessor property (get/set vs data)
35
+ */
36
+ export declare const PROP_FLAG_WRITABLE: number;
37
+ export declare const PROP_FLAG_ENUMERABLE: number;
38
+ export declare const PROP_FLAG_CONFIGURABLE: number;
39
+ export declare const PROP_FLAG_DEFINED: number;
40
+ export declare const PROP_FLAG_ACCESSOR: number;
41
+ /**
42
+ * Compute a compile-time flags integer from parsed descriptor booleans.
43
+ * Unspecified flags default to false per the ES spec for Object.defineProperty.
44
+ */
45
+ export declare function computeDescriptorFlags(writable: boolean | undefined, enumerable: boolean | undefined, configurable: boolean | undefined, isAccessor: boolean): number;
46
+ /**
47
+ * Emit code to check existing property flags and throw TypeError if the
48
+ * Object.defineProperty operation violates the spec. Also stores the new flags.
49
+ *
50
+ * Uses __extern_get/set with "__pf_<propName>" keys to store flags as boxed numbers.
51
+ * Uses "__ne" key to check non-extensibility.
52
+ *
53
+ * @param objLocal - local index holding the externref object
54
+ * @param propName - compile-time property name
55
+ * @param newFlags - the flags integer for the new descriptor
56
+ * @param hasValue - whether the new descriptor specifies a value
57
+ */
58
+ export declare function emitDefinePropertyFlagCheck(ctx: CodegenContext, fctx: FunctionContext, objLocal: number, propName: string, newFlags: number, hasValue: boolean): void;
59
+ /**
60
+ * Compile Object.defineProperty(obj, prop, descriptor).
61
+ *
62
+ * If the descriptor is an object literal with a `value` property, we extract
63
+ * the value and emit __extern_set(obj, prop, value).
64
+ * If the descriptor has `get` and/or `set` properties, we compile them as
65
+ * struct accessor methods (getter/setter functions).
66
+ * Otherwise we compile all arguments for side effects and return the object unchanged.
67
+ *
68
+ * Returns obj (externref).
69
+ */
70
+ export declare function compileObjectDefineProperty(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): ValType | null;
71
+ /**
72
+ * Compile Object.defineProperties(obj, descriptors).
73
+ *
74
+ * Static path: when descriptors is an object literal, iterate each property
75
+ * and synthesize individual Object.defineProperty calls at compile time.
76
+ *
77
+ * Dynamic fallback: delegate to __defineProperties host import.
78
+ */
79
+ export declare function compileObjectDefineProperties(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): ValType | null;
80
+ /**
81
+ * Compile Object.keys(obj) or Object.values(obj) by expanding struct fields
82
+ * at compile time. Object.keys returns a string[] of field names,
83
+ * Object.values returns an array of the field values.
84
+ */
85
+ export declare function compileObjectKeysOrValues(ctx: CodegenContext, fctx: FunctionContext, method: string, expr: ts.CallExpression): ValType | null;
86
+ /**
87
+ * Compile obj.hasOwnProperty(key) / obj.propertyIsEnumerable(key).
88
+ * For WasmGC structs all own fields are enumerable, so both methods behave
89
+ * identically: return true iff `key` names an own field of the struct type.
90
+ *
91
+ * Static resolution (string literal arg): constant fold to i32.const 0/1.
92
+ * Dynamic resolution: runtime string comparison against known field names.
93
+ */
94
+ export declare function compilePropertyIntrospection(ctx: CodegenContext, fctx: FunctionContext, propAccess: ts.PropertyAccessExpression, expr: ts.CallExpression): InnerResult;