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.
6 #include "platform/ScriptForbiddenScope.h"
8 #include "wtf/Assertions.h"
9 #include "wtf/MainThread.h"
13 static unsigned s_scriptForbiddenCount
= 0;
15 ScriptForbiddenScope::ScriptForbiddenScope()
17 ASSERT(isMainThread());
18 ++s_scriptForbiddenCount
;
21 ScriptForbiddenScope::~ScriptForbiddenScope()
23 ASSERT(isMainThread());
24 ASSERT(s_scriptForbiddenCount
);
25 --s_scriptForbiddenCount
;
28 void ScriptForbiddenScope::enter()
30 ASSERT(isMainThread());
31 ++s_scriptForbiddenCount
;
34 void ScriptForbiddenScope::exit()
36 ASSERT(isMainThread());
37 ASSERT(s_scriptForbiddenCount
);
38 --s_scriptForbiddenCount
;
41 bool ScriptForbiddenScope::isScriptForbidden()
43 return isMainThread() && s_scriptForbiddenCount
;
46 ScriptForbiddenScope::AllowUserAgentScript::AllowUserAgentScript()
49 m_change
.emplace(s_scriptForbiddenCount
, 0);
52 ScriptForbiddenScope::AllowUserAgentScript::~AllowUserAgentScript()
54 ASSERT(!isMainThread() || !s_scriptForbiddenCount
);