You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -66,21 +73,24 @@ export class ElementInternals implements IElementInternals {
66
73
refMap.set(this,ref);
67
74
validityMap.set(this,validity);
68
75
internalsMap.set(ref,this);
69
-
const{ labels, form }=this;
70
76
initAom(ref,this);
77
+
initRef(ref,this);
71
78
Object.seal(this);
72
79
73
-
initRef(ref,this);
74
-
initLabels(ref,labels);
75
-
initForm(ref,form,this);
80
+
if(ref.constructor['formAssociated']){
81
+
const{ labels, form }=this;
82
+
initLabels(ref,labels);
83
+
initForm(ref,form,this);
84
+
}
76
85
}
77
86
78
87
/**
79
88
* Will return true if the element is in a valid state
80
89
*/
81
90
checkValidity(): boolean{
82
-
constvalidity=validityMap.get(this);
83
91
constref=refMap.get(this);
92
+
throwIfNotFormAssociated(ref,`Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
93
+
constvalidity=validityMap.get(this);
84
94
if(!validity.valid){
85
95
constvalidityEvent=newEvent('invalid',{
86
96
bubbles: false,
@@ -95,6 +105,7 @@ export class ElementInternals implements IElementInternals {
95
105
/** The form element the custom element is associated with */
96
106
getform(): HTMLFormElement{
97
107
constref=refMap.get(this);
108
+
throwIfNotFormAssociated(ref,`Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.`);
98
109
letform;
99
110
if(ref.constructor['formAssociated']===true){
100
111
form=findParentForm(ref);
@@ -105,6 +116,7 @@ export class ElementInternals implements IElementInternals {
105
116
/** A list of all relative form labels for this element */
106
117
getlabels(): LabelsList{
107
118
constref=refMap.get(this);
119
+
throwIfNotFormAssociated(ref,`Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.`);
108
120
constid=ref.getAttribute('id');
109
121
consthostRoot=getHostRoot(ref);
110
122
if(hostRoot&&id){
@@ -115,9 +127,10 @@ export class ElementInternals implements IElementInternals {
115
127
116
128
/** Will report the elements validity state */
117
129
reportValidity(): boolean{
130
+
constref=refMap.get(this);
131
+
throwIfNotFormAssociated(ref,`Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
118
132
constvalid=this.checkValidity();
119
133
constanchor=validationAnchorMap.get(this);
120
-
constref=refMap.get(this);
121
134
if(anchor&&!ref.constructor['formAssociated']){
122
135
thrownewDOMException(`Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
123
136
}
@@ -131,9 +144,7 @@ export class ElementInternals implements IElementInternals {
throwIfNotFormAssociated(ref,`Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element.`);
164
176
if(!validityChanges){
165
177
thrownewTypeError('Failed to execute \'setValidity\' on \'ElementInternals\': 1 argument required, but only 0 present.');
166
178
}
@@ -191,19 +203,23 @@ export class ElementInternals implements IElementInternals {
191
203
192
204
/** The element's validation message set during a call to ElementInternals.setValidity */
193
205
getvalidationMessage(): string{
206
+
constref=refMap.get(this);
207
+
throwIfNotFormAssociated(ref,`Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element.`);
194
208
returnvalidationMessageMap.get(this);
195
209
}
196
210
197
211
/** The current validity state of the object */
198
212
getvalidity(): globalThis.ValidityState{
213
+
constref=refMap.get(this);
214
+
throwIfNotFormAssociated(ref,`Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element.`);
199
215
constvalidity=validityMap.get(this);
200
216
returnvalidity;
201
217
}
202
218
203
219
/** If true the element will participate in a form's constraint validation. */
204
220
getwillValidate(): boolean{
205
221
constref=refMap.get(this);
206
-
222
+
throwIfNotFormAssociated(ref,`Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element.`);
0 commit comments