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

Symbol.hasInstance is not used in instanceof lookup #1468

Closed
wcandillon opened this issue Aug 3, 2024 · 2 comments
Closed

Symbol.hasInstance is not used in instanceof lookup #1468

wcandillon opened this issue Aug 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@wcandillon
Copy link

wcandillon commented Aug 3, 2024

The following example returns true on v8:

class Foo {
  static [Symbol.hasInstance](instance) {
    return instance.__brand === "foo";
  }
}

console.log({ __brand: "foo" } instanceof Foo);

But returns false on Hermes.

The following example has the exact same issue as well:

function Foo() {}

Object.defineProperty(Foo, Symbol.hasInstance, {
  value: function (instance) {
    return instance.__brand === "foo";
  },
});

console.log({ __brand: "foo" } instanceof Foo);

I did find the following from the tests:

C[Symbol.hasInstance] = function(o) {
But it looks like the examples above are not compliant?

@wcandillon wcandillon added the bug Something isn't working label Aug 3, 2024
@tmikov
Copy link
Contributor

tmikov commented Aug 4, 2024

Thanks for reporting this. I just verified that it appears broken in Hermes, but works correctly in Static Hermes.

I will look into identifying and back-porting the fix to Hermes (which then will have to be cherry picked by RN). Our hope is that pretty soon everyone would simply be using Static Hermes as a drop-in replacement for Hermes.

@avp
Copy link
Contributor

avp commented Aug 7, 2024

This was due to an incorrect fast path that we removed in Static Hermes. We just ported the fix to Hermes in f60d2b8

@avp avp closed this as completed Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants