The following test (is a baseline before adding any changes in relation to PR 1987). These tests were performed using the standard untouched code base from https://github.com/rustwasm/wasm-bindgen.git
cargo test -p wasm-bindgen-cli --test reference
Finished test [unoptimized + debuginfo] target(s) in 0.12s
Running target/debug/deps/reference-c3db2c64df48e6fd
failed tests:
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/anyref-empty.rs failure
found a difference:
(module
(type (;0;) (func))
(import "./reference_test.js" "__wbindgen_init_anyref_table" (func (;0;) (type 0)))
(table (;0;) 32 anyref)
- (memory (;0;) 17)
+ (memory (;0;) 16)
(export "memory" (memory 0))
(export "__wbindgen_export_0" (table 0))
(export "__wbindgen_start" (func 0)))
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/empty.rs failure
found a difference:
(module
- (memory (;0;) 17)
+ (memory (;0;) 16)
(export "memory" (memory 0)))
Error: tests failed
error: test failed, to rerun pass '-p wasm-bindgen-cli --test reference'
The next step after this is to use the BLESS=1
. For now, this is just as is without using BLESS at all.
cargo test -p wasm-bindgen-cli --test reference
Compiling wasm-bindgen-cli-support v0.2.58 (/Users/tpmccallum/wasm-bindgen/crates/cli-support)
Compiling wasm-bindgen-cli v0.2.58 (/Users/tpmccallum/wasm-bindgen/crates/cli)
Finished test [unoptimized + debuginfo] target(s) in 5.94s
Running target/debug/deps/reference-c3db2c64df48e6fd
failed tests:
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/anyref-empty.rs failure
found a difference:
(module
(type (;0;) (func))
(import "./reference_test.js" "__wbindgen_init_anyref_table" (func (;0;) (type 0)))
(table (;0;) 32 anyref)
- (memory (;0;) 17)
+ (memory (;0;) 16)
(export "memory" (memory 0))
(export "__wbindgen_export_0" (table 0))
(export "__wbindgen_start" (func 0)))
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/empty.rs failure
found a difference:
(module
- (memory (;0;) 17)
+ (memory (;0;) 16)
(export "memory" (memory 0)))
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/import-catch.rs failure
found a difference:
import * as wasm from './reference_test_bg.wasm';
-const heap = new Array(32);
+const heap = [];
-heap.fill(undefined);
+heap.length = 32;
heap.push(undefined, null, true, false);
function getObject(idx) { return heap[idx]; }
let heap_next = heap.length;
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function handleError(e) {
wasm.__wbindgen_exn_store(addHeapObject(e));
}
/**
*/
export function exported() {
wasm.exported();
}
export const __wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
export const __wbg_foo_8d66ddef0ff279d6 = function() {
try {
foo();
} catch (e) {
handleError(e)
}
};
export const __wbindgen_rethrow = function(arg0) {
throw takeObject(arg0);
};
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/interface-types-empty.rs failure
found a difference:
(module
- (type (;0;) (func))
- (func $empty (type 0))
- (memory (;0;) 17)
- (export "memory" (memory 0))
- (export "empty" (func $empty))
- (@interface type (;0;) (func))
- (@interface func (;0;) (type 0)
- call-core $empty)
- (@interface export "empty" (func 0)))
+ (memory (;0;) 16)
+ (export "memory" (memory 0)))
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/interface-types-strings.rs failure
found a difference:
(module
- (type (;0;) (func (param i32) (result i32)))
- (type (;1;) (func (param i32 i32)))
- (type (;2;) (func (param i32 i32) (result i32 i32)))
- (type (;3;) (func (param i32 i32 i32 i32)))
- (func $__wbindgen_malloc (type 0) (param i32) (result i32))
- (func $many_strings (type 3) (param i32 i32 i32 i32))
- (func $__wbindgen_free (type 1) (param i32 i32))
- (func $strings multivalue shim (type 2) (param i32 i32) (result i32 i32))
- (memory (;0;) 17)
- (export "memory" (memory 0))
- (export "strings" (func $strings multivalue shim))
- (export "many_strings" (func $many_strings))
- (@interface type (;0;) (func (param string) (result string)))
- (@interface type (;1;) (func (param string) (param string)))
- (@interface func (;0;) (type 0)
- arg.get 0
- string-to-memory $__wbindgen_malloc
- call-core $strings multivalue shim
- defer-call-core $__wbindgen_free
- memory-to-string)
- (@interface func (;1;) (type 1)
- arg.get 0
- string-to-memory $__wbindgen_malloc
- arg.get 1
- string-to-memory $__wbindgen_malloc
- call-core $many_strings)
- (@interface export "strings" (func 0))
- (@interface export "many_strings" (func 1)))
+ (memory (;0;) 16)
+ (export "memory" (memory 0)))
/Users/tpmccallum/wasm-bindgen/crates/cli/tests/reference/string-arg.rs failure
found a difference:
import * as wasm from './reference_test_bg.wasm';
-const lTextDecoder = typeof TextDecoder === 'undefined' ? require('util').TextDecoder : TextDecoder;
-
-let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
-
-cachedTextDecoder.decode();
-
-let cachegetUint8Memory0 = null;
-function getUint8Memory0() {
- if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
- cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
- }
- return cachegetUint8Memory0;
-}
-
-function getStringFromWasm0(ptr, len) {
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
-}
-
-let WASM_VECTOR_LEN = 0;
-
-const lTextEncoder = typeof TextEncoder === 'undefined' ? require('util').TextEncoder : TextEncoder;
-
-let cachedTextEncoder = new lTextEncoder('utf-8');
-
-const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
- ? function (arg, view) {
- return cachedTextEncoder.encodeInto(arg, view);
-}
- : function (arg, view) {
- const buf = cachedTextEncoder.encode(arg);
- view.set(buf);
- return {
- read: arg.length,
- written: buf.length
- };
-});
-
-function passStringToWasm0(arg, malloc, realloc) {
-
- if (realloc === undefined) {
- const buf = cachedTextEncoder.encode(arg);
- const ptr = malloc(buf.length);
- getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
- WASM_VECTOR_LEN = buf.length;
- return ptr;
- }
-
- let len = arg.length;
- let ptr = malloc(len);
-
- const mem = getUint8Memory0();
-
- let offset = 0;
-
- for (; offset < len; offset++) {
- const code = arg.charCodeAt(offset);
- if (code > 0x7F) break;
- mem[ptr + offset] = code;
- }
-
- if (offset !== len) {
- if (offset !== 0) {
- arg = arg.slice(offset);
- }
- ptr = realloc(ptr, len, len = offset + arg.length * 3);
- const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
- const ret = encodeString(arg, view);
-
- offset += ret.written;
- }
-
- WASM_VECTOR_LEN = offset;
- return ptr;
-}
-/**
-* @param {string} a
-*/
-export function foo(a) {
- var ptr0 = passStringToWasm0(a, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
- var len0 = WASM_VECTOR_LEN;
- wasm.foo(ptr0, len0);
-}
-
-export const __wbindgen_throw = function(arg0, arg1) {
- throw new Error(getStringFromWasm0(arg0, arg1));
-};
-
Error: tests failed
error: test failed, to rerun pass '-p wasm-bindgen-cli --test reference'
The following test was performed with new code changes (as per PR 1987) using the system variable BLESS=1
export BLESS=1
cargo test -p wasm-bindgen-cli --test reference
Finished test [unoptimized + debuginfo] target(s) in 0.11s
Running target/debug/deps/reference-c3db2c64df48e6fd
13 tests passed