diff --git a/feature_tests/js/api/ResultOpaque.d.ts b/feature_tests/js/api/ResultOpaque.d.ts index 2db9692a8..c5da9daea 100644 --- a/feature_tests/js/api/ResultOpaque.d.ts +++ b/feature_tests/js/api/ResultOpaque.d.ts @@ -9,8 +9,6 @@ export class ResultOpaque { get ffiValue(): pointer; - static new_(i: number): ResultOpaque; - static newFailingFoo(): ResultOpaque; static newFailingBar(): ResultOpaque; @@ -26,4 +24,6 @@ export class ResultOpaque { static newInEnumErr(i: number): ErrorEnum; assertInteger(i: number): void; + + constructor(i: number); } \ No newline at end of file diff --git a/feature_tests/js/api/ResultOpaque.mjs b/feature_tests/js/api/ResultOpaque.mjs index b82fbba1a..a59a3cc71 100644 --- a/feature_tests/js/api/ResultOpaque.mjs +++ b/feature_tests/js/api/ResultOpaque.mjs @@ -37,7 +37,7 @@ export class ResultOpaque { return this.#ptr; } - static new_(i) { + #defaultConstructor(i) { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.ResultOpaque_new(diplomatReceive.buffer, i); @@ -186,7 +186,13 @@ export class ResultOpaque { finally {} } - constructor(symbol, ptr, selfEdge) { - return this.#internalConstructor(...arguments) + constructor(i) { + if (arguments[0] === diplomatRuntime.exposeConstructor) { + return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); + } else if (arguments[0] === diplomatRuntime.internalConstructor) { + return this.#internalConstructor(...arguments); + } else { + return this.#defaultConstructor(...arguments); + } } } \ No newline at end of file diff --git a/feature_tests/js/test/result.mts b/feature_tests/js/test/result.mts index b30d0b8dc..4084fcb48 100644 --- a/feature_tests/js/test/result.mts +++ b/feature_tests/js/test/result.mts @@ -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()); diff --git a/feature_tests/src/result.rs b/feature_tests/src/result.rs index da4b07420..15e8a27b6 100644 --- a/feature_tests/src/result.rs +++ b/feature_tests/src/result.rs @@ -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, 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, ErrorEnum> { Err(ErrorEnum::Bar) } @@ -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")] pub fn new_failing_struct(i: i32) -> Result, ErrorStruct> { Err(ErrorStruct { i, j: 12 }) } diff --git a/tool/src/js/mod.rs b/tool/src/js/mod.rs index d99fe635d..a5d97e65e 100644 --- a/tool/src/js/mod.rs +++ b/tool/src/js/mod.rs @@ -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