Skip to content

Immutable.fromJS incorrectly handles object with "constructor" key #1050

Open
@matthewfranglen

Description

@matthewfranglen

When converting an object using fromJS the original object can be returned. This occurs when the original object has a constructor value within it, and that value doesn't equal Object.

The relevant code appears to be this. Presumably this is being done to prevent converting an Immutable data structure a second time.

How can I convert such an object?

What happened

I converted an object created from downloaded json data. The conversion method, fromJS, returned the original object. My further attempts to use the object failed because the required methods were missing.

How to reproduce

let a = JSON.parse('{ "constructor": { "noun": [ "builder", "creator" ] } }');
// OR: let a = { constructor: { noun: [ "builder", "creator" ] } };
let b = Immutable.fromJS(a);

console.log(a === b); // true
console.log(a.constructor === Object); // false
b.get('constructor'); // TypeError: b.get is not a function

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions