Skip to content

Commit

Permalink
Better string args test
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Nov 29, 2024
1 parent 5827321 commit 05a3945
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion crates/cli/tests/reference/string-arg.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* tslint:disable */
/* eslint-disable */
export function foo(a: string): void;
export function bar(a: string, b: string, ptr: number, len: number): string;
export function two_strings(a: string, b: string): string;
export function two_strings_and_some_more(a: string, b: string, ptr: number, len: number): string;
24 changes: 22 additions & 2 deletions crates/cli/tests/reference/string-arg.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,40 @@ export function foo(a) {
wasm.foo(ptr, len);
}

/**
* @param {string} a
* @param {string} b
* @returns {string}
*/
export function two_strings(a, b) {
try {
const ptr = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(b, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len2 = WASM_VECTOR_LEN;
const ret = wasm.two_strings(ptr, len, ptr1, len2);
var deferred0 = ret[0];
var deferred1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred0, deferred1, 1);
}
}

/**
* @param {string} a
* @param {string} b
* @param {number} ptr
* @param {number} len
* @returns {string}
*/
export function bar(a, b, ptr, len) {
export function two_strings_and_some_more(a, b, ptr, len) {
try {
const ptr1 = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len2 = WASM_VECTOR_LEN;
const ptr3 = passStringToWasm0(b, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len4 = WASM_VECTOR_LEN;
const ret = wasm.bar(ptr1, len2, ptr3, len4, ptr, len);
const ret = wasm.two_strings_and_some_more(ptr1, len2, ptr3, len4, ptr, len);
var deferred0 = ret[0];
var deferred1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
Expand Down
7 changes: 6 additions & 1 deletion crates/cli/tests/reference/string-arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ pub fn foo(a: &str) {
}

#[wasm_bindgen]
pub fn bar(a: &str, b: String, ptr: u32, len: u32) -> String {
pub fn two_strings(a: &str, b: String) -> String {
b
}

#[wasm_bindgen]
pub fn two_strings_and_some_more(a: &str, b: String, ptr: u32, len: u32) -> String {
b
}
9 changes: 6 additions & 3 deletions crates/cli/tests/reference/string-arg.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
(type (;2;) (func (param i32 i32) (result i32)))
(type (;3;) (func (param i32 i32 i32)))
(type (;4;) (func (param i32 i32 i32 i32) (result i32)))
(type (;5;) (func (param i32 i32 i32 i32 i32 i32) (result i32 i32)))
(type (;5;) (func (param i32 i32 i32 i32) (result i32 i32)))
(type (;6;) (func (param i32 i32 i32 i32 i32 i32) (result i32 i32)))
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0)))
(func $__wbindgen_realloc (;1;) (type 4) (param i32 i32 i32 i32) (result i32))
(func $__wbindgen_malloc (;2;) (type 2) (param i32 i32) (result i32))
(func $foo (;3;) (type 1) (param i32 i32))
(func $__wbindgen_free (;4;) (type 3) (param i32 i32 i32))
(func $"bar multivalue shim" (;5;) (type 5) (param i32 i32 i32 i32 i32 i32) (result i32 i32))
(func $"two_strings_and_some_more multivalue shim" (;5;) (type 6) (param i32 i32 i32 i32 i32 i32) (result i32 i32))
(func $"two_strings multivalue shim" (;6;) (type 5) (param i32 i32 i32 i32) (result i32 i32))
(table (;0;) 128 externref)
(memory (;0;) 17)
(export "memory" (memory 0))
(export "foo" (func $foo))
(export "bar" (func $"bar multivalue shim"))
(export "two_strings" (func $"two_strings multivalue shim"))
(export "two_strings_and_some_more" (func $"two_strings_and_some_more multivalue shim"))
(export "__wbindgen_export_0" (table 0))
(export "__wbindgen_malloc" (func $__wbindgen_malloc))
(export "__wbindgen_realloc" (func $__wbindgen_realloc))
Expand Down

0 comments on commit 05a3945

Please sign in to comment.