rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
45 lines • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReferenceCountedStrategy = void 0;
const lifecycle_stack_js_1 = require("./lifecycle-stack.js");
const reference_counted_node_js_1 = require("../../lifecycle/reference-counted-node.js");
const debug_shared_pointer_checks_js_1 = require("../util/debug-shared-pointer-checks.js");
/**
* @public
* The recommended lifecycle strategy. This strategy only adds debug checks for leaking objects; you must unlink
* objects from their owners once they are finished with them.
*/
class ReferenceCountedStrategy {
createNode(owner) {
owner !== null && owner !== void 0 ? owner : (owner = lifecycle_stack_js_1.lifecycleStack.getTop());
const newNode = new reference_counted_node_js_1.ReferenceCountedNode();
owner.getLinked().link(newNode);
newNode.onReleased();
return newNode;
}
/**
* @internal
*/
createRootNode() {
return new reference_counted_node_js_1.ReferenceCountedNode();
}
onSharedPointerCreated(sharedPtr, metadata, protectedView) {
if (_BUILD.DEBUG) {
debug_shared_pointer_checks_js_1.DebugSharedPointerChecks.registerWithCleanup(this.wrapper, sharedPtr, metadata, protectedView);
this.wrapper.debugUtils.sharedObjectLifeCycleChecks.registerFinalizationCheck(sharedPtr, metadata);
}
}
onManagedObjectCreated(object) {
if (_BUILD.DEBUG) {
this.wrapper.debugUtils.sharedObjectLifeCycleChecks.registerFinalizationCheck(object, null);
}
}
/**
* @internal
*/
setWrapper(wrapper) {
this.wrapper = wrapper;
}
}
exports.ReferenceCountedStrategy = ReferenceCountedStrategy;
//# sourceMappingURL=reference-counted-strategy.js.map