* Implement OptionIntoWasmAbi for Closure references
* Add tests for optional closure arguments
* Uncomment None test for optional closure argument
* Tighten None test for optional closure argument
* Add tests for dropping optional closures
Co-authored-by: Billy Bradley <billy@squeno.com>
* add Descriptor RESULT and Instruction::UnwrapResult
* ResultAbi / ResultAbiUnion
basic wasmresult support
one WasmResult ctor per WasmAbi
Remove WasmResult class
* Reverse the fields on ResultAbi, remove is_ok as err can be 0
impl OptionIntoWasmAbi for JsValue
* implement ResultAbi
* Add tests for `-> Result<T, JsError>`
* split result.rs tests in two
remove console_log
* initial implementation of `-> Result<T, JsError>`
describe Result<_, JsError>
implement Intrinsics::ErrorNew
Revert impl From<()> for JsValue (src/lib.rs)
impl WasmDescribe etc for JsError
remove unused JsError
* docs on JsError, move to lib.rs
* Add test for returning Result<(), _>
* Add failing test for returning `Result<Option<f64>, _>`
This fails because the generated LoadRetptr instructions do not
have any conception of how big the previous args are. It only fails
when any part of T is an f64.
* Make LoadRetptr offsets factor in alignment and previously read values
* Add a doc comment to UnwrapResult
* Slight correction to a comment
* Better error message
* un-implement OptionIntoWasmAbi for JsValue, use discriminant instead
* Add some documentation from the PR discussion to ResultAbi
* un-implement OptionIntoWasmAbi for &'a JsValue too
* bless some UI tests, not sure why
* bless the CLI's output tests
* fix indentation of if (is_ok === 0) { throw ... } code
* add tests for async fn() -> Result<_, JsError> and custom error types
* cargo fmt
* fix bug where takeObject was missing
* support externref in UnwrapResult
* add a WASM_BINDGEN_EXTERNREF=1 test to ci
* getFromExternrefTable -> takeFromExternrefTable
Now we do not leak externrefs, as the take function
calls drop on them.
* rewrite outgoing_result
There was a crash where _outgoing inserted more than
one instruction, e.g. for string. In that case,
the deferred free() call was using the wrong popped
values, and tried to free nonsense formed by
the is_ok/err pair.
Now it does a similar idea, but without assuming exactly
one instruction will be pushed by self._outgoing().
* rename is_ok -> is_err, which makes generated glue easier to read
* update ui tests
* add a crashing (if you uncomment the throw) test of Result<String, _>
* add result-string reference test
* Fix the crashy Result<String, _> by setting ptr/len to 0 on error
* Use GitHub Actions for CI
This commit migrates away from Azure Pipelines to GitHub Actions. I've
attempted to make sure everything is still tested and the various
auto-release mechanisms still work as well. Time will tell for sure
though!
* Tweak branch listings
* Add bindings for `ResizeObserver`
I had to add a `Constructor` attribute to `ResizeObserver`, since the new constructor syntax isn't supported yet (#1952).
* Mark API as unstable
* reset ci
The current code, I assume, attempted to hand over such implementation to that of `From<&Number> for f64`, but not only did it use the ambiguous `.` dot method syntax, it also forgot to take a reference to `n`, resulting `<Number as Into<f64>>::into` being called, whose implementation comes from the blanket `From -> Into` impl, effectively resulting in a recursive definition.
Currently if one has a function that takes over 26 arguments, the
generated typescript definitions contain invalid typescript identifiers
for the function parameters. The invalid code will cause the typescript
compiler to fail (even if one specifies `skipLibCheck`). To give a
contrived example:
```rust
pub fn param_silliness(
_data0: u8,
_data1: u8,
_data2: u8,
_data3: u8,
_data4: u8,
_data5: u8,
_data6: u8,
_data7: u8,
_data8: u8,
_data9: u8,
_data10: u8,
_data11: u8,
_data12: u8,
_data13: u8,
_data14: u8,
_data15: u8,
_data16: u8,
_data17: u8,
_data18: u8,
_data19: u8,
_data20: u8,
_data21: u8,
_data22: u8,
_data23: u8,
_data24: u8,
_data25: u8,
_data26: u8,
_data27: u8,
) -> usize {
0
}
```
Generates a `_bg.wasm.d.ts` that uses `{` as an parameter name which is invalid.
A non-contrived example is bundling the brotli crate:
```rust
pub fn brotli_compress(data: &[u8]) -> Vec<u8> {
let out = Vec::with_capacity(data.len() / 10);
let mut reader = Cursor::new(data);
let cursor = Cursor::new(out);
let mut compressor = brotli::CompressorWriter::new(cursor, 4096, 9, 22);
std::io::copy(&mut reader, &mut compressor).unwrap();
compressor.into_inner().into_inner()
}
```
Which generates a function (`BroccoliDestroyInstance`) with a cool 121
parameters and a lot of invalid identifiers.
The commit fixes this issue by appending additional English letters to
the parameter names when a function exceeds 26 arguments. Functions with
less than 26 arguments will see no difference in output. Functions
greater than 26 arguments will see an output like:
```ts
export function param_silliness(
// ...
z: number, a1: number, b1: number
): number
```
* Allow accessing JS math operators from Rust
Useful for dealing with JS `BigInt`s
* Add `typeof` and `in` methods/intrinsics
* Add comparison operators
* Remove Object.is intrinsic
* Make conversion into f64 faillible
* Add `#[inline]`s
* Fix methods to make them take references
* cargo fmt
* Add BigInt to js-sys (no constructor yet)
* Remove useless import
* Fix UI tests
* Add BigInt constructor
* Allow catching `to_string` method for BigInt
* Fix tests again
* Add inlines
* Rework PartialEq impl
* Implement FromStr for BigInt
* Add more inlines
* Update formatting
* Add more trait impls and feature for integration with `rust-num`
* Add `PartialOrd` and `Ord` impls for more types
* Cargo fmt
* Remove `num-traits` from `wasm-bindgen`, integrate `js-sys` with `rust-num` further
* Update Cargo.toml
* Update Rust version for CI (to allow proc-macro2 to build again)
* Fix link in Markdown
* Remove all `rust-num` code from `js-sys`
* Generate TypeScript return types for `async` functions
* Fix tests to respect returning only `Result<T, JsValue>`
* Fix smoke test
* add `simple_async_fn` to `typescript-tests`
* cleanup and set JsDoc comment correctly for `Promise<void>`
* clean up now that `ts_ret_ty` is complete w/ Promise
* add `.d.ts` reference tests
* add async reference tests
* don't test `.js` and `.wat` in async reference tests
PR #2656 added support settings `type` and `request_credentials` on
`WorkerOptions`. However, the `WorkerType` struct` was not exposed, as
the feature was not added to Cargo.toml.
* Upgraded the webpack examples' npm dependencies which (among other things) upgrades them to webpack 5
For the weather_report, had to choose the syncWebAssembly experiment,
whereas the rest works fine with asyncWebAssembly
* Fix the weather report example compilation by adding it to the main workspace.
This currently fails with:
error: current package believes it's in a workspace when it's not:
current:
<project-root>/examples/weather_report/Cargo.toml
workspace: <project-root>/Cargo.toml
* Fix the build of the webxr example with webpack 5
* run cargo fmt
* Add Default impls for WebIDL types with zero-argument constructors
* Implement Default for js-sys types where it's appropriate
* Implement Default for JsValue
* Remove some `Default` impls to better match Rust