@@ -94,7 +94,6 @@ std::unique_ptr<StringBuffer> Utf8ToStringView(const std::string& message) {
94
94
utf16.length ());
95
95
return StringBuffer::create (view);
96
96
}
97
-
98
97
} // namespace
99
98
100
99
class V8NodeInspector ;
@@ -145,6 +144,8 @@ class AgentImpl {
145
144
void FatalException (v8::Local<v8::Value> error,
146
145
v8::Local<v8::Message> message);
147
146
147
+ void SchedulePauseOnNextStatement (const std::string& reason);
148
+
148
149
void PostIncomingMessage (InspectorAction action, int session_id,
149
150
const std::string& message);
150
151
void ResumeStartup () {
@@ -160,6 +161,8 @@ class AgentImpl {
160
161
static void ThreadCbIO (void * agent);
161
162
static void WriteCbIO (uv_async_t * async);
162
163
static void MainThreadAsyncCb (uv_async_t * req);
164
+ static void CallAndPauseOnStart (
165
+ const v8::FunctionCallbackInfo<v8::Value>& args);
163
166
164
167
void InstallInspectorOnProcess ();
165
168
@@ -310,6 +313,14 @@ class V8NodeInspector : public v8_inspector::V8InspectorClient {
310
313
session_->dispatchProtocolMessage (message);
311
314
}
312
315
316
+ void schedulePauseOnNextStatement (const std::string& reason) {
317
+ if (session_ != nullptr ) {
318
+ std::unique_ptr<StringBuffer> buffer = Utf8ToStringView (reason);
319
+ session_->schedulePauseOnNextStatement (buffer->string (),
320
+ buffer->string ());
321
+ }
322
+ }
323
+
313
324
v8::Local<v8::Context> ensureDefaultContextInGroup (int contextGroupId)
314
325
override {
315
326
return env_->context ();
@@ -477,6 +488,28 @@ void AgentImpl::InstallInspectorOnProcess() {
477
488
v8::Local<v8::Object> inspector = v8::Object::New (env->isolate ());
478
489
READONLY_PROPERTY (process, " inspector" , inspector);
479
490
env->SetMethod (inspector, " wrapConsoleCall" , InspectorWrapConsoleCall);
491
+ if (options_.wait_for_connect ()) {
492
+ env->SetMethod (inspector, " callAndPauseOnStart" , CallAndPauseOnStart);
493
+ }
494
+ }
495
+
496
+ // static
497
+ void AgentImpl::CallAndPauseOnStart (
498
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
499
+ Environment* env = Environment::GetCurrent (args);
500
+ CHECK_GT (args.Length (), 1 );
501
+ CHECK (args[0 ]->IsFunction ());
502
+ std::vector<v8::Local<v8::Value>> call_args;
503
+ for (int i = 2 ; i < args.Length (); i++) {
504
+ call_args.push_back (args[i]);
505
+ }
506
+
507
+ env->inspector_agent ()->SchedulePauseOnNextStatement (" Break on start" );
508
+
509
+ v8::MaybeLocal<v8::Value> retval =
510
+ args[0 ].As <v8::Function>()->Call (env->context (), args[1 ],
511
+ call_args.size (), call_args.data ());
512
+ args.GetReturnValue ().Set (retval.ToLocalChecked ());
480
513
}
481
514
482
515
std::unique_ptr<StringBuffer> ToProtocolString (v8::Local<v8::Value> value) {
@@ -682,6 +715,10 @@ void AgentImpl::Write(TransportAction action, int session_id,
682
715
CHECK_EQ (0 , err);
683
716
}
684
717
718
+ void AgentImpl::SchedulePauseOnNextStatement (const std::string& reason) {
719
+ inspector_->schedulePauseOnNextStatement (reason);
720
+ }
721
+
685
722
// Exported class Agent
686
723
Agent::Agent (node::Environment* env) : impl(new AgentImpl(env)) {}
687
724
@@ -715,6 +752,10 @@ void Agent::FatalException(v8::Local<v8::Value> error,
715
752
impl->FatalException (error, message);
716
753
}
717
754
755
+ void Agent::SchedulePauseOnNextStatement (const std::string& reason) {
756
+ impl->SchedulePauseOnNextStatement (reason);
757
+ }
758
+
718
759
InspectorAgentDelegate::InspectorAgentDelegate (AgentImpl* agent,
719
760
const std::string& script_path,
720
761
const std::string& script_name,
0 commit comments