diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-09 06:46:43 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-09 06:46:43 -0500 |
commit | ac46df8daea09899ce30dc8fd70986e258c746bf (patch) | |
tree | 2750d3125fc253fd5b0671e4bd268eff1fd97296 /addon-sdk/source/test/test-weak-set.js | |
parent | 8cecf8d5208f3945b35f879bba3015bb1a11bec6 (diff) | |
download | UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.gz UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.lz UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.tar.xz UXP-ac46df8daea09899ce30dc8fd70986e258c746bf.zip |
Move Add-on SDK source to toolkit/jetpack
Diffstat (limited to 'addon-sdk/source/test/test-weak-set.js')
-rw-r--r-- | addon-sdk/source/test/test-weak-set.js | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/addon-sdk/source/test/test-weak-set.js b/addon-sdk/source/test/test-weak-set.js deleted file mode 100644 index f7cc19e04..000000000 --- a/addon-sdk/source/test/test-weak-set.js +++ /dev/null @@ -1,146 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -"use strict"; - -const { Cu } = require("chrome"); -const memory = require("sdk/test/memory"); -const { add, remove, has, clear, iterator } = require("sdk/lang/weak-set"); -const { setInterval, clearInterval } = require("sdk/timers"); - -function gc(assert) { - let wait = 1; - let interval = setInterval(function() { - assert.pass("waited " + (wait++ * 0.250) + "secs for gc().."); - }, 250); - - return memory.gc().then(() => { - assert.pass("gc completed!"); - clearInterval(interval); - }); -} - -exports['test add/remove/iterate/clear item'] = function*(assert) { - let addItems = {}; - let removeItems = {}; - let iterateItems = {}; - let clearItems = {}; - let nonReferencedItems = {}; - - let item = {}; - let addedItems = [{}, {}]; - - assert.pass("adding things to items"); - add(addItems, item); - add(removeItems, item); - add(iterateItems, addedItems[0]); - add(iterateItems, addedItems[1]); - add(iterateItems, addedItems[0]); // weak set shouldn't add this twice - add(clearItems, addedItems[0]); - add(clearItems, addedItems[1]); - add(nonReferencedItems, {}); - - assert.pass("removing things from removeItems"); - remove(removeItems, item); - - assert.pass("clear things from clearItems"); - clear(clearItems); - - assert.pass("starting gc.."); - yield gc(assert); - let count = 0; - - assert.equal(has(addItems, item), true, 'the addItems is in the weak set'); - assert.equal(has(removeItems, item), false, 'the removeItems is not in weak set'); - - assert.pass("iterating iterateItems.."); - for (let item of iterator(iterateItems)) { - assert.equal(item, addedItems[count], "item in the expected order"); - count++; - } - - assert.equal(count, 2, 'items in the expected number'); - - assert.pass("iterating clearItems.."); - for (let item of iterator(clearItems)) { - assert.fail("the loop should not be executed"); - count++ - } - - for (let item of iterator(nonReferencedItems)) { - assert.fail("the loop should not be executed"); - count++ - } - - assert.equal(count, 2, 'items in the expected number'); -}; - -exports['test adding non object or null item'] = function(assert) { - let items = {}; - - assert.throws(() => { - add(items, 'foo'); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(items, 0); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(items, undefined); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(items, null); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(items, true); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); -}; - -exports['test adding to non object or null item'] = function(assert) { - let item = {}; - - assert.throws(() => { - add('foo', item); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(0, item); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(undefined, item); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(null, item); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); - - assert.throws(() => { - add(true, item); - }, - /^\w+ is not a non-null object/, - 'only non-null object are allowed'); -}; - -require("sdk/test").run(exports); |