Skip to content

Commit 531bf5c

Browse files
committed
Bug 1723521 - Part 2: Add available-to-element-internals flag in ShadowRoot; r=smaug
See whatwg/dom#893. Differential Revision: https://phabricator.services.mozilla.com/D121565
1 parent 314227d commit 531bf5c

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

dom/base/Element.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -1160,23 +1160,19 @@ bool Element::CanAttachShadowDOM() const {
11601160
return true;
11611161
}
11621162

1163-
// https://dom.spec.whatwg.org/#dom-element-attachshadow
1163+
// https://dom.spec.whatwg.org/commit-snapshots/1eadf0a4a271acc92013d1c0de8c730ac96204f9/#dom-element-attachshadow
11641164
already_AddRefed<ShadowRoot> Element::AttachShadow(const ShadowRootInit& aInit,
11651165
ErrorResult& aError) {
11661166
/**
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.
11711168
*/
11721169
if (!CanAttachShadowDOM()) {
11731170
aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
11741171
return nullptr;
11751172
}
11761173

11771174
/**
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.
11801176
*/
11811177
if (GetShadowRoot()) {
11821178
aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
@@ -1214,7 +1210,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
12141210
}
12151211

12161212
/**
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
12181214
* context object's node document, host is context object,
12191215
* and mode is init's mode.
12201216
*/
@@ -1227,7 +1223,17 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
12271223
}
12281224

12291225
/**
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.
12311237
*/
12321238
SetShadowRoot(shadowRoot);
12331239

@@ -1240,7 +1246,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
12401246
}
12411247

12421248
/**
1243-
* 6. Return shadow.
1249+
* 10. Return shadow.
12441250
*/
12451251
return shadowRoot.forget();
12461252
}

dom/base/ShadowRoot.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ ShadowRoot::ShadowRoot(Element* aElement, ShadowRootMode aMode,
5454
DocumentOrShadowRoot(this),
5555
mMode(aMode),
5656
mSlotAssignment(aSlotAssignment),
57-
mIsUAWidget(false) {
57+
mIsUAWidget(false),
58+
mIsAvailableToElementInternals(false) {
5859
SetHost(aElement);
5960

6061
// Nodes in a shadow tree should never store a value

dom/base/ShadowRoot.h

+11
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ class ShadowRoot final : public DocumentFragment,
208208
mIsUAWidget = true;
209209
}
210210

211+
bool IsAvailableToElementInternals() const {
212+
return mIsAvailableToElementInternals;
213+
}
214+
215+
void SetAvailableToElementInternals() {
216+
mIsAvailableToElementInternals = true;
217+
}
218+
211219
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
212220

213221
// nsIRadioGroupContainer
@@ -280,6 +288,9 @@ class ShadowRoot final : public DocumentFragment,
280288

281289
bool mIsUAWidget : 1;
282290

291+
// https://dom.spec.whatwg.org/#shadowroot-available-to-element-internals
292+
bool mIsAvailableToElementInternals : 1;
293+
283294
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
284295
};
285296

0 commit comments

Comments
 (0)