mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-25 02:40:22 -10:00
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
71 lines
1.9 KiB
JavaScript
71 lines
1.9 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
// Test WeakMapMap.
|
|
|
|
"use strict";
|
|
|
|
const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
|
|
const WeakMapMap = require("devtools/client/shared/WeakMapMap");
|
|
|
|
const myWeakMapMap = new WeakMapMap();
|
|
const key = { randomObject: true };
|
|
|
|
// eslint-disable-next-line
|
|
function run_test() {
|
|
test_set();
|
|
test_has();
|
|
test_get();
|
|
test_delete();
|
|
test_clear();
|
|
}
|
|
|
|
function test_set() {
|
|
// myWeakMapMap.set
|
|
myWeakMapMap.set(key, "text1", "value1");
|
|
myWeakMapMap.set(key, "text2", "value2");
|
|
myWeakMapMap.set(key, "text3", "value3");
|
|
}
|
|
|
|
function test_has() {
|
|
// myWeakMapMap.has
|
|
ok(myWeakMapMap.has(key, "text1"), "text1 exists");
|
|
ok(myWeakMapMap.has(key, "text2"), "text2 exists");
|
|
ok(myWeakMapMap.has(key, "text3"), "text3 exists");
|
|
ok(!myWeakMapMap.has(key, "notakey"), "notakey does not exist");
|
|
}
|
|
|
|
function test_get() {
|
|
// myWeakMapMap.get
|
|
const value1 = myWeakMapMap.get(key, "text1");
|
|
equal(value1, "value1", "test value1");
|
|
|
|
const value2 = myWeakMapMap.get(key, "text2");
|
|
equal(value2, "value2", "test value2");
|
|
|
|
const value3 = myWeakMapMap.get(key, "text3");
|
|
equal(value3, "value3", "test value3");
|
|
|
|
const value4 = myWeakMapMap.get(key, "notakey");
|
|
equal(value4, undefined, "test value4");
|
|
}
|
|
|
|
function test_delete() {
|
|
// myWeakMapMap.delete
|
|
myWeakMapMap.delete(key, "text2");
|
|
|
|
// Check that the correct entry was deleted
|
|
ok(myWeakMapMap.has(key, "text1"), "text1 exists");
|
|
ok(!myWeakMapMap.has(key, "text2"), "text2 no longer exists");
|
|
ok(myWeakMapMap.has(key, "text3"), "text3 exists");
|
|
}
|
|
|
|
function test_clear() {
|
|
// myWeakMapMap.clear
|
|
myWeakMapMap.clear();
|
|
|
|
// Ensure myWeakMapMap was properly cleared
|
|
ok(!myWeakMapMap.has(key, "text1"), "text1 no longer exists");
|
|
ok(!myWeakMapMap.has(key, "text3"), "text3 no longer exists");
|
|
}
|