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

Implement serializeSelf/deserializeSelf for Map, Set, and WeakMap #1980

Merged
merged 5 commits into from
May 17, 2018

Conversation

tejaede
Copy link
Collaborator

@tejaede tejaede commented May 17, 2018

This PR allows for serialization of native Map, Set, and WeakMap. Instead of pointing the serialization prototype to a moduleId, it points to the constructor directly e.g. "prototype": "Map"

Set

Set#deserializeSelf() looks for a values property. Set#serializeSelf() generates this structure

{
    "root": {
        "prototype": "Set",
        "values": {
             "values": ["A", "B", "C", "D"]
        }
   }
}

Map & Weak Map

Map#deserializeSelf() and WeakMap#deserializeSelf() support the same serialization structures. Each can be serialized in two ways.

  1. With keys and values arrays where keys[i] ==> values[i]
    This structure is more efficient to deserialize than the second so Map#serializeSelf() and WeakMap#serializeSelf() both produce this version.
{
    "root": {
        "prototype": "Map",
        "values": {
             "keys": ["A", "B", "C", "D"]
             "values": [1, 2, 3, 4]
        }
    }
}
  1. With an entries array where each item in the array is an object with a key and value property
{
    "root": {
        "prototype": "WeakMap",
        "values": {
             "entries": [
                   {"key": {"name": "Paul"}, "value": "McCartney"},
                   {"key": {"name": "John"}, "value": "Lennon"}
             ]
         }
    }
}

@tejaede tejaede self-assigned this May 17, 2018
@tejaede tejaede requested a review from marchant May 17, 2018 19:53
@marchant
Copy link
Member

Looks good!

@marchant marchant merged commit e8e9da2 into master May 17, 2018
@cdebost cdebost deleted the features/native-serialization branch January 30, 2019 04:43
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.

3 participants