summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/html/custom/custom_element_reaction_queue.cc
blob: 386f02a974621247da8c1a77b4671ae70296a75b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/html/custom/custom_element_reaction_queue.h"

#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/html/custom/custom_element_reaction.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"

namespace blink {

CustomElementReactionQueue::CustomElementReactionQueue() : index_(0u) {}

CustomElementReactionQueue::~CustomElementReactionQueue() = default;

void CustomElementReactionQueue::Trace(Visitor* visitor) {
  visitor->Trace(reactions_);
}

void CustomElementReactionQueue::Add(CustomElementReaction& reaction) {
  reactions_.push_back(&reaction);
}

// There is one queue per element, so this could be invoked
// recursively.
void CustomElementReactionQueue::InvokeReactions(Element& element) {
  TRACE_EVENT1("blink", "CustomElementReactionQueue::invokeReactions", "name",
               element.localName().Utf8());
  while (index_ < reactions_.size()) {
    CustomElementReaction* reaction = reactions_[index_];
    reactions_[index_++] = nullptr;
    reaction->Invoke(element);
  }
  // Unlike V0CustomElementsCallbackQueue, reactions are always
  // inserted by steps which bump the global element queue. This
  // means we do not need queue "owner" guards.
  // https://html.spec.whatwg.org/multipage/scripting.html#custom-element-reactions
  Clear();
}

void CustomElementReactionQueue::Clear() {
  index_ = 0;
  reactions_.resize(0);
}

}  // namespace blink