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

lib: restate the code to use primordials #36561

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/internal/v8_prof_polyfill.js
Expand Up @@ -28,6 +28,10 @@
/* eslint-disable no-restricted-globals */

module.exports = { versionCheck };
const {
StringPrototypeSplit,
StringPrototypeReplace,
} = primordials;

// Don't execute when required directly instead of being eval'd from
// lib/internal/v8_prof_processor.js. This way we can test functions
Expand Down Expand Up @@ -154,8 +158,8 @@ function macCppfiltNm(out) {
}

let i = 0;
filtered = filtered.split('\n');
return out.replace(FUNC_RE, (all, prefix, postfix) => {
filtered = StringPrototypeSplit(filtered, '\n');
return StringPrototypeReplace(out, FUNC_RE, (all, prefix, postfix) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that calling StringPrototypeReplace on a RegExp is unsafe, as it calls RegExp.prototype[Symbol.replace].


This should instead use:

Suggested change
return StringPrototypeReplace(out, FUNC_RE, (all, prefix, postfix) => {
return RegExpPrototypeSymbolReplace(FUNC_RE, out, (all, prefix, postfix) => {

return prefix + (filtered[i++] || postfix);
});
}