| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Review requested:
|
Sorry, something went wrong.
There was a problem hiding this comment.
@joyeecheung @addaleax when I try to define FinalizationRegistry and WeakRef in primordials, I get a compilation error because the WeakRef and FinalizationRegistry are undefined at the time when primordials is initially loaded.
Any thoughts?
Sorry, something went wrong.
There was a problem hiding this comment.
WeakRef and FinalizationRegistry cannot be used with snapshots because they can be disabled using a flag at runtime.
Sorry, something went wrong.
There was a problem hiding this comment.
I think this means we can't use them for a utility like this?
We don't want source maps to stop working because the flag isn't set.
Sorry, something went wrong.
There was a problem hiding this comment.
It's a V8 --harmony flag, that's not supported and undocumented in Node.js. I'd say it's fine to use them.
Sorry, something went wrong.
There was a problem hiding this comment.
I don't understand how this works - this appears to create a new WeakRef each time the key is set even if the key "value" already exists in the map? Is this intentional?
Sorry, something went wrong.
There was a problem hiding this comment.
var m = new Map();
var o = {};
var r1 = new WeakRef(o);
var r2 = new WeakRef(o);
m.set(r1, "foo");
console.log(m.get(r1)); // foo
console.log(m.get(r2)); // undefined
Sorry, something went wrong.
There was a problem hiding this comment.
this appears to create a new WeakRef each time the key is set even if the key "value" already exists in the map? Is this intentional
I'll add unit tests for the IterableWeakMap implementation, and will make sure this case is covered.
Sorry, something went wrong.
There was a problem hiding this comment.
I'm saying - I don't understand how it works and to my understanding it's not supposed to. A test is fine, but a "this works because X" is also fine :]
Sorry, something went wrong.
There was a problem hiding this comment.
@benjamingr I'm pretty sure you've identified a bug in the IterableWeakMap shared on the TC39 spec page -- we should only create a new WeakRef if there's not already an entry, otherwise we should perform an update.
Once I've fixed this, I'll share the updated code, and can provide a walk through of the logic if it's still confusing.
Sorry, something went wrong.
There was a problem hiding this comment.
Sure, feel free to ping me when updated and I'll take a look :]
Sorry, something went wrong.
|
CC: @mcollina, I noticed a conversation you had on Twitter contemplating using IterableWeakMaps for a similar purpose. |
Sorry, something went wrong.
There was a problem hiding this comment.
to call it out explicitly: i think these primordials todos should be considered blockers
Sorry, something went wrong.
There was a problem hiding this comment.
@ljharb @aduh95, how about the approach of exposing the makeSafe from primordials, and freezing WeakRef and FinalizationRegistry when iterable-weak-map.js is loaded:
// TODO(aduh95): Add WeakRef to primordials
const SafeWeakRef = makeSafe(
globalThis.WeakRef,
class SafeWeakRef extends globalThis.WeakRef {}
);
// This class is modified from the example code in the WeakRefs specification:
// https://github.com/tc39/proposal-weakrefs
// Licensed under ECMA's MIT-style license, see:
// https://github.com/tc39/ecma262/blob/master/LICENSE.md
class IterableWeakMap {
// ...
}}source_map_cache.js pretty early on in the application lifecycle, _I think, before any userland code.
Sorry, something went wrong.
There was a problem hiding this comment.
That seems fine, but I’m not sure what’s wrong with eagerly freezing it, like all the other primordials?
Sorry, something went wrong.
There was a problem hiding this comment.
When the primordials are prepared, we only have access to a subset of builtins. V8 does not provide us the ones that can be disabled with flags by the user.
Sorry, something went wrong.
There was a problem hiding this comment.
ahhhh thanks, that makes sense.
Sorry, something went wrong.
|
Generally look fine, lmk when it's ready and I'll check the branch out and play with it a bit :] |
Sorry, something went wrong.
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sorry, something went wrong.
|
@benjamingr happy with how this is looking? |
Sorry, something went wrong.
There was a problem hiding this comment.
lgtm
Sorry, something went wrong.
Using an iterable WeakMap (a data-structure that uses WeakRef and WeakMap), we are able to: stop relying on Module._cache to serialize source maps; stop requiring an error object when calling findSourceMap(). PR-URL: #35915 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Using an iterable WeakMap (a data-structure that uses WeakRef and WeakMap), we are able to: stop relying on Module._cache to serialize source maps; stop requiring an error object when calling findSourceMap(). PR-URL: #35915 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Using an iterable WeakMap (a data-structure that uses WeakRef and WeakMap), we are able to: stop relying on Module._cache to serialize source maps; stop requiring an error object when calling findSourceMap(). PR-URL: #35915 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
| Back | FazBrowse Home | New Git URL |
Using an iterable WeakMap (a data-structure that uses WeakRef and
WeakMap), we are able to: stop relying on Module._cache to
serialize source maps; stop requiring an error object when calling
findSourceMap().
Checklist