diff --git a/src/call-context.ts b/src/call-context.ts index d8e0b54..d3be7e0 100644 --- a/src/call-context.ts +++ b/src/call-context.ts @@ -199,6 +199,11 @@ export class CallContext { block?.view.setBigUint64(Number(offset), n, true); }, + input_offset: () => { + const blockIdx = this.#stack[this.#stack.length - 1][0]; + return Block.indexToAddress(blockIdx || 0); + }, + input_length: () => { return BigInt(this.#input?.byteLength ?? 0); }, diff --git a/src/mod.test.ts b/src/mod.test.ts index cdc26da..32665f6 100644 --- a/src/mod.test.ts +++ b/src/mod.test.ts @@ -505,6 +505,17 @@ if (typeof WebAssembly === 'undefined') { } }); + test('plugin can call input_offset', async () => { + const plugin = await createPlugin('http://localhost:8124/wasm/input_offset.wasm'); + try { + const input = 'hello world'; + const hw = await plugin.call('input_offset_length', input); + assert.equal(hw?.getBigUint64(0, true), input.length); + } finally { + await plugin.close(); + } + }); + test('plugin can fail gracefully', async () => { const plugin = await createPlugin('http://localhost:8124/wasm/fail.wasm'); try { diff --git a/wasm/input_offset.wasm b/wasm/input_offset.wasm new file mode 100644 index 0000000..163adce Binary files /dev/null and b/wasm/input_offset.wasm differ