blob: e150feacda3a433ed5c8b81b3a9203686a79110e [file] [log] [blame]
[email protected]1771610d2014-02-27 06:08:241// 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
[email protected]df55d2592014-02-27 19:49:395#ifndef GIN_SHELL_RUNNER_H_
6#define GIN_SHELL_RUNNER_H_
[email protected]1771610d2014-02-27 06:08:247
8#include "gin/runner.h"
9
10namespace gin {
11
12class ContextHolder;
13class ShellRunner;
14class TryCatch;
15
16// Subclass ShellRunnerDelegate to customize the behavior of ShellRunner.
17// Typical embedders will want to subclass one of the specialized
18// ShellRunnerDelegates, such as ModuleRunnerDelegate.
19class GIN_EXPORT ShellRunnerDelegate {
20 public:
21 ShellRunnerDelegate();
22 virtual ~ShellRunnerDelegate();
23
24 // Returns the template for the global object.
deepak.sfaaa1b62015-04-30 07:30:4825 virtual v8::Local<v8::ObjectTemplate> GetGlobalTemplate(
[email protected]1771610d2014-02-27 06:08:2426 ShellRunner* runner,
27 v8::Isolate* isolate);
28 virtual void DidCreateContext(ShellRunner* runner);
29 virtual void WillRunScript(ShellRunner* runner);
30 virtual void DidRunScript(ShellRunner* runner);
31 virtual void UnhandledException(ShellRunner* runner, TryCatch& try_catch);
32};
33
34// ShellRunner executes the script/functions directly in a v8::Context.
35// ShellRunner owns a ContextHolder and v8::Context, both of which are destroyed
36// when the ShellRunner is deleted.
37class GIN_EXPORT ShellRunner : public Runner {
38 public:
39 ShellRunner(ShellRunnerDelegate* delegate, v8::Isolate* isolate);
dcheng074c0392014-10-23 19:08:2540 ~ShellRunner() override;
[email protected]1771610d2014-02-27 06:08:2441
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:
dcheng074c0392014-10-23 19:08:2546 void Run(const std::string& source,
47 const std::string& resource_name) override;
deepak.sfaaa1b62015-04-30 07:30:4848 v8::Local<v8::Value> Call(v8::Local<v8::Function> function,
49 v8::Local<v8::Value> receiver,
dcheng074c0392014-10-23 19:08:2550 int argc,
deepak.sfaaa1b62015-04-30 07:30:4851 v8::Local<v8::Value> argv[]) override;
dcheng074c0392014-10-23 19:08:2552 ContextHolder* GetContextHolder() override;
[email protected]1771610d2014-02-27 06:08:2453
54 private:
55 friend class Scope;
56
deepak.sfaaa1b62015-04-30 07:30:4857 void Run(v8::Local<v8::Script> script);
[email protected]1771610d2014-02-27 06:08:2458
59 ShellRunnerDelegate* delegate_;
60
61 scoped_ptr<ContextHolder> context_holder_;
62
63 DISALLOW_COPY_AND_ASSIGN(ShellRunner);
64};
65
66} // namespace gin
67
[email protected]df55d2592014-02-27 19:49:3968#endif // GIN_SHELL_RUNNER_H_