Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement custom element reactions #17614
Conversation
highfive
commented
Jul 5, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jul 5, 2017
|
63015e5
to
787111d
c9efe47
to
20c8a58
|
Ready for review. r? @jdm I am going to submit the changes for |
3b21819
to
b2b5f06
|
The unit tests are still failing. |
b2b5f06
to
944ca90
|
|
| @@ -221,6 +221,15 @@ unsafe impl<T: JSTraceable> JSTraceable for Vec<T> { | |||
| } | |||
| } | |||
|
|
|||
| unsafe impl<T: JSTraceable> JSTraceable for [T] { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| /// Steps 10.3, 10.4 | ||
| #[allow(unsafe_code)] | ||
| fn get_callbacks(&self, prototype: HandleObject) -> Fallible<LifecycleCallbacks> { | ||
| macro_rules! get_callback { |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 12, 2017
Member
This can be a function that returns Result<Function, Error>, right? I don't see a reason to use a macro here.
This comment has been minimized.
This comment has been minimized.
| }, | ||
| _ => return Err(Error::JSFailed), | ||
| }; | ||
| Ok(observed_attributes) |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 12, 2017
Member
We can return this expression directly:
match conversion {
Ok(ConversionResult::Success(attributes)) => Ok(attributes),
Ok(ConversionResult::Failure(error)) => Err(Error::Type(error)),
Err(()) => Err(Error::JSFailed),
}| MutationObserver::queue_a_mutation_record(owner.upcast::<Node>(), mutation); | ||
|
|
||
| let reaction = CallbackReaction::AttributeChanged(name, Some(old_value), Some(new_value), namespace); | ||
| ScriptThread::enqueue_callback_reaction(self.owner().unwrap(), reaction); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -456,6 +456,196 @@ impl CustomElementDefinition { | |||
| } | |||
| } | |||
|
|
|||
| #[derive(HeapSizeOf, JSTraceable)] | |||
| pub enum CustomElementReaction { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| fn invoke_reactions(&self) { | ||
| // Steps 1-2 | ||
| for element in self.queue.borrow().iter() { | ||
| element.invoke_reactions() |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
cbrewster
Jul 13, 2017
Author
Member
I do not believe so, there are two queues an element can be added to:
- The current element queue.
- The backup element queue.
For the first case, the current element queue is popped from the custom element reaction stack thus it is no longer the current element queue which means no element will be added to it.
The second case is the backup element queue has the processing_backup_element_queue flag which prevents elements being enqueued until the flag is set to NotProcessing.
This comment has been minimized.
This comment has been minimized.
cbrewster
Jul 13, 2017
Author
Member
Oh actually in the second case, an element can be appended to the backup element queue is being invoked. The flag check occurs after the element is appended to the queue. This is what causes the crash in the test expectations.
I want to change it so the queue is not borrowed for the duration of the loop. Instead if element are popped and processed, new element can be appended to the queue. But I always run into unrooted must root errors. any ideas?
while let Some(element) = self.queue.borrow_mut().pop_front().map(|e| Root::from_ref(&*e)) {
element.invoke_reactions()
}
This comment has been minimized.
This comment has been minimized.
cbrewster
Jul 17, 2017
Author
Member
Avoiding the closure appears to appease the lint
self.queue.borrow_mut().pop_front().as_ref().map(JS::deref).map(Root::from_ref)
| pub fn invoke_reactions(&self) { | ||
| let mut reaction_queue = self.custom_element_reaction_queue.borrow_mut(); | ||
| while let Some(reaction) = reaction_queue.pop_front() { | ||
| reaction.invoke(Root::from_ref(self)); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| @@ -313,6 +315,11 @@ impl Node { | |||
| // e.g. when removing a <form>. | |||
| vtable_for(&&*node).unbind_from_tree(&context); | |||
| node.style_and_layout_data.get().map(|d| node.dispose(d)); | |||
| if let Some(element) = node.downcast::<Element>() { | |||
This comment has been minimized.
This comment has been minimized.
jdm
Jul 12, 2017
Member
Add a link to https://dom.spec.whatwg.org/#concept-node-remove step 14 here.
| for descendant in node.traverse_preorder() { | ||
| // Step 3.2. | ||
| if let Some(element) = node.downcast::<Element>() { | ||
| if element.get_custom_element_definition().is_some() { |
This comment has been minimized.
This comment has been minimized.
jdm
Jul 12, 2017
Member
We may want to write a Node::as_custom_element helper which combines the downcast and custom check into one.
This comment has been minimized.
This comment has been minimized.
| @@ -1,5 +1,6 @@ | |||
| [reaction-timing.html] | |||
| type: testharness | |||
| expected: CRASH | |||
This comment has been minimized.
This comment has been minimized.
944ca90
to
30afac6
30afac6
to
348251b
| while let Some(element) = self.next_element() { | ||
| element.invoke_reactions() | ||
| } | ||
| self.queue.borrow_mut().clear(); |
This comment has been minimized.
This comment has been minimized.
|
Looks like the sizeof unit tests are failing again, too. |
348251b
to
9b587a4
|
@bors-servo r=jdm |
|
|
Implement custom element reactions <!-- Please describe your changes on the following line: --> Initial work for implementing custom element reactions: https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reactions --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #17433 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17614) <!-- Reviewable:end -->
|
|
Add [CEReactions] to webidls <!-- Please describe your changes on the following line: --> Relies on #17614 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17761) <!-- Reviewable:end -->
Add [CEReactions] to webidls <!-- Please describe your changes on the following line: --> Relies on #17614 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17761) <!-- Reviewable:end -->
cbrewster commentedJul 5, 2017
•
edited
Initial work for implementing custom element reactions: https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reactions
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is