sciter-sdk / rust-sciter

Rust bindings for Sciter
https://sciter.com
MIT License
811 stars 75 forks source link

can't throw exception from Rust #127

Open gaoqiangz opened 2 years ago

gaoqiangz commented 2 years ago

rust:

impl Frame {
    fn throw(&self, ex: String) -> Result<(),String> {
        Err(ex)
    }
}
impl EventHandler for Frame {
    displatch_script_call! {
        fn throw(Value);
    }
}

js:

try {
    Window.this.xcall("throw","exception");
} catch(ex) {
    console.log(ex);
}
pravic commented 2 years ago

Let me check as well. It used to work for TIS.

SonnyX commented 2 years ago

Isn't ex supposed to be of type Value rather than String?

pravic commented 2 years ago

@SonnyX not really, there's a conversion from result: https://github.com/sciter-sdk/rust-sciter/blob/master/src/value.rs#L1037

pravic commented 2 years ago

I confirm, it doesn't work in JS.

      try {
        stdout.println("call", view.throw());
      }
      catch(e) {
        stdout.println("exception", e);
      }
      try {
        console.log("call", Window.this.xcall("throw"));
      } catch(e) {
        console.log("exception", e);
      }

It prints "exception" in TIS but "call" in JS.

@c-smile Andrew, we initialize an exception here similar to value::make_error by calling ValueStringDataSet with UT_STRING_ERROR. It used to work in TIScript but doesn't work in JS (and seems has never been working judging by to a quick pick of several JS versions).