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: remove usages on ScriptCompiler::CompileFunctionInContext #44198

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Aug 10, 2022

V8 APIs like HostImportModuleDynamicallyCallback and
ScriptCompiler::CompileFunction are moving away from ScriptOrModule.

Replaces ScriptCompiler::CompileFunctionInContext with
ScriptCompiler::CompileFunction to remove the usages on the optional
out param ScriptOrModule.

Fixes: nodejs/node-v8#214

V8 APIs like HostImportModuleDynamicallyCallback and
ScriptCompiler::CompileFunction is moving away from ScriptOrModule.

Replaces ScriptCompiler::CompileFunctionInContext with
ScriptCompiler::CompileFunction to remove the usages on the optional
out param ScriptOrModule.
@nodejs-github-bot
Copy link
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++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 10, 2022
@targos
Copy link
Member

targos commented Aug 10, 2022

Fixes nodejs/node-v8#214 ?

@targos
Copy link
Member

targos commented Aug 10, 2022

Why is it draft?

@legendecas
Copy link
Member Author

legendecas commented Aug 10, 2022

@targos: Why is it draft?

I was verifying that the lifetime of CompiledFnEntry is still correct with this change. But I found that even without this change, the following script can cause an OOM quite quickly:

const vm = require('vm');

function work() {
  const context = vm.createContext({});
  const fn = vm.compileFunction(`
    import('foo').then(() => {});
  `, [], {
    parsingContext: context,
    importModuleDynamically: async (specifier, fn, importAssertions) => {
      const m = new vm.SyntheticModule(['x'], () => {
        m.setExport('x', 1);
      }, {
        context,
      });

      await m.link(() => {});
      await m.evaluate();

      return m;
    },
  });

  fn();
}

(function main() {
  work()
  // yielding to give chance to the evaluation of promises.
  setTimeout(main, 1);
})();

The reference in the importModuleDynamically to the created function object https://github.com/nodejs/node/blob/main/lib/vm.js#L389 is invalidating the weak reference in CompiledFnEntry.

As this change is not worsening the condition, I'm marking it ready for review in order to land https://chromium-review.googlesource.com/c/v8/v8/+/3172764, with which we can get rid of the current id-based host-defined-options lookups.

(Opened issue #44211 to track this problem)

@legendecas legendecas marked this pull request as ready for review August 10, 2022 16:32
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 11, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 11, 2022
@nodejs-github-bot
Copy link
Collaborator

@legendecas
Copy link
Member Author

@nodejs/vm would you mind taking a look at this PR? thank you!

legendecas added a commit that referenced this pull request Aug 15, 2022
V8 APIs like HostImportModuleDynamicallyCallback and
ScriptCompiler::CompileFunction is moving away from ScriptOrModule.

Replaces ScriptCompiler::CompileFunctionInContext with
ScriptCompiler::CompileFunction to remove the usages on the optional
out param ScriptOrModule.

PR-URL: #44198
Fixes: nodejs/node-v8#214
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@legendecas
Copy link
Member Author

Landed in eefe553. Thank you for the review!

@legendecas legendecas closed this Aug 15, 2022
@legendecas legendecas deleted the deprecate-compile-function-in-context branch August 15, 2022 17:39
danielleadams pushed a commit that referenced this pull request Aug 16, 2022
V8 APIs like HostImportModuleDynamicallyCallback and
ScriptCompiler::CompileFunction is moving away from ScriptOrModule.

Replaces ScriptCompiler::CompileFunctionInContext with
ScriptCompiler::CompileFunction to remove the usages on the optional
out param ScriptOrModule.

PR-URL: #44198
Fixes: nodejs/node-v8#214
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
ruyadorno pushed a commit that referenced this pull request Aug 23, 2022
V8 APIs like HostImportModuleDynamicallyCallback and
ScriptCompiler::CompileFunction is moving away from ScriptOrModule.

Replaces ScriptCompiler::CompileFunctionInContext with
ScriptCompiler::CompileFunction to remove the usages on the optional
out param ScriptOrModule.

PR-URL: #44198
Fixes: nodejs/node-v8#214
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Fyko pushed a commit to Fyko/node that referenced this pull request Sep 15, 2022
V8 APIs like HostImportModuleDynamicallyCallback and
ScriptCompiler::CompileFunction is moving away from ScriptOrModule.

Replaces ScriptCompiler::CompileFunctionInContext with
ScriptCompiler::CompileFunction to remove the usages on the optional
out param ScriptOrModule.

PR-URL: nodejs#44198
Fixes: nodejs/node-v8#214
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
legendecas added a commit to legendecas/node that referenced this pull request Nov 7, 2023
Usages of `v8::ScriptOrModule` were removed in nodejs#44198
so the flag can be disabled by default.
nodejs-github-bot pushed a commit that referenced this pull request Nov 17, 2023
Usages of `v8::ScriptOrModule` were removed in #44198
so the flag can be disabled by default.

PR-URL: #50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
targos pushed a commit that referenced this pull request Nov 23, 2023
Usages of `v8::ScriptOrModule` were removed in #44198
so the flag can be disabled by default.

PR-URL: #50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
martenrichter pushed a commit to martenrichter/node that referenced this pull request Nov 26, 2023
Usages of `v8::ScriptOrModule` were removed in nodejs#44198
so the flag can be disabled by default.

PR-URL: nodejs#50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
lucshi pushed a commit to lucshi/node that referenced this pull request Nov 27, 2023
Usages of `v8::ScriptOrModule` were removed in nodejs#44198
so the flag can be disabled by default.

PR-URL: nodejs#50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
RafaelGSS pushed a commit that referenced this pull request Nov 29, 2023
Usages of `v8::ScriptOrModule` were removed in #44198
so the flag can be disabled by default.

PR-URL: #50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
RafaelGSS pushed a commit that referenced this pull request Nov 30, 2023
Usages of `v8::ScriptOrModule` were removed in #44198
so the flag can be disabled by default.

PR-URL: #50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
UlisesGascon pushed a commit that referenced this pull request Dec 11, 2023
Usages of `v8::ScriptOrModule` were removed in #44198
so the flag can be disabled by default.

PR-URL: #50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
UlisesGascon pushed a commit that referenced this pull request Dec 19, 2023
Usages of `v8::ScriptOrModule` were removed in #44198
so the flag can be disabled by default.

PR-URL: #50616
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
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++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CompileFunctionInContext is deprecated
4 participants