@@ -1160,23 +1160,19 @@ bool Element::CanAttachShadowDOM() const {
1160
1160
return true ;
1161
1161
}
1162
1162
1163
- // https://dom.spec.whatwg.org/#dom-element-attachshadow
1163
+ // https://dom.spec.whatwg.org/commit-snapshots/1eadf0a4a271acc92013d1c0de8c730ac96204f9/ #dom-element-attachshadow
1164
1164
already_AddRefed<ShadowRoot> Element::AttachShadow (const ShadowRootInit& aInit,
1165
1165
ErrorResult& aError) {
1166
1166
/* *
1167
- * 1. If context object's namespace is not the HTML namespace,
1168
- * then throw a "NotSupportedError" DOMException.
1169
- * 2. If context object's local name is not valid to attach shadow DOM to,
1170
- * then throw a "NotSupportedError" DOMException.
1167
+ * Step 1, 2, and 3.
1171
1168
*/
1172
1169
if (!CanAttachShadowDOM ()) {
1173
1170
aError.Throw (NS_ERROR_DOM_NOT_SUPPORTED_ERR);
1174
1171
return nullptr ;
1175
1172
}
1176
1173
1177
1174
/* *
1178
- * 4. If context object is a shadow host, then throw
1179
- * an "NotSupportedError" DOMException.
1175
+ * 4. If this is a shadow host, then throw a "NotSupportedError" DOMException.
1180
1176
*/
1181
1177
if (GetShadowRoot ()) {
1182
1178
aError.Throw (NS_ERROR_DOM_NOT_SUPPORTED_ERR);
@@ -1214,7 +1210,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
1214
1210
}
1215
1211
1216
1212
/* *
1217
- * 4 . Let shadow be a new shadow root whose node document is
1213
+ * 5 . Let shadow be a new shadow root whose node document is
1218
1214
* context object's node document, host is context object,
1219
1215
* and mode is init's mode.
1220
1216
*/
@@ -1227,7 +1223,17 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
1227
1223
}
1228
1224
1229
1225
/* *
1230
- * 5. Set context object's shadow root to shadow.
1226
+ * 7. If this’s custom element state is "precustomized" or "custom", then set
1227
+ * shadow’s available to element internals to true.
1228
+ */
1229
+ CustomElementData* ceData = GetCustomElementData ();
1230
+ if (ceData && (ceData->mState == CustomElementData::State::ePrecustomized ||
1231
+ ceData->mState == CustomElementData::State::eCustom)) {
1232
+ shadowRoot->SetAvailableToElementInternals ();
1233
+ }
1234
+
1235
+ /* *
1236
+ * 9. Set context object's shadow root to shadow.
1231
1237
*/
1232
1238
SetShadowRoot (shadowRoot);
1233
1239
@@ -1240,7 +1246,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
1240
1246
}
1241
1247
1242
1248
/* *
1243
- * 6 . Return shadow.
1249
+ * 10 . Return shadow.
1244
1250
*/
1245
1251
return shadowRoot.forget ();
1246
1252
}
0 commit comments