Skip to content

Hash full signature for imported functions #4269

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 3 commits into from
Nov 14, 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
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/anyref-import-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function exported() {
}
}

export function __wbg_foo_95fe1a04017077db() { return handleError(function () {
export function __wbg_foo_4e8309b1aa95a4ac() { return handleError(function () {
foo();
}, arguments) };

Expand Down
12 changes: 6 additions & 6 deletions crates/cli/tests/reference/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ export function exported() {
}
}

export function __wbg_add_dd5307a7ca6818d5(arg0, arg1) {
export function __wbg_add_7fbfb2c172506d12(arg0, arg1) {
const ret = add(arg0, arg1);
return ret;
};

export function __wbg_barfromfoo_d097f3ec35aab47c() {
export function __wbg_barfromfoo_29614885590bfb6f() {
bar_from_foo();
};

export function __wbg_catchme_a7bca7f3d5a5f319() { return handleError(function () {
export function __wbg_catchme_f7d87ea824a61e87() { return handleError(function () {
catch_me();
}, arguments) };

export function __wbg_nocatch_62552fa42a58590b() {
export function __wbg_nocatch_be850a8dddd9599d() {
no_catch();
};

export function __wbg_reload_90d82b22b83c1d99() {
export function __wbg_reload_84c12f152ad689f0() {
window.location.reload();
};

export function __wbg_write_d258674ff6f0ea8d(arg0, arg1) {
export function __wbg_write_c2ce0ce33a6087d5(arg0, arg1) {
window.document.write(getStringFromWasm0(arg0, arg1));
};

3 changes: 3 additions & 0 deletions crates/cli/tests/reference/modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* tslint:disable */
/* eslint-disable */
export function exported(): void;
78 changes: 78 additions & 0 deletions crates/cli/tests/reference/modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
let wasm;
export function __wbg_set_wasm(val) {
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);

function getObject(idx) { return heap[idx]; }

let heap_next = heap.length;

function dropObject(idx) {
if (idx < 132) 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;
}

export function exported() {
wasm.exported();
}

export function __wbg_parseFloat_2be7f01c31025438(arg0, arg1) {
const ret = parseFloat(getStringFromWasm0(arg0, arg1));
return ret;
};

export function __wbg_parseFloat_7bc8aecd47f33642(arg0) {
const ret = parseFloat(getObject(arg0));
return ret;
};

export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};

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

38 changes: 38 additions & 0 deletions crates/cli/tests/reference/modules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use wasm_bindgen::prelude::*;

mod a {
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = parseFloat)]
pub fn parse_float(text: &JsValue) -> f64;
}
}

mod b {
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = parseFloat)]
pub fn parse_float(text: &str) -> f64;
}
}

mod a_again {
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = parseFloat)]
pub fn parse_float(text: &JsValue) -> f64;
}
}

#[wasm_bindgen]
pub fn exported() {
let _ = a::parse_float(&JsValue::from_str("3.14"));
let _ = b::parse_float("3.14");
let _ = a_again::parse_float(&JsValue::from_str("3.14"));
}
9 changes: 9 additions & 0 deletions crates/cli/tests/reference/modules.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(module $reference_test.wasm
(type (;0;) (func))
(func $exported (;0;) (type 0))
(memory (;0;) 17)
(export "memory" (memory 0))
(export "exported" (func $exported))
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
)

2 changes: 1 addition & 1 deletion crates/cli/tests/reference/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class Test {
}
}

export function __wbg_test2_39fe629b9aa739cf() {
export function __wbg_test2_ae36e154b7589768() {
const ret = test2();
return addHeapObject(ret);
};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/targets-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function add_that_might_fail(a, b) {
return ret >>> 0;
}

export function __wbg_random_5d40be260a2cfbac() {
export function __wbg_random_8be0a899673d8681() {
const ret = Math.random();
return ret;
};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/targets-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function __wbg_load(module, imports) {
function __wbg_get_imports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbg_random_5d40be260a2cfbac = function() {
imports.wbg.__wbg_random_8be0a899673d8681 = function() {
const ret = Math.random();
return ret;
};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/targets-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let wasm_bindgen;
function __wbg_get_imports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbg_random_5d40be260a2cfbac = function() {
imports.wbg.__wbg_random_8be0a899673d8681 = function() {
const ret = Math.random();
return ret;
};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/targets-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports.add_that_might_fail = function(a, b) {
return ret >>> 0;
};

module.exports.__wbg_random_5d40be260a2cfbac = function() {
module.exports.__wbg_random_8be0a899673d8681 = function() {
const ret = Math.random();
return ret;
};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/targets-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function add_that_might_fail(a, b) {

const imports = {
__wbindgen_placeholder__: {
__wbg_random_5d40be260a2cfbac: function() {
__wbg_random_8be0a899673d8681: function() {
const ret = Math.random();
return ret;
},
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/reference/web-sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function get_media_source() {

const __wbindgen_enum_MediaSourceEnum = ["camera", "screen", "application", "window", "browser", "microphone", "audioCapture", "other"];

export function __wbg_new_1cabf49927794f50() { return handleError(function (arg0, arg1) {
export function __wbg_new_561a91ce53f10a66() { return handleError(function (arg0, arg1) {
const ret = new URL(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
}, arguments) };
Expand Down
2 changes: 1 addition & 1 deletion crates/macro-support/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ impl<'a> ConvertToAst<(&ast::Program, BindgenAttrs, &'a Option<ast::ImportModule
ast::ImportFunctionKind::Normal => (0, "n"),
ast::ImportFunctionKind::Method { ref class, .. } => (1, &class[..]),
};
let data = (ns, &self.sig.ident, module);
let data = (ns, self.sig.to_token_stream().to_string(), module);
format!(
"__wbg_{}_{}",
wasm.name
Expand Down