Repository navigation
fix(inspector): console timestamps, handler errors, and promise callbacks while paused #617
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -782,6 +782,13 @@ bool GetInt32(const json& value, long long& out) { | |
|
|
||
| void JsV8InspectorClient::quitMessageLoopOnPause() { pauseTerminated_ = true; } | ||
|
|
||
| // V8 stamps console messages and exceptions with it; its default is 0. | ||
| double JsV8InspectorClient::currentTimeMS() { | ||
| return std::chrono::duration<double, std::milli>( | ||
| std::chrono::system_clock::now().time_since_epoch()) | ||
| .count(); | ||
| } | ||
|
|
||
| void JsV8InspectorClient::SendToConnection(uint64_t connectionId, const std::string& message) { | ||
| this->SendRawToConnection(connectionId, MaybeRewriteSourceMapURL(message)); | ||
| } | ||
|
|
@@ -935,8 +942,9 @@ bool GetInt32(const json& value, long long& out) { | |
| } | ||
|
|
||
| Local<Value> result; | ||
| std::optional<std::string> thrownMessage; | ||
| success = this->CallDomainHandlerFunction(context, domainMethodFunc, argObject, domainDebugger, | ||
| result); | ||
| result, thrownMessage); | ||
| if (enabling) { | ||
| auto& enablers = this->jsDomainEnablers_[domain]; | ||
| auto it = enablers.find(connectionId); | ||
|
|
@@ -967,6 +975,15 @@ bool GetInt32(const json& value, long long& out) { | |
| return; | ||
| } | ||
| this->pendingJsReplies_.erase(handlerId); | ||
|
|
||
| // The handler owns the command, so V8, which does not know the domain, | ||
| // must not answer it instead. | ||
| if (thrownMessage.has_value()) { | ||
| json error = {{"id", json_message["id"]}, | ||
| {"error", {{"code", -32000}, {"message", *thrownMessage}}}}; | ||
| this->SendRawToConnection(connectionId, error.dump()); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // if no handler handled the message successfully, fall-through to the default V8 implementation | ||
|
|
@@ -977,8 +994,11 @@ bool GetInt32(const json& value, long long& out) { | |
| this->StopHolding(connectionId, true); | ||
| } | ||
|
|
||
| // TODO: check why this is needed (it should trigger automatically when script depth is 0) | ||
| isolate->PerformMicrotaskCheckpoint(); | ||
| // Runs what the command queued. Not while paused, as in Chrome: it would | ||
| // also run the app's own promise callbacks in the middle of paused JS. | ||
| if (!runningPauseLoop_) { | ||
| isolate->PerformMicrotaskCheckpoint(); | ||
| } | ||
| } | ||
|
|
||
| void JsV8InspectorClient::HandleLoadNetworkResource(uint64_t connectionId, int msgId, | ||
|
|
@@ -1421,7 +1441,8 @@ bool GetInt32(const json& value, long long& out) { | |
| Local<Function> domainMethodFunc, | ||
| const Local<Object>& arg, | ||
| Local<Object>& domainDebugger, | ||
| Local<Value>& result) { | ||
| Local<Value>& result, | ||
| std::optional<std::string>& thrownMessage) { | ||
| if (domainMethodFunc.IsEmpty() || !domainMethodFunc->IsFunction()) { | ||
| return false; | ||
| } | ||
|
|
@@ -1454,6 +1475,24 @@ bool GetInt32(const json& value, long long& out) { | |
| // log any other errors - they are caught, but still make them visible to the user. | ||
| tns::LogError(isolate, tc); | ||
|
|
||
| // The error's message, as Chromium reports a failed command; the whole | ||
| // text for anything else that was thrown. | ||
| if (!tc.HasTerminated()) { | ||
| Local<Value> exception = tc.Exception(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capture the handler exception before error logging. If the handler throws Capture the response message before calling
|
||
| TryCatch messageTc(isolate); | ||
| Local<Value> message; | ||
| if (exception->IsNativeError() && | ||
| exception.As<Object>()->Get(context, tns::ToV8String(isolate, "message")).ToLocal(&message) && | ||
| message->IsString()) { | ||
| thrownMessage = tns::ToString(isolate, message); | ||
| } else if (exception->ToString(context).ToLocal(&message)) { | ||
| thrownMessage = tns::ToString(isolate, message); | ||
| } | ||
| if (!thrownMessage.has_value()) { | ||
| thrownMessage = std::string(); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.