summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/blink/renderer/modules/webaudio/audio_param_map.cc
blob: 2dd5f543a89be39ead6819ad76b243449e8f10ca (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 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/modules/webaudio/audio_param_map.h"

namespace blink {

class AudioParamMapIterationSource final
    : public PairIterable<String, AudioParam*>::IterationSource {
 public:
  AudioParamMapIterationSource(
      const HeapHashMap<String, Member<AudioParam>>& map) {
    for (const auto& name : map.Keys()) {
      parameter_names_.push_back(name);
      parameter_objects_.push_back(map.at(name));
    }
  }

  bool Next(ScriptState* scrip_state,
            String& key,
            AudioParam*& audio_param,
            ExceptionState&) override {
    if (current_index_ == parameter_names_.size())
      return false;
    key = parameter_names_[current_index_];
    audio_param = parameter_objects_[current_index_];
    ++current_index_;
    return true;
  }

  void Trace(Visitor* visitor) const override {
    visitor->Trace(parameter_objects_);
    PairIterable<String, AudioParam*>::IterationSource::Trace(visitor);
  }

 private:
  // For sequential iteration (e.g. Next()).
  Vector<String> parameter_names_;
  HeapVector<Member<AudioParam>> parameter_objects_;
  unsigned current_index_;
};

AudioParamMap::AudioParamMap(
    const HeapHashMap<String, Member<AudioParam>>& parameter_map)
    : parameter_map_(parameter_map) {}

PairIterable<String, AudioParam*>::IterationSource*
    AudioParamMap::StartIteration(ScriptState*, ExceptionState&) {
  return MakeGarbageCollected<AudioParamMapIterationSource>(parameter_map_);
}

bool AudioParamMap::GetMapEntry(ScriptState*,
                                const String& key,
                                AudioParam*& audio_param,
                                ExceptionState&) {
  if (parameter_map_.Contains(key)) {
    audio_param = parameter_map_.at(key);
    return true;
  }

  return false;
}

}  // namespace blink