On 5/29/12 5:52 PM, Benjamin Striegel wrote:
>> * The system _must_ not prevent, some day, developers from calling Rust
>> from JavaScript.
>> * The system _must_ not prevent, some day, developers from calling
>> JavaScript from Rust.
> 
> I'm not aware of any precedents for calling out of or into Javascript,
> in any language. What specific constraints does this impose?

Well, in Firefox, we have been calling out of/into JS for ages, first
with XPConnect and now with js-ctypes. Neither is fully satisfactory,
but they are both useful.

XPConnect connects the C++ subset used at Mozilla (in particular, C++
witout exceptions) and JavaScript (and possibly other languages). Calls
can only be placed through well-defined interfaces. JavaScript
exceptions are converted to C++ error return value, with two rules:
- throwing an integer from JavaScript passes that integer to C++;
- throwing any other value from JavaScript converts it to a default
error value.
Conversely, returning an error value from C++ is converted to throwing
the corresponding integer in JS.

js-ctypes connects C to JavaScript. As C has no exceptions, this
simplifies things (although decoding 64-bit C return values in JS is a
bit messy). I do not know the semantics of throwing an exception from JS
to C, but I suspect this is messy.

Now, in Rust, I do not know exactly how to best do this, but I suspect
that we would want calls to JavaScript to return a sum type result/error.

Cheers,
 David
-- 
David Rajchenbach-Teller, PhD
 Performance Team, Mozilla

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to