Skip to content
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

JS also supports fallible ctors #762

Merged
merged 1 commit into from
Jan 15, 2025
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
4 changes: 2 additions & 2 deletions feature_tests/js/api/ResultOpaque.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions feature_tests/js/api/ResultOpaque.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js/test/result.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';
import { ErrorEnum, ErrorStruct, MyStruct, ResultOpaque } from 'diplomat-wasm-js-feature-tests';

test('Verify result methods', t => {
const s = ResultOpaque.new_(5);
const s = new ResultOpaque(5);
s.assertInteger(5);

const error1 = t.throws(() => ResultOpaque.newFailingFoo());
Expand Down
6 changes: 3 additions & 3 deletions feature_tests/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub mod ffi {
Ok(Box::new(ResultOpaque(i)))
}

#[diplomat::attr(all(*, supports = fallible_constructors), named_constructor = "failing_foo")]
#[diplomat::attr(all(supports = named_constructors, supports = fallible_constructors), named_constructor = "failing_foo")]
pub fn new_failing_foo() -> Result<Box<ResultOpaque>, ErrorEnum> {
Err(ErrorEnum::Foo)
}

#[diplomat::attr(all(*, supports = fallible_constructors), named_constructor = "failing_bar")]
#[diplomat::attr(all(supports = named_constructors, supports = fallible_constructors), named_constructor = "failing_bar")]
pub fn new_failing_bar() -> Result<Box<ResultOpaque>, ErrorEnum> {
Err(ErrorEnum::Bar)
}
Expand All @@ -40,7 +40,7 @@ pub mod ffi {
Err(())
}

#[diplomat::attr(all(*, supports = fallible_constructors), named_constructor = "failing_struct")]
#[diplomat::attr(all(supports = named_constructors, supports = fallible_constructors), named_constructor = "failing_struct")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: we should support auto inside toplevel all even if we don't support it inside any

pub fn new_failing_struct(i: i32) -> Result<Box<ResultOpaque>, ErrorStruct> {
Err(ErrorStruct { i, j: 12 })
}
Expand Down
2 changes: 1 addition & 1 deletion tool/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn attr_support() -> BackendAttrSupport {

a.constructors = true;
a.named_constructors = false;
a.fallible_constructors = false;
a.fallible_constructors = true;
a.accessors = true;
a.comparators = false;
a.stringifiers = false; // TODO
Expand Down
Loading