doc: add esm and cjs examples to node:v8
#61328
Open
+217
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the missing
ESMandCJSexamples to their respective counterparts for the V8 documentation.For the
setFlagsFromStringexample, we weren't printing anything back to the user so the example looked like we just hang the terminal for one minute and then come back. So I added some events (the ones usingnew Array()) to add some computation that would trigger the GC so we can get some output for the example, then it showcases the actual behavior by invokingsetFlagsFromString('--notrace-gc')that stops the tracing, users can see we're still creating Arrays for one more second but the GC events are now stopped viasetFlagsFromString().The same was happening for the
Promise hooksexample (in this case I added itsCJScounterpart). We were not giving any output back to the users, so it may not be clear what it's going on, I just added the invocation of one Promise (promisePrint) so now we can see all theconsole.logfrom the Promise life cycle.The same was also happening for the
isStringOneByteRepresentationexample so i just added a couple ofconsole.logto print thebufferand see its contents.Now all these examples give some output to users trying to understand this parts of the documentation.
There was one particular example that I couldn't make work using
ESM, it's theStartup Snapshot APIexample, it works fine usingCJSbut when usingESMit throws an error, sadly I lack the V8 knowledge right now to make it work, I tested it on versionsv18.20.8,v20.19.6,v22.21.1,v24.12.0andv25.1.0For version
v18.20.8the error is:And from version
v20.19.6onwards the error is:I made a simple POC to reproduce the error easily here, I already asked for help in the discord but we couldn't make it work, maybe someone with better V8 expertise can help with this one.
That's it for now! Thank you and happy new year! 💚 🥳