-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ReactJS: Fixes to proxy object wrapping (#851)
This resolves some more bugs reported by a user. This time I sent them a test JAR and they confirmed that everything now works and they could remove their previous workarounds, so I hope this is the last round of fixes required. Specifically these commits: - Refactor the code to ensure map values are always mapped - Adds unit tests specifically for the proxy mapper - Adds examples of mapping lists
- Loading branch information
Showing
8 changed files
with
126 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...s-react/src/test/groovy/io/micronaut/views/react/IntrospectableBeansAreProxiedSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.micronaut.views.react | ||
|
||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import jakarta.inject.Inject | ||
import org.graalvm.polyglot.Value | ||
import org.graalvm.polyglot.proxy.ProxyObject | ||
import spock.lang.Specification | ||
|
||
@MicronautTest(startApplication = false) | ||
class IntrospectableBeansAreProxiedSpec extends Specification { | ||
@Inject | ||
JSContextPool contextPool | ||
|
||
void "introspectable bean can be proxied"() { | ||
given: | ||
def jsContext = contextPool.acquire() | ||
def context = jsContext.polyglotContext | ||
def bean = new SomeBean("foo value", "bar value", new SomeBean.InnerBean(10, Map.of("key", 123), List.of("one", "two", "three"))) | ||
|
||
when: | ||
ProxyObject proxy = ProxyObjectWithIntrospectableSupport.wrap(context, bean).asProxyObject() | ||
context.getBindings("js").putMember("bean", proxy) | ||
|
||
then: | ||
proxy.getMember("foo") == context.asValue("foo value") | ||
proxy.getMember("innerBean") instanceof Value | ||
|
||
when: | ||
ProxyObject innerBean = ((Value) proxy.getMember("innerBean")).asProxyObject() | ||
|
||
then: | ||
innerBean instanceof ProxyObjectWithIntrospectableSupport | ||
|
||
when: | ||
ProxyObject innerBeanMap = ((Value) innerBean.getMember("map")).asProxyObject() | ||
|
||
then: | ||
((Value) innerBeanMap.getMember("key")).asInt() == 123 | ||
context.eval("js", "bean.innerBean.map[\"key\"]").asInt() == 123 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
views-react/src/test/groovy/io/micronaut/views/react/TestProps.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.micronaut.views.react | ||
|
||
class TestProps { | ||
static def basic = ["name": "Mike", "someNull": null, "obj": new SomeBean("foo", null, new SomeBean.InnerBean(10, Map.of(), List.of("one", "two")))] | ||
static def triggerSandbox = basic + ["triggerSandbox": true] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters