Skip to content

More tests for result type #4208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions crates/cli/tests/reference/result-string.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions crates/cli/tests/reference/result-string.rs

This file was deleted.

12 changes: 0 additions & 12 deletions crates/cli/tests/reference/result-string.wat

This file was deleted.

5 changes: 5 additions & 0 deletions crates/cli/tests/reference/result.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* tslint:disable */
/* eslint-disable */
export function result_string(): string;
export function result_void(): void;
export function result_i32(): number;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ export function __wbg_set_wasm(val) {
}


const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);
Expand Down Expand Up @@ -32,34 +52,14 @@ function takeObject(idx) {
dropObject(idx);
return ret;
}

const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
/**
* @returns {string}
*/
export function exported() {
export function result_string() {
let deferred2_0;
let deferred2_1;
try {
const ret = wasm.exported();
const ret = wasm.result_string();
var ptr1 = ret[0];
var len1 = ret[1];
if (ret[3]) {
Expand All @@ -74,6 +74,29 @@ export function exported() {
}
}

export function result_void() {
const ret = wasm.result_void();
if (ret[1]) {
throw takeObject(ret[0]);
}
}

/**
* @returns {number}
*/
export function result_i32() {
const ret = wasm.result_i32();
if (ret[2]) {
throw takeObject(ret[1]);
}
return ret[0];
}

export function __wbindgen_error_new(arg0, arg1) {
const ret = new Error(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};

export function __wbindgen_number_new(arg0) {
const ret = arg0;
return addHeapObject(ret);
Expand Down
16 changes: 16 additions & 0 deletions crates/cli/tests/reference/result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn result_string() -> Result<String, JsValue> {
Err(JsValue::from(5i32))
}

#[wasm_bindgen]
pub fn result_void() -> Result<(), JsError> {
Err(JsError::new("message"))
}

#[wasm_bindgen]
pub fn result_i32() -> Result<i32, JsError> {
Ok(1)
}
18 changes: 18 additions & 0 deletions crates/cli/tests/reference/result.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(module $reference_test.wasm
(type (;0;) (func (result i32 i32)))
(type (;1;) (func (result i32 i32 i32)))
(type (;2;) (func (result i32 i32 i32 i32)))
(type (;3;) (func (param i32 i32 i32)))
(func $__wbindgen_free (;0;) (type 3) (param i32 i32 i32))
(func $"result_string multivalue shim" (;1;) (type 2) (result i32 i32 i32 i32))
(func $"result_i32 multivalue shim" (;2;) (type 1) (result i32 i32 i32))
(func $"result_void multivalue shim" (;3;) (type 0) (result i32 i32))
(memory (;0;) 17)
(export "memory" (memory 0))
(export "result_string" (func $"result_string multivalue shim"))
(export "result_void" (func $"result_void multivalue shim"))
(export "result_i32" (func $"result_i32 multivalue shim"))
(export "__wbindgen_free" (func $__wbindgen_free))
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)