google / google/jsinterop-base

Support for multiple window contexts for globals

Open
#4 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
76
Forks
18
PR merge metrics
No merged PRs in 30d

Description

This is sort of obscure, but it would be nice to have support for the same classes existing in different global window contexts. For example, if you have an iframe, it will have its own set of global system classes in its own window object. Sometimes, you need to construct objects from this separate context or do weird comparisons etc.

```
// Example JS code of different system classes
// How can this be done in JsInterop?
a = new iframe.contentWindow.Date()
b = new Date()
a.constructor === b.constructor // returns false
```

Whatever pattern you come up with for that might also be useful when running JavaScript code inside Java because in that case, you might have multiple JavaScript contexts, and you need to specify which JS context you are constructing objects in.

```
JSInterpreter jsInterpreter1 = new JSInterpreter();
JSInterpreter jsInterpreter2 = new JSInterpreter();
jsInterpreter2.create(Int8Array.class, 10);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.