OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 #ifndef GIN_DEFAULT_RUNNER_H_ | |
sky
2014/02/25 22:39:33
This is really a move, but as so much changed git
| |
6 #define GIN_DEFAULT_RUNNER_H_ | |
7 | |
8 #include "gin/runner.h" | |
9 | |
10 namespace gin { | |
11 | |
12 class ContextHolder; | |
13 class DefaultRunner; | |
14 class TryCatch; | |
15 | |
16 // Subclass DefaultRunnerDelegate to customize the behavior of | |
17 // |DefaultRunner|. Typical embedders will want to subclass one of the | |
18 // specialized DefaultRunnerDelegates, such as ModuleRunnerDelegate. | |
19 class GIN_EXPORT DefaultRunnerDelegate { | |
20 public: | |
21 DefaultRunnerDelegate(); | |
22 virtual ~DefaultRunnerDelegate(); | |
23 | |
24 // Returns the template for the global object. | |
25 virtual v8::Handle<v8::ObjectTemplate> GetGlobalTemplate( | |
26 DefaultRunner* runner, | |
27 v8::Isolate* isolate); | |
28 virtual void DidCreateContext(DefaultRunner* runner); | |
29 virtual void WillRunScript(DefaultRunner* runner); | |
30 virtual void DidRunScript(DefaultRunner* runner); | |
31 virtual void UnhandledException(DefaultRunner* runner, TryCatch& try_catch); | |
32 }; | |
33 | |
34 // DefaultRunner executes the script/functions directly in a v8::Context. | |
35 // DefaultRunner owns a ContextHolder and v8::Context, both of which are | |
36 // destroyed when the DefaultRunner is deleted. | |
37 class GIN_EXPORT DefaultRunner : public Runner { | |
38 public: | |
39 DefaultRunner(DefaultRunnerDelegate* delegate, v8::Isolate* isolate); | |
40 virtual ~DefaultRunner(); | |
41 | |
42 // Before running script in this context, you'll need to enter the runner's | |
43 // context by creating an instance of Runner::Scope on the stack. | |
44 | |
45 // Runner overrides: | |
46 virtual void Run(const std::string& source, | |
47 const std::string& resource_name) OVERRIDE; | |
48 virtual v8::Handle<v8::Value> Call(v8::Handle<v8::Function> function, | |
49 v8::Handle<v8::Value> receiver, | |
50 int argc, | |
51 v8::Handle<v8::Value> argv[]) OVERRIDE; | |
52 virtual ContextHolder* GetContextHolder() OVERRIDE; | |
53 | |
54 private: | |
55 friend class Scope; | |
56 | |
57 void Run(v8::Handle<v8::Script> script); | |
58 | |
59 DefaultRunnerDelegate* delegate_; | |
60 | |
61 scoped_ptr<ContextHolder> context_holder_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(DefaultRunner); | |
64 }; | |
65 | |
66 } // namespace gin | |
67 | |
68 #endif // GIN_DEFAULT_RUNNER_H_ | |
OLD | NEW |