Open sgammon opened 1 week ago
Hi @sgammon , thanks for reaching out to us. We'll be taking a look into this shortly
I've considered the alternative of a facade guest type, like: ... but, constructors can't return other types
In fact, constructors (in JavaScript) can return arbitrary objects and you can abuse that to implement what you need using something like
class SomeType {
constructor(...args) {
return new RawSomeType(...args);
};
static [Symbol.hasInstance](o) {
// some code that is able to recognize instances of RawSomeType
// and return true for them (and false otherwise)
}
}
Would that work for you?
@iamstolis Lol. JavaScript never ceases to amaze. I updated my description.
This will work for us for now, yes, but this approach generally requires us to execute preparatory code in the guest context before executing actual guest code which relies on instanceof
working.
Ideally, we'd be able to inject a type from the host context, without resorting to guest code. It would be really cool to make static [Symbol.hasInstance]
possible from the host, and I don't know of a way to do that today.
This will work for us for now, yes, but this approach generally requires us to execute preparatory code in the guest context before executing actual guest code ... Ideally, we'd be able to inject a type from the host context, without resorting to guest code.
I am sorry, I don't understand why exactly are you more concerned by the execution of preparatory code compared to the usage of methods of Value
class (like putMember()
).
Describe the issue I want to create polyglot-capable objects with a
ProxyInstantiable
, but I also want such objects to pass type checks in guest languages.Code snippet or code repository that reproduces the issue
Later, in a guest language...
Additional context I've considered the alternative of a facade guest type, like:
But this requires up-front execution of preparatory code in the guest context.
I've also tried installing the host type directly, but then I must register my constructors for reflective access, and I must share host constructors with guest constructors, which especially complicates instantiation with
varargs Value
. The flexibility ofProxyInstantiable
, which allowsvararg Value
, is especially useful for interop with JavaScript, but is hard to adapt to type checks.