prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
79 lines (62 loc) • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LoggingTracer = undefined;
var _environment = require("../environment.js");
var _realm = require("../realm.js");
var _index = require("../methods/index.js");
var _completions = require("../completions.js");
var _index2 = require("../values/index.js");
var _singletons = require("../singletons.js");
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function describeValue(realm, v) {
if (v instanceof _index2.NumberValue || v instanceof _index2.BooleanValue) return v.value.toString();
if (v instanceof _index2.UndefinedValue) return "undefined";
if (v instanceof _index2.NullValue) return "null";
if (v instanceof _index2.StringValue) return `"${v.value}"`; // TODO: proper escaping
if (v instanceof _index2.FunctionValue) return _singletons.To.ToStringPartial(realm, (0, _index.Get)(realm, v, "name")) || "(anonymous function)";
if (v instanceof _index2.ObjectValue) return "(some object)";
if (v instanceof _index2.AbstractValue) return "(some abstract value)";
(0, _invariant2.default)(false);
} /**
* 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.
*/
class LoggingTracer extends _realm.Tracer {
constructor(realm) {
super();
this.realm = realm;
this.nesting = [];
}
log(message) {
console.log(`[calls] ${this.nesting.map(_ => " ").join("")}${message}`);
}
beginEvaluateForEffects(state) {
this.log(`>evaluate for effects`);
this.nesting.push("(evaluate for effects)");
}
endEvaluateForEffects(state, effects) {
let name = this.nesting.pop();
(0, _invariant2.default)(name === "(evaluate for effects)");
this.log(`<evaluate for effects`);
}
beforeCall(F, thisArgument, argumentsList, newTarget) {
let realm = this.realm;
let name = describeValue(realm, F);
this.log(`>${name}(${argumentsList.map(v => describeValue(realm, v)).join(", ")})`);
this.nesting.push(name);
}
afterCall(F, thisArgument, argumentsList, newTarget, result) {
let name = this.nesting.pop();
this.log(`<${name}${result instanceof _completions.ThrowCompletion ? ": error" : ""}`);
}
}
exports.LoggingTracer = LoggingTracer;
//# sourceMappingURL=LoggingTracer.js.map