Re: [w3ctag/design-reviews] Realms API ECMAScript Proposal (#542)

> 1.b) Presumably if one wants multiple exports from a module, they'd need to call importValue once for each export. Hopefully the module is only actually imported once?

Yes, this is analogous to import, which means you can call that method multiple times for the same specifier, and you get the same module. And yes, you can use Promise.all, etc. to try to construct the object in the incubator realm that contains access to various exported values.

> 2. The mechanism for how values are passed back and forth seem unclear from our reading. There are mentions of transferrables, but presumable non-transferrable objects are copied in each direction?

As @leobalter mentioned, it is a hard stop, throwing.

> a) if objects are copied, this leads to more questions, are they individual copies for every invocation? e.g.: const doSomething = realm.importValue('module.js', 'doSomething); doSomething(someObject, someObject); does the doSomething function get two different copies of someObject?

Yes, you get two different exotic objects, both bound to `someObject` on the other side.

> b) If the doSomething() function above returns some object that's state local to the Realm, does each return create a new copy of that object?

You can't return an object, that will throw, but if you return another callable, yes, every time you return that ref, the other side gets a new exotic object. Basically there is no identity preserving semantics here, that can happen in user-land with a fancy membrane. Another good example here is when you pass a function to the other side, and the other side calls you back with the same reference that they have received, you get a new wrapped exotic object. Double wrapping can occur at any given time, while implementers will be able to optimize this to avoid going over multiple jumps to evaluate the target function.

> Here's an example, consider the following (off the cuff, untested) code being imported into a Realm:
> What gets logged? '1 1', '1 2', or ?

It will log `1 2`, the exotic object that wraps the `doSomething` gets invoked twice, which means `doSomething` gets invoked twice, the closure and everything works the same like if you were accessing `doSomething` from across realms in an iframe scenario.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3ctag/design-reviews/issues/542#issuecomment-840883373

Received on Thursday, 13 May 2021 23:03:47 UTC