UNPKG

prepack

Version:

Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.

90 lines (69 loc) 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggingTracer = void 0; 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 = _interopRequireDefault(require("../invariant.js")); var _babelhelpers = require("../utils/babelhelpers.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * 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 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 JSON.stringify(v.value); 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, _invariant.default)(false); } 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, _invariant.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" : ""}`); } beginOptimizingFunction(optimizedFunctionId, functionValue) { this.log(`>Starting Optimized Function ${optimizedFunctionId} ${functionValue.intrinsicName ? functionValue.intrinsicName : "[unknown name]"} ${functionValue.expressionLocation ? (0, _babelhelpers.stringOfLocation)(functionValue.expressionLocation) : ""}`); } endOptimizingFunction(optimizedFunctionId) { this.log(`<Ending Optimized Function ${optimizedFunctionId}`); } } exports.LoggingTracer = LoggingTracer; //# sourceMappingURL=LoggingTracer.js.map