Skip to content

Commit e256534

Browse files
committed
Merge pull request #426 from NativeScript/KristinaKoeva/UseJSContext
Use JSAgentContext as all the other agents
2 parents 80428ba + d51e9f1 commit e256534

6 files changed

+30
-38
lines changed

Diff for: src/NativeScript/inspector/DomainBackendDispatcher.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ static EncodedJSValue JSC_HOST_CALL dispatchMessage(ExecState* execState) {
1919
return JSValue::encode(jsUndefined());
2020
}
2121

22-
Ref<DomainBackendDispatcher> DomainBackendDispatcher::create(WTF::String domain, JSCell* constructorFunction, Inspector::BackendDispatcher* backendDispatcher, NativeScript::GlobalObject& globalObject) {
23-
return adoptRef(*new DomainBackendDispatcher(domain, constructorFunction, *backendDispatcher, globalObject));
22+
Ref<DomainBackendDispatcher> DomainBackendDispatcher::create(WTF::String domain, JSCell* constructorFunction, Inspector::JSAgentContext& context) {
23+
return adoptRef(*new DomainBackendDispatcher(domain, constructorFunction, context));
2424
}
2525

26-
DomainBackendDispatcher::DomainBackendDispatcher(WTF::String domain, JSCell* constructorFunction, Inspector::BackendDispatcher& backendDispatcher, NativeScript::GlobalObject& globalObject)
27-
: SupplementalBackendDispatcher(backendDispatcher)
28-
, m_globalObject(globalObject) {
26+
DomainBackendDispatcher::DomainBackendDispatcher(WTF::String domain, JSCell* constructorFunction, Inspector::JSAgentContext& context)
27+
: SupplementalBackendDispatcher(context.backendDispatcher)
28+
, m_globalObject(context.inspectedGlobalObject) {
2929
ConstructData constructData;
3030
ConstructType constructType = getConstructData(constructorFunction, constructData);
3131
JSFunction* dispatchMessageFunction = JSFunction::create(m_globalObject.vm(), &m_globalObject, 0, WTF::ASCIILiteral("dispatchMessage"), &dispatchMessage);

Diff for: src/NativeScript/inspector/DomainBackendDispatcher.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
#define DomainBackendDispatcher_h
33

44
#include <inspector/InspectorBackendDispatcher.h>
5+
#include <inspector/InspectorAgentBase.h>
56
#include <JavaScriptCore/StrongInlines.h>
67

78
namespace NativeScript {
89
class JS_EXPORT_PRIVATE DomainBackendDispatcher final : public Inspector::SupplementalBackendDispatcher {
910
public:
10-
static Ref<DomainBackendDispatcher> create(WTF::String domain, JSC::JSCell* constructorFunction, Inspector::BackendDispatcher*, NativeScript::GlobalObject&);
11+
static Ref<DomainBackendDispatcher> create(WTF::String domain, JSC::JSCell* constructorFunction, Inspector::JSAgentContext&);
1112
virtual void dispatch(long callId, const String& method, Ref<Inspector::InspectorObject>&& message) override;
1213

1314
private:
14-
DomainBackendDispatcher(WTF::String domain, JSC::JSCell* constructorFunction, Inspector::BackendDispatcher&, NativeScript::GlobalObject&);
15+
DomainBackendDispatcher(WTF::String domain, JSC::JSCell* constructorFunction, Inspector::JSAgentContext&);
1516

16-
NativeScript::GlobalObject& m_globalObject;
17+
JSC::JSGlobalObject& m_globalObject;
1718
JSC::Strong<JSC::JSObject> m_domainDispatcher;
1819
};
1920
}

Diff for: src/NativeScript/inspector/DomainInspectorAgent.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
#include "GlobalObjectInspectorController.h"
44

55
namespace NativeScript {
6-
DomainInspectorAgent::DomainInspectorAgent(GlobalObject& globalObject, WTF::String domainName, JSC::JSCell* constructorFunction)
6+
DomainInspectorAgent::DomainInspectorAgent(WTF::String domainName, JSC::JSCell* constructorFunction, Inspector::JSAgentContext& context)
77
: Inspector::InspectorAgentBase(domainName)
8-
, m_globalObject(globalObject)
9-
, m_constructorFunction(m_globalObject.vm(), constructorFunction) {}
8+
, m_context(context)
9+
, m_constructorFunction(m_context.inspectedGlobalObject.vm(), constructorFunction) {}
1010

1111
void DomainInspectorAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher* backendDispatcher) {
12-
m_backendDispatcher = backendDispatcher;
13-
14-
this->m_domainBackendDispatcher = DomainBackendDispatcher::create(this->domainName(), m_constructorFunction.get(), m_backendDispatcher, m_globalObject);
12+
this->m_domainBackendDispatcher = DomainBackendDispatcher::create(this->domainName(), m_constructorFunction.get(), m_context);
1513
}
1614

1715
void DomainInspectorAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason) {

Diff for: src/NativeScript/inspector/DomainInspectorAgent.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ class DomainInspectorAgent : public Inspector::InspectorAgentBase {
1111
WTF_MAKE_FAST_ALLOCATED;
1212

1313
public:
14-
DomainInspectorAgent(GlobalObject&, WTF::String domainName, JSC::JSCell* constructorFunction);
14+
DomainInspectorAgent(WTF::String domainName, JSC::JSCell* constructorFunction, Inspector::JSAgentContext&);
1515

1616
virtual void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
1717
virtual void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
1818

1919
private:
20-
GlobalObject& m_globalObject;
21-
Inspector::BackendDispatcher* m_backendDispatcher;
20+
Inspector::JSAgentContext& m_context;
2221
RefPtr<DomainBackendDispatcher> m_domainBackendDispatcher;
2322
JSC::Strong<JSC::JSCell> m_constructorFunction;
2423
};

Diff for: src/NativeScript/inspector/GlobalObjectInspectorController.cpp

+10-20
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,18 @@ GlobalObjectInspectorController::GlobalObjectInspectorController(GlobalObject& g
8181
, m_frontendRouter(FrontendRouter::create())
8282
, m_backendDispatcher(BackendDispatcher::create(m_frontendRouter.copyRef()))
8383
, m_globalObject(globalObject)
84+
, m_agentContext({ *this, *m_injectedScriptManager, m_frontendRouter.get(), m_backendDispatcher.get() })
85+
, m_jsAgentContext(m_agentContext, m_globalObject)
86+
8487
{
85-
AgentContext baseContext = {
86-
*this,
87-
*m_injectedScriptManager,
88-
m_frontendRouter.get(),
89-
m_backendDispatcher.get()
90-
};
91-
92-
JSAgentContext context = {
93-
baseContext,
94-
globalObject
95-
};
96-
97-
9888
globalObject.putDirectNativeFunction(globalObject.vm(), &globalObject, Identifier::fromString(&globalObject.vm(), WTF::ASCIILiteral("__registerDomainDispatcher")), 0, &registerDispatcher, NoIntrinsic, DontEnum);
9989

100-
auto inspectorAgent = std::make_unique<InspectorAgent>(context);
101-
auto runtimeAgent = std::make_unique<JSGlobalObjectRuntimeAgent>(context);
102-
auto consoleAgent = std::make_unique<JSGlobalObjectConsoleAgent>(context);
103-
auto debuggerAgent = std::make_unique<GlobalObjectDebuggerAgent>(context, consoleAgent.get());
104-
auto pageAgent = std::make_unique<InspectorPageAgent>(context);
105-
auto timelineAgent = std::make_unique<InspectorTimelineAgent>(context);
90+
auto inspectorAgent = std::make_unique<InspectorAgent>(m_jsAgentContext);
91+
auto runtimeAgent = std::make_unique<JSGlobalObjectRuntimeAgent>(m_jsAgentContext);
92+
auto consoleAgent = std::make_unique<JSGlobalObjectConsoleAgent>(m_jsAgentContext);
93+
auto debuggerAgent = std::make_unique<GlobalObjectDebuggerAgent>(m_jsAgentContext, consoleAgent.get());
94+
auto pageAgent = std::make_unique<InspectorPageAgent>(m_jsAgentContext);
95+
auto timelineAgent = std::make_unique<InspectorTimelineAgent>(m_jsAgentContext);
10696

10797
m_inspectorAgent = inspectorAgent.get();
10898
m_debuggerAgent = debuggerAgent.get();
@@ -124,7 +114,7 @@ GlobalObjectInspectorController::~GlobalObjectInspectorController() {
124114
}
125115

126116
void GlobalObjectInspectorController::registerDomainDispatcher(WTF::String domainIdentifier, JSC::JSCell* constructorFunction) {
127-
std::unique_ptr<DomainInspectorAgent> domainInspectorAgent = std::make_unique<DomainInspectorAgent>(m_globalObject, domainIdentifier, constructorFunction);
117+
std::unique_ptr<DomainInspectorAgent> domainInspectorAgent = std::make_unique<DomainInspectorAgent>(domainIdentifier, constructorFunction, this->m_jsAgentContext);
128118

129119
appendExtraAgent(WTF::move(domainInspectorAgent));
130120
}

Diff for: src/NativeScript/inspector/GlobalObjectInspectorController.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#ifndef GlobalObjectInspectorController_h
2727
#define GlobalObjectInspectorController_h
2828

29+
#include <JavaScriptCore/InspectorAgentBase.h>
2930
#include <JavaScriptCore/InspectorAgentRegistry.h>
3031
#include <JavaScriptCore/InspectorEnvironment.h>
3132
#include <JavaScriptCore/InspectorFrontendRouter.h>
@@ -144,7 +145,10 @@ class GlobalObjectInspectorController final
144145
bool m_isAutomaticInspection { false };
145146

146147
GlobalObject& m_globalObject;
147-
148+
149+
Inspector::AgentContext m_agentContext;
150+
Inspector::JSAgentContext m_jsAgentContext;
151+
148152
#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
149153
Inspector::AugmentableInspectorControllerClient* m_augmentingClient { nullptr };
150154
#endif

0 commit comments

Comments
 (0)