From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- toolkit/modules/FormLikeFactory.sys.mjs | 191 ++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 toolkit/modules/FormLikeFactory.sys.mjs (limited to 'toolkit/modules/FormLikeFactory.sys.mjs') diff --git a/toolkit/modules/FormLikeFactory.sys.mjs b/toolkit/modules/FormLikeFactory.sys.mjs new file mode 100644 index 0000000000..4950ee0f82 --- /dev/null +++ b/toolkit/modules/FormLikeFactory.sys.mjs @@ -0,0 +1,191 @@ +/* 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/. */ + +/** + * 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. + */ +export 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 (!HTMLFormElement.isInstance(aForm)) { + 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