Greetings from TC39-land! I'm currently working on a proposal for immutable
data structures, and there's a puzzle I'm trying to solve that I was hoping
someone with knowledge of engine internals might be able to help me out
with. In the spirit of the car talk puzzler, here we go:
I'm hoping to be able to use deeply-frozen no-proto objects and arrays as
the language basis for records. The advantage here is that there is no risk
of prototype pollution, which is appropriate for a data-only structure such
a struct/record is.
While I find it extremely promising that the language already contains
these objects and has well-defined semantics for them, the trouble I have
is that I can't figure out how to construct them in a reasonable amount of
time.
The naive way is like this: `Object.setPrototypeOf([], null)` and it's
very, very slow.
Is there any faster way to create these objects? I was hoping that
`structuredClone` might let me make one the slow way and make more the fast
way, but no it copies a no-proto array into an array-proto array.
`new Array({ __proto__: null })` was another idea I had, but proved
similarly fruitless as it sets up the array prototype.
If there was a workaround -- a reasonably performant way to get instances
-- a Records feature could be introduced to the language with a performant
polyfill, making them usable right away. If not, records would be more like
a hard-breaking change. I'd really like to understand which situation we're
in!
All the best,
Conrad
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/v8-dev/cf604a4e-a1a0-4962-b37b-8f78190c86ccn%40googlegroups.com.