Skip to content

Commit 10f03e5

Browse files
anonrigaduh95
authored andcommitted
src: omit unconvertible names in cjs_lexer::Parse
Follow-up to aa25a0a. When an export or re-export name cannot be converted to a V8 string (e.g. on string allocation failure), omit that individual name and continue instead of bailing out of the whole preparse. A single pathological name no longer fails the module's exports preparse; the remaining names are still returned. Refs: #63885 Refs: #63323 Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> PR-URL: #63943 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent a44f51e commit 10f03e5

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/node_cjs_lexer.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,26 @@ void Parse(const FunctionCallbackInfo<Value>& args) {
6767

6868
const auto& analysis = result.value();
6969

70-
// Convert exports to JS Set
70+
// Convert exports to JS Set, omitting any name that cannot be turned into a
71+
// V8 string (e.g. on string allocation failure) instead of aborting.
7172
Local<Set> exports_set = Set::New(isolate);
7273
for (const auto& exp : analysis.exports) {
7374
Local<String> exp_str;
74-
if (!CreateString(isolate, exp).ToLocal(&exp_str) ||
75+
if (CreateString(isolate, exp).ToLocal(&exp_str) &&
7576
exports_set->Add(context, exp_str).IsEmpty()) {
7677
return;
7778
}
7879
}
7980

80-
// Convert reexports to JS array using batch creation
81+
// Convert reexports to JS array, omitting any name that cannot be turned into
82+
// a V8 string.
8183
LocalVector<Value> reexports_vec(isolate);
8284
reexports_vec.reserve(analysis.re_exports.size());
8385
for (const auto& reexp : analysis.re_exports) {
8486
Local<String> reexp_str;
85-
if (!CreateString(isolate, reexp).ToLocal(&reexp_str)) {
86-
return;
87+
if (CreateString(isolate, reexp).ToLocal(&reexp_str)) {
88+
reexports_vec.push_back(reexp_str);
8789
}
88-
reexports_vec.push_back(reexp_str);
8990
}
9091

9192
// Create result array [exports (Set), reexports (Array)]

0 commit comments

Comments
 (0)