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

lib: add WeakRef and FinalizationRegistry to primordials #37263

Merged

Conversation

ExE-Boss
Copy link
Contributor

@ExE-Boss ExE-Boss commented Feb 7, 2021

This cleans up the two TODOs in:

// TODO(aduh95): Add FinalizationRegistry to primordials
const SafeFinalizationRegistry = makeSafe(
globalThis.FinalizationRegistry,
class SafeFinalizationRegistry extends globalThis.FinalizationRegistry {}
);
// TODO(aduh95): Add WeakRef to primordials
const SafeWeakRef = makeSafe(
globalThis.WeakRef,
class SafeWeakRef extends globalThis.WeakRef {}
);

@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Feb 7, 2021
@benjamingr
Copy link
Member

Thanks!

Any chance you could also make the (new'ish) weak event handler machinery in event_target use this? (It's the other place I know in the code that uses FinalizationRegistry and WeakRef).

@targos
Copy link
Member

targos commented Feb 7, 2021

I wouldn't expect this to work yet. WeakRef can still be disabled with a V8 flag (--no-harmony-weak-refs) so they are not available while bootstrapping.

@devsnek
Copy link
Member

devsnek commented Feb 7, 2021

I might just go change that, moving the error snapshot use instead of creation.

@jasnell
Copy link
Member

jasnell commented Feb 23, 2021

FWIW, Node.js already fails to start when the --no-harmony-weak-refs flag is used...

root@DESKTOP-5KK9VIR:~/node/node# ./node --no-harmony-weak-refs
node:internal/util/iterable_weak_map:14
  class SafeFinalizationRegistry extends globalThis.FinalizationRegistry {}
                                                    ^

TypeError: Class extends value undefined is not a constructor or null
    at node:internal/util/iterable_weak_map:14:53
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:283:7)
    at nativeModuleRequire (node:internal/bootstrap/loaders:312:14)
    at node:internal/source_map/source_map_cache:28:29
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:283:7)
    at nativeModuleRequire (node:internal/bootstrap/loaders:312:14)
    at node:internal/modules/cjs/loader:78:5
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:283:7)
    at nativeModuleRequire (node:internal/bootstrap/loaders:312:14)
    at node:internal/modules/esm/loader:4:1

@devsnek
Copy link
Member

devsnek commented Feb 23, 2021

@jasnell the issue is that V8 disables flagged globals during snapshot, regardless of whether you expect them to be available later or not.

@aduh95
Copy link
Contributor

aduh95 commented Mar 7, 2021

I'v e submitted https://chromium-review.googlesource.com/c/v8/v8/+/2741582/ to unblock this.

@devsnek
Copy link
Member

devsnek commented Mar 7, 2021

@aduh95 cloudflare uses that flag for workers, probably can't land.

@devsnek
Copy link
Member

devsnek commented Mar 7, 2021

I'd like to talk to the V8 team about a new flag system which allows them to be snapshotted, but they don't seem to care at all about our design constraints or maintaining contact with us so it's been delayed.

@aduh95
Copy link
Contributor

aduh95 commented Apr 9, 2021

Flag has been removed upstream, I've opened #38162 to test if that makes the tests pass.

@aduh95 aduh95 force-pushed the lib/primordials/add-weakref-primordials branch from 846fc79 to f98f3b5 Compare April 9, 2021 18:21
@aduh95
Copy link
Contributor

aduh95 commented Apr 9, 2021

Tests are passing :) @ExE-Boss I've forced-pushed to your branch to include the V8 patch, please have a look in case I did something wrong (oh and I added f98f3b5, I hope that's OK; if you disagree of course feel free to revert).

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@ExE-Boss ExE-Boss force-pushed the lib/primordials/add-weakref-primordials branch from f98f3b5 to 0669710 Compare April 12, 2021 22:49
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: nodejs#37263
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@aduh95 aduh95 force-pushed the lib/primordials/add-weakref-primordials branch from 0669710 to 78343bb Compare April 13, 2021 10:37
@aduh95 aduh95 merged commit 78343bb into nodejs:master Apr 13, 2021
@aduh95
Copy link
Contributor

aduh95 commented Apr 13, 2021

Landed in 78343bb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants