Skip to content

Equality fails for objects with no prototype #5357

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

Closed
ClaireNeveu opened this issue Jan 21, 2022 · 0 comments · Fixed by #5358
Closed

Equality fails for objects with no prototype #5357

ClaireNeveu opened this issue Jan 21, 2022 · 0 comments · Fixed by #5358

Comments

@ClaireNeveu
Copy link
Contributor

Some javascript libraries expose objects without prototypes created using Object.create(null). compare from caml_obj fails on these because it calls hasOwnProperty directly on the object instead of using Object.prototype.hasOwnProperty.call

Here's a very small reproduction:

let prototype: Js.t<{"a": int}> = {"a": 5}
let noPrototype: Js.t<{"a": int}> = %raw(`(function(){
  let o = Object.create(null);
  o.a = 5;
  return o;
})()`)

prototype == noPrototype

This can be worked around if the foreign object can be converted to JSON and back but it'd be nice if this worked out of the box since there's an easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant