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

Compat regression fix: Hash#to_n should return a JS object #2613

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

hmdne
Copy link
Member

@hmdne hmdne commented Nov 23, 2023

Before we have merged a Hash->Map patchset, Hash#to_n used to return a JS object, then it returned Map. #to_n is an API of the native library, so it is called by the unwrapping part. Let's suppose a sample JS library, that is often called like this inside JS:

combomizer.enhance("feature", { fast: true })

This sample is very similar to how Ruby kwargs work, or at least used to, or still work this way in Opal. Such a code was represented in Opal this way:

combomizer = Native(`js_combomizer`)
combomizer.enhance("feature", fast: true)

Or... without kwargs, the second line becomes:

combomizer.enhance("feature", {fast: true})

After the Hash->Map patchset, this code has changed its behavior, now passing hash as a Map, which is breaking compatibility assumptions. From what I know, Map is very rarely used in JS and the JS libraries can be assumed to never expect a Map, but a JS Object.

This commit restores previous behavior of Hash#to_n returning a JS object, like before.

Thanks to Jean-Eric Godard (@jeezs) for reporting this bug.

Before we have merged a Hash->Map patchset, `Hash#to_n` used to
return a JS object, then it returned Map. `#to_n` is an API of the
`native` library, so it is called by the unwrapping part. Let's
suppose a sample JS library, that is often called like this inside
JS:

```js
combomizer.enhance("feature", { fast: true })
```

This sample is very similar to how Ruby kwargs work, or at least
used to, or still work this way in Opal. Such a code was represented
in Opal this way:

```ruby
combomizer = Native(`js_combomizer`)
combomizer.enhance("feature", fast: true)
```

Or... without kwargs, the second line becomes:

```ruby
combomizer.enhance("feature", {fast: true})
```

After the Hash->Map patchset, this code has changed its behavior, now
passing hash as a Map, which is breaking compatibility assumptions.
From what I know, Map is very rarely used in JS and the JS libraries
can be assumed to never expect a Map, but a JS Object.

This commit restores previous behavior of `Hash#to_n` returning a
JS object, like before.

Thanks to Jean-Eric Godard (@jeezs) for reporting this bug.
@elia elia merged commit 7615bcc into master Nov 23, 2023
20 checks passed
@elia elia deleted the hmdne/hash-to-obj branch November 23, 2023 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants