@polyengine/runtime 0.4.0-pre.g234c440 → 0.4.0-pre.gd7d6e28

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.
@@ -26,15 +26,32 @@ export class LiftLowerContext {
26
26
  this.borrowScope = borrowScope;
27
27
  }
28
28
  /**
29
- * definitions.py `LiftLowerContext.reallocate` routes the call through
30
- * canon_lift (reentrance bookkeeping and may_leave toggling around a
31
- * guest-side realloc export). v1 simplification: call the provided realloc
32
- * directly. The full path returns with the task machinery.
29
+ * definitions.py `LiftLowerContext.reallocate`: the guest's realloc runs
30
+ * with `may_leave` cleared, so a realloc that lowers an import traps
31
+ * (`canon_lower`'s `trap_if(not ...may_leave)`, implemented here by
32
+ * exec/boundary.ts `createLoweredImport`). That bracket is implemented
33
+ * below. What remains deferred is only the reference's routing of the call
34
+ * through `canon_lift`; upstream component-model PR #705 removes that
35
+ * routing, leaving this bracket as the whole story. polyengine issue #147.
33
36
  */
34
37
  reallocate(old, oldByteLength, alignment, newByteLength) {
35
38
  const realloc = this.opts.realloc;
36
39
  trapIf(realloc === null, "realloc required but not provided");
37
- return realloc(old, oldByteLength, alignment, newByteLength);
40
+ // A null instance is the value-interpreter unit-test harness only
41
+ // (tests/support/driver.ts `mkCx`); every real runtime path constructs
42
+ // this context with an instance, so there is no flag to bracket.
43
+ if (this.inst === null) {
44
+ return realloc(old, oldByteLength, alignment, newByteLength);
45
+ }
46
+ assert_(this.inst.mayLeave, "realloc with may_leave already false");
47
+ this.inst.mayLeave = false;
48
+ // NO try/finally, deliberately: same bare bracket as the post-return one
49
+ // in intrinsics/fact_calls.ts (#91) and the reference's `assert`/restore
50
+ // pair. A trapping realloc skips the restore exactly as the reference
51
+ // does; the host-boundary unwind and instance poisoning handle the rest.
52
+ const ptr = realloc(old, oldByteLength, alignment, newByteLength);
53
+ this.inst.mayLeave = true;
54
+ return ptr;
38
55
  }
39
56
  allocate(alignment, byteLength) {
40
57
  return this.reallocate(0, 0, alignment, byteLength);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyengine/runtime",
3
- "version": "0.4.0-pre.g234c440",
3
+ "version": "0.4.0-pre.gd7d6e28",
4
4
  "description": "A WebAssembly Component Model host for JavaScript engines: plan executor, canonical ABI, 0.3 task scheduler, JSPI bridge, and embedder API.",
5
5
  "homepage": "https://github.com/polymorph-components/polyengine#readme",
6
6
  "repository": {
@@ -49,10 +49,13 @@ export declare class LiftLowerContext {
49
49
  borrowScope: SubtaskBorrowScope | TaskBorrowScope | null;
50
50
  constructor(opts: LiftLowerOptions, inst?: ComponentInstanceLike | null, borrowScope?: SubtaskBorrowScope | TaskBorrowScope | null);
51
51
  /**
52
- * definitions.py `LiftLowerContext.reallocate` routes the call through
53
- * canon_lift (reentrance bookkeeping and may_leave toggling around a
54
- * guest-side realloc export). v1 simplification: call the provided realloc
55
- * directly. The full path returns with the task machinery.
52
+ * definitions.py `LiftLowerContext.reallocate`: the guest's realloc runs
53
+ * with `may_leave` cleared, so a realloc that lowers an import traps
54
+ * (`canon_lower`'s `trap_if(not ...may_leave)`, implemented here by
55
+ * exec/boundary.ts `createLoweredImport`). That bracket is implemented
56
+ * below. What remains deferred is only the reference's routing of the call
57
+ * through `canon_lift`; upstream component-model PR #705 removes that
58
+ * routing, leaving this bracket as the whole story. polyengine issue #147.
56
59
  */
57
60
  reallocate(old: number, oldByteLength: number, alignment: number, newByteLength: number): number;
58
61
  allocate(alignment: number, byteLength: number): number;