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

src: expose MaybeInitializeContext to allow existing contexts #28544

Conversation

MarshallOfSound
Copy link
Member

Splits the node.js specific tweak intialization of NewContext into a new helper MaybeInitializeContext so that embedders with existing contexts can still use them in a node Environment now that primordials are initialized and required so early.

Found this issue while upgrading Electron to node 12.4, now primordials are created in every context --> electron/node@3da36d0 we need to initialize a context the same way node does but we don't create the context so this method had to be split into two to allow folks with pre-created contexts to still use them in node Environments

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jul 4, 2019
@MarshallOfSound
Copy link
Member Author

Refs: electron/electron@afefa92

src/node.h Outdated Show resolved Hide resolved
Splits the node.js specific tweak intialization of NewContext into a new
helper MaybeInitializeContext so that embedders with existing contexts
can still use them in a node Environment now that primordials are
initialized and required so early.
@MarshallOfSound MarshallOfSound force-pushed the expose-maybe-initialize-context branch from edddd5d to 98b6cf5 Compare July 4, 2019 23:44
src/node.h Outdated
@@ -305,6 +305,12 @@ NODE_EXTERN v8::Local<v8::Context> NewContext(
v8::Local<v8::ObjectTemplate> object_template =
v8::Local<v8::ObjectTemplate>());

// Runs Node.js-specific tweaks on an already constructed context
NODE_EXTERN v8::Local<v8::Context> MaybeInitializeContext(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For legacy reasons NewContext still need to return a Local, but for a new API I think we should return a MaybeLocal here. I would drop the word Maybe in the function name in favor of a more practical signature.

@BridgeAR
Copy link
Member

Ping @MarshallOfSound

@MarshallOfSound
Copy link
Member Author

Sorry @BridgeAR had PTO last week 🌴

I ended up with a slightly different approach here, I realized that MaybeInitializeContext was just returning either the context you passed in or a new empty maybe to indicate success / failure. It's more normal to use a boolean to indicate that so now InitializeContext returns a success boolean indicating whether or not the initialization succeeded.

@MarshallOfSound MarshallOfSound force-pushed the expose-maybe-initialize-context branch from 9c6cacf to a954ce8 Compare July 16, 2019 18:37
src/node.h Outdated Show resolved Hide resolved
src/api/environment.cc Outdated Show resolved Hide resolved
@MarshallOfSound MarshallOfSound force-pushed the expose-maybe-initialize-context branch from a954ce8 to 2dcfc04 Compare July 22, 2019 20:18
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@Trott
Copy link
Member

Trott commented Aug 24, 2019

This can technically land but another review or two would be good I think. @addaleax @BridgeAR

I'm also going to re-run CI since it's been over a month...

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Aug 24, 2019

@Trott
Copy link
Member

Trott commented Aug 27, 2019

Landed in 33ae95c

@Trott Trott closed this Aug 27, 2019
Trott pushed a commit that referenced this pull request Aug 27, 2019
Splits the node.js specific tweak intialization of NewContext into a new
helper MaybeInitializeContext so that embedders with existing contexts
can still use them in a Node.js Environment now that primordials are
initialized and required so early.

Update MaybeInitializeContext to return MaybeLocal,

PR-URL: #28544
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR pushed a commit that referenced this pull request Sep 3, 2019
Splits the node.js specific tweak intialization of NewContext into a new
helper MaybeInitializeContext so that embedders with existing contexts
can still use them in a Node.js Environment now that primordials are
initialized and required so early.

Update MaybeInitializeContext to return MaybeLocal,

PR-URL: #28544
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR BridgeAR mentioned this pull request Sep 3, 2019
BridgeAR pushed a commit that referenced this pull request Sep 4, 2019
Splits the node.js specific tweak intialization of NewContext into a new
helper MaybeInitializeContext so that embedders with existing contexts
can still use them in a Node.js Environment now that primordials are
initialized and required so early.

Update MaybeInitializeContext to return MaybeLocal,

PR-URL: #28544
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
codebytere added a commit to electron/electron that referenced this pull request Sep 5, 2019
codebytere added a commit to electron/electron that referenced this pull request Sep 5, 2019
codebytere added a commit to electron/electron that referenced this pull request Sep 5, 2019
codebytere added a commit to electron/electron that referenced this pull request Sep 5, 2019
codebytere added a commit to electron/electron that referenced this pull request Sep 6, 2019
codebytere added a commit to electron/electron that referenced this pull request Sep 19, 2019
codebytere added a commit to electron/electron that referenced this pull request Sep 23, 2019
codebytere added a commit to electron/electron that referenced this pull request Sep 27, 2019
codebytere added a commit to electron/electron that referenced this pull request Oct 14, 2019
codebytere added a commit to electron/electron that referenced this pull request Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants