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

Cross-realm serialization/deserialization issues #31

Open
ethanresnick opened this issue Jul 20, 2017 · 5 comments
Open

Cross-realm serialization/deserialization issues #31

ethanresnick opened this issue Jul 20, 2017 · 5 comments

Comments

@ethanresnick
Copy link
Contributor

I just wanted to open a dedicated issue for the conversation here, so that it doesn't get lost.

@caridy
Copy link
Contributor

caridy commented Jul 21, 2017

Identity discontinuity is a real pain. I don't think providing expansion slots of any kind will help here because we also serialize functions, and if those functions are parsed and evaluated in a different realm, the objects that they produce (imagine that the function returns a regexp) will always exhibit different identity. The solution must be in user-land by evaluating the code in the correct sandbox, or work around the identity discontinuity problems.

@ethanresnick
Copy link
Contributor Author

The solution must be in user-land by evaluating the code in the correct sandbox, or work around the identity discontinuity problems.

This sounds like the third option I mentioned here, right? I.e., the user should just make sure to eval the serialized result in a realm with globals that come from the same realm that serialize-js is running in.

If so, that seems suboptimal to me. Of course, I agree that this library can't control the identity of the objects produced during deserialization. Still, during serialization, it does seem like the library could correctly identify objects as RegExps or Dates, even if those objects come from a different realm. I think that would be a good thing to do, probably using the second option I mentioned in #27:

We can switch to user-land implementations of util.isDate and util.isRegExp that work around the cross-realm issue (idk how reliably), like https://github.com/ljharb/is-regex and https://github.com/ljharb/is-date-object

@caridy
Copy link
Contributor

caridy commented Jul 21, 2017

Still, during serialization, it does seem like the library could correctly identify objects as RegExps or Dates

Yeah, I'm fine with that. My only concern is the performance of the serialization. @ljharb's packages seem to be optimized (I can probably raise this question next week when I see him in person) but I haven't try them. Remember that we will have to do that for every non-function object node in the object graph.

@ethanresnick
Copy link
Contributor Author

My only concern is the performance of the serialization. @ljharb's packages seem to be optimized (I can probably raise this question next week when I see him in person) but I haven't try them.

Makes perfect sense. I'll let you raise it with him and decide what's best.

@ljharb
Copy link

ljharb commented Jul 21, 2017

All of my "is-*" libraries are "optimized" in the sense that they have as many fast paths as possible - they return false as early as they can, and in environments that are pre-Symbol.toStringTag, they use Object.prototype.toString.call - but in modern environments, they always have to use a try/catch around a brand-checking prototype method.

If you want to do fast brand checking, the proper path is likely to be https://github.com/jasnell/proposal-istypes (which my packages could help to polyfill).

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

3 participants