1/*
2 * Copyright (C) 2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#pragma once
21
22#include <JavaScriptCore/Strong.h>
23#include <JavaScriptCore/StrongInlines.h>
24#include <memory>
25#include <wtf/Vector.h>
26#include <wtf/text/WTFString.h>
27
28namespace JSC {
29class JSGlobalObject;
30}
31
32namespace WebCore {
33
34class DOMWrapperWorld;
35class Document;
36class ScriptExecutionContext;
37class WorkerGlobalScope;
38
39class ScheduledAction {
40 WTF_MAKE_FAST_ALLOCATED;
41public:
42 static std::unique_ptr<ScheduledAction> create(DOMWrapperWorld&, JSC::Strong<JSC::Unknown>&&);
43 static std::unique_ptr<ScheduledAction> create(DOMWrapperWorld&, String&&);
44 ~ScheduledAction();
45
46 void addArguments(Vector<JSC::Strong<JSC::Unknown>>&&);
47
48 enum class Type { Code, Function };
49 Type type() const;
50
51 void execute(ScriptExecutionContext&);
52
53private:
54 ScheduledAction(DOMWrapperWorld&, JSC::Strong<JSC::Unknown>&&);
55 ScheduledAction(DOMWrapperWorld&, String&&);
56
57 void executeFunctionInContext(JSC::JSGlobalObject*, JSC::JSValue thisValue, ScriptExecutionContext&);
58 void execute(Document&);
59 void execute(WorkerGlobalScope&);
60
61 Ref<DOMWrapperWorld> m_isolatedWorld;
62 JSC::Strong<JSC::Unknown> m_function;
63 Vector<JSC::Strong<JSC::Unknown>> m_arguments;
64 String m_code;
65};
66
67} // namespace WebCore
68