Skip to content
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

fix(inspector): Catch and log inspector_modules.js loading errors #1081

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/NativeScript/TNSRuntime+Inspector.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <JavaScriptCore/Debugger.h>
#include <JavaScriptCore/InspectorAgentBase.h>
#include <JavaScriptCore/InspectorFrontendChannel.h>
#include <JavaScriptCore/JSONObject.h>
#include <JavaScriptCore/JSInternalPromise.h>
#include <JavaScriptCore/JSNativeStdFunction.h>
#include <JavaScriptCore/inspector/ScriptArguments.h>

#include "GlobalObjectConsoleClient.h"
#include "GlobalObjectInspectorController.h"
Expand Down Expand Up @@ -106,11 +108,28 @@ - (void)setup {
JSC::JSLockHolder lock(_runtime->_vm.get());

WTF::Deque<WTF::RefPtr<JSC::Microtask>> other;
GlobalObject* globalObject = self->_runtime->_globalObject.get();
NativeScript::GlobalObject* globalObject = self->_runtime->_globalObject.get();

globalObject->microtasks().swap(other);
auto execState = globalObject->globalExec();

loadAndEvaluateModule(_runtime->_globalObject->globalExec(), "inspector_modules.js"_s, jsUndefined(), jsUndefined());
loadAndEvaluateModule(execState, "inspector_modules.js"_s, jsUndefined(), jsUndefined())
->then(execState, nullptr, JSNativeStdFunction::create(execState->vm(), globalObject, 1, String("reject"), [globalObject](ExecState* execState) {
JSValue error = execState->argument(0);
Vector<JSC::Strong<JSC::Unknown>> argsVector({ JSC::Strong<JSC::Unknown>(execState->vm(), jsString(execState, String("Loading inspector modules failed: "))),
JSC::Strong<JSC::Unknown>(execState->vm(), error)

});

Ref<Inspector::ScriptArguments> logArgs = Inspector::ScriptArguments::create(*execState, WTFMove(argsVector));

globalObject->inspectorController().consoleClient()->messageWithTypeAndLevel(
MessageType::Log,
MessageLevel::Warning,
execState,
WTFMove(logArgs));
return encodedJSUndefined();
}));

globalObject->drainMicrotasks();
globalObject->microtasks().swap(other);
Expand Down
3 changes: 2 additions & 1 deletion src/NativeScript/inspector/GlobalObjectConsoleClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ class GlobalObjectConsoleClient : public JSC::ConsoleClient {
static bool logToSystemConsole();
static void setLogToSystemConsole(bool);

protected:
virtual void messageWithTypeAndLevel(MessageType, MessageLevel, JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;

protected:
virtual void count(JSC::ExecState*, Ref<Inspector::ScriptArguments>&&) override;
virtual void profile(JSC::ExecState*, const String& title) override;
virtual void profileEnd(JSC::ExecState*, const String& title) override;
Expand Down
6 changes: 4 additions & 2 deletions src/NativeScript/inspector/GlobalObjectInspectorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#ifndef GlobalObjectInspectorController_h
#define GlobalObjectInspectorController_h

#include "GlobalObjectConsoleClient.h"

#include <JavaScriptCore/InspectorAgentBase.h>
#include <JavaScriptCore/InspectorAgentRegistry.h>
#include <JavaScriptCore/InspectorEnvironment.h>
Expand Down Expand Up @@ -102,7 +104,7 @@ class GlobalObjectInspectorController final
void pause();
void reportAPIException(JSC::ExecState*, JSC::Exception*);

JSC::ConsoleClient* consoleClient() const {
GlobalObjectConsoleClient* consoleClient() const {
return m_consoleClient.get();
}

Expand Down Expand Up @@ -155,7 +157,7 @@ class GlobalObjectInspectorController final
void appendAPIBacktrace(Inspector::ScriptCallStack* callStack);

std::unique_ptr<Inspector::InjectedScriptManager> m_injectedScriptManager;
std::unique_ptr<JSC::ConsoleClient> m_consoleClient;
std::unique_ptr<GlobalObjectConsoleClient> m_consoleClient;
Ref<WTF::Stopwatch> m_executionStopwatch;
Inspector::JSGlobalObjectScriptDebugServer m_scriptDebugServer;
Inspector::AgentRegistry m_agents;
Expand Down