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

Runtime exception when using Decode.dict on a JSON created with Object.create(null) #24

Open
jfmengels opened this issue May 31, 2020 · 0 comments

Comments

@jfmengels
Copy link

jfmengels commented May 31, 2020

SSCCE

result = Json.Decode.decodeValue (Json.Decode.dict Json.Decode.string) jsValue

when jsValue has been created in JavaScript using Object.create(null) and sent through flags or a port.

Attempting the decoding above results in a runtime exception with this error:

Uncaught TypeError: value.hasOwnProperty is not a function
    at _Json_runHelp (VM37 workspace:1461)
    at _Json_runHelp (VM37 workspace:1478)
    at Function.f (VM37 workspace:1400)
    at A2 (VM37 workspace:56)
    at $author$project$Main$init (VM37 workspace:10540)
    at VM37 workspace:8540
    at VM37 workspace:20
    at _Platform_initialize (VM37 workspace:1877)
    at VM37 workspace:3973
    at Object.init (VM37 workspace:20)

I created an Ellie here that you can interact with: https://ellie-app.com/8ZWrTfBzWRZa1

Additional Details

  • Elm: 0.19.1
  • elm/json: 1.1.3
  • Browser: Brave

Object.create(null) is sometimes used to create a JavaScript dictionary . The difference with {} is that {} contains fields from the Object prototype, where Object.create(null) has no prototype and no fields at all.

> ({}).toString
[Function: toString]
> Object.create(null).toString
undefined

This distinction, at least in JavaScript, can be important when you use this value as a set and only care about whether the field exists.

This distinction is irrelevant when decoding, but this runtime error makes it impossible to send values that in JS-land needed to be created this way without somehow cloning them beforehand.

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

No branches or pull requests

1 participant