1/*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
5 * Copyright (C) 2009 Google, Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#pragma once
23
24#include "DOMWrapperWorld.h"
25#include "WebCoreBuiltinNames.h"
26#include "WebCoreJSBuiltins.h"
27#include <wtf/HashSet.h>
28#include <wtf/RefPtr.h>
29
30namespace WebCore {
31
32class JSVMClientData : public JSC::VM::ClientData {
33 WTF_MAKE_NONCOPYABLE(JSVMClientData); WTF_MAKE_FAST_ALLOCATED;
34 friend class VMWorldIterator;
35
36public:
37 explicit JSVMClientData(JSC::VM&);
38
39 virtual ~JSVMClientData();
40
41 WEBCORE_EXPORT static void initNormalWorld(JSC::VM*);
42
43 DOMWrapperWorld& normalWorld() { return *m_normalWorld; }
44
45 void getAllWorlds(Vector<Ref<DOMWrapperWorld>>&);
46
47 void rememberWorld(DOMWrapperWorld& world)
48 {
49 ASSERT(!m_worldSet.contains(&world));
50 m_worldSet.add(&world);
51 }
52
53 void forgetWorld(DOMWrapperWorld& world)
54 {
55 ASSERT(m_worldSet.contains(&world));
56 m_worldSet.remove(&world);
57 }
58
59 WebCoreBuiltinNames& builtinNames() { return m_builtinNames; }
60 JSBuiltinFunctions& builtinFunctions() { return m_builtinFunctions; }
61
62 JSC::IsoSubspace& runtimeMethodSpace() { return m_runtimeMethodSpace; }
63
64 JSC::CompleteSubspace& outputConstraintSpace() { return m_outputConstraintSpace; }
65 JSC::CompleteSubspace& globalObjectOutputConstraintSpace() { return m_globalObjectOutputConstraintSpace; }
66
67 template<typename Func>
68 void forEachOutputConstraintSpace(const Func& func)
69 {
70 func(m_outputConstraintSpace);
71 func(m_globalObjectOutputConstraintSpace);
72 }
73
74private:
75 HashSet<DOMWrapperWorld*> m_worldSet;
76 RefPtr<DOMWrapperWorld> m_normalWorld;
77
78 JSBuiltinFunctions m_builtinFunctions;
79 WebCoreBuiltinNames m_builtinNames;
80
81 JSC::IsoSubspace m_runtimeMethodSpace;
82
83 JSC::CompleteSubspace m_outputConstraintSpace;
84 JSC::CompleteSubspace m_globalObjectOutputConstraintSpace;
85};
86
87} // namespace WebCore
88