first commit

This commit is contained in:
s.golasch
2023-08-01 13:49:46 +02:00
commit 1fc239fd54
20238 changed files with 3112246 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var Breakpoint = exports.Breakpoint = function Breakpoint(filePath, line) {
var column = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var temporary = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var enabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
_classCallCheck(this, Breakpoint);
this.filePath = filePath;
this.line = line;
this.temporary = temporary;
this.enabled = enabled;
this.column = column;
}
//real breakpoint set by client or temporary one set by debugger
;
//# sourceMappingURL=Breakpoint.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/server/Breakpoint.js"],"names":["Breakpoint","filePath","line","column","temporary","enabled"],"mappings":";;;;;;;;AAAA;;;;;;;;;IAWaA,U,WAAAA,U,GACX,oBAAYC,QAAZ,EAA8BC,IAA9B,EAAqH;AAAA,MAAzEC,MAAyE,uEAAxD,CAAwD;AAAA,MAArDC,SAAqD,uEAAhC,KAAgC;AAAA,MAAzBC,OAAyB,uEAAN,IAAM;;AAAA;;AACnH,OAAKJ,QAAL,GAAgBA,QAAhB;AACA,OAAKC,IAAL,GAAYA,IAAZ;AACA,OAAKE,SAAL,GAAiBA,SAAjB;AACA,OAAKC,OAAL,GAAeA,OAAf;AACA,OAAKF,MAAL,GAAcA,MAAd;AACD;;AAKD","file":"Breakpoint.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nexport class Breakpoint {\n constructor(filePath: string, line: number, column: number = 0, temporary: boolean = false, enabled: boolean = true) {\n this.filePath = filePath;\n this.line = line;\n this.temporary = temporary;\n this.enabled = enabled;\n this.column = column;\n }\n filePath: string;\n line: number;\n column: number;\n\n //real breakpoint set by client or temporary one set by debugger\n temporary: boolean;\n enabled: boolean;\n}\n"]}

View File

@@ -0,0 +1,152 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BreakpointManager = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _PerFileBreakpointMap = require("./PerFileBreakpointMap.js");
var _Breakpoint = require("./Breakpoint.js");
var _babelTypes = require("babel-types");
var _is = require("./../../methods/is.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Storing BreakpointStores for all source files
var BreakpointManager = exports.BreakpointManager = function () {
function BreakpointManager() {
_classCallCheck(this, BreakpointManager);
this._breakpointMaps = new Map();
}
_createClass(BreakpointManager, [{
key: "getStoppableBreakpoint",
value: function getStoppableBreakpoint(ast) {
if (!(0, _is.IsStatement)(ast)) return;
if (ast.loc && ast.loc.source) {
var location = ast.loc;
var filePath = location.source;
if (filePath === null) return;
var lineNum = location.start.line;
var colNum = location.start.column;
// Check whether there is a breakpoint we need to stop on here
var breakpoint = this._findStoppableBreakpoint(filePath, lineNum, colNum);
if (breakpoint === null) return;
return breakpoint;
}
}
// Try to find a breakpoint at the given location and check if we should stop on it
}, {
key: "_findStoppableBreakpoint",
value: function _findStoppableBreakpoint(filePath, lineNum, colNum) {
var breakpoint = this.getBreakpoint(filePath, lineNum, colNum);
if (breakpoint && breakpoint.enabled) {
return breakpoint;
}
return null;
}
}, {
key: "addBreakpointMulti",
value: function addBreakpointMulti(breakpoints) {
this._doBreakpointsAction(breakpoints, this._addBreakpoint.bind(this));
}
}, {
key: "_addBreakpoint",
value: function _addBreakpoint(bp) {
var breakpointMap = this._breakpointMaps.get(bp.filePath);
if (!breakpointMap) {
breakpointMap = new _PerFileBreakpointMap.PerFileBreakpointMap(bp.filePath);
this._breakpointMaps.set(bp.filePath, breakpointMap);
}
breakpointMap.addBreakpoint(bp.line, bp.column);
}
}, {
key: "getBreakpoint",
value: function getBreakpoint(filePath, lineNum) {
var columnNum = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var breakpointMap = this._breakpointMaps.get(filePath);
if (breakpointMap) return breakpointMap.getBreakpoint(lineNum, columnNum);
return undefined;
}
}, {
key: "removeBreakpointMulti",
value: function removeBreakpointMulti(breakpoints) {
this._doBreakpointsAction(breakpoints, this._removeBreakpoint.bind(this));
}
}, {
key: "_removeBreakpoint",
value: function _removeBreakpoint(bp) {
var breakpointMap = this._breakpointMaps.get(bp.filePath);
if (breakpointMap) breakpointMap.removeBreakpoint(bp.line, bp.column);
}
}, {
key: "enableBreakpointMulti",
value: function enableBreakpointMulti(breakpoints) {
this._doBreakpointsAction(breakpoints, this._enableBreakpoint.bind(this));
}
}, {
key: "_enableBreakpoint",
value: function _enableBreakpoint(bp) {
var breakpointMap = this._breakpointMaps.get(bp.filePath);
if (breakpointMap) breakpointMap.enableBreakpoint(bp.line, bp.column);
}
}, {
key: "disableBreakpointMulti",
value: function disableBreakpointMulti(breakpoints) {
this._doBreakpointsAction(breakpoints, this._disableBreakpoint.bind(this));
}
}, {
key: "_disableBreakpoint",
value: function _disableBreakpoint(bp) {
var breakpointMap = this._breakpointMaps.get(bp.filePath);
if (breakpointMap) breakpointMap.disableBreakpoint(bp.line, bp.column);
}
}, {
key: "_doBreakpointsAction",
value: function _doBreakpointsAction(breakpoints, action) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = breakpoints[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var bp = _step.value;
action(bp);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}]);
return BreakpointManager;
}();
//# sourceMappingURL=BreakpointManager.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,303 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DebugServer = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _BreakpointManager = require("./BreakpointManager.js");
var _invariant = require("../common/invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _DebugMessage = require("./../common/channel/DebugMessage.js");
var _DebuggerError = require("./../common/DebuggerError.js");
var _realm = require("./../../realm.js");
var _VariableManager = require("./VariableManager.js");
var _SteppingManager = require("./SteppingManager.js");
var _StopEventManager = require("./StopEventManager.js");
var _environment = require("./../../environment.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var DebugServer = exports.DebugServer = function () {
function DebugServer(channel, realm) {
_classCallCheck(this, DebugServer);
this._channel = channel;
this._realm = realm;
this._breakpointManager = new _BreakpointManager.BreakpointManager();
this._variableManager = new _VariableManager.VariableManager(realm);
this._stepManager = new _SteppingManager.SteppingManager(this._realm, /* default discard old steppers */false);
this._stopEventManager = new _StopEventManager.StopEventManager();
this.waitForRun(undefined);
}
// the collection of breakpoints
// the channel to communicate with the adapter
_createClass(DebugServer, [{
key: "waitForRun",
/* Block until adapter says to run
/* ast: the current ast node we are stopped on
/* reason: the reason the debuggee is stopping
*/
value: function waitForRun(ast) {
var keepRunning = false;
var request = void 0;
while (!keepRunning) {
request = this._channel.readIn();
keepRunning = this.processDebuggerCommand(request, ast);
}
}
// Checking if the debugger needs to take any action on reaching this ast node
}, {
key: "checkForActions",
value: function checkForActions(ast) {
if (this._checkAndUpdateLastExecuted(ast)) {
var stoppables = this._stepManager.getAndDeleteCompletedSteppers(ast);
var breakpoint = this._breakpointManager.getStoppableBreakpoint(ast);
if (breakpoint) stoppables.push(breakpoint);
var reason = this._stopEventManager.getDebuggeeStopReason(ast, stoppables);
if (reason) {
(0, _invariant2.default)(ast.loc && ast.loc.source);
this._channel.sendStoppedResponse(reason, ast.loc.source, ast.loc.start.line, ast.loc.start.column);
this.waitForRun(ast);
}
}
}
// Process a command from a debugger. Returns whether Prepack should unblock
// if it is blocked
}, {
key: "processDebuggerCommand",
value: function processDebuggerCommand(request, ast) {
var requestID = request.id;
var command = request.command;
var args = request.arguments;
switch (command) {
case _DebugMessage.DebugMessage.BREAKPOINT_ADD_COMMAND:
(0, _invariant2.default)(args.kind === "breakpoint");
this._breakpointManager.addBreakpointMulti(args.breakpoints);
this._channel.sendBreakpointsAcknowledge(_DebugMessage.DebugMessage.BREAKPOINT_ADD_ACKNOWLEDGE, requestID, args);
break;
case _DebugMessage.DebugMessage.BREAKPOINT_REMOVE_COMMAND:
(0, _invariant2.default)(args.kind === "breakpoint");
this._breakpointManager.removeBreakpointMulti(args.breakpoints);
this._channel.sendBreakpointsAcknowledge(_DebugMessage.DebugMessage.BREAKPOINT_REMOVE_ACKNOWLEDGE, requestID, args);
break;
case _DebugMessage.DebugMessage.BREAKPOINT_ENABLE_COMMAND:
(0, _invariant2.default)(args.kind === "breakpoint");
this._breakpointManager.enableBreakpointMulti(args.breakpoints);
this._channel.sendBreakpointsAcknowledge(_DebugMessage.DebugMessage.BREAKPOINT_ENABLE_ACKNOWLEDGE, requestID, args);
break;
case _DebugMessage.DebugMessage.BREAKPOINT_DISABLE_COMMAND:
(0, _invariant2.default)(args.kind === "breakpoint");
this._breakpointManager.disableBreakpointMulti(args.breakpoints);
this._channel.sendBreakpointsAcknowledge(_DebugMessage.DebugMessage.BREAKPOINT_DISABLE_ACKNOWLEDGE, requestID, args);
break;
case _DebugMessage.DebugMessage.PREPACK_RUN_COMMAND:
(0, _invariant2.default)(args.kind === "run");
this._onDebuggeeResume();
return true;
case _DebugMessage.DebugMessage.STACKFRAMES_COMMAND:
(0, _invariant2.default)(args.kind === "stackframe");
this.processStackframesCommand(requestID, args, ast);
break;
case _DebugMessage.DebugMessage.SCOPES_COMMAND:
(0, _invariant2.default)(args.kind === "scopes");
this.processScopesCommand(requestID, args);
break;
case _DebugMessage.DebugMessage.VARIABLES_COMMAND:
(0, _invariant2.default)(args.kind === "variables");
this.processVariablesCommand(requestID, args);
break;
case _DebugMessage.DebugMessage.STEPINTO_COMMAND:
(0, _invariant2.default)(ast !== undefined);
this._stepManager.processStepCommand("in", ast);
this._onDebuggeeResume();
return true;
case _DebugMessage.DebugMessage.STEPOVER_COMMAND:
(0, _invariant2.default)(ast !== undefined);
this._stepManager.processStepCommand("over", ast);
this._onDebuggeeResume();
return true;
case _DebugMessage.DebugMessage.EVALUATE_COMMAND:
(0, _invariant2.default)(args.kind === "evaluate");
this.processEvaluateCommand(requestID, args);
break;
default:
throw new _DebuggerError.DebuggerError("Invalid command", "Invalid command from adapter: " + command);
}
return false;
}
}, {
key: "processStackframesCommand",
value: function processStackframesCommand(requestID, args, ast) {
var frameInfos = [];
var loc = this._getFrameLocation(ast ? ast.loc : null);
var fileName = loc.fileName;
var line = loc.line;
var column = loc.column;
// the UI displays the current frame as index 0, so we iterate backwards
// from the current frame
for (var i = this._realm.contextStack.length - 1; i >= 0; i--) {
var frame = this._realm.contextStack[i];
var functionName = "(anonymous function)";
if (frame.function && frame.function.__originalName) {
functionName = frame.function.__originalName;
}
var frameInfo = {
id: this._realm.contextStack.length - 1 - i,
functionName: functionName,
fileName: fileName,
line: line,
column: column
};
frameInfos.push(frameInfo);
loc = this._getFrameLocation(frame.loc);
fileName = loc.fileName;
line = loc.line;
column = loc.column;
}
this._channel.sendStackframeResponse(requestID, frameInfos);
}
}, {
key: "_getFrameLocation",
value: function _getFrameLocation(loc) {
var fileName = "unknown";
var line = 0;
var column = 0;
if (loc && loc.source) {
fileName = loc.source;
line = loc.start.line;
column = loc.start.column;
}
return {
fileName: fileName,
line: line,
column: column
};
}
}, {
key: "processScopesCommand",
value: function processScopesCommand(requestID, args) {
// first check that frameId is in the valid range
if (args.frameId < 0 || args.frameId >= this._realm.contextStack.length) {
throw new _DebuggerError.DebuggerError("Invalid command", "Invalid frame id for scopes request: " + args.frameId);
}
// here the frameId is in reverse order of the contextStack, ie frameId 0
// refers to last element of contextStack
var stackIndex = this._realm.contextStack.length - 1 - args.frameId;
var context = this._realm.contextStack[stackIndex];
(0, _invariant2.default)(context instanceof _realm.ExecutionContext);
var scopes = [];
var lexicalEnv = context.lexicalEnvironment;
while (lexicalEnv) {
var scope = {
name: this._getScopeName(lexicalEnv.environmentRecord),
// key used by UI to retrieve variables in this scope
variablesReference: this._variableManager.getReferenceForValue(lexicalEnv),
// the variables are easy to retrieve
expensive: false
};
scopes.push(scope);
lexicalEnv = lexicalEnv.parent;
}
this._channel.sendScopesResponse(requestID, scopes);
}
}, {
key: "_getScopeName",
value: function _getScopeName(envRec) {
if (envRec instanceof _environment.GlobalEnvironmentRecord) {
return "Global";
} else if (envRec instanceof _environment.DeclarativeEnvironmentRecord) {
if (envRec instanceof _environment.FunctionEnvironmentRecord) {
return "Local: " + (envRec.$FunctionObject.__originalName || "anonymous function");
} else {
return "Block";
}
} else if (envRec instanceof _environment.ObjectEnvironmentRecord) {
return "With";
} else {
(0, _invariant2.default)(false, "Invalid type of environment record");
}
}
}, {
key: "processVariablesCommand",
value: function processVariablesCommand(requestID, args) {
var variables = this._variableManager.getVariablesByReference(args.variablesReference);
this._channel.sendVariablesResponse(requestID, variables);
}
}, {
key: "processEvaluateCommand",
value: function processEvaluateCommand(requestID, args) {
var evalResult = this._variableManager.evaluate(args.frameId, args.expression);
this._channel.sendEvaluateResponse(requestID, evalResult);
}
// actions that need to happen before Prepack can resume
}, {
key: "_onDebuggeeResume",
value: function _onDebuggeeResume() {
// resets the variable manager
this._variableManager.clean();
}
}, {
key: "_checkAndUpdateLastExecuted",
value: function _checkAndUpdateLastExecuted(ast) {
if (ast.loc && ast.loc.source) {
var filePath = ast.loc.source;
var line = ast.loc.start.line;
var column = ast.loc.start.column;
// check if the current location is same as the last one
if (this._lastExecuted && filePath === this._lastExecuted.filePath && line === this._lastExecuted.line && column === this._lastExecuted.column) {
return false;
}
this._lastExecuted = {
filePath: filePath,
line: line,
column: column
};
return true;
}
return false;
}
}, {
key: "shutdown",
value: function shutdown() {
// clean the channel pipes
this._channel.shutdown();
}
}]);
return DebugServer;
}();
//# sourceMappingURL=Debugger.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,107 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PerFileBreakpointMap = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _Breakpoint = require("./Breakpoint.js");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Storage for all the breakpoints in one source file
// Each source file will be associated with one PerFileBreakpointMap
var PerFileBreakpointMap = exports.PerFileBreakpointMap = function () {
function PerFileBreakpointMap(filePath) {
_classCallCheck(this, PerFileBreakpointMap);
this._filePath = filePath;
this._breakpoints = new Map();
}
//map of line:column to Breakpoint objects
_createClass(PerFileBreakpointMap, [{
key: "addBreakpoint",
value: function addBreakpoint(line) {
var column = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var temporary = arguments[2];
var enabled = arguments[3];
var breakpoint = new _Breakpoint.Breakpoint(this._filePath, line, column, temporary, enabled);
var key = this._getKey(line, column);
this._breakpoints.set(key, breakpoint);
}
}, {
key: "getBreakpoint",
value: function getBreakpoint(line) {
var column = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
//check for a column breakpoint first, then line breakpoint
if (column !== 0) {
var key = this._getKey(line, column);
if (this._breakpoints.has(key)) {
return this._breakpoints.get(key);
} else {
key = this._getKey(line, 0);
if (this._breakpoints.has(key)) {
return this._breakpoints.get(key);
}
}
} else {
var _key = this._getKey(line, 0);
if (this._breakpoints.has(_key)) {
return this._breakpoints.get(_key);
}
}
return undefined;
}
}, {
key: "removeBreakpoint",
value: function removeBreakpoint(line) {
var column = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var key = this._getKey(line, column);
if (this._breakpoints.has(key)) {
this._breakpoints.delete(key);
}
}
}, {
key: "enableBreakpoint",
value: function enableBreakpoint(line) {
var column = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var key = this._getKey(line, column);
var breakpoint = this._breakpoints.get(key);
if (breakpoint) breakpoint.enabled = true;
}
}, {
key: "disableBreakpoint",
value: function disableBreakpoint(line) {
var column = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var key = this._getKey(line, column);
var breakpoint = this._breakpoints.get(key);
if (breakpoint) breakpoint.enabled = false;
}
}, {
key: "_getKey",
value: function _getKey(line, column) {
return line + ":" + column;
}
}]);
return PerFileBreakpointMap;
}();
//# sourceMappingURL=PerFileBreakpointMap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/server/PerFileBreakpointMap.js"],"names":["PerFileBreakpointMap","filePath","_filePath","_breakpoints","Map","line","column","temporary","enabled","breakpoint","key","_getKey","set","has","get","undefined","delete"],"mappings":";;;;;;;qjBAAA;;;;;;;;;AAWA;;;;AAEA;AACA;IACaA,oB,WAAAA,oB;AACX,gCAAYC,QAAZ,EAA8B;AAAA;;AAC5B,SAAKC,SAAL,GAAiBD,QAAjB;AACA,SAAKE,YAAL,GAAoB,IAAIC,GAAJ,EAApB;AACD;;AAGD;;;;;kCAGcC,I,EAA0E;AAAA,UAA5DC,MAA4D,uEAA3C,CAA2C;AAAA,UAAxCC,SAAwC;AAAA,UAAnBC,OAAmB;;AACtF,UAAIC,aAAa,2BAAe,KAAKP,SAApB,EAA+BG,IAA/B,EAAqCC,MAArC,EAA6CC,SAA7C,EAAwDC,OAAxD,CAAjB;AACA,UAAIE,MAAM,KAAKC,OAAL,CAAaN,IAAb,EAAmBC,MAAnB,CAAV;AACA,WAAKH,YAAL,CAAkBS,GAAlB,CAAsBF,GAAtB,EAA2BD,UAA3B;AACD;;;kCAEaJ,I,EAAqD;AAAA,UAAvCC,MAAuC,uEAAtB,CA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EiBH,I,EAAkC;AAAA,UAApBC,MAAoB,uEAAH,CAAG;;AAClD,UAAII,MAAM,KAAKC,OAAL,CAAaN,IAAb,EAAmBC,MAAnB,CAAV;AACA,UAAIG,aAAa,KAAKN,YAAL,CAAkBW,GAAlB,CAAsBJ,GAAtB,CAAjB;AACA,UAAID,UAAJ,EAAgBA,WAAWD,OAAX,GAAqB,KAArB;AACjB;;;4BAEOH,I,EAAcC,M,EAAwB;AAC5C,aAAUD,IAAV,SAAkBC,MAAlB;AACD","file":"PerFileBreakpointMap.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nimport { Breakpoint } from \"./Breakpoint.js\";\n\n// Storage for all the breakpoints in one source file\n// Each source file will be associated with one PerFileBreakpointMap\nexport class PerFileBreakpointMap {\n constructor(filePath: string) {\n this._filePath = filePath;\n this._breakpoints = new Map();\n }\n _filePath: string;\n\n //map of line:column to Breakpoint objects\n _breakpoints: Map<string, Breakpoint>;\n\n addBreakpoint(line: number, column: number = 0, temporary?: boolean, enabled?: boolean) {\n let breakpoint = new Breakpoint(this._filePath, line, column, temporary, enabled);\n let key = this._getKey(line, column);\n this._breakpoints.set(key, breakpoint);\n }\n\n getBreakpoint(line: number, column: number = 0): void | Breakpoint {\n //check for a column breakpoint first, then line breakpoint\n if (column !== 0) {\n let key = this._getKey(line, column);\n if (this._breakpoints.has(key)) {\n return this._breakpoints.get(key);\n } else {\n key = this._getKey(line, 0);\n if (this._breakpoints.has(key)) {\n return this._breakpoints.get(key);\n }\n }\n } else {\n let key = this._getKey(line, 0);\n if (this._breakpoints.has(key)) {\n return this._breakpoints.get(key);\n }\n }\n\n return undefined;\n }\n\n removeBreakpoint(line: number, column: number = 0) {\n let key = this._getKey(line, column);\n if (this._breakpoints.has(key)) {\n this._breakpoints.delete(key);\n }\n }\n\n enableBreakpoint(line: number, column: number = 0) {\n let key = this._getKey(line, column);\n let breakpoint = this._breakpoints.get(key);\n if (breakpoint) breakpoint.enabled = true;\n }\n\n disableBreakpoint(line: number, column: number = 0) {\n let key = this._getKey(line, column);\n let breakpoint = this._breakpoints.get(key);\n if (breakpoint) breakpoint.enabled = false;\n }\n\n _getKey(line: number, column: number): string {\n return `${line}:${column}`;\n }\n}\n"]}

View File

@@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// A map with an incrementing counter as the keys
// Used to store references to variable collections since DebugProtocol
// specifies fetching variable collections via unique IDs
var ReferenceMap = exports.ReferenceMap = function () {
function ReferenceMap() {
_classCallCheck(this, ReferenceMap);
this._counter = 0;
this._mapping = new Map();
}
_createClass(ReferenceMap, [{
key: "add",
value: function add(value) {
this._counter++;
this._mapping.set(this._counter, value);
return this._counter;
}
}, {
key: "get",
value: function get(reference) {
return this._mapping.get(reference);
}
}, {
key: "clean",
value: function clean() {
this._counter = 0;
this._mapping = new Map();
}
}]);
return ReferenceMap;
}();
//# sourceMappingURL=ReferenceMap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/server/ReferenceMap.js"],"names":["ReferenceMap","_counter","_mapping","Map","value","set","reference","get"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;AAWA;AACA;AACA;IACaA,Y,WAAAA,Y;AACX,0BAAc;AAAA;;AACZ,SAAKC,QAAL,GAAgB,CAAhB;AACA,SAAKC,QAAL,GAAgB,IAAIC,GAAJ,EAAhB;AACD;;;;wBAIGC,K,EAAkB;AACpB,WAAKH,QAAL;AACA,WAAKC,QAAL,CAAcG,GAAd,CAAkB,KAAKJ,QAAvB,EAAiCG,KAAjC;AACA,aAAO,KAAKH,QAAZ;AACD;;;wBAEGK,S,EAA6B;AAC/B,aAAO,KAAKJ,QAAL,CAAcK,GAAd,CAAkBD,SAAlB,CAAP;AACD;;;4BAEO;AACN,WAAKL,QAAL,GAAgB,CAAhB;AACA,WAAKC,QAAL,GAAgB,IAAIC,GAAJ,EAAhB;AACD","file":"ReferenceMap.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\n// A map with an incrementing counter as the keys\n// Used to store references to variable collections since DebugProtocol\n// specifies fetching variable collections via unique IDs\nexport class ReferenceMap<T> {\n constructor() {\n this._counter = 0;\n this._mapping = new Map();\n }\n _counter: number;\n _mapping: Map<number, T>;\n\n add(value: T): number {\n this._counter++;\n this._mapping.set(this._counter, value);\n return this._counter;\n }\n\n get(reference: number): void | T {\n return this._mapping.get(reference);\n }\n\n clean() {\n this._counter = 0;\n this._mapping = new Map();\n }\n}\n"]}

View File

@@ -0,0 +1,126 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.StepOverStepper = exports.StepIntoStepper = exports.Stepper = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _is = require("./../../methods/is.js");
var _babelTypes = require("babel-types");
var _invariant = require("./../common/invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Stepper = exports.Stepper = function () {
function Stepper(filePath, line, column) {
_classCallCheck(this, Stepper);
this._stepStartData = {
filePath: filePath,
line: line,
column: column
};
}
_createClass(Stepper, [{
key: "isComplete",
value: function isComplete(ast, currentStackSize) {
(0, _invariant2.default)(false, "Abstract method, please override");
}
}, {
key: "isAstLocationChanged",
value: function isAstLocationChanged(ast) {
// we should only step to statements
if (!(0, _is.IsStatement)(ast)) return false;
var loc = ast.loc;
if (!loc) return false;
var filePath = loc.source;
var line = loc.start.line;
var column = loc.start.column;
if (!filePath) return false;
if (this._stepStartData) {
if (filePath === this._stepStartData.filePath && line === this._stepStartData.line && column === this._stepStartData.column) {
return false;
}
} else {
return false;
}
return true;
}
}]);
return Stepper;
}();
var StepIntoStepper = exports.StepIntoStepper = function (_Stepper) {
_inherits(StepIntoStepper, _Stepper);
function StepIntoStepper(filePath, line, column) {
_classCallCheck(this, StepIntoStepper);
return _possibleConstructorReturn(this, (StepIntoStepper.__proto__ || Object.getPrototypeOf(StepIntoStepper)).call(this, filePath, line, column));
}
// Override
_createClass(StepIntoStepper, [{
key: "isComplete",
value: function isComplete(ast, currentStackSize) {
return this.isAstLocationChanged(ast);
}
}]);
return StepIntoStepper;
}(Stepper);
var StepOverStepper = exports.StepOverStepper = function (_Stepper2) {
_inherits(StepOverStepper, _Stepper2);
function StepOverStepper(filePath, line, column, stackSize) {
_classCallCheck(this, StepOverStepper);
var _this2 = _possibleConstructorReturn(this, (StepOverStepper.__proto__ || Object.getPrototypeOf(StepOverStepper)).call(this, filePath, line, column));
_this2._startStackSize = stackSize;
return _this2;
}
_createClass(StepOverStepper, [{
key: "isComplete",
value: function isComplete(ast, currentStackSize) {
if (!this.isAstLocationChanged(ast)) return false;
if (currentStackSize <= this._startStackSize) {
// two cases here:
// if current stack length < starting stack length, the program must have
// hit an exception so this stepper is no longer relevant
// if current stack length === starting stack length, the program returned
// to the same stack depth, so a step over is complete
return true;
}
return false;
}
}]);
return StepOverStepper;
}(Stepper);
//# sourceMappingURL=Stepper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/server/Stepper.js"],"names":["Stepper","filePath","line","column","_stepStartData","ast","currentStackSize","loc","source","start","StepIntoStepper","isAstLocationChanged","StepOverStepper","stackSize","_startStackSize"],"mappings":";;;;;;;qjBAAA;;;;;;;;;AAWA;;AACA;;AACA;;;;;;;;;;;;IAEaA,O,WAAAA,O;AACX,mBAAYC,QAAZ,EAA8BC,IAA9B,EAA4CC,MAA5C,EAA4D;AAAA;;AAC1D,SAAKC,cAAL,GAAsB;AACpBH,gBAAUA,QADU;AAEpBC,YAAMA,IAFc;AAGpBC,cAAQA;AAHY,KAAtB;AAKD;;;;+BAGUE,G,EAAgBC,gB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AA7B,EAA8C;AAC5C;AACA;AACA;AACA;AACA;AACA,eAAO,IAAP;AACD;AACD,aAAO,KAAP;AACD;;;;EAlBkCd,O","file":"Stepper.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\nimport type { SourceData } from \"./../common/types.js\";\nimport { IsStatement } from \"./../../methods/is.js\";\nimport { BabelNode } from \"babel-types\";\nimport invariant from \"./../common/invariant.js\";\n\nexport class Stepper {\n constructor(filePath: string, line: number, column: number) {\n this._stepStartData = {\n filePath: filePath,\n line: line,\n column: column,\n };\n }\n _stepStartData: SourceData;\n\n isComplete(ast: BabelNode, currentStackSize: number): boolean {\n invariant(false, \"Abstract method, please override\");\n }\n\n isAstLocationChanged(ast: BabelNode) {\n // we should only step to statements\n if (!IsStatement(ast)) return false;\n let loc = ast.loc;\n if (!loc) return false;\n let filePath = loc.source;\n let line = loc.start.line;\n let column = loc.start.column;\n if (!filePath) return false;\n if (this._stepStartData) {\n if (\n filePath === this._stepStartData.filePath &&\n line === this._stepStartData.line &&\n column === this._stepStartData.column\n ) {\n return false;\n }\n } else {\n return false;\n }\n return true;\n }\n}\n\nexport class StepIntoStepper extends Stepper {\n constructor(filePath: string, line: number, column: number) {\n super(filePath, line, column);\n }\n\n // Override\n isComplete(ast: BabelNode, currentStackSize: number): boolean {\n return this.isAstLocationChanged(ast);\n }\n}\n\nexport class StepOverStepper extends Stepper {\n constructor(filePath: string, line: number, column: number, stackSize: number) {\n super(filePath, line, column);\n this._startStackSize = stackSize;\n }\n _startStackSize: number;\n\n isComplete(ast: BabelNode, currentStackSize: number): boolean {\n if (!this.isAstLocationChanged(ast)) return false;\n if (currentStackSize <= this._startStackSize) {\n // two cases here:\n // if current stack length < starting stack length, the program must have\n // hit an exception so this stepper is no longer relevant\n // if current stack length === starting stack length, the program returned\n // to the same stack depth, so a step over is complete\n return true;\n }\n return false;\n }\n}\n"]}

View File

@@ -0,0 +1,89 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SteppingManager = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _babelTypes = require("babel-types");
var _invariant = require("./../common/invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _Stepper = require("./Stepper.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var SteppingManager = exports.SteppingManager = function () {
function SteppingManager(realm, keepOldSteppers) {
_classCallCheck(this, SteppingManager);
this._realm = realm;
this._steppers = [];
this._keepOldSteppers = false;
if (keepOldSteppers) this._keepOldSteppers = true;
}
_createClass(SteppingManager, [{
key: "processStepCommand",
value: function processStepCommand(kind, currentNode) {
if (kind === "in") {
this._processStepIn(currentNode);
} else if (kind === "over") {
this._processStepOver(currentNode);
}
// TODO: implement stepOver and stepOut
}
}, {
key: "_processStepIn",
value: function _processStepIn(ast) {
(0, _invariant2.default)(this._stepInto === undefined);
(0, _invariant2.default)(ast.loc && ast.loc.source);
if (!this._keepOldSteppers) {
this._steppers = [];
}
this._steppers.push(new _Stepper.StepIntoStepper(ast.loc.source, ast.loc.start.line, ast.loc.start.column));
}
}, {
key: "_processStepOver",
value: function _processStepOver(ast) {
(0, _invariant2.default)(ast.loc && ast.loc.source);
if (!this._keepOldSteppers) {
this._steppers = [];
}
this._steppers.push(new _Stepper.StepOverStepper(ast.loc.source, ast.loc.start.line, ast.loc.start.column, this._realm.contextStack.length));
}
}, {
key: "getAndDeleteCompletedSteppers",
value: function getAndDeleteCompletedSteppers(ast) {
(0, _invariant2.default)(ast.loc && ast.loc.source);
var i = 0;
var completedSteppers = [];
while (i < this._steppers.length) {
var stepper = this._steppers[i];
if (stepper.isComplete(ast, this._realm.contextStack.length)) {
completedSteppers.push(stepper);
this._steppers.splice(i, 1);
} else {
i++;
}
}
return completedSteppers;
}
}]);
return SteppingManager;
}();
//# sourceMappingURL=SteppingManager.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/server/SteppingManager.js"],"names":["SteppingManager","realm","keepOldSteppers","_realm","_steppers","_keepOldSteppers","kind","currentNode","_processStepIn","_processStepOver","ast","_stepInto","undefined","loc","source","push","start","line","column","contextStack","length","i","completedSteppers","stepper","isComplete","splice"],"mappings":";;;;;;;qjBAAA;;;;;;;;;AAWA;;AACA;;;;AACA;;;;;;IAIaA,e,WAAAA,e;AACX,2BAAYC,KAAZ,EAA0BC,eAA1B,EAAqD;AAAA;;AACnD,SAAKC,MAAL,GAAcF,KAAd;AACA,SAAKG,SAAL,GAAiB,EAAjB;AACA,SAAKC,gBAAL,GAAwB,KAAxB;AACA,QAAIH,eAAJ,EAAqB,KAAKG,gBAAL,GAAwB,IAAxB;AACtB;;;;uCAKkBC,I,EAA6BC,W,EAAwB;AACtE,UAAID,SAAS,IAAb,EAAmB;AACjB,aAAKE,cAAL,CAAoBD,WAApB;AACD,OAFD,MAEO,IAAID,SAAS,MAAb,EAAqB;AAC1B,aAAKG,gBAAL,CAAsBF,WAAtB;AACD;AACD;AACD;;;mCAEcG,G,EAAgB;AAC7B,+BAAU,KAAKC,SAAL,KAAmBC,SAA7B;AACA,+BAAUF,IAAIG,GAAJ,IAAWH,IA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sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nimport { BabelNode } from \"babel-types\";\nimport invariant from \"./../common/invariant.js\";\nimport { Stepper, StepIntoStepper, StepOverStepper } from \"./Stepper.js\";\nimport type { Realm } from \"./../../realm.js\";\nimport type { StoppableObject } from \"./StopEventManager.js\";\n\nexport class SteppingManager {\n constructor(realm: Realm, keepOldSteppers?: boolean) {\n this._realm = realm;\n this._steppers = [];\n this._keepOldSteppers = false;\n if (keepOldSteppers) this._keepOldSteppers = true;\n }\n _realm: Realm;\n _keepOldSteppers: boolean;\n _steppers: Array<Stepper>;\n\n processStepCommand(kind: \"in\" | \"over\" | \"out\", currentNode: BabelNode) {\n if (kind === \"in\") {\n this._processStepIn(currentNode);\n } else if (kind === \"over\") {\n this._processStepOver(currentNode);\n }\n // TODO: implement stepOver and stepOut\n }\n\n _processStepIn(ast: BabelNode) {\n invariant(this._stepInto === undefined);\n invariant(ast.loc && ast.loc.source);\n if (!this._keepOldSteppers) {\n this._steppers = [];\n }\n this._steppers.push(new StepIntoStepper(ast.loc.source, ast.loc.start.line, ast.loc.start.column));\n }\n\n _processStepOver(ast: BabelNode) {\n invariant(ast.loc && ast.loc.source);\n if (!this._keepOldSteppers) {\n this._steppers = [];\n }\n this._steppers.push(\n new StepOverStepper(ast.loc.source, ast.loc.start.line, ast.loc.start.column, this._realm.contextStack.length)\n );\n }\n\n getAndDeleteCompletedSteppers(ast: BabelNode): Array<StoppableObject> {\n invariant(ast.loc && ast.loc.source);\n let i = 0;\n let completedSteppers: Array<StoppableObject> = [];\n while (i < this._steppers.length) {\n let stepper = this._steppers[i];\n if (stepper.isComplete(ast, this._realm.contextStack.length)) {\n completedSteppers.push(stepper);\n this._steppers.splice(i, 1);\n } else {\n i++;\n }\n }\n return completedSteppers;\n }\n}\n"]}

View File

@@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.StopEventManager = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _invariant = require("./../common/invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _Breakpoint = require("./Breakpoint.js");
var _Stepper = require("./Stepper.js");
var _babelTypes = require("babel-types");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Manage whether the debuggee should stop
// All stopping related logic is centralized here
var StopEventManager = exports.StopEventManager = function () {
function StopEventManager() {
_classCallCheck(this, StopEventManager);
}
_createClass(StopEventManager, [{
key: "getDebuggeeStopReason",
// stoppables is a list of objects the debuggee should be stopped on
// (e.g. breakpoint, completed steppers). The debuggee should stop if there
// is at least one element in the list. Currently the reason of the first element
// is chosen as the reason sent to the UI
value: function getDebuggeeStopReason(ast, stoppables) {
if (stoppables.length === 0) return;
var stoppable = stoppables[0];
var stoppedReason = void 0;
if (stoppable instanceof _Breakpoint.Breakpoint) {
stoppedReason = "Breakpoint";
} else if (stoppable instanceof _Stepper.StepIntoStepper) {
stoppedReason = "Step Into";
} else if (stoppable instanceof _Stepper.StepOverStepper) {
stoppedReason = "Step Over";
} else {
(0, _invariant2.default)(false, "Invalid stoppable object");
}
return stoppedReason;
}
}]);
return StopEventManager;
}();
//# sourceMappingURL=StopEventManager.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/server/StopEventManager.js"],"names":["StopEventManager","ast","stoppables","length","stoppable","stoppedReason"],"mappings":";;;;;;;qjBAAA;;;;;;;;;AAWA;;;;AACA;;AACA;;AACA;;;;;;AAKA;AACA;;IAEaA,gB,WAAAA,gB;;;;;;;;AACX;AACA;AACA;AACA;0CACsBC,G,EAAgBC,U,EAA0D;AAC9F,UAAIA,WAAWC,MAAX,KAAsB,CAA1B,EAA6B;AAC7B,UAAIC,YAAYF,WAAW,CAAX,CAAhB;AACA,UAAIG,sBAAJ;AACA,UAAID,2CAAJ,EAAqC;AACnCC,wBAAgB,YAAhB;AACD,OAFD,MAEO,IAAID,6CAAJ,EAA0C;AAC/CC,wBAAgB,WAAhB;AACD,OAFM,MAEA,IAAID,6CAAJ,EAA0C;AAC/CC,wBAAgB,WAAhB;AACD,OAFM,MAEA;AACL,iCAAU,KAAV,EAAiB,0BAAjB;AACD;AACD,aAAOA,aAAP;AACD","file":"StopEventManager.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nimport invariant from \"./../common/invariant.js\";\nimport { Breakpoint } from \"./Breakpoint.js\";\nimport { Stepper, StepIntoStepper, StepOverStepper } from \"./Stepper.js\";\nimport { BabelNode } from \"babel-types\";\nimport type { StoppedReason } from \"./../common/types.js\";\n\nexport type StoppableObject = Breakpoint | Stepper;\n\n// Manage whether the debuggee should stop\n// All stopping related logic is centralized here\n\nexport class StopEventManager {\n // stoppables is a list of objects the debuggee should be stopped on\n // (e.g. breakpoint, completed steppers). The debuggee should stop if there\n // is at least one element in the list. Currently the reason of the first element\n // is chosen as the reason sent to the UI\n getDebuggeeStopReason(ast: BabelNode, stoppables: Array<StoppableObject>): void | StoppedReason {\n if (stoppables.length === 0) return;\n let stoppable = stoppables[0];\n let stoppedReason;\n if (stoppable instanceof Breakpoint) {\n stoppedReason = \"Breakpoint\";\n } else if (stoppable instanceof StepIntoStepper) {\n stoppedReason = \"Step Into\";\n } else if (stoppable instanceof StepOverStepper) {\n stoppedReason = \"Step Over\";\n } else {\n invariant(false, \"Invalid stoppable object\");\n }\n return stoppedReason;\n }\n}\n"]}

View File

@@ -0,0 +1,304 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.VariableManager = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _ReferenceMap = require("./ReferenceMap.js");
var _environment = require("./../../environment.js");
var _index = require("./../../values/index.js");
var _invariant = require("./../common/invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _is = require("./../../methods/is.js");
var _DebuggerError = require("./../common/DebuggerError.js");
var _singletons = require("./../../singletons.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// This class manages the handling of variable requests in the debugger
// The DebugProtocol specifies collections of variables are to be fetched using a
// unique reference ID called a variablesReference. This class can generate new
// variablesReferences to pass to the UI and then perform lookups for those
// variablesReferences when they are requested.
var VariableManager = exports.VariableManager = function () {
function VariableManager(realm) {
_classCallCheck(this, VariableManager);
this._containerCache = new Map();
this._referenceMap = new _ReferenceMap.ReferenceMap();
this._realm = realm;
}
// cache for created references
// map for looking up references
_createClass(VariableManager, [{
key: "getReferenceForValue",
// Given a container, either returns a cached reference for that container if
// it exists or return a new reference
value: function getReferenceForValue(value) {
var cachedRef = this._containerCache.get(value);
if (cachedRef !== undefined) {
return cachedRef;
}
var varRef = this._referenceMap.add(value);
this._containerCache.set(value, varRef);
return varRef;
}
// The entry point for retrieving a collection of variables by a reference
}, {
key: "getVariablesByReference",
value: function getVariablesByReference(reference) {
var container = this._referenceMap.get(reference);
if (!container) return [];
if (container instanceof _environment.LexicalEnvironment) {
return this._getVariablesFromEnvRecord(container.environmentRecord);
} else if (container instanceof _index.ObjectValue) {
return this._getVariablesFromObject(container);
} else if (container instanceof _index.AbstractValue) {
return this._getAbstractValueContent(container);
} else {
(0, _invariant2.default)(false, "Invalid variable container");
}
}
}, {
key: "_getVariablesFromObject",
value: function _getVariablesFromObject(object) {
var variables = [];
var names = object.properties.keys();
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var name = _step.value;
var binding = object.properties.get(name);
(0, _invariant2.default)(binding !== undefined);
if (binding.descriptor) {
if ((0, _is.IsDataDescriptor)(this._realm, binding.descriptor)) {
var value = binding.descriptor.value;
if (value instanceof _index.Value) {
var variable = this._getVariableFromValue(name, value);
variables.push(variable);
}
}
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return variables;
}
}, {
key: "_getAbstractValueContent",
value: function _getAbstractValueContent(value) {
var kindVar = {
name: "kind",
value: value.kind || "undefined",
variablesReference: 0
};
var contents = [kindVar];
var argCount = 1;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = value.args[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var arg = _step2.value;
contents.push(this._getVariableFromValue("arg-" + argCount, arg));
argCount++;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
return contents;
}
}, {
key: "_getVariablesFromEnvRecord",
value: function _getVariablesFromEnvRecord(envRecord) {
if (envRecord instanceof _environment.DeclarativeEnvironmentRecord) {
return this._getVariablesFromDeclarativeEnv(envRecord);
} else if (envRecord instanceof _environment.ObjectEnvironmentRecord) {
if (envRecord.object instanceof _index.ObjectValue) {
return this._getVariablesFromObject(envRecord.object);
} else if (envRecord.object instanceof _index.AbstractObjectValue) {
// TODO: call _getVariablesFromAbstractObject when it is implemented
return [];
} else {
(0, _invariant2.default)(false, "Invalid type of object environment record");
}
} else if (envRecord instanceof _environment.GlobalEnvironmentRecord) {
var declVars = this._getVariablesFromEnvRecord(envRecord.$DeclarativeRecord);
var objVars = this._getVariablesFromEnvRecord(envRecord.$ObjectRecord);
return declVars.concat(objVars);
} else {
(0, _invariant2.default)(false, "Invalid type of environment record");
}
}
}, {
key: "_getVariablesFromDeclarativeEnv",
value: function _getVariablesFromDeclarativeEnv(env) {
var variables = [];
var bindings = env.bindings;
for (var name in bindings) {
var binding = bindings[name];
if (binding.value) {
var variable = this._getVariableFromValue(name, binding.value);
variables.push(variable);
}
}
return variables;
}
}, {
key: "_getVariableFromValue",
value: function _getVariableFromValue(name, value) {
if (value instanceof _index.ConcreteValue) {
return this._getVariableFromConcreteValue(name, value);
} else if (value instanceof _index.AbstractValue) {
return this._getVariableFromAbstractValue(name, value);
} else {
(0, _invariant2.default)(false, "Value is neither concrete nor abstract");
}
}
}, {
key: "_getVariableFromAbstractValue",
value: function _getVariableFromAbstractValue(name, value) {
var variable = {
name: name,
value: this._getAbstractValueDisplay(value),
variablesReference: this.getReferenceForValue(value)
};
return variable;
}
}, {
key: "_getAbstractValueDisplay",
value: function _getAbstractValueDisplay(value) {
if (value.intrinsicName && !value.intrinsicName.startsWith("_")) {
return value.intrinsicName;
}
return "Abstract " + value.types.getType().name;
}
}, {
key: "_getVariableFromConcreteValue",
value: function _getVariableFromConcreteValue(name, value) {
if (value instanceof _index.PrimitiveValue) {
var variable = {
name: name,
value: value.toDisplayString(),
variablesReference: 0
};
return variable;
} else if (value instanceof _index.ObjectValue) {
var _variable = {
name: name,
value: value.getKind(),
variablesReference: this.getReferenceForValue(value)
};
return _variable;
} else {
(0, _invariant2.default)(false, "Concrete value must be primitive or object");
}
}
}, {
key: "evaluate",
value: function evaluate(frameId, expression) {
var evalRealm = this._realm;
var isDirect = false;
var isStrict = false;
if (frameId !== undefined) {
if (frameId < 0 || frameId >= this._realm.contextStack.length) {
throw new _DebuggerError.DebuggerError("Invalid command", "Invalid value for frame ID");
}
// frameId's are in reverse order of context stack
var stackIndex = this._realm.contextStack.length - 1 - frameId;
var context = this._realm.contextStack[stackIndex];
isDirect = true;
isStrict = true;
evalRealm = context.realm;
}
var evalString = new _index.StringValue(this._realm, expression);
try {
var value = _singletons.Functions.PerformEval(this._realm, evalString, evalRealm, isStrict, isDirect);
var varInfo = this._getVariableFromValue(expression, value);
var result = {
kind: "evaluate",
displayValue: varInfo.value,
type: value.getType().name,
variablesReference: varInfo.variablesReference
};
return result;
} catch (e) {
var _result = {
kind: "evaluate",
displayValue: "Failed to evaluate: " + expression,
type: "unknown",
variablesReference: 0
};
return _result;
}
}
}, {
key: "clean",
value: function clean() {
this._containerCache = new Map();
this._referenceMap.clean();
}
}]);
return VariableManager;
}();
//# sourceMappingURL=VariableManager.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,127 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DebugChannel = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _invariant = require("./../../common/invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _FileIOWrapper = require("./../../common/channel/FileIOWrapper.js");
var _DebugMessage = require("./../../common/channel/DebugMessage.js");
var _MessageMarshaller = require("./../../common/channel/MessageMarshaller.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
//Channel used by the DebugServer in Prepack to communicate with the debug adapter
var DebugChannel = exports.DebugChannel = function () {
function DebugChannel(ioWrapper) {
_classCallCheck(this, DebugChannel);
this._requestReceived = false;
this._ioWrapper = ioWrapper;
this._marshaller = new _MessageMarshaller.MessageMarshaller();
}
_createClass(DebugChannel, [{
key: "debuggerIsAttached",
/*
/* Only called in the beginning to check if a debugger is attached
*/
value: function debuggerIsAttached() {
var message = this._ioWrapper.readInSyncOnce();
if (message === null) return false;
var parts = message.split(" ");
var requestID = parseInt(parts[0], 10);
(0, _invariant2.default)(!isNaN(requestID), "Request ID must be a number");
var command = parts[1];
if (command === _DebugMessage.DebugMessage.DEBUGGER_ATTACHED) {
this._requestReceived = true;
this._ioWrapper.clearInFile();
this.writeOut(requestID + " " + _DebugMessage.DebugMessage.PREPACK_READY_RESPONSE);
return true;
}
return false;
}
/* Reads in a request from the debug adapter
/* The caller is responsible for sending a response with the appropriate
/* contents at the right time.
*/
}, {
key: "readIn",
value: function readIn() {
var message = this._ioWrapper.readInSync();
this._requestReceived = true;
return this._marshaller.unmarshallRequest(message);
}
// Write out a response to the debug adapter
}, {
key: "writeOut",
value: function writeOut(contents) {
//Prepack only writes back to the debug adapter in response to a request
(0, _invariant2.default)(this._requestReceived, "Prepack writing message without being requested: " + contents);
this._ioWrapper.writeOutSync(contents);
this._requestReceived = false;
}
}, {
key: "sendBreakpointsAcknowledge",
value: function sendBreakpointsAcknowledge(messageType, requestID, args) {
this.writeOut(this._marshaller.marshallBreakpointAcknowledge(requestID, messageType, args.breakpoints));
}
}, {
key: "sendStoppedResponse",
value: function sendStoppedResponse(reason, filePath, line, column) {
this.writeOut(this._marshaller.marshallStoppedResponse(reason, filePath, line, column));
}
}, {
key: "sendStackframeResponse",
value: function sendStackframeResponse(requestID, stackframes) {
this.writeOut(this._marshaller.marshallStackFramesResponse(requestID, stackframes));
}
}, {
key: "sendScopesResponse",
value: function sendScopesResponse(requestID, scopes) {
this.writeOut(this._marshaller.marshallScopesResponse(requestID, scopes));
}
}, {
key: "sendVariablesResponse",
value: function sendVariablesResponse(requestID, variables) {
this.writeOut(this._marshaller.marshallVariablesResponse(requestID, variables));
}
}, {
key: "sendEvaluateResponse",
value: function sendEvaluateResponse(requestID, evalResult) {
this.writeOut(this._marshaller.marshallEvaluateResponse(requestID, evalResult));
}
}, {
key: "shutdown",
value: function shutdown() {
this._ioWrapper.clearInFile();
this._ioWrapper.clearOutFile();
}
}]);
return DebugChannel;
}();
//# sourceMappingURL=DebugChannel.js.map

File diff suppressed because one or more lines are too long