Skip to content

src: store EventTarget and Event constructors on env - #36088

Closed
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:store-eventtarget-on-env
Closed

jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:store-eventtarget-on-env

Conversation

@jasnell

@jasnell jasnell commented Nov 11, 2020

Copy link
Copy Markdown
Member

Start to an answer for https://github.com/nodejs/node/discussions/35870

Allows creating instances of EventTarget and Event at the native layer. With additional work, can be used to create classes that inherit from EventTarget and Event.

Signed-off-by: James M Snell jasnell@gmail.com

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

Start to an answer for https://github.com/nodejs/node/discussions/35870

Allows creating instances of EventTarget and Event at the native layer.
With additional work, can be used to create classes that inherit from
EventTarget and Event.

Signed-off-by: James M Snell <jasnell@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. util Issues and PRs related to the built-in util module. labels Nov 11, 2020
@joyeecheung

Copy link
Copy Markdown
Member

I don't think it's possible to obtain a FunctionTemplate from an existing Function created in JS with the current V8 APIs..so IIUC the only way to inherit it would be through prototypal inheritance (maybe from C++)?

@benjamingr

Copy link
Copy Markdown
Member

IIUC the only way to inherit it would be through prototypal inheritance

Can someone explain what the issue with that is? :]

@jasnell

jasnell commented Nov 12, 2020

Copy link
Copy Markdown
Member Author

There shouldn't be an issue really. At the c++ level it'll just mean that we have to create the objects separately then set the EventTarget or Event as the prototype of whatever other object you're creating. Slightly less efficient but it works (I've already verified that we can).

@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 12, 2020
@jasnell

jasnell commented Nov 12, 2020

Copy link
Copy Markdown
Member Author

/cc @gabrielschulhof

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 12, 2020
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@addaleax

Copy link
Copy Markdown
Member

IIUC the only way to inherit it would be through prototypal inheritance

Can someone explain what the issue with that is? :]

The main drawbacks there are that a) you can’t make native classes inherit from them easily and b) you can’t instantiate these classes for other vm.Contexts.

Fwiw, the code here LGTM, just not sure that we should add it until it’s needed?

@XadillaX

Copy link
Copy Markdown
Contributor

emmm, i don't know why we need it now🤔

@jasnell
jasnell marked this pull request as draft November 14, 2020 14:32
@jasnell

jasnell commented Nov 14, 2020

Copy link
Copy Markdown
Member Author

Yep, this was largely just to show how in case @gabrielschulhof wanted to move forward on it. I've moved this to a draft. If we decide later to move forward on it I'll switch it back.

@jasnell jasnell closed this Jan 22, 2021
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++. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants