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

better structured clone support #50

Open
7 tasks
jimmywarting opened this issue Oct 31, 2022 · 4 comments
Open
7 tasks

better structured clone support #50

jimmywarting opened this issue Oct 31, 2022 · 4 comments

Comments

@jimmywarting
Copy link
Contributor

jimmywarting commented Oct 31, 2022

I just publish this test page today to test out different binary package

Maybe this is something you wish to improve on?
(you can also click on each ❌ to see more details - and see the result in the console for more detail)

A summary of what i think should be supported

  • should be able to encode/decode -0
  • should be able to encode really large BigInts structuredClone(BigInt('0x' + 'FF'.repeat(1024)))
  • should support Object literals Object(2n)
  • Better handle sparse arrays.
  • Support cloning ArrayBuffer and return it as an ArrayBuffer (not as an Uint8Array with an offset)
  • support circular ref: var input = {}; input.input = input, var input = [0]; input[0] = input
  • Support more instances of Error classes

I don't know about Blob/Files.
I think it would be better to just encode a references point to some blob index rather than trying encode a hole file into memory. So first you would encode the structure, emit all the data and then transfer/pipe the blobs over the wire later in your own way. kind of how the web has a transferable list when using postMessage

@jimmywarting
Copy link
Contributor Author

jimmywarting commented Oct 31, 2022

before you jump onto the conclusion of why -0 should be supported:

Code can do different things depending on if it's signed or not.

Math.atan2(0, 0);  //returns 0
Math.atan2(0, -0); //returns Pi

the reason why we have +0 and -0 is mostly due to being able to represent positive and negative ∞ in a mathematically way

  • 1/-0 === -Infinity
  • 1/0 === Infinity

@kriszyp
Copy link
Owner

kriszyp commented Nov 1, 2022

This is really cool, nice work! Yes, I will take a look to see if there are some improvements that can be made, when I get a chance, although no guarantees, since there may be some limitations from data formats. Again, this is a great analysis and set of tests!

@jimmywarting
Copy link
Contributor Author

I added the mapsAsObjects: true and then it passed more tests...
I update my post to include a list of what i think should be supported. That way you can create sub issues and use this a meta ticket if you like.

@jimmywarting
Copy link
Contributor Author

I think Object literals could just be as simple as just prefixing the next following value...
You don't need a seperate Tags for each String/Boolean/Number/BigInt etc?

var isObjectLiteral = buffer[x]
if (isObjectLiteral) {
  return Object( read_next_value_as_normal() )
}

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

2 participants