Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / ScriptForbiddenScope.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/dom/ScriptForbiddenScope.h"
7
8 #include "wtf/Assertions.h"
9 #include "wtf/MainThread.h"
10
11 namespace WebCore {
12
13 #if ASSERT_ENABLED
14
15 static unsigned s_scriptForbiddenCount = 0;
16
17 ScriptForbiddenScope::ScriptForbiddenScope()
18 {
19     ASSERT(isMainThread());
20     ++s_scriptForbiddenCount;
21 }
22
23 ScriptForbiddenScope::~ScriptForbiddenScope()
24 {
25     ASSERT(isMainThread());
26     --s_scriptForbiddenCount;
27 }
28
29 bool ScriptForbiddenScope::isScriptForbidden()
30 {
31     return isMainThread() && s_scriptForbiddenCount;
32 }
33
34 ScriptForbiddenScope::AllowUserAgentScript::AllowUserAgentScript()
35     : m_change(s_scriptForbiddenCount, 0)
36 {
37 }
38
39 ScriptForbiddenScope::AllowUserAgentScript::~AllowUserAgentScript()
40 {
41     ASSERT(!s_scriptForbiddenCount);
42 }
43
44 #endif
45
46 } // namespace WebCore