@@ -89,6 +89,7 @@ JsStackTrace CaptureStackTrace(Isolate *isolate) {
8989// Function to capture stack traces from all registered threads
9090void CaptureStackTraces (const FunctionCallbackInfo<Value> &args) {
9191 auto capture_from_isolate = args.GetIsolate ();
92+ auto current_context = capture_from_isolate->GetCurrentContext ();
9293
9394 using ThreadResult = std::tuple<std::string, JsStackTrace>;
9495 std::vector<std::future<ThreadResult>> futures;
@@ -117,13 +118,12 @@ void CaptureStackTraces(const FunctionCallbackInfo<Value> &args) {
117118 NewStringType::kNormal )
118119 .ToLocalChecked ();
119120
120- Local<Array> jsFrames =
121- Array::New (capture_from_isolate, static_cast <int >(frames.size ()));
121+ Local<Array> jsFrames = Array::New (capture_from_isolate, frames.size ());
122122 for (size_t i = 0 ; i < frames.size (); ++i) {
123123 const auto &f = frames[i];
124124 Local<Object> frameObj = Object::New (capture_from_isolate);
125125 frameObj
126- ->Set (capture_from_isolate-> GetCurrentContext () ,
126+ ->Set (current_context ,
127127 String::NewFromUtf8 (capture_from_isolate, " function" ,
128128 NewStringType::kInternalized )
129129 .ToLocalChecked (),
@@ -133,7 +133,7 @@ void CaptureStackTraces(const FunctionCallbackInfo<Value> &args) {
133133 .ToLocalChecked ())
134134 .Check ();
135135 frameObj
136- ->Set (capture_from_isolate-> GetCurrentContext () ,
136+ ->Set (current_context ,
137137 String::NewFromUtf8 (capture_from_isolate, " filename" ,
138138 NewStringType::kInternalized )
139139 .ToLocalChecked (),
@@ -142,27 +142,24 @@ void CaptureStackTraces(const FunctionCallbackInfo<Value> &args) {
142142 .ToLocalChecked ())
143143 .Check ();
144144 frameObj
145- ->Set (capture_from_isolate-> GetCurrentContext () ,
145+ ->Set (current_context ,
146146 String::NewFromUtf8 (capture_from_isolate, " lineno" ,
147147 NewStringType::kInternalized )
148148 .ToLocalChecked (),
149149 Integer::New (capture_from_isolate, f.lineno ))
150150 .Check ();
151151 frameObj
152- ->Set (capture_from_isolate-> GetCurrentContext () ,
152+ ->Set (current_context ,
153153 String::NewFromUtf8 (capture_from_isolate, " colno" ,
154154 NewStringType::kInternalized )
155155 .ToLocalChecked (),
156156 Integer::New (capture_from_isolate, f.colno ))
157157 .Check ();
158- jsFrames
159- ->Set (capture_from_isolate->GetCurrentContext (),
160- static_cast <uint32_t >(i), frameObj)
158+ jsFrames->Set (current_context, static_cast <uint32_t >(i), frameObj)
161159 .Check ();
162160 }
163161
164- result->Set (capture_from_isolate->GetCurrentContext (), key, jsFrames)
165- .Check ();
162+ result->Set (current_context, key, jsFrames).Check ();
166163 }
167164
168165 args.GetReturnValue ().Set (result);
0 commit comments