@@ -320,23 +320,21 @@ static void GetCallSites(const FunctionCallbackInfo<Value>& args) {
320320 args.GetReturnValue ().Set (callsites);
321321}
322322
323+ /* *
324+ * Checks whether the current call directly initiated from a file inside
325+ * node_modules. This checks up to `frame_limit` stack frames, until it finds
326+ * a frame that is not part of node internal modules.
327+ */
323328static void IsInsideNodeModules (const FunctionCallbackInfo<Value>& args) {
324329 Isolate* isolate = args.GetIsolate ();
325- CHECK_EQ (args.Length (), 2 );
326- CHECK (args[0 ]->IsInt32 ()); // frame_limit
327- // The second argument is the default value.
328330
329- int frames_limit = args[0 ].As <v8::Int32>()->Value ();
331+ int frames_limit = (args.Length () > 0 && args[0 ]->IsInt32 ())
332+ ? args[0 ].As <v8::Int32>()->Value ()
333+ : 10 ;
330334 Local<StackTrace> stack =
331335 StackTrace::CurrentStackTrace (isolate, frames_limit);
332336 int frame_count = stack->GetFrameCount ();
333337
334- // If the search requires looking into more than |frames_limit| frames, give
335- // up and return the specified default value.
336- if (frame_count == frames_limit) {
337- return args.GetReturnValue ().Set (args[1 ]);
338- }
339-
340338 bool result = false ;
341339 for (int i = 0 ; i < frame_count; ++i) {
342340 Local<StackFrame> stack_frame = stack->GetFrame (isolate, i);
@@ -350,13 +348,11 @@ static void IsInsideNodeModules(const FunctionCallbackInfo<Value>& args) {
350348 if (script_name_str.starts_with (" node:" )) {
351349 continue ;
352350 }
353- if (script_name_str.find (" /node_modules/" ) != std::string::npos ||
354- script_name_str.find (" \\ node_modules\\ " ) != std::string::npos ||
355- script_name_str.find (" /node_modules\\ " ) != std::string::npos ||
356- script_name_str.find (" \\ node_modules/" ) != std::string::npos) {
357- result = true ;
358- break ;
359- }
351+ result = script_name_str.find (" /node_modules/" ) != std::string::npos ||
352+ script_name_str.find (" \\ node_modules\\ " ) != std::string::npos ||
353+ script_name_str.find (" /node_modules\\ " ) != std::string::npos ||
354+ script_name_str.find (" \\ node_modules/" ) != std::string::npos;
355+ break ;
360356 }
361357
362358 args.GetReturnValue ().Set (result);
0 commit comments