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: '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 { uuid } = require('../util/uuid'); michael@0: michael@0: // NOTE: use lang/functional memoize when it is updated to use WeakMap michael@0: function memoize(f) { michael@0: const memo = new WeakMap(); michael@0: michael@0: return function memoizer(o) { michael@0: let key = o; michael@0: if (!memo.has(key)) michael@0: memo.set(key, f.apply(this, arguments)); michael@0: return memo.get(key); michael@0: }; michael@0: } michael@0: michael@0: let identify = method('identify'); michael@0: identify.define(Object, memoize(function() { return uuid(); })); michael@0: exports.identify = identify;