diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 06:08:24 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 06:08:24 +0000 |
commit | 1771610df43ea45158fcb5f2776852f1e5f4e92b (patch) | |
tree | f32652253b296d125497b25dcc51534e4cbc677a /gin/runner.h | |
parent | 2b2e427dcaa14737774a166adf38b68666bfad1e (diff) | |
download | chromium_src-1771610df43ea45158fcb5f2776852f1e5f4e92b.zip chromium_src-1771610df43ea45158fcb5f2776852f1e5f4e92b.tar.gz chromium_src-1771610df43ea45158fcb5f2776852f1e5f4e92b.tar.bz2 |
Refactors parts of gin:
. Runner no longer extends ContextHolder. It will still have a
ContextHolder, but not own it. This enables a couple of
things:
. Runner no longer need own a v8::Context.
. Runner can be lazily created after the ContextHolder.
. Runner becomes a (mostly) pure virtual interface. This enables an
implementation to execute through blink rather than v8 directly.
. What was Runner is now DefaultRunner (and
DefaultRunnerDelegate). I'm not a fan of these names, if you have
better ideas let me know. Maybe DirectRunner?
BUG=none
TEST=none
R=abarth@chromium.org
Review URL: https://codereview.chromium.org/179803007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/runner.h')
-rw-r--r-- | gin/runner.h | 51 |
1 files changed, 15 insertions, 36 deletions
diff --git a/gin/runner.h b/gin/runner.h index 943bced..36a75d2 100644 --- a/gin/runner.h +++ b/gin/runner.h @@ -10,47 +10,28 @@ #include "base/memory/weak_ptr.h" #include "gin/gin_export.h" #include "gin/public/context_holder.h" +#include "v8/include/v8.h" namespace gin { -class Runner; -class TryCatch; - -// Subclass RunnerDelegate to customize the behavior of |Runner|. Typical -// embedders will want to subclass one of the specialized RunnerDelegates, -// such as ModuleRunnerDelegate. -class GIN_EXPORT RunnerDelegate { - public: - RunnerDelegate(); - virtual ~RunnerDelegate(); - - // Returns the template for the global object. - virtual v8::Handle<v8::ObjectTemplate> GetGlobalTemplate(Runner* runner); - virtual void DidCreateContext(Runner* runner); - virtual void WillRunScript(Runner* runner); - virtual void DidRunScript(Runner* runner); - virtual void UnhandledException(Runner* runner, TryCatch& try_catch); -}; - -// Runner lets you run code in a v8::Context. Upon construction, Runner will -// create a v8::Context. Upon destruction, Runner will dispose the context. -class GIN_EXPORT Runner : public ContextHolder { +// Runner is responsible for running code in a v8::Context. +class GIN_EXPORT Runner { public: - Runner(RunnerDelegate* delegate, v8::Isolate* isolate); - ~Runner(); + Runner(); + virtual ~Runner(); // Before running script in this context, you'll need to enter the runner's // context by creating an instance of Runner::Scope on the stack. - void Run(const std::string& source, const std::string& resource_name); - void Run(v8::Handle<v8::Script> script); - - v8::Handle<v8::Value> Call(v8::Handle<v8::Function> function, - v8::Handle<v8::Value> receiver, - int argc, - v8::Handle<v8::Value> argv[]); - - v8::Handle<v8::Object> global() const { - return context()->Global(); + virtual void Run(const std::string& source, + const std::string& resource_name) = 0; + virtual v8::Handle<v8::Value> Call(v8::Handle<v8::Function> function, + v8::Handle<v8::Value> receiver, + int argc, + v8::Handle<v8::Value> argv[]) = 0; + virtual ContextHolder* GetContextHolder() = 0; + + v8::Handle<v8::Object> global() { + return GetContextHolder()->context()->Global(); } // Useful for running script in this context asynchronously. Rather than @@ -75,8 +56,6 @@ class GIN_EXPORT Runner : public ContextHolder { private: friend class Scope; - RunnerDelegate* delegate_; - base::WeakPtrFactory<Runner> weak_factory_; DISALLOW_COPY_AND_ASSIGN(Runner); |