Skip to content

Commit e5890b1

Browse files
committedSep 30, 2023
Add an optional handler for detecting memory.grow() use in the runtime
This handler can be used with an import for users not using ESM bindings to recreate views into memory only when necessary.
1 parent 1126ef1 commit e5890b1

File tree

165 files changed

+6118
-1436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+6118
-1436
lines changed
 

‎std/assembly/rt/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ declare function __finalize(ptr: usize): void;
2929
declare const ASC_RTRACE: bool;
3030
declare const ASC_PROFILE: bool;
3131

32+
// Memory growth handling
33+
declare function ASC_RT_GROW_HANDLER(): void;
34+
3235
// Incremental GC constants
3336
declare const ASC_GC_GRANULARITY: i32;
3437
declare const ASC_GC_SWEEPFACTOR: i32;

‎std/assembly/rt/stub.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function maybeGrowMemory(newOffset: usize): void {
1818
if (memory.grow(pagesWanted) < 0) {
1919
if (memory.grow(pagesNeeded) < 0) unreachable(); // out of memory
2020
}
21+
if (isDefined(ASC_RT_GROW_HANDLER)) ASC_RT_GROW_HANDLER();
2122
}
2223
offset = newOffset;
2324
}

0 commit comments

Comments
 (0)