michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: module.metadata = { michael@0: "stability": "experimental" michael@0: }; michael@0: michael@0: const method = require("../../method/core"); michael@0: const { Class } = require("./heritage"); michael@0: michael@0: // Object that inherit or mix WeakRefence inn will register michael@0: // weak observes for system notifications. michael@0: const WeakReference = Class({}); michael@0: exports.WeakReference = WeakReference; michael@0: michael@0: michael@0: // If `isWeak(object)` is `true` observer installed michael@0: // for such `object` will be weak, meaning that it will michael@0: // be GC-ed if nothing else but observer is observing it. michael@0: // By default everything except `WeakReference` will return michael@0: // `false`. michael@0: const isWeak = method("reference/weak?"); michael@0: exports.isWeak = isWeak; michael@0: michael@0: isWeak.define(Object, _ => false); michael@0: isWeak.define(WeakReference, _ => true);