From 7f18c4084f9bac120caccb4accd6545f24ac7c93 Mon Sep 17 00:00:00 2001 From: Till Schneidereit Date: Mon, 4 Jan 2016 13:06:55 +0100 Subject: [PATCH] Bug 1101817 - Part 3: Remove WeakMap.prototype.clear usages from Addons SDK. r=mossop --HG-- extra : rebase_source : 45c1935d03eb07b24a72208397a3c35261f7d1aa --- addon-sdk/source/lib/sdk/lang/weak-set.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/addon-sdk/source/lib/sdk/lang/weak-set.js b/addon-sdk/source/lib/sdk/lang/weak-set.js index 5a8f08aa700d..8972602a50c1 100644 --- a/addon-sdk/source/lib/sdk/lang/weak-set.js +++ b/addon-sdk/source/lib/sdk/lang/weak-set.js @@ -13,16 +13,21 @@ const { Cu } = require("chrome"); function makeGetterFor(Type) { let cache = new WeakMap(); - return function getFor(target) { - if (!cache.has(target)) - cache.set(target, new Type()); + return { + getFor(target) { + if (!cache.has(target)) + cache.set(target, new Type()); - return cache.get(target); + return cache.get(target); + }, + clearFor(target) { + return cache.delete(target) + } } } -var getLookupFor = makeGetterFor(WeakMap); -var getRefsFor = makeGetterFor(Set); +var {getFor: getLookupFor, clearFor: clearLookupFor} = makeGetterFor(WeakMap); +var {getFor: getRefsFor, clearFor: clearRefsFor} = makeGetterFor(Set); function add(target, value) { if (has(target, value)) @@ -44,8 +49,8 @@ function has(target, value) { exports.has = has; function clear(target) { - getLookupFor(target).clear(); - getRefsFor(target).clear(); + clearLookupFor(target); + clearRefsFor(target); } exports.clear = clear;