-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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: implement IsInsideNodeModules() in C++ #55286
base: main
Are you sure you want to change the base?
Conversation
The performance doesn't really matter all that much for const array = [];
console.time('new Buffer');
for (let i = 0; i < 10000; ++i) {
array.push(new Buffer(10));
}
console.timeEnd('new Buffer');
|
This previously compiles a script and run it in a new context to avoid global pollution, which is more complex than necessary and can be too slow for it to be reused in other cases. The new implementation just checks the frames in C++ which is safe from global pollution, faster and simpler. The previous implementation also had a bug when the call site is in a ESM, because ESM have URLs as their script names, which don't start with '/' or '\' and will be skipped. The new implementation removes the skipping to fix it for ESM.
5273982
to
d0d6f97
Compare
Failed to start CI⚠ No approving reviews found ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/11196042300 |
Interesting |
continue; | ||
} | ||
|
||
std::string script_name_str = Utf8Value(isolate, script_name).ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this string view and avoid a copy?
@@ -292,10 +292,47 @@ static void GetCallSite(const FunctionCallbackInfo<Value>& args) { | |||
|
|||
callsite_objects.push_back(obj); | |||
} | |||
} | |||
|
|||
static void IsInsideNodeModules(const FunctionCallbackInfo<Value>& args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add V8 fast api to this to speed things up.
This previously compiles a script and run it in a new context to avoid global pollution, which is more complex than necessary and can be too slow for it to be reused in other cases. The new implementation just checks the frames in C++ which is safe from global pollution, faster and simpler.
The previous implementation also had a bug when the call site is in a ESM, because ESM have URLs as their script names, which don't start with '/' or '\' and will be skipped. The new implementation removes the skipping to fix it for ESM.