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,209 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AdapterChannel = 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 _FileIOWrapper = require("./FileIOWrapper.js");
var _MessageMarshaller = require("./MessageMarshaller.js");
var _queueFifo = require("queue-fifo");
var _queueFifo2 = _interopRequireDefault(_queueFifo);
var _events = require("events");
var _events2 = _interopRequireDefault(_events);
var _invariant = require("./../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _DebugMessage = require("./DebugMessage.js");
var _child_process = require("child_process");
var _child_process2 = _interopRequireDefault(_child_process);
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 debug adapter to communicate with Prepack
var AdapterChannel = exports.AdapterChannel = function () {
function AdapterChannel(inFilePath, outFilePath) {
_classCallCheck(this, AdapterChannel);
this._ioWrapper = new _FileIOWrapper.FileIOWrapper(true, inFilePath, outFilePath);
this._marshaller = new _MessageMarshaller.MessageMarshaller();
this._queue = new _queueFifo2.default();
this._pendingRequestCallbacks = new Map();
this._eventEmitter = new _events2.default();
}
_createClass(AdapterChannel, [{
key: "_handleFileReadError",
// Error handler for errors in files from the adapter channel
value: function _handleFileReadError(err) {
console.error(err);
process.exit(1);
}
}, {
key: "_processPrepackMessage",
value: function _processPrepackMessage(message) {
var dbgResponse = this._marshaller.unmarshallResponse(message);
if (dbgResponse.result.kind === "ready") {
this._eventEmitter.emit(_DebugMessage.DebugMessage.PREPACK_READY_RESPONSE, dbgResponse);
} else if (dbgResponse.result.kind === "breakpoint-add") {
this._eventEmitter.emit(_DebugMessage.DebugMessage.BREAKPOINT_ADD_ACKNOWLEDGE, dbgResponse.id, dbgResponse);
} else if (dbgResponse.result.kind === "breakpoint-stopped") {
this._eventEmitter.emit(_DebugMessage.DebugMessage.BREAKPOINT_STOPPED_RESPONSE, dbgResponse);
}
this._prepackWaiting = true;
this._processRequestCallback(dbgResponse);
this.trySendNextRequest();
}
// Check to see if the next request to Prepack can be sent and send it if so
}, {
key: "trySendNextRequest",
value: function trySendNextRequest() {
// check to see if Prepack is ready to accept another request
if (!this._prepackWaiting) return false;
// check that there is a message to send
if (this._queue.isEmpty()) return false;
var request = this._queue.dequeue();
this.listenOnFile(this._processPrepackMessage.bind(this));
this.writeOut(request);
this._prepackWaiting = false;
return true;
}
}, {
key: "_addRequestCallback",
value: function _addRequestCallback(requestID, callback) {
(0, _invariant2.default)(!(requestID in this._pendingRequestCallbacks), "Request ID already exists in pending requests");
this._pendingRequestCallbacks[requestID] = callback;
}
}, {
key: "_processRequestCallback",
value: function _processRequestCallback(response) {
(0, _invariant2.default)(response.id in this._pendingRequestCallbacks, "Request ID does not exist in pending requests: " + response.id);
var callback = this._pendingRequestCallbacks[response.id];
callback(response);
}
}, {
key: "registerChannelEvent",
value: function registerChannelEvent(event, listener) {
this._eventEmitter.addListener(event, listener);
}
}, {
key: "launch",
value: function launch(requestID, args, callback) {
var _this = this;
this.sendDebuggerStart(requestID);
this.listenOnFile(this._processPrepackMessage.bind(this));
var prepackCommand = [args.sourceFile].concat(args.prepackArguments);
// Note: here the input file for the adapter is the output file for Prepack, and vice versa.
prepackCommand = prepackCommand.concat(["--debugInFilePath", args.debugOutFilePath, "--debugOutFilePath", args.debugInFilePath]);
var runtime = "prepack";
if (args.prepackRuntime.length > 0) {
// user specified a Prepack path
runtime = "node";
prepackCommand = [args.prepackRuntime].concat(prepackCommand);
}
this._prepackProcess = _child_process2.default.spawn(runtime, prepackCommand);
process.on("exit", function () {
_this._prepackProcess.kill();
_this.clean();
process.exit();
});
process.on("SIGINT", function () {
_this._prepackProcess.kill();
process.exit();
});
this._prepackProcess.stdout.on("data", args.outputCallback);
this._prepackProcess.on("exit", args.exitCallback);
this._addRequestCallback(requestID, callback);
}
}, {
key: "run",
value: function run(requestID, callback) {
this._queue.enqueue(this._marshaller.marshallContinueRequest(requestID));
this.trySendNextRequest();
this._addRequestCallback(requestID, callback);
}
}, {
key: "setBreakpoints",
value: function setBreakpoints(requestID, breakpoints, callback) {
this._queue.enqueue(this._marshaller.marshallSetBreakpointsRequest(requestID, breakpoints));
this.trySendNextRequest();
this._addRequestCallback(requestID, callback);
}
}, {
key: "getStackFrames",
value: function getStackFrames(requestID, callback) {
this._queue.enqueue(this._marshaller.marshallStackFramesRequest(requestID));
this.trySendNextRequest();
this._addRequestCallback(requestID, callback);
}
}, {
key: "getScopes",
value: function getScopes(requestID, frameId, callback) {
this._queue.enqueue(this._marshaller.marshallScopesRequest(requestID, frameId));
this.trySendNextRequest();
this._addRequestCallback(requestID, callback);
}
}, {
key: "getVariables",
value: function getVariables(requestID, variablesReference, callback) {
this._queue.enqueue(this._marshaller.marshallVariablesRequest(requestID, variablesReference));
this.trySendNextRequest();
this._addRequestCallback(requestID, callback);
}
}, {
key: "writeOut",
value: function writeOut(contents) {
this._ioWrapper.writeOutSync(contents);
}
}, {
key: "sendDebuggerStart",
value: function sendDebuggerStart(requestID) {
this.writeOut(this._marshaller.marshallDebuggerStart(requestID));
}
}, {
key: "listenOnFile",
value: function listenOnFile(messageProcessor) {
this._ioWrapper.readIn(this._handleFileReadError.bind(this), messageProcessor);
}
}, {
key: "clean",
value: function clean() {
this._ioWrapper.clearInFile();
this._ioWrapper.clearOutFile();
}
}]);
return AdapterChannel;
}();
//# sourceMappingURL=AdapterChannel.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("./../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _FileIOWrapper = require("./FileIOWrapper.js");
var _DebugMessage = require("./DebugMessage.js");
var _MessageMarshaller = require("./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: "sendBreakpointStopped",
value: function sendBreakpointStopped(filePath, line, column) {
var breakpointInfo = {
kind: "breakpoint",
filePath: filePath,
line: line,
column: column
};
this.writeOut(this._marshaller.marshallBreakpointStopped(breakpointInfo));
}
}, {
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: "sendPrepackFinish",
value: function sendPrepackFinish() {
this.writeOut(this._marshaller.marshallPrepackFinish());
}
}]);
return DebugChannel;
}();
//# sourceMappingURL=DebugChannel.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,42 @@
"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.
*/
//A collection of messages used between Prepack and the debug adapter
var DebugMessage = exports.DebugMessage = function DebugMessage() {
_classCallCheck(this, DebugMessage);
};
DebugMessage.DEBUGGER_ATTACHED = "DebuggerAttached";
DebugMessage.PREPACK_RUN_COMMAND = "PrepackRun";
DebugMessage.BREAKPOINT_ADD_COMMAND = "Breakpoint-add-command";
DebugMessage.BREAKPOINT_REMOVE_COMMAND = "Breakpoint-remove-command";
DebugMessage.BREAKPOINT_ENABLE_COMMAND = "Breakpoint-enable-command";
DebugMessage.BREAKPOINT_DISABLE_COMMAND = "Breakpoint-disable-command";
DebugMessage.STACKFRAMES_COMMAND = "Stackframes-command";
DebugMessage.SCOPES_COMMAND = "Scopes-command";
DebugMessage.VARIABLES_COMMAND = "Variables-command";
DebugMessage.PREPACK_READY_RESPONSE = "PrepackReady";
DebugMessage.PREPACK_FINISH_RESPONSE = "PrepackFinish";
DebugMessage.BREAKPOINT_STOPPED_RESPONSE = "Breakpoint-stopped-response";
DebugMessage.STACKFRAMES_RESPONSE = "Stackframes-response";
DebugMessage.SCOPES_RESPONSE = "Scopes-response";
DebugMessage.VARIABLES_RESPONSE = "Variables-response";
DebugMessage.BREAKPOINT_ADD_ACKNOWLEDGE = "Breakpoint-add-acknowledge";
DebugMessage.BREAKPOINT_REMOVE_ACKNOWLEDGE = "Breakpoint-remove-acknowledge";
DebugMessage.BREAKPOINT_ENABLE_ACKNOWLEDGE = "Breakpoint-enable-acknowledge";
DebugMessage.BREAKPOINT_DISABLE_ACKNOWLEDGE = "Breakpoint-disable-acknowledge";
//# sourceMappingURL=DebugMessage.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/channel/DebugMessage.js"],"names":["DebugMessage","DEBUGGER_ATTACHED","PREPACK_RUN_COMMAND","BREAKPOINT_ADD_COMMAND","BREAKPOINT_REMOVE_COMMAND","BREAKPOINT_ENABLE_COMMAND","BREAKPOINT_DISABLE_COMMAND","STACKFRAMES_COMMAND","SCOPES_COMMAND","VARIABLES_COMMAND","PREPACK_READY_RESPONSE","PREPACK_FINISH_RESPONSE","BREAKPOINT_STOPPED_RESPONSE","STACKFRAMES_RESPONSE","SCOPES_RESPONSE","VARIABLES_RESPONSE","BREAKPOINT_ADD_ACKNOWLEDGE","BREAKPOINT_REMOVE_ACKNOWLEDGE","BREAKPOINT_ENABLE_ACKNOWLEDGE","BREAKPOINT_DISABLE_ACKNOWLEDGE"],"mappings":";;;;;;;;AAAA;;;;;;;;;AAWA;IACaA,Y,WAAAA,Y;;;;AAAAA,Y,CAGJC,iB,GAA4B,kB;AAHxBD,Y,CAKJE,mB,GAA8B,Y;AAL1BF,Y,CAOJG,sB,GAAiC,wB;AAP7BH,Y,CASJI,yB,GAAoC,2B;AAThCJ,Y,CAWJK,yB,GAAoC,2B;AAXhCL,Y,CAaJM,0B,GAAqC,4B;AAbjCN,Y,CAeJO,mB,GAA8B,qB;AAf1BP,Y,CAiBJQ,c,GAAyB,gB;AAjBrBR,Y,CAmBJS,iB,GAA4B,mB;AAnBxBT,Y,CAuBJU,sB,GAAiC,c;AAvB7BV,Y,CAyBJW,uB,GAAkC,e;AAzB9BX,Y,CA2BJY,2B,GAAsC,6B;AA3BlCZ,Y,CA6BJa,oB,GAA+B,sB;AA7B3Bb,Y,CA+BJc,e,GAA0B,iB;AA/BtBd,Y,CAiCJe,kB,GAA6B,oB;AAjCzBf,Y,CAqCJgB,0B,GAAqC,4B;AArCjChB,Y,CAuCJiB,6B,GAAwC,+B;AAvCpCjB,Y,CAyCJkB,6B,GAAwC,+B;AAzCpClB,Y,CA2CJmB,8B,GAAyC,gC","file":"DebugMessage.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 collection of messages used between Prepack and the debug adapter\nexport class DebugMessage {\n /* Messages from adapter to Prepack */\n // Tell Prepack a debugger is present\n static DEBUGGER_ATTACHED: string = \"DebuggerAttached\";\n // Command Prepack to keep running\n static PREPACK_RUN_COMMAND: string = \"PrepackRun\";\n // Command to set a breakpoint\n static BREAKPOINT_ADD_COMMAND: string = \"Breakpoint-add-command\";\n // Command to remove a breakpoint\n static BREAKPOINT_REMOVE_COMMAND: string = \"Breakpoint-remove-command\";\n // Command to enable a breakpoint\n static BREAKPOINT_ENABLE_COMMAND: string = \"Breakpoint-enable-command\";\n // Command to disable a breakpoint\n static BREAKPOINT_DISABLE_COMMAND: string = \"Breakpoint-disable-command\";\n // Command to fetch stack frames\n static STACKFRAMES_COMMAND: string = \"Stackframes-command\";\n // Command to fetch scopes\n static SCOPES_COMMAND: string = \"Scopes-command\";\n // Command to fetch variables\n static VARIABLES_COMMAND: string = \"Variables-command\";\n\n /* Messages from Prepack to adapter with requested information */\n // Respond to the adapter that Prepack is ready\n static PREPACK_READY_RESPONSE: string = \"PrepackReady\";\n // Respond to the adapter that Prepack is finished\n static PREPACK_FINISH_RESPONSE: string = \"PrepackFinish\";\n // Respond to the adapter that Prepack has stopped on a breakpoint\n static BREAKPOINT_STOPPED_RESPONSE: string = \"Breakpoint-stopped-response\";\n // Respond to the adapter with the request stackframes\n static STACKFRAMES_RESPONSE: string = \"Stackframes-response\";\n // Respond to the adapter with the requested scopes\n static SCOPES_RESPONSE: string = \"Scopes-response\";\n // Respond to the adapter with the requested variables\n static VARIABLES_RESPONSE: string = \"Variables-response\";\n\n /* Messages from Prepack to adapter to acknowledge having received the request */\n // Acknowledgement for setting a breakpoint\n static BREAKPOINT_ADD_ACKNOWLEDGE: string = \"Breakpoint-add-acknowledge\";\n // Acknowledgement for removing a breakpoint\n static BREAKPOINT_REMOVE_ACKNOWLEDGE: string = \"Breakpoint-remove-acknowledge\";\n // Acknowledgement for enabling a breakpoint\n static BREAKPOINT_ENABLE_ACKNOWLEDGE: string = \"Breakpoint-enable-acknowledge\";\n // Acknoledgement for disabling a breakpoint\n static BREAKPOINT_DISABLE_ACKNOWLEDGE: string = \"Breakpoint-disable-acknowledge\";\n}\n"]}

View File

@@ -0,0 +1,121 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FileIOWrapper = 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 _fs = require("fs");
var _fs2 = _interopRequireDefault(_fs);
var _path = require("path");
var _path2 = _interopRequireDefault(_path);
var _MessagePackager = require("./MessagePackager.js");
var _invariant = require("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
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 FileIOWrapper = exports.FileIOWrapper = function () {
function FileIOWrapper(isAdapter, inFilePath, outFilePath) {
_classCallCheck(this, FileIOWrapper);
// the paths are expected to be relative to Prepack top level directory
this._inFilePath = _path2.default.join(__dirname, "../../../", inFilePath);
this._outFilePath = _path2.default.join(__dirname, "../../../", outFilePath);
this._packager = new _MessagePackager.MessagePackager(isAdapter);
this._isAdapter = isAdapter;
}
_createClass(FileIOWrapper, [{
key: "readIn",
// Read in a message from the input asynchronously
value: function readIn(errorHandler, messageProcessor) {
var _this = this;
_fs2.default.readFile(this._inFilePath, { encoding: "utf8" }, function (err, contents) {
if (err) {
errorHandler(err);
return;
}
var message = _this._packager.unpackage(contents);
if (message === null) {
_this.readIn(errorHandler, messageProcessor);
return;
}
//clear the file
_fs2.default.writeFileSync(_this._inFilePath, "");
//process the message
messageProcessor(message);
});
}
// Read in a message from the input synchronously
}, {
key: "readInSync",
value: function readInSync() {
var message = null;
while (true) {
var contents = _fs2.default.readFileSync(this._inFilePath, "utf8");
message = this._packager.unpackage(contents);
if (message === null) continue;
break;
}
// loop should not break when message is still null
(0, _invariant2.default)(message !== null);
//clear the file
_fs2.default.writeFileSync(this._inFilePath, "");
return message;
}
// Read in a message from the input synchronously only once
}, {
key: "readInSyncOnce",
value: function readInSyncOnce() {
var contents = _fs2.default.readFileSync(this._inFilePath, "utf8");
var message = this._packager.unpackage(contents);
return message;
}
// Write out a message to the output synchronously
}, {
key: "writeOutSync",
value: function writeOutSync(contents) {
_fs2.default.writeFileSync(this._outFilePath, this._packager.package(contents));
}
}, {
key: "clearInFile",
value: function clearInFile() {
_fs2.default.writeFileSync(this._inFilePath, "");
}
}, {
key: "clearOutFile",
value: function clearOutFile() {
_fs2.default.writeFileSync(this._outFilePath, "");
}
}]);
return FileIOWrapper;
}();
//# sourceMappingURL=FileIOWrapper.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/channel/FileIOWrapper.js"],"names":["FileIOWrapper","isAdapter","inFilePath","outFilePath","_inFilePath","join","__dirname","_outFilePath","_packager","_isAdapter","errorHandler","messageProcessor","readFile","encoding","err","contents","message","unpackage","readIn","writeFileSync","readFileSync","package"],"mappings":";;;;;;;qjBAAA;;;;;;;;;AAWA;;;;AACA;;;;AACA;;AACA;;;;;;;;IAEaA,a,WAAAA,a;AACX,yBAAYC,SAAZ,EAAgCC,UAAhC,EAAoDC,WAApD,EAAyE;AAAA;;AACvE;AACA,SAAKC,WAAL,GAAmB,eAAKC,IAAL,CAAUC,SAAV,EAAqB,WAArB,EAAkCJ,UAAlC,CAAnB;AACA,SAAKK,YAAL,GAAoB,eAAKF,IAAL,CAAUC,SAAV,EAAqB,WAArB,EAAkCH,WAAlC,CAApB;AACA,SAAKK,SAAL,GAAiB,qCAAoBP,SAApB,CAAjB;AACA,SAAKQ,UAAL,GAAkBR,SAAlB;AACD;;;;;;AAMD;2BACOS,Y,EAA0CC,gB,EAA6C;AAAA;;AAC5F,mBAAGC,QAAH,CAAY,KAAKR,WAAjB,EAA8B,EAAES,UAAU,MAAZ,EAA9B,EAAoD,UAACC,GAAD,EAAmBC,QAAnB,EAAwC;AAC1F,YAAID,GAAJ,EAAS;AACPJ,uBAAaI,GAAb;AACA;AACD;AACD,YAAIE,UAAU,MAAKR,SAAL,CAAeS,SAAf,CAAyBF,QAAzB,CAAd;AACA,YAAIC,YAAY,IAAhB,EAAsB;AACpB,gBAAKE,MAAL,CAAYR,YAAZ,EAA0BC,gBAA1B;AACA;AACD;AACD;AACA,qBAAGQ,aAAH,CAAiB,MAAKf,WAAtB,EAAmC,EAAnC;AACA;AACAO,yBAAiBK,OAAjB;AACD,OAdD;AAeD;;AAED;;;;iCACqB;AACnB,UAAIA,UAAyB,IAA7B;AACA,aAAO,IAAP,EAAa;AACX,YAAID,WAAW,aAAGK,YAAH,CAAgB,KAAKhB,WAArB,EAAkC,MAAlC,CAAf;AACAY,kBAAU,KAAKR,SAAL,CAAeS,SAAf,CAAyBF,QAAzB,CAAV;AACA,YAAIC,YAAY,IAAhB,EAAsB;AACtB;AACD;AACD;AACA,+BAAUA,YAAY,IAAtB;AACA;AACA,mBAAGG,aAAH,CAAiB,KAAKf,WAAtB,EAAmC,EAAnC;AACA,aAAOY,OAAP;AACD;;AAED;;;;qCACgC;AAC9B,UAAID,WAAW,aAAGK,YAAH,CAAgB,KAAKhB,WAArB,EAAkC,MAAlC,CAAf;AACA,UAAIY,UAAU,KAAKR,SAAL,CAAeS,SAAf,CAAyBF,QAAzB,CAAd;AACA,aAAOC,OAAP;AACD;;AAED;;;;iCACaD,Q,EAAkB;AAC7B,mBAAGI,aAAH,CAAiB,KAAKZ,YAAtB,EAAoC,KAAKC,SAAL,CAAea,OAAf,CAAuBN,QAAvB,CAApC;AACD;;;kCAEa;AACZ,mBAAGI,aAAH,CAAiB,KAAKf,WAAtB,EAAmC,EAAnC;AACD;;;mCAEc;AACb,mBAAGe,aAAH,CAAiB,KAAKZ,YAAtB,EAAoC,EAApC;AACD","file":"FileIOWrapper.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 fs from \"fs\";\nimport path from \"path\";\nimport { MessagePackager } from \"./MessagePackager.js\";\nimport invariant from \"../../invariant.js\";\n\nexport class FileIOWrapper {\n constructor(isAdapter: boolean, inFilePath: string, outFilePath: string) {\n // the paths are expected to be relative to Prepack top level directory\n this._inFilePath = path.join(__dirname, \"../../../\", inFilePath);\n this._outFilePath = path.join(__dirname, \"../../../\", outFilePath);\n this._packager = new MessagePackager(isAdapter);\n this._isAdapter = isAdapter;\n }\n _inFilePath: string;\n _outFilePath: string;\n _packager: MessagePackager;\n _isAdapter: boolean;\n\n // Read in a message from the input asynchronously\n readIn(errorHandler: (err: ?ErrnoError) => void, messageProcessor: (message: string) => void) {\n fs.readFile(this._inFilePath, { encoding: \"utf8\" }, (err: ?ErrnoError, contents: string) => {\n if (err) {\n errorHandler(err);\n return;\n }\n let message = this._packager.unpackage(contents);\n if (message === null) {\n this.readIn(errorHandler, messageProcessor);\n return;\n }\n //clear the file\n fs.writeFileSync(this._inFilePath, \"\");\n //process the message\n messageProcessor(message);\n });\n }\n\n // Read in a message from the input synchronously\n readInSync(): string {\n let message: null | string = null;\n while (true) {\n let contents = fs.readFileSync(this._inFilePath, \"utf8\");\n message = this._packager.unpackage(contents);\n if (message === null) continue;\n break;\n }\n // loop should not break when message is still null\n invariant(message !== null);\n //clear the file\n fs.writeFileSync(this._inFilePath, \"\");\n return message;\n }\n\n // Read in a message from the input synchronously only once\n readInSyncOnce(): null | string {\n let contents = fs.readFileSync(this._inFilePath, \"utf8\");\n let message = this._packager.unpackage(contents);\n return message;\n }\n\n // Write out a message to the output synchronously\n writeOutSync(contents: string) {\n fs.writeFileSync(this._outFilePath, this._packager.package(contents));\n }\n\n clearInFile() {\n fs.writeFileSync(this._inFilePath, \"\");\n }\n\n clearOutFile() {\n fs.writeFileSync(this._outFilePath, \"\");\n }\n}\n"]}

View File

@@ -0,0 +1,469 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MessageMarshaller = 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 _DebugMessage = require("./DebugMessage.js");
var _invariant = require("./../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
var _DebuggerError = require("./../DebuggerError.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 MessageMarshaller = exports.MessageMarshaller = function () {
function MessageMarshaller() {
_classCallCheck(this, MessageMarshaller);
this._lastRunRequestID = 0;
}
_createClass(MessageMarshaller, [{
key: "marshallBreakpointAcknowledge",
value: function marshallBreakpointAcknowledge(requestID, messageType, breakpoints) {
return requestID + " " + messageType + " " + JSON.stringify(breakpoints);
}
}, {
key: "marshallBreakpointStopped",
value: function marshallBreakpointStopped(args) {
return this._lastRunRequestID + " " + _DebugMessage.DebugMessage.BREAKPOINT_STOPPED_RESPONSE + " " + args.filePath + " " + args.line + " " + args.column;
}
}, {
key: "marshallPrepackFinish",
value: function marshallPrepackFinish() {
return this._lastRunRequestID + " " + _DebugMessage.DebugMessage.PREPACK_FINISH_RESPONSE;
}
}, {
key: "marshallDebuggerStart",
value: function marshallDebuggerStart(requestID) {
return requestID + " " + _DebugMessage.DebugMessage.DEBUGGER_ATTACHED;
}
}, {
key: "marshallContinueRequest",
value: function marshallContinueRequest(requestID) {
return requestID + " " + _DebugMessage.DebugMessage.PREPACK_RUN_COMMAND;
}
}, {
key: "marshallSetBreakpointsRequest",
value: function marshallSetBreakpointsRequest(requestID, breakpoints) {
return requestID + " " + _DebugMessage.DebugMessage.BREAKPOINT_ADD_COMMAND + " " + JSON.stringify(breakpoints);
}
}, {
key: "marshallStackFramesRequest",
value: function marshallStackFramesRequest(requestID) {
return requestID + " " + _DebugMessage.DebugMessage.STACKFRAMES_COMMAND;
}
}, {
key: "marshallStackFramesResponse",
value: function marshallStackFramesResponse(requestID, stackframes) {
return requestID + " " + _DebugMessage.DebugMessage.STACKFRAMES_RESPONSE + " " + JSON.stringify(stackframes);
}
}, {
key: "marshallScopesRequest",
value: function marshallScopesRequest(requestID, frameId) {
return requestID + " " + _DebugMessage.DebugMessage.SCOPES_COMMAND + " " + frameId;
}
}, {
key: "marshallScopesResponse",
value: function marshallScopesResponse(requestID, scopes) {
return requestID + " " + _DebugMessage.DebugMessage.SCOPES_RESPONSE + " " + JSON.stringify(scopes);
}
}, {
key: "marshallVariablesRequest",
value: function marshallVariablesRequest(requestID, variablesReference) {
return requestID + " " + _DebugMessage.DebugMessage.VARIABLES_COMMAND + " " + variablesReference;
}
}, {
key: "marshallVariablesResponse",
value: function marshallVariablesResponse(requestID, variables) {
return requestID + " " + _DebugMessage.DebugMessage.VARIABLES_RESPONSE + " " + JSON.stringify(variables);
}
}, {
key: "unmarshallRequest",
value: function unmarshallRequest(message) {
var parts = message.split(" ");
// each request must have a length and a command
(0, _invariant2.default)(parts.length >= 2, "Request is not well formed");
// unique ID for each request
var requestID = parseInt(parts[0], 10);
(0, _invariant2.default)(!isNaN(requestID), "Request ID must be a number");
var command = parts[1];
var args = void 0;
switch (command) {
case _DebugMessage.DebugMessage.PREPACK_RUN_COMMAND:
this._lastRunRequestID = requestID;
var runArgs = {
kind: "run"
};
args = runArgs;
break;
case _DebugMessage.DebugMessage.BREAKPOINT_ADD_COMMAND:
args = this._unmarshallBreakpointsArguments(requestID, parts.slice(2).join(" "));
break;
case _DebugMessage.DebugMessage.STACKFRAMES_COMMAND:
var stackFrameArgs = {
kind: "stackframe"
};
args = stackFrameArgs;
break;
case _DebugMessage.DebugMessage.SCOPES_COMMAND:
args = this._unmarshallScopesArguments(requestID, parts[2]);
break;
case _DebugMessage.DebugMessage.VARIABLES_COMMAND:
args = this._unmarshallVariablesArguments(requestID, parts[2]);
break;
default:
throw new _DebuggerError.DebuggerError("Invalid command", "Invalid command from adapter: " + command);
}
(0, _invariant2.default)(args !== undefined);
var result = {
id: requestID,
command: command,
arguments: args
};
return result;
}
}, {
key: "unmarshallResponse",
value: function unmarshallResponse(message) {
var parts = message.split(" ");
var requestID = parseInt(parts[0], 10);
(0, _invariant2.default)(!isNaN(requestID));
var messageType = parts[1];
var dbgResponse = void 0;
if (messageType === _DebugMessage.DebugMessage.PREPACK_READY_RESPONSE) {
dbgResponse = this._unmarshallReadyResponse(requestID);
} else if (messageType === _DebugMessage.DebugMessage.BREAKPOINT_ADD_ACKNOWLEDGE) {
dbgResponse = this._unmarshallBreakpointsAddResponse(requestID, parts.slice(2).join(" "));
} else if (messageType === _DebugMessage.DebugMessage.BREAKPOINT_STOPPED_RESPONSE) {
dbgResponse = this._unmarshallBreakpointStoppedResponse(requestID, parts.slice(2));
} else if (messageType === _DebugMessage.DebugMessage.STACKFRAMES_RESPONSE) {
dbgResponse = this._unmarshallStackframesResponse(requestID, parts.slice(2).join(" "));
} else if (messageType === _DebugMessage.DebugMessage.SCOPES_RESPONSE) {
dbgResponse = this._unmarshallScopesResponse(requestID, parts.slice(2).join(" "));
} else if (messageType === _DebugMessage.DebugMessage.VARIABLES_RESPONSE) {
dbgResponse = this._unmarshallVariablesResponse(requestID, parts.slice(2).join(" "));
} else if (messageType === _DebugMessage.DebugMessage.PREPACK_FINISH_RESPONSE) {
dbgResponse = this._unmarshallFinishResponse(requestID);
} else {
(0, _invariant2.default)(false, "Unexpected response type");
}
return dbgResponse;
}
}, {
key: "_unmarshallBreakpointsArguments",
value: function _unmarshallBreakpointsArguments(requestID, breakpointsString) {
try {
var breakpoints = JSON.parse(breakpointsString);
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 breakpoint = _step.value;
(0, _invariant2.default)(breakpoint.hasOwnProperty("filePath"), "breakpoint missing filePath property");
(0, _invariant2.default)(breakpoint.hasOwnProperty("line"), "breakpoint missing line property");
(0, _invariant2.default)(breakpoint.hasOwnProperty("column"), "breakpoint missing column property");
(0, _invariant2.default)(!isNaN(breakpoint.line));
(0, _invariant2.default)(!isNaN(breakpoint.column));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var result = {
kind: "breakpoint",
breakpoints: breakpoints
};
return result;
} catch (e) {
throw new _DebuggerError.DebuggerError("Invalid command", e.message);
}
}
}, {
key: "_unmarshallScopesArguments",
value: function _unmarshallScopesArguments(requestID, frameIdString) {
var frameId = parseInt(frameIdString, 10);
(0, _invariant2.default)(!isNaN(frameId));
var result = {
kind: "scopes",
frameId: frameId
};
return result;
}
}, {
key: "_unmarshallVariablesArguments",
value: function _unmarshallVariablesArguments(requestID, varRefString) {
var varRef = parseInt(varRefString, 10);
(0, _invariant2.default)(!isNaN(varRef));
var result = {
kind: "variables",
variablesReference: varRef
};
return result;
}
}, {
key: "_unmarshallStackframesResponse",
value: function _unmarshallStackframesResponse(requestID, responseBody) {
try {
var frames = JSON.parse(responseBody);
(0, _invariant2.default)(Array.isArray(frames), "Stack frames is not an array");
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;
(0, _invariant2.default)(frame.hasOwnProperty("id"), "Stack frame is missing id");
(0, _invariant2.default)(frame.hasOwnProperty("fileName"), "Stack frame is missing filename");
(0, _invariant2.default)(frame.hasOwnProperty("line"), "Stack frame is missing line number");
(0, _invariant2.default)(frame.hasOwnProperty("column"), "Stack frame is missing column number");
(0, _invariant2.default)(frame.hasOwnProperty("functionName"), "Stack frame is missing function name");
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
var result = {
kind: "stackframe",
stackframes: frames
};
var dbgResponse = {
id: requestID,
result: result
};
return dbgResponse;
} catch (e) {
throw new _DebuggerError.DebuggerError("Invalid response", e.message);
}
}
}, {
key: "_unmarshallScopesResponse",
value: function _unmarshallScopesResponse(requestID, responseBody) {
try {
var scopes = JSON.parse(responseBody);
(0, _invariant2.default)(Array.isArray(scopes), "Scopes is not an array");
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = scopes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var scope = _step3.value;
(0, _invariant2.default)(scope.hasOwnProperty("name"), "Scope is missing name");
(0, _invariant2.default)(scope.hasOwnProperty("variablesReference"), "Scope is missing variablesReference");
(0, _invariant2.default)(scope.hasOwnProperty("expensive"), "Scope is missing expensive");
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
var result = {
kind: "scopes",
scopes: scopes
};
var dbgResponse = {
id: requestID,
result: result
};
return dbgResponse;
} catch (e) {
throw new _DebuggerError.DebuggerError("Invalid response", e.message);
}
}
}, {
key: "_unmarshallVariablesResponse",
value: function _unmarshallVariablesResponse(requestID, responseBody) {
try {
var variables = JSON.parse(responseBody);
(0, _invariant2.default)(Array.isArray(variables), "Variables is not an array");
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = variables[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var variable = _step4.value;
(0, _invariant2.default)(variable.hasOwnProperty("name"));
(0, _invariant2.default)(variable.hasOwnProperty("value"));
(0, _invariant2.default)(variable.hasOwnProperty("variablesReference"));
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
var result = {
kind: "variables",
variables: variables
};
var dbgResponse = {
id: requestID,
result: result
};
return dbgResponse;
} catch (e) {
throw new _DebuggerError.DebuggerError("Invalid response", e.message);
}
}
}, {
key: "_unmarshallBreakpointsAddResponse",
value: function _unmarshallBreakpointsAddResponse(requestID, breakpointsString) {
try {
var breakpoints = JSON.parse(breakpointsString);
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
try {
for (var _iterator5 = breakpoints[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var breakpoint = _step5.value;
(0, _invariant2.default)(breakpoint.hasOwnProperty("filePath"), "breakpoint missing filePath property");
(0, _invariant2.default)(breakpoint.hasOwnProperty("line"), "breakpoint missing line property");
(0, _invariant2.default)(breakpoint.hasOwnProperty("column"), "breakpoint missing column property");
(0, _invariant2.default)(!isNaN(breakpoint.line));
(0, _invariant2.default)(!isNaN(breakpoint.column));
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
}
}
}
var result = {
kind: "breakpoint-add",
breakpoints: breakpoints
};
var dbgResponse = {
id: requestID,
result: result
};
return dbgResponse;
} catch (e) {
throw new _DebuggerError.DebuggerError("Invalid response", e.message);
}
}
}, {
key: "_unmarshallBreakpointStoppedResponse",
value: function _unmarshallBreakpointStoppedResponse(requestID, parts) {
(0, _invariant2.default)(parts.length === 3, "Incorrect number of arguments in breakpoint stopped response");
var filePath = parts[0];
var line = parseInt(parts[1], 10);
(0, _invariant2.default)(!isNaN(line), "Invalid line number");
var column = parseInt(parts[2], 10);
(0, _invariant2.default)(!isNaN(column), "Invalid column number");
var result = {
kind: "breakpoint-stopped",
filePath: filePath,
line: line,
column: column
};
var dbgResponse = {
id: requestID,
result: result
};
return dbgResponse;
}
}, {
key: "_unmarshallReadyResponse",
value: function _unmarshallReadyResponse(requestID) {
var result = {
kind: "ready"
};
var dbgResponse = {
id: requestID,
result: result
};
return dbgResponse;
}
}, {
key: "_unmarshallFinishResponse",
value: function _unmarshallFinishResponse(requestID) {
var result = {
kind: "finish"
};
var dbgResponse = {
id: requestID,
result: result
};
return dbgResponse;
}
}]);
return MessageMarshaller;
}();
//# sourceMappingURL=MessageMarshaller.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,78 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MessagePackager = 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("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
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 LENGTH_SEPARATOR = "--";
// Package a message sent or unpackage a message received
var MessagePackager = exports.MessagePackager = function () {
function MessagePackager(isAdapter) {
_classCallCheck(this, MessagePackager);
this._isAdapter = isAdapter;
}
_createClass(MessagePackager, [{
key: "package",
// package a message to be sent
value: function _package(contents) {
// format: <length>--<contents>
return contents.length + LENGTH_SEPARATOR + contents;
}
// unpackage a message received, verify it, and return it
// returns null if no message or the message is only partially read
// errors if the message violates the format
}, {
key: "unpackage",
value: function unpackage(contents) {
// format: <length>--<contents>
var separatorIndex = contents.indexOf(LENGTH_SEPARATOR);
// if the separator is not written in yet --> partial read
if (separatorIndex === -1) {
return null;
}
var messageLength = parseInt(contents.slice(0, separatorIndex), 10);
// if the part before the separator is not a valid length, it is a
// violation of protocol
(0, _invariant2.default)(!isNaN(messageLength));
var startIndex = separatorIndex + LENGTH_SEPARATOR.length;
var endIndex = startIndex + messageLength;
// there should only be one message in the contents at a time
(0, _invariant2.default)(contents.length <= startIndex + messageLength);
// if we didn't read the whole message yet --> partial read
if (contents.length < endIndex) {
return null;
}
var message = contents.slice(startIndex, endIndex);
return message;
}
}]);
return MessagePackager;
}();
//# sourceMappingURL=MessagePackager.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/debugger/channel/MessagePackager.js"],"names":["LENGTH_SEPARATOR","MessagePackager","isAdapter","_isAdapter","contents","length","separatorIndex","indexOf","messageLength","parseInt","slice","isNaN","startIndex","endIndex","message"],"mappings":";;;;;;;qjBAAA;;;;;;;;;AAWA;;;;;;;;AAEA,IAAMA,mBAAmB,IAAzB;;AAEA;;IACaC,e,WAAAA,e;AACX,2BAAYC,SAAZ,EAAgC;AAAA;;AAC9B,SAAKC,UAAL,GAAkBD,SAAlB;AACD;;;;;;AAGD;6BACQE,Q,EAA0B;AAChC;AACA,aAAOA,SAASC,MAAT,GAAkBL,gBAAlB,GAAqCI,QAA5C;AACD;;AAED;AACA;AACA;;;;8BACUA,Q,EAAiC;AACzC;AACA,UAAIE,iBAAiBF,SAASG,OAAT,CAAiBP,gBAAjB,CAArB;AACA;AACA,UAAIM,mBAAmB,CAAC,CAAxB,EAA2B;AACzB,eAAO,IAAP;AACD;AACD,UAAIE,gBAAgBC,SAASL,SAASM,KAAT,CAAe,CAAf,EAAkBJ,cAAlB,CAAT,EAA4C,EAA5C,CAApB;AACA;AACA;AACA,+BAAU,CAACK,MAAMH,aAAN,CAAX;AACA,UAAII,aAAaN,iBAAiBN,iBAAiBK,MAAnD;AACA,UAAIQ,WAAWD,aAAaJ,aAA5B;AACA;AACA,+BAAUJ,SAASC,MAAT,IAAmBO,aAAaJ,aAA1C;AACA;AACA,UAAIJ,SAASC,MAAT,GAAkBQ,QAAtB,EAAgC;AAC9B,eAAO,IAAP;AACD;AACD,UAAIC,UAAUV,SAASM,KAAT,CAAeE,UAAf,EAA2BC,QAA3B,CAAd;AACA,aAAOC,OAAP;AACD","file":"MessagePackager.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 \"../../invariant.js\";\n\nconst LENGTH_SEPARATOR = \"--\";\n\n// Package a message sent or unpackage a message received\nexport class MessagePackager {\n constructor(isAdapter: boolean) {\n this._isAdapter = isAdapter;\n }\n _isAdapter: boolean;\n\n // package a message to be sent\n package(contents: string): string {\n // format: <length>--<contents>\n return contents.length + LENGTH_SEPARATOR + contents;\n }\n\n // unpackage a message received, verify it, and return it\n // returns null if no message or the message is only partially read\n // errors if the message violates the format\n unpackage(contents: string): null | string {\n // format: <length>--<contents>\n let separatorIndex = contents.indexOf(LENGTH_SEPARATOR);\n // if the separator is not written in yet --> partial read\n if (separatorIndex === -1) {\n return null;\n }\n let messageLength = parseInt(contents.slice(0, separatorIndex), 10);\n // if the part before the separator is not a valid length, it is a\n // violation of protocol\n invariant(!isNaN(messageLength));\n let startIndex = separatorIndex + LENGTH_SEPARATOR.length;\n let endIndex = startIndex + messageLength;\n // there should only be one message in the contents at a time\n invariant(contents.length <= startIndex + messageLength);\n // if we didn't read the whole message yet --> partial read\n if (contents.length < endIndex) {\n return null;\n }\n let message = contents.slice(startIndex, endIndex);\n return message;\n }\n}\n"]}