Commit eaa38da0 authored by GauthamBanasandra's avatar GauthamBanasandra Committed by Commit Bot

DevTools: Implement a reliable check for isNodeJS()

The isNodeJS() method validates whether target
has only SDK.Target.Capability.JS set. This
patch makes it more explicit and resolves the
existing TODO in the isNodeJS() method.

The creator of the target must now explicitly
mark the target as Node.js by calling
markAsNodeJS() on the target object, thus
avoiding the dependency on SDK.Target.Capability.JS.

Change-Id: I4da9af58ddc42eba2b6b91f7b1b81b411180256b
Reviewed-on: https://chromium-review.googlesource.com/1116761
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Reviewed-by: default avatarAndrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572375}
parent ce008f8a
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
var testMapping = BindingsTestRunner.initializeTestMapping(); var testMapping = BindingsTestRunner.initializeTestMapping();
// Pretend we are running under V8 front-end. // Pretend we are running under V8 front-end.
SDK.targetManager.mainTarget().setIsNodeJSForTest(); SDK.targetManager.mainTarget().markAsNodeJS();
var content = ['', '', 'var express = require("express");', '//TODO'].join('\n'); var content = ['', '', 'var express = require("express");', '//TODO'].join('\n');
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
await TestRunner.loadModule('sdk_test_runner'); await TestRunner.loadModule('sdk_test_runner');
await TestRunner.showPanel('sources'); await TestRunner.showPanel('sources');
SDK.targetManager.mainTarget().setIsNodeJSForTest(); SDK.targetManager.mainTarget().markAsNodeJS();
SourcesTestRunner.startDebuggerTest(); SourcesTestRunner.startDebuggerTest();
var debuggerModel = SDK.targetManager.mainTarget().model(SDK.DebuggerModel); var debuggerModel = SDK.targetManager.mainTarget().model(SDK.DebuggerModel);
......
...@@ -34,6 +34,8 @@ InspectorMain.InspectorMain = class extends Common.Object { ...@@ -34,6 +34,8 @@ InspectorMain.InspectorMain = class extends Common.Object {
const target = SDK.targetManager.createTarget( const target = SDK.targetManager.createTarget(
'main', Common.UIString('Main'), this._capabilitiesForMainTarget(), this._createMainConnection.bind(this), 'main', Common.UIString('Main'), this._capabilitiesForMainTarget(), this._createMainConnection.bind(this),
null); null);
if (Runtime.queryParam('v8only'))
target.markAsNodeJS();
target.runtimeAgent().runIfWaitingForDebugger(); target.runtimeAgent().runIfWaitingForDebugger();
} }
......
...@@ -13,6 +13,7 @@ JsMain.JsMain = class extends Common.Object { ...@@ -13,6 +13,7 @@ JsMain.JsMain = class extends Common.Object {
Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConnectToNodeJSDirectly); Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConnectToNodeJSDirectly);
const target = SDK.targetManager.createTarget( const target = SDK.targetManager.createTarget(
'main', Common.UIString('Main'), SDK.Target.Capability.JS, this._createMainConnection.bind(this), null); 'main', Common.UIString('Main'), SDK.Target.Capability.JS, this._createMainConnection.bind(this), null);
target.markAsNodeJS();
target.runtimeAgent().runIfWaitingForDebugger(); target.runtimeAgent().runIfWaitingForDebugger();
InspectorFrontendHost.connectionReady(); InspectorFrontendHost.connectionReady();
} }
......
...@@ -100,6 +100,7 @@ NodeMain.NodeChildTargetManager = class extends SDK.SDKModel { ...@@ -100,6 +100,7 @@ NodeMain.NodeChildTargetManager = class extends SDK.SDKModel {
const target = this._targetManager.createTarget( const target = this._targetManager.createTarget(
targetInfo.targetId, Common.UIString('Node.js: %s', targetInfo.url), SDK.Target.Capability.JS, targetInfo.targetId, Common.UIString('Node.js: %s', targetInfo.url), SDK.Target.Capability.JS,
this._createChildConnection.bind(this, this._targetAgent, sessionId), this._parentTarget); this._createChildConnection.bind(this, this._targetAgent, sessionId), this._parentTarget);
target.markAsNodeJS();
target.runtimeAgent().runIfWaitingForDebugger(); target.runtimeAgent().runIfWaitingForDebugger();
} }
......
...@@ -46,12 +46,11 @@ SDK.Target = class extends Protocol.TargetBase { ...@@ -46,12 +46,11 @@ SDK.Target = class extends Protocol.TargetBase {
* @return {boolean} * @return {boolean}
*/ */
isNodeJS() { isNodeJS() {
// TODO(lushnikov): this is an unreliable way to detect Node.js targets. return this._isNodeJS;
return this._capabilitiesMask === SDK.Target.Capability.JS || this._isNodeJSForTest;
} }
setIsNodeJSForTest() { markAsNodeJS() {
this._isNodeJSForTest = true; this._isNodeJS = true;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment