/* 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"; var EXPORTED_SYMBOLS = ["FormLikeFactory"]; const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" ); /** * A factory to generate FormLike objects that represent a set of related fields * which aren't necessarily marked up with a
element. FormLike's emulate * the properties of an HTMLFormElement which are relevant to form tasks. */ let FormLikeFactory = { _propsFromForm: ["action", "autocomplete", "ownerDocument"], /** * Create a FormLike object from a . * * @param {HTMLFormElement} aForm * @return {FormLike} * @throws Error if aForm isn't an HTMLFormElement */ createFromForm(aForm) { if (ChromeUtils.getClassName(aForm) !== "HTMLFormElement") { throw new Error("createFromForm: aForm must be a HTMLFormElement"); } let formLike = { elements: [...aForm.elements], rootElement: aForm, }; for (let prop of this._propsFromForm) { formLike[prop] = aForm[prop]; } this._addToJSONProperty(formLike); return formLike; }, /** * Create a FormLike object from an // or