src: handle empty MaybeLocal in cjs_lexer::Parse#63885
Open
anonrig wants to merge 1 commit into
Open
Conversation
CreateString() and Parse() in node_cjs_lexer.cc unconditionally called ToLocalChecked() on the results of String::NewFromOneByte(), String::NewFromUtf8() and Set::Add(). If string or handle allocation fails or an exception is pending on the isolate, these return an empty MaybeLocal and ToLocalChecked() aborts the process with "FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal". Since Parse() is on the hot path of every ESM import of a CJS module (cjsPreparseModuleExports), propagate the failure as a regular pending JavaScript exception instead so callers can recover. Fixes: nodejs#63323 Refs: nodejs#61456
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CreateString()andParse()insrc/node_cjs_lexer.ccunconditionally calledToLocalChecked()on the results ofString::NewFromOneByte(),String::NewFromUtf8()andSet::Add(). If string or handle allocation fails or an exception is pending on the isolate, these return an emptyMaybeLocalandToLocalChecked()aborts the whole process:Parse()is on the hot path of every ESM import of a CJS module (cjsPreparseModuleExportsinlib/internal/modules/esm/translators.js), which sits on a normal JS frame and can handle a thrown exception. This change makesCreateString()returnMaybeLocal<String>and propagates failure fromParse()as a regular pending JavaScript exception, so an allocation failure surfaces as a recoverable module load error instead of a fatal abort. This matches the failure behavior of the previous WASM-basedcjs-module-lexerand theMaybeLocalhandling conventions used elsewhere insrc/(e.g.AsArrayinsrc/util-inl.h).No regression test: the failure requires V8 string/handle allocation to fail inside the binding (export names are bounded by source length, and
Set::Addon a freshSetruns no user code), which cannot be triggered deterministically from JS. Verified locally thattest/es-modulepasses and that the stress reproducer from the issue runs clean.Fixes: #63323
Refs: #61456