-
Notifications
You must be signed in to change notification settings - Fork 9
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
Cross Realm Interfaces #12
Comments
Meaning that if you create an interface, it would become a global in all realms? As-is, if you pass the first-class interface value across realms, I'd expect it to work. |
@ljharb global, mmm no it would still have a home realm, but being safely passable between home/target realms without leaking the home realm. this would require: protocol InterfaceName {
youGetThisMethodForFree(...parameters) {
}
} To make a |
ah, you're saying that runtime lookups of globals inside an interface method should use the current realm, not the realm in which they were defined? |
I need to rephrase all of this with a more concrete example. // safe realm
const vm = require('vm');
const unsafeRealm = vm.createContext();
let lastId = 1;
const ids = new WeakMap;
protocol HasId {
id() {
if (ids.has(this)) return ids.get(this);
const id = lastId++;
ids.set(this, id);
return id;
}
}
// setup our interface
const implement = vm.runInContext(`(_HasId => HasId = _HasId)`, unsafeRealm);
implement(HasId); If In order for |
ahhh thanks. How would you have a function that doesn't inherit from a specific Realm's |
@ljharb |
looking back on this, it would be a channel to get primordials that would not otherwise be accessible like grabbing them off |
FYI. I have a library in which I implemented my own custom protocols long before I was aware of this proposal. I too ran into the realm issue when I was running my code in MS Dynamics where for security purposes the platform creates separate realms for different components. I ran into issues when my protocols balked at not being able to lookup the symbol on an array. Turns out the array was created in another realm where protocols hadn't been applied. To solve the issue I applied them to all known realms. It seemed heavy handed but worked. The crossrealm situation is not a simple one to address. You'll see in my README I had to observe certain principles to avoid issues. It's also worth noting I implemented this support long after I had implemented protocols for use in a single realm. So this feature need not encumber the initial specification. |
As long as interfaces do not inherit from Object, is it possible to have them be cross realm?
The text was updated successfully, but these errors were encountered: