Implement instanceof in golang
As the title says, how can I implement instanceof using goja and golang?
You can implement a simple JS function and export it to Go.
It would be trivial to expose instanceOfOperator except for one thing: error handling. I've realised there is a problem with the current API, things like Object.Get(), Object.String(), Object.ToInteger(), and even Object.Export() can throw JS exceptions which currently results in a panic (whereas calling them on primitives cannot). And this is only half the problem, after such a panic the Runtime may be left in an unusable state (because the stacks are not properly unrolled).
On the other hand when using those within a Go implementation of a JS function these panics are ok, they will be propagated as JS exceptions and handled properly. Even if they are not caught in JS code, they would be caught by the top-level Run* method or a Callable call and returned as an error.
Also, there is already inconsistency within the API: methods like Runtime.New(), Runtime.Set(), Object.Set() return error, whereas Object.Get() does not (it panics instead). Exposing instanceOfOperator would cause the same dilemma, should it return an error or propagate the panic?
I don't think I will be adding any more methods to the API until I figure out how to address this issue. Any comments or suggestions are welcome.