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,77 @@
"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.
*/
//separator for messages according to the protocol
var TWO_CRLF = "\r\n\r\n";
var DataHandler = exports.DataHandler = function () {
function DataHandler() {
_classCallCheck(this, DataHandler);
this._rawData = new Buffer(0);
this._contentLength = -1;
}
_createClass(DataHandler, [{
key: "handleData",
value: function handleData(data, messageProcessor) {
this._rawData = Buffer.concat([this._rawData, data]);
// the following code parses a message according to the protocol.
while (this._rawData.length > 0) {
// if we know what length we are expecting
if (this._contentLength >= 0) {
// we have enough data to check for the expected message
if (this._rawData.byteLength >= this._contentLength) {
// first get the expected message
var _message = this._rawData.toString("utf8", 0, this._contentLength);
// reduce the buffer by the message we got
this._rawData = this._rawData.slice(this._contentLength);
// reset the content length to ensure it is extracted for the next message
this._contentLength = -1;
// process the message
messageProcessor(_message);
continue; // there may be more complete messages to process
}
} else {
// if we don't know the length to expect, we need to extract it first
var idx = this._rawData.indexOf(TWO_CRLF);
if (idx !== -1) {
var header = this._rawData.toString("utf8", 0, idx);
var lines = header.split("\r\n");
for (var i = 0; i < lines.length; i++) {
var pair = lines[i].split(/: +/);
if (pair[0] === "Content-Length") {
this._contentLength = parseInt(pair[1], 10);
// reset the contentlength if it is invalid
if (isNaN(this._contentLength)) this._contentLength = -1;
}
}
this._rawData = this._rawData.slice(idx + TWO_CRLF.length);
continue;
}
// if we don't find the length we fall through and break
}
break;
}
}
}]);
return DataHandler;
}();
//# sourceMappingURL=DataHandler.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/mock-ui/DataHandler.js"],"names":["TWO_CRLF","DataHandler","_rawData","Buffer","_contentLength","data","messageProcessor","concat","length","byteLength","message","toString","slice","idx","indexOf","header","lines","split","i","pair","parseInt","isNaN"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;AAWA;AACA,IAAMA,WAAW,UAAjB;;IAEaC,W,WAAAA,W;AACX,yBAAc;AAAA;;AACZ,SAAKC,QAAL,GAAgB,IAAIC,MAAJ,CAAW,CAAX,CAAhB;AACA,SAAKC,cAAL,GAAsB,CAAC,CAAvB;AACD;;;;+BAIUC,I,EAAcC,gB,EAAmD;AAC1E,WAAKJ,QAAL,GAAgBC,OAAOI,MAAP,CAAc,CAAC,KAAKL,QAAN,EAAgBG,IAAhB,CAAd,CAAhB;AACA;AACA,aAAO,KAAKH,QAAL,CAAcM,MAAd,GAAuB,CAA9B,EAAiC;AAC/B;AACA,YAAI,KAAKJ,cAAL,IAAuB,CAA3B,EAA8B;AAC5B;AACA,cAAI,KAAKF,QAAL,CAAcO,UAAd,IAA4B,KAAKL,cAArC,EAAqD;AACnD;AACA,gBAAIM,WAAU,KAAKR,QAAL,CAAcS,QAAd,CAAuB,MAAvB,EAA+B,CAA/B,EAAkC,KAAKP,cAAvC,CAAd;AACA;AACA,iBAAKF,QAAL,GAAgB,KAAKA,QAAL,CAAcU,KAAd,CAAoB,KAAKR,cAAzB,CAAhB;AACA;AACA,iBAAKA,cAAL,GAAsB,CAAC,CAAvB;AACA;AACAE,6BAAiBI,QAAjB;AACA,qBATmD,CASzC;AACX;AACF,SAbD,MAaO;AACL;AACA,cAAIG,MAAM,KAAKX,QAAL,CAAcY,OAAd,CAAsBd,QAAtB,CAAV;AACA,cAAIa,QAAQ,CAAC,CAAb,EAAgB;AACd,gBAAIE,SAAS,KAAKb,QAAL,CAAcS,QAAd,CAAuB,MAAvB,EAA+B,CAA/B,EAAkCE,GAAlC,CAAb;AACA,gBAAIG,QAAQD,OAAOE,KAAP,CAAa,MAAb,CAAZ;AACA,iBAAK,IAAIC,IAAI,CAAb,EAAgBA,IAAIF,MAAMR,MAA1B,EAAkCU,GAAlC,EAAuC;AACrC,kBAAIC,OAAOH,MAAME,CAAN,EAASD,KAAT,CAAe,KAAf,CAAX;AACA,kBAAIE,KAAK,CAAL,MAAY,gBAAhB,EAAkC;AAChC,qBAAKf,cAAL,GAAsBgB,SAASD,KAAK,CAAL,CAAT,EAAkB,EAAlB,CAAtB;AACA;AACA,oBAAIE,MAAM,KAAKjB,cAAX,CAAJ,EAAgC,KAAKA,cAAL,GAAsB,CAAC,CAAvB;AACjC;AACF;AACD,iBAAKF,QAAL,GAAgB,KAAKA,QAAL,CAAcU,KAAd,CAAoBC,MAAMb,SAASQ,MAAnC,CAAhB;AACA;AACD;AACD;AACD;AACD;AACD;AACF","file":"DataHandler.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//separator for messages according to the protocol\nconst TWO_CRLF = \"\\r\\n\\r\\n\";\n\nexport class DataHandler {\n constructor() {\n this._rawData = new Buffer(0);\n this._contentLength = -1;\n }\n _rawData: Buffer;\n _contentLength: number;\n\n handleData(data: Buffer, messageProcessor: (message: string) => void): void {\n this._rawData = Buffer.concat([this._rawData, data]);\n // the following code parses a message according to the protocol.\n while (this._rawData.length > 0) {\n // if we know what length we are expecting\n if (this._contentLength >= 0) {\n // we have enough data to check for the expected message\n if (this._rawData.byteLength >= this._contentLength) {\n // first get the expected message\n let message = this._rawData.toString(\"utf8\", 0, this._contentLength);\n // reduce the buffer by the message we got\n this._rawData = this._rawData.slice(this._contentLength);\n // reset the content length to ensure it is extracted for the next message\n this._contentLength = -1;\n // process the message\n messageProcessor(message);\n continue; // there may be more complete messages to process\n }\n } else {\n // if we don't know the length to expect, we need to extract it first\n let idx = this._rawData.indexOf(TWO_CRLF);\n if (idx !== -1) {\n let header = this._rawData.toString(\"utf8\", 0, idx);\n let lines = header.split(\"\\r\\n\");\n for (let i = 0; i < lines.length; i++) {\n let pair = lines[i].split(/: +/);\n if (pair[0] === \"Content-Length\") {\n this._contentLength = parseInt(pair[1], 10);\n // reset the contentlength if it is invalid\n if (isNaN(this._contentLength)) this._contentLength = -1;\n }\n }\n this._rawData = this._rawData.slice(idx + TWO_CRLF.length);\n continue;\n }\n // if we don't find the length we fall through and break\n }\n break;\n }\n }\n}\n"]}

View File

@@ -0,0 +1,685 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.UISession = 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 _readline = require("readline");
var _readline2 = _interopRequireDefault(_readline);
var _child_process = require("child_process");
var _child_process2 = _interopRequireDefault(_child_process);
var _vscodeDebugprotocol = require("vscode-debugprotocol");
var DebugProtocol = _interopRequireWildcard(_vscodeDebugprotocol);
var _DataHandler = require("./DataHandler.js");
var _DebuggerConstants = require("./../common/DebuggerConstants");
var _types = require("./../common/types.js");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
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"); } }
//separator for messages according to the protocol
var TWO_CRLF = "\r\n\r\n";
/* Represents one debugging session in the CLI.
* Read in user input from the command line, parses the input into commands,
* sends the commands to the adapter and process any responses
*/
var UISession = exports.UISession = function () {
function UISession(proc, args) {
_classCallCheck(this, UISession);
this._proc = proc;
this._adapterPath = args.adapterPath;
this._prepackRuntime = args.prepackRuntime;
this._sourceFile = args.sourceFile;
this._prepackArguments = args.prepackArguments;
this._sequenceNum = 1;
this._invalidCount = 0;
this._dataHandler = new _DataHandler.DataHandler();
this._prepackWaiting = false;
this._prepackLaunched = false;
}
// the parent (i.e. ui) process
//path to the debug adapter
// the child (i.e. adapter) process
// id number for each message sent
// interface to read in input from the CLI client
// number of invalid commands
// Prepack runtime command (e.g. lib/prepack-cli.js)
// input source file to Prepack
// arguments to start Prepack with
// handler for any received messages
// flag whether Prepack is waiting for a command
// flag whether Prepack has been launched
_createClass(UISession, [{
key: "_startAdapter",
value: function _startAdapter() {
var _this = this;
var adapterArgs = [this._adapterPath];
this._adapterProcess = _child_process2.default.spawn("node", adapterArgs);
this._proc.on("exit", function () {
_this.shutdown();
});
this._proc.on("SIGINT", function () {
_this.shutdown();
});
this._adapterProcess.stdout.on("data", function (data) {
//handle the received data
_this._dataHandler.handleData(data, _this._processMessage.bind(_this));
});
this._adapterProcess.stderr.on("data", function (data) {
console.error(data.toString());
_this.shutdown();
});
}
// called from data handler to process a received message
}, {
key: "_processMessage",
value: function _processMessage(message) {
var _this2 = this;
try {
var msg = JSON.parse(message);
if (msg.type === "event") {
this._processEvent(msg);
} else if (msg.type === "response") {
this._processResponse(msg);
}
} catch (e) {
console.error(e);
console.error("Invalid message: " + message.slice(0, 1000));
}
//ask the user for the next command
if (this._prepackLaunched && this._prepackWaiting) {
this._reader.question("(dbg) ", function (input) {
_this2._dispatch(input);
});
}
}
}, {
key: "_processEvent",
value: function _processEvent(event) {
if (event.event === "initialized") {
// the adapter is ready to accept any persisted debug information
// (e.g. persisted breakpoints from previous sessions). the CLI
var configDoneArgs = {};
this._sendConfigDoneRequest(configDoneArgs);
} else if (event.event === "output") {
this._uiOutput("Prepack output:\n" + event.body.output);
} else if (event.event === "terminated") {
this._uiOutput("Prepack exited! Shutting down...");
this.shutdown();
} else if (event.event === "stopped") {
this._prepackWaiting = true;
if (event.body) {
this._uiOutput(event.body.reason);
}
}
}
}, {
key: "_processResponse",
value: function _processResponse(response) {
if (response.command === "initialize") {
this._processInitializeResponse(response);
} else if (response.command === "launch") {
this._processLaunchResponse(response);
} else if (response.command === "threads") {
this._processThreadsResponse(response);
} else if (response.command === "stackTrace") {
//flow doesn't have type refinement for interfaces, so must do a cast here
this._processStackTraceResponse(response);
} else if (response.command === "scopes") {
this._processScopesResponse(response);
} else if (response.command === "variables") {
this._processVariablesResponse(response);
} else if (response.command === "evaluate") {
this._processEvaluateResponse(response);
}
}
}, {
key: "_processScopesResponse",
value: function _processScopesResponse(response) {
var scopes = response.body.scopes;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = scopes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var scope = _step.value;
this._uiOutput(scope.name + " " + scope.variablesReference);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
}, {
key: "_processInitializeResponse",
value: function _processInitializeResponse(response) {
var launchArgs = {
prepackRuntime: this._prepackRuntime,
sourceFile: this._sourceFile,
prepackArguments: this._prepackArguments
};
this._sendLaunchRequest(launchArgs);
}
}, {
key: "_processLaunchResponse",
value: function _processLaunchResponse(response) {
var _this3 = this;
this._uiOutput("Prepack is ready");
this._prepackLaunched = true;
this._prepackWaiting = true;
// start reading requests from the user
this._reader.question("(dbg) ", function (input) {
_this3._dispatch(input);
});
}
}, {
key: "_processStackTraceResponse",
value: function _processStackTraceResponse(response) {
var frames = response.body.stackFrames;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = frames[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var frame = _step2.value;
if (frame.source && frame.source.path) {
this._uiOutput(frame.id + ": " + frame.name + " " + frame.source.path + " " + frame.line + ":" + frame.column);
} else {
this._uiOutput(frame.id + ": " + frame.name + " unknown source");
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
}, {
key: "_processThreadsResponse",
value: function _processThreadsResponse(response) {
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = response.body.threads[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var thread = _step3.value;
this._uiOutput(thread.id + ": " + thread.name);
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
}
}, {
key: "_processVariablesResponse",
value: function _processVariablesResponse(response) {
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = response.body.variables[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var variable = _step4.value;
if (variable.variablesReference === 0) {
// 0 means there are not more nested variables to return
this._uiOutput(variable.name + ": " + variable.value);
} else {
this._uiOutput(variable.name + ": " + variable.value + " " + variable.variablesReference);
}
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
}
}, {
key: "_processEvaluateResponse",
value: function _processEvaluateResponse(response) {
var evalInfo = response.body;
this._uiOutput("Type: " + (evalInfo.type || "unknown"));
this._uiOutput(evalInfo.result);
this._uiOutput("Variables Reference: " + evalInfo.variablesReference);
}
// execute a command if it is valid
// returns whether the command was valid
}, {
key: "_executeCommand",
value: function _executeCommand(input) {
var parts = input.split(" ");
var command = parts[0];
// for testing purposes, init and configDone are made into user commands
// they can be done from the adapter without user input
switch (command) {
case "run":
// format: run
if (parts.length !== 1) return false;
var continueArgs = {
// Prepack will only have 1 thread, this argument will be ignored
threadId: _DebuggerConstants.DebuggerConstants.PREPACK_THREAD_ID
};
this._sendContinueRequest(continueArgs);
break;
case "breakpoint":
// format: breakpoint add <filePath> <line> ?<column>
if (parts.length !== 4 && parts.length !== 5) return false;
if (parts[1] === "add") {
var filePath = parts[2];
var line = parseInt(parts[3], 10);
if (isNaN(line)) return false;
var column = 0;
if (parts.length === 5) {
column = parseInt(parts[4], 10);
if (isNaN(column)) return false;
}
this._sendBreakpointRequest(filePath, line, column);
}
break;
case "stackframes":
// format: stackFrames
var stackFrameArgs = {
// Prepack will only have 1 thread, this argument will be ignored
threadId: _DebuggerConstants.DebuggerConstants.PREPACK_THREAD_ID
};
this._sendStackFramesRequest(stackFrameArgs);
break;
case "threads":
if (parts.length !== 1) return false;
this._sendThreadsRequest();
break;
case "scopes":
if (parts.length !== 2) return false;
var frameId = parseInt(parts[1], 10);
if (isNaN(frameId)) return false;
var scopesArgs = {
frameId: frameId
};
this._sendScopesRequest(scopesArgs);
break;
case "variables":
if (parts.length !== 2) return false;
var varRef = parseInt(parts[1], 10);
if (isNaN(varRef)) return false;
var variableArgs = {
variablesReference: varRef
};
this._sendVariablesRequest(variableArgs);
break;
case "stepInto":
if (parts.length !== 1) return false;
var stepIntoArgs = {
threadId: _DebuggerConstants.DebuggerConstants.PREPACK_THREAD_ID
};
this._sendStepIntoRequest(stepIntoArgs);
break;
case "stepOver":
if (parts.length !== 1) return false;
var stepOverArgs = {
threadId: _DebuggerConstants.DebuggerConstants.PREPACK_THREAD_ID
};
this._sendStepOverRequest(stepOverArgs);
break;
case "eval":
if (parts.length < 2) return false;
var evalFrameId = parseInt(parts[1], 10);
if (isNaN(evalFrameId)) {
var expression = parts.slice(1).join(" ");
var evaluateArgs = {
expression: expression
};
this._sendEvaluateRequest(evaluateArgs);
} else {
var _expression = parts.slice(2).join(" ");
var _evaluateArgs = {
expression: _expression,
frameId: evalFrameId
};
this._sendEvaluateRequest(_evaluateArgs);
}
break;
default:
// invalid command
return false;
}
return true;
}
// parses the user input into a command and executes it
}, {
key: "_dispatch",
value: function _dispatch(input) {
var _this4 = this;
if (input === "exit") {
this.shutdown();
}
var success = this._executeCommand(input);
if (!success) {
// input was invalid
this._invalidCount++;
//prevent stack overflow from recursion
if (this._invalidCount >= 10) {
console.error("Too many invalid commands, shutting down...");
this.shutdown();
}
console.error("Invalid command: " + input);
this._reader.question("(dbg) ", function (line) {
_this4._dispatch(line);
});
}
//reset the invalid command counter
this._invalidCount = 0;
}
// tell the adapter about some configuration details
}, {
key: "_sendInitializeRequest",
value: function _sendInitializeRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "initialize",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
// tell the adapter to start Prepack
}, {
key: "_sendLaunchRequest",
value: function _sendLaunchRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "launch",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
// tell the adapter that configuration is done so it can expect other commands
}, {
key: "_sendConfigDoneRequest",
value: function _sendConfigDoneRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "configurationDone",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
// tell the adapter to continue running Prepack
}, {
key: "_sendContinueRequest",
value: function _sendContinueRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "continue",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
this._prepackWaiting = false;
}
}, {
key: "_sendBreakpointRequest",
value: function _sendBreakpointRequest(filePath, line) {
var column = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var source = {
path: filePath
};
var breakpoint = {
line: line,
column: column
};
var args = {
source: source,
breakpoints: [breakpoint]
};
var message = {
type: "request",
seq: this._sequenceNum,
command: "setBreakpoints",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
}, {
key: "_sendStackFramesRequest",
value: function _sendStackFramesRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "stackTrace",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
}, {
key: "_sendThreadsRequest",
value: function _sendThreadsRequest() {
var message = {
type: "request",
seq: this._sequenceNum,
command: "threads"
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
}, {
key: "_sendScopesRequest",
value: function _sendScopesRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "scopes",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
}, {
key: "_sendVariablesRequest",
value: function _sendVariablesRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "variables",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
}, {
key: "_sendStepIntoRequest",
value: function _sendStepIntoRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "stepIn",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
}, {
key: "_sendStepOverRequest",
value: function _sendStepOverRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "next",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
}, {
key: "_sendEvaluateRequest",
value: function _sendEvaluateRequest(args) {
var message = {
type: "request",
seq: this._sequenceNum,
command: "evaluate",
arguments: args
};
var json = JSON.stringify(message);
this._packageAndSend(json);
}
// write out a message to the adapter on stdout
}, {
key: "_packageAndSend",
value: function _packageAndSend(message) {
// format: Content-Length: <length> separator <message>
this._adapterProcess.stdin.write("Content-Length: " + Buffer.byteLength(message, "utf8") + TWO_CRLF + message, "utf8");
this._sequenceNum++;
}
}, {
key: "_uiOutput",
value: function _uiOutput(message) {
console.log(message);
}
}, {
key: "serve",
value: function serve() {
this._uiOutput("Debugger is starting up Prepack...");
// Set up the adapter connection
this._startAdapter();
// send an initialize request to the adapter to fetch some configuration details
var initArgs = {
// a unique name for each UI (e.g Nuclide, VSCode, CLI)
clientID: _DebuggerConstants.DebuggerConstants.CLI_CLIENTID,
// a unique name for each adapter
adapterID: "Prepack-Debugger-Adapter",
linesStartAt1: true,
columnsStartAt1: true,
supportsVariableType: true,
supportsVariablePaging: false,
supportsRunInTerminalRequest: false,
pathFormat: "path"
};
this._sendInitializeRequest(initArgs);
this._reader = _readline2.default.createInterface({ input: this._proc.stdin, output: this._proc.stdout });
}
}, {
key: "shutdown",
value: function shutdown() {
this._reader.close();
this._adapterProcess.kill();
this._proc.exit(0);
}
}]);
return UISession;
}();
//# sourceMappingURL=UISession.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,77 @@
"use strict";
var _UISession = require("./UISession.js");
/* The entry point to start up the debugger CLI
* Reads in command line arguments and starts up a UISession
*/
function run(process, console) {
var args = readCLIArguments(process, console);
var session = new _UISession.UISession(process, args);
try {
session.serve();
} catch (e) {
console.error(e);
session.shutdown();
}
} /**
* 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.
*/
function readCLIArguments(process, console) {
var adapterPath = "";
var prepackRuntime = "";
var prepackArguments = [];
var sourceFile = "";
var args = Array.from(process.argv);
args.splice(0, 2);
//read in the arguments
while (args.length > 0) {
var arg = args.shift();
if (!arg.startsWith("--")) {
console.error("Invalid argument: " + arg);
process.exit(1);
}
arg = arg.slice(2);
if (arg === "adapterPath") {
adapterPath = args.shift();
} else if (arg === "prepackRuntime") {
prepackRuntime = args.shift();
} else if (arg === "prepackArguments") {
prepackArguments = args.shift().split(" ");
} else if (arg === "sourceFile") {
sourceFile = args.shift();
} else {
console.error("Unknown argument: " + arg);
process.exit(1);
}
}
if (adapterPath.length === 0) {
console.error("No path to the debug adapter provided!");
process.exit(1);
}
if (prepackRuntime.length === 0) {
console.error("No Prepack runtime given to start Prepack");
process.exit(1);
}
if (sourceFile.length === 0) {
console.error("No source code input file provided");
}
var result = {
adapterPath: adapterPath,
prepackRuntime: prepackRuntime,
prepackArguments: prepackArguments,
sourceFile: sourceFile
};
return result;
}
run(process, console);
//# sourceMappingURL=debugger-cli.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/mock-ui/debugger-cli.js"],"names":["run","process","console","args","readCLIArguments","session","serve","e","error","shutdown","adapterPath","prepackRuntime","prepackArguments","sourceFile","Array","from","argv","splice","length","arg","shift","startsWith","exit","slice","split","result"],"mappings":";;AAWA;;AAEA;;;;AAIA,SAASA,GAAT,CAAaC,OAAb,EAAsBC,OAAtB,EAA+B;AAC7B,MAAIC,OAAOC,iBAAiBH,OAAjB,EAA0BC,OAA1B,CAAX;AACA,MAAIG,UAAU,yBAAcJ,OAAd,EAAuBE,IAAvB,CAAd;AACA,MAAI;AACFE,YAAQC,KAAR;AACD,GAFD,CAEE,OAAOC,CAAP,EAAU;AACVL,YAAQM,KAAR,CAAcD,CAAd;AACAF,YAAQI,QAAR;AACD;AACF,C,CA1BD;;;;;;;;;AA4BA,SAASL,gBAAT,CAA0BH,OAA1B,EAAmCC,OAAnC,EAAkE;AAChE,MAAIQ,cAAc,EAAlB;AACA,MAAIC,iBAAiB,EAArB;AACA,MAAIC,mBAAmB,EAAvB;AACA,MAAIC,aAAa,EAAjB;;AAEA,MAAIV,OAAOW,MAAMC,IAAN,CAAWd,QAAQe,IAAnB,CAAX;AACAb,OAAKc,MAAL,CAAY,CAAZ,EAAe,CAAf;AACA;AACA,SAAOd,KAAKe,MAAL,GAAc,CAArB,EAAwB;AACtB,QAAIC,MAAMhB,KAAKiB,KAAL,EAAV;AACA,QAAI,CAACD,IAAIE,UAAJ,CAAe,IAAf,CAAL,EAA2B;AACzBnB,cAAQM,KAAR,CAAc,uBAAuBW,GAArC;AACAlB,cAAQqB,IAAR,CAAa,CAAb;AACD;AACDH,UAAMA,IAAII,KAAJ,CAAU,CAAV,CAAN;AACA,QAAIJ,QAAQ,aAAZ,EAA2B;AACzBT,oBAAcP,KAAKiB,KAAL,EAAd;AACD,KAFD,MAEO,IAAID,QAAQ,gBAAZ,EAA8B;AACnCR,uBAAiBR,KAAKiB,KAAL,EAAjB;AACD,KAFM,MAEA,IAAID,QAAQ,kBAAZ,EAAgC;AACrCP,yBAAmBT,KAAKiB,KAAL,GAAaI,KAAb,CAAmB,GAAnB,CAAnB;AACD,KAFM,MAEA,IAAIL,QAAQ,YAAZ,EAA0B;AAC/BN,mBAAaV,KAAKiB,KAAL,EAAb;AACD,KAFM,MAEA;AACLlB,cAAQM,KAAR,CAAc,uBAAuBW,GAArC;AACAlB,cAAQqB,IAAR,CAAa,CAAb;AACD;AACF;;AAED,MAAIZ,YAAYQ,MAAZ,KAAuB,CAA3B,EAA8B;AAC5BhB,YAAQM,KAAR,CAAc,wCAAd;AACAP,YAAQqB,IAAR,CAAa,CAAb;AACD;AACD,MAAIX,eAAeO,MAAf,KAA0B,CAA9B,EAAiC;AAC/BhB,YAAQM,KAAR,CAAc,2CAAd;AACAP,YAAQqB,IAAR,CAAa,CAAb;AACD;AACD,MAAIT,WAAWK,MAAX,KAAsB,CAA1B,EAA6B;AAC3BhB,YAAQM,KAAR,CAAc,oCAAd;AACD;AACD,MAAIiB,SAA+B;AACjCf,iBAAaA,WADoB;AAEjCC,oBAAgBA,cAFiB;AAGjCC,sBAAkBA,gBAHe;AAIjCC,gBAAYA;AAJqB,GAAnC;AAMA,SAAOY,MAAP;AACD;AACDzB,IAAIC,OAAJ,EAAaC,OAAb","file":"debugger-cli.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 { UISession } from \"./UISession.js\";\nimport type { DebuggerCLIArguments } from \"./UISession.js\";\n/* The entry point to start up the debugger CLI\n * Reads in command line arguments and starts up a UISession\n*/\n\nfunction run(process, console) {\n let args = readCLIArguments(process, console);\n let session = new UISession(process, args);\n try {\n session.serve();\n } catch (e) {\n console.error(e);\n session.shutdown();\n }\n}\n\nfunction readCLIArguments(process, console): DebuggerCLIArguments {\n let adapterPath = \"\";\n let prepackRuntime = \"\";\n let prepackArguments = [];\n let sourceFile = \"\";\n\n let args = Array.from(process.argv);\n args.splice(0, 2);\n //read in the arguments\n while (args.length > 0) {\n let arg = args.shift();\n if (!arg.startsWith(\"--\")) {\n console.error(\"Invalid argument: \" + arg);\n process.exit(1);\n }\n arg = arg.slice(2);\n if (arg === \"adapterPath\") {\n adapterPath = args.shift();\n } else if (arg === \"prepackRuntime\") {\n prepackRuntime = args.shift();\n } else if (arg === \"prepackArguments\") {\n prepackArguments = args.shift().split(\" \");\n } else if (arg === \"sourceFile\") {\n sourceFile = args.shift();\n } else {\n console.error(\"Unknown argument: \" + arg);\n process.exit(1);\n }\n }\n\n if (adapterPath.length === 0) {\n console.error(\"No path to the debug adapter provided!\");\n process.exit(1);\n }\n if (prepackRuntime.length === 0) {\n console.error(\"No Prepack runtime given to start Prepack\");\n process.exit(1);\n }\n if (sourceFile.length === 0) {\n console.error(\"No source code input file provided\");\n }\n let result: DebuggerCLIArguments = {\n adapterPath: adapterPath,\n prepackRuntime: prepackRuntime,\n prepackArguments: prepackArguments,\n sourceFile: sourceFile,\n };\n return result;\n}\nrun(process, console);\n"]}