forked from mirrors/gecko-dev
Bug 1806951 - P4. Make CreditCardRuleset an ESModule. r=credential-management-reviewers,sgalich,dimi
Differential Revision: https://phabricator.services.mozilla.com/D174626
This commit is contained in:
parent
8a227dfff2
commit
0baa427d01
5 changed files with 15 additions and 18 deletions
|
|
@ -69,7 +69,7 @@ toolkit/components/backgroundtasks/defaults
|
|||
|
||||
# A mainly-imported file, that we don't want to format, but want to keep an eye
|
||||
# on with the other imported files.
|
||||
toolkit/components/formautofill/CreditCardRuleset.sys.mjs
|
||||
toolkit/components/formautofill/shared/CreditCardRuleset.sys.mjs
|
||||
|
||||
##############################################################################
|
||||
# The list below is copied from .eslintignore. Prettier doesn't currently
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* By default this test only tests 1 sample. This is to avoid publishing all samples we have
|
||||
* to the codebase. If you update the Fathom CC model, please follow the instruction below
|
||||
* and run the test. Doing this makes sure the optimized (Native implementation) CC fathom model produces
|
||||
* exactly the same result as the non-optimized model (JS implementation, See CreditCardRuleset.jsm).
|
||||
* exactly the same result as the non-optimized model (JS implementation, See CreditCardRuleset.sys.mjs).
|
||||
*
|
||||
* To test this:
|
||||
* 1. Run the test setup script (fathom/test-setup.sh) to download all samples to the local
|
||||
|
|
@ -102,7 +102,7 @@ async function run_test(path, dirs) {
|
|||
}
|
||||
|
||||
// This value should sync with the number of supported types in
|
||||
// CreditCardRuleset.jsm (See `get types()` in `this.creditCardRulesets`).
|
||||
// CreditCardRuleset.sys.mjs (See `get types()` in `this.creditCardRulesets`).
|
||||
const EXPECTED_NUM_OF_CONFIDENCE = 2;
|
||||
for (let i = 0; i < eligibleFields.length; i++) {
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|||
CreditCard: "resource://gre/modules/CreditCard.sys.mjs",
|
||||
FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs",
|
||||
LabelUtils: "resource://gre/modules/shared/LabelUtils.sys.mjs",
|
||||
creditCardRulesets: "resource://autofill/CreditCardRuleset.sys.mjs",
|
||||
creditCardRulesets: "resource://gre/modules/shared/CreditCardRuleset.sys.mjs",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(lazy, "log", () =>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ with Files("**"):
|
|||
BUG_COMPONENT = ("Toolkit", "Form Autofill")
|
||||
|
||||
EXTRA_JS_MODULES.shared += [
|
||||
"shared/CreditCardRuleset.sys.mjs",
|
||||
"shared/FormAutofillNameUtils.sys.mjs",
|
||||
"shared/FormAutofillUtils.sys.mjs",
|
||||
"shared/LabelUtils.sys.mjs",
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@
|
|||
* CODE UNIQUE TO PRODUCTION--NOT IN THE TRAINING REPOSITORY:
|
||||
*/
|
||||
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
|
||||
import {
|
||||
element as clickedElement,
|
||||
out,
|
||||
|
|
@ -29,18 +27,14 @@ import {
|
|||
score,
|
||||
type,
|
||||
} from "resource://gre/modules/third_party/fathom/fathom.mjs";
|
||||
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
|
||||
import { FormAutofillUtils } from "resource://gre/modules/shared/FormAutofillUtils.sys.mjs";
|
||||
import {
|
||||
CreditCard,
|
||||
NETWORK_NAMES,
|
||||
} from "resource://gre/modules/CreditCard.sys.mjs";
|
||||
|
||||
const lazy = {};
|
||||
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs" ,
|
||||
FormLikeFactory: "resource://gre/modules/FormLikeFactory.sys.mjs",
|
||||
LabelUtils: "resource://gre/modules/shared/LabelUtils.sys.mjs",
|
||||
});
|
||||
import { FormLikeFactory } from "resource://gre/modules/FormLikeFactory.sys.mjs";
|
||||
import { LabelUtils } from "resource://gre/modules/shared/LabelUtils.sys.mjs";
|
||||
|
||||
/**
|
||||
* Callthrough abstraction to allow .getAutocompleteInfo() to be mocked out
|
||||
|
|
@ -351,9 +345,9 @@ function autocompleteStringMatches(element, ccString) {
|
|||
}
|
||||
|
||||
function getFillableFormElements(element) {
|
||||
const formLike = lazy.FormLikeFactory.createFromField(element);
|
||||
const formLike = FormLikeFactory.createFromField(element);
|
||||
return Array.from(formLike.elements).filter(el =>
|
||||
lazy.FormAutofillUtils.isCreditCardOrAddressFieldType(el)
|
||||
FormAutofillUtils.isCreditCardOrAddressFieldType(el)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -405,9 +399,9 @@ function idOrNameMatchRegExp(element, regExp) {
|
|||
function getElementLabels(element) {
|
||||
return {
|
||||
*[Symbol.iterator]() {
|
||||
const labels = lazy.LabelUtils.findLabelElements(element);
|
||||
const labels = LabelUtils.findLabelElements(element);
|
||||
for (let label of labels) {
|
||||
yield* lazy.LabelUtils.extractLabelStrings(label);
|
||||
yield* LabelUtils.extractLabelStrings(label);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
@ -1210,3 +1204,5 @@ export var creditCardRulesets = {
|
|||
};
|
||||
|
||||
creditCardRulesets.init();
|
||||
|
||||
export default creditCardRulesets;
|
||||
Loading…
Reference in a new issue