Skip to content

Commit

Permalink
test variant memory
Browse files Browse the repository at this point in the history
  • Loading branch information
justjake committed Jan 24, 2024
1 parent 6265b45 commit 117953d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/quickjs-emscripten-core/src/lifetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export abstract class UsingDisposable implements Disposable {
const SymbolDispose = Symbol.dispose ?? Symbol.for("Symbol.dispose")
const prototypeAsAny = UsingDisposable.prototype as any
if (!prototypeAsAny[SymbolDispose]) {
prototypeAsAny[SymbolDispose] = function () { return this.dispose() }
prototypeAsAny[SymbolDispose] = function () {
return this.dispose()
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/quickjs-emscripten/src/quickjs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
DefaultIntrinsics,
RELEASE_SYNC,
RELEASE_ASYNC,
newVariant,
} from "."

const TEST_NO_ASYNC = Boolean(process.env.TEST_NO_ASYNC)
Expand Down Expand Up @@ -1180,6 +1181,21 @@ describe("QuickJSWASMModule", () => {
for (const variant of variants) {
moduleTests(variant)
}

describe("newVariant", () => {
it("uses the provided WebAssembly.Memory", async () => {
const wasmMemory = new WebAssembly.Memory({
initial: 16777216 / 65536,
maximum: 2147483648 / 65536,
})
const variant = newVariant(RELEASE_SYNC, {
wasmMemory,
})
const mod = await newQuickJSWASMModule(variant)

expect(mod.getWasmMemory()).toBe(wasmMemory)
})
})
})

function moduleTests(args: { name: string; loader: () => Promise<QuickJSWASMModule> }) {
Expand Down

0 comments on commit 117953d

Please sign in to comment.