Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / inspector / InspectorNodeIds.cpp
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/inspector/InspectorNodeIds.h"
7
8 #include "core/dom/WeakNodeMap.h"
9
10 namespace WebCore {
11
12 static WeakNodeMap& nodeIds()
13 {
14     DEFINE_STATIC_LOCAL(WeakNodeMap, self, ());
15     return self;
16 }
17
18 int InspectorNodeIds::idForNode(Node* node)
19 {
20     static int s_nextNodeId = 1;
21     WeakNodeMap& ids = nodeIds();
22     int result = ids.value(node);
23     if (!result) {
24         result = s_nextNodeId++;
25         ids.put(node, result);
26     }
27     return result;
28 }
29
30 Node* InspectorNodeIds::nodeForId(int id)
31 {
32     return nodeIds().node(id);
33 }
34
35 }