-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
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');
|
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 |
@@ -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.
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.
I don't know if it's safe to iterate over the stack in the fast calls - probably safer to leave it to a follow up to avoid regressions if it's not and isn't reproducible from the tests.
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.
d0d6f97
to
eb8eba8
Compare
Rebased to resolve the merge conflict which caused the CI failures. PTAL again @anonrig |
Linter is complaining @joyeecheung |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #55286 +/- ##
==========================================
- Coverage 88.41% 88.40% -0.02%
==========================================
Files 652 652
Lines 186756 186759 +3
Branches 36100 36106 +6
==========================================
- Hits 165126 165109 -17
- Misses 14906 14915 +9
- Partials 6724 6735 +11
|
Landed in 1435338 |
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. PR-URL: nodejs#55286 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
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.