Closed
Description
I am trying to pass an array of strings into a Web API.
I believe I am correctly creating the array using this function:
fn js_array(values: &[&str]) -> JsValue {
return JsValue::from(values.into_iter()
.map(|x| JsValue::from_str(x))
.collect::<Array>());
}
When I log this into the console, it shows the correct array.
When I pass this array into the generate_key_with_str method, it causes a crash in the browser.
The code looks like this:
let window = web_sys::window().expect("no global `window` exists");
let crypto = window.crypto().expect("Crypto does not exist").subtle();
let algs = js_array(&["sign"]);
let key_promise = crypto.generate_key_with_str("RSA-PSS", true, &algs)
.expect("Key not generated");
let key_pair: CryptoKeyPair = JsFuture::from(key_promise).await.unwrap().into();
The error:
panicked at 'called `Result::unwrap()` on an `Err` value: JsValue(SyntaxError: An invalid or illegal string was specified
init/imports.wbg.__wbg_generateKey_a00ff12147e79f53<@http://localhost:8000/pkg/my_module.js:322:35
handleError/<@http://localhost:8000/pkg/my_module.js:224:22
If I do not unwrap in the last line of the code snippet above, then I still get this logged into the console:
SyntaxError: An invalid or illegal string was specified
The JavaScript code that the browser links to is this:
imports.wbg.__wbg_generateKey_a00ff12147e79f53 = handleError(function(arg0, arg1, arg2, arg3, arg4) {
var ret = getObject(arg0).generateKey(getStringFromWasm0(arg1, arg2), arg3 !== 0, getObject(arg4));
return addHeapObject(ret);
});