first commit
This commit is contained in:
127
build/node_modules/prepack/lib/serializer/ResidualHeapRefCounter.js
generated
vendored
Normal file
127
build/node_modules/prepack/lib/serializer/ResidualHeapRefCounter.js
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ResidualHeapRefCounter = 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; }; }();
|
||||
|
||||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _ResidualHeapInspector = require("./ResidualHeapInspector.js");
|
||||
|
||||
var _ResidualHeapVisitor2 = require("./ResidualHeapVisitor.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"); } }
|
||||
|
||||
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; } /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Record residual heap object's incoming and outgoing reference counts.
|
||||
*/
|
||||
var ResidualHeapRefCounter = exports.ResidualHeapRefCounter = function (_ResidualHeapVisitor) {
|
||||
_inherits(ResidualHeapRefCounter, _ResidualHeapVisitor);
|
||||
|
||||
function ResidualHeapRefCounter(realm, logger, modules, additionalFunctionValuesAndEffects) {
|
||||
_classCallCheck(this, ResidualHeapRefCounter);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (ResidualHeapRefCounter.__proto__ || Object.getPrototypeOf(ResidualHeapRefCounter)).call(this, realm, logger, modules, additionalFunctionValuesAndEffects));
|
||||
|
||||
_this._valueToEdgeRecord = new Map();
|
||||
_this._path = [];
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(ResidualHeapRefCounter, [{
|
||||
key: "getResult",
|
||||
// Contains the path of nodes from root to current visiting node.
|
||||
|
||||
value: function getResult() {
|
||||
return this._valueToEdgeRecord;
|
||||
}
|
||||
}, {
|
||||
key: "_shouldIgnore",
|
||||
value: function _shouldIgnore(val) {
|
||||
return val instanceof _index.EmptyValue || val.isIntrinsic() || _ResidualHeapInspector.ResidualHeapInspector.isLeaf(val);
|
||||
}
|
||||
}, {
|
||||
key: "preProcessValue",
|
||||
value: function preProcessValue(val) {
|
||||
if (this._shouldIgnore(val)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._path.length > 0) {
|
||||
this._updateParentOutgoingEdgeCount();
|
||||
}
|
||||
this._path.push(val);
|
||||
|
||||
return this._updateValueIncomingEdgeCount(val);
|
||||
}
|
||||
}, {
|
||||
key: "_updateParentOutgoingEdgeCount",
|
||||
value: function _updateParentOutgoingEdgeCount() {
|
||||
var parent = this._path[this._path.length - 1];
|
||||
var edgeRecord = this._valueToEdgeRecord.get(parent);
|
||||
(0, _invariant2.default)(edgeRecord);
|
||||
++edgeRecord.outGoing;
|
||||
}
|
||||
}, {
|
||||
key: "_updateValueIncomingEdgeCount",
|
||||
value: function _updateValueIncomingEdgeCount(val) {
|
||||
var edgeRecord = this._valueToEdgeRecord.get(val);
|
||||
if (edgeRecord === undefined) {
|
||||
this._valueToEdgeRecord.set(val, {
|
||||
inComing: 1,
|
||||
outGoing: 0
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
++edgeRecord.inComing;
|
||||
return false; // visited node, skip its children.
|
||||
}
|
||||
}
|
||||
|
||||
// Override.
|
||||
|
||||
}, {
|
||||
key: "postProcessValue",
|
||||
value: function postProcessValue(val) {
|
||||
if (this._shouldIgnore(val)) {
|
||||
return;
|
||||
}
|
||||
(0, _invariant2.default)(this._path.length > 0);
|
||||
this._path.pop();
|
||||
}
|
||||
|
||||
// Override.
|
||||
|
||||
}, {
|
||||
key: "visitRoots",
|
||||
value: function visitRoots() {
|
||||
_get(ResidualHeapRefCounter.prototype.__proto__ || Object.getPrototypeOf(ResidualHeapRefCounter.prototype), "visitRoots", this).call(this);
|
||||
(0, _invariant2.default)(this._path.length === 0, "Path should be balanced empty after traversal.");
|
||||
}
|
||||
}]);
|
||||
|
||||
return ResidualHeapRefCounter;
|
||||
}(_ResidualHeapVisitor2.ResidualHeapVisitor);
|
||||
//# sourceMappingURL=ResidualHeapRefCounter.js.map
|
||||
Reference in New Issue
Block a user