Skip to content
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

Allow wrapping Ruby and JS object to each other #18

Merged
merged 5 commits into from
May 20, 2022

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented May 19, 2022

This PR adds Ruby's JS::Object <-> JS's RbValue object interoperability by wrapping them with each other.

Example

// JS -> Ruby object
const hash = vm.eval(`Hash.new`)
hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
# Ruby -> JS object
js_obj = JS.eval(`return {}`)
js_reflect = JS.eval("return Reflect")
js_reflect.call(:set, JS::Object.wrap(Object.new))

When passing a non-interoperated Ruby Object like `Object` to JS method
from Ruby world, the object has to be JS object.
This patch provides a way to wrap a Ruby object by `RbValue`, which is a
Ruby object representation in JS world.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant