diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-10 05:00:50 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-10 05:00:50 +0000 |
commit | a22998a223ecdcd926d152baea8a8703bcb57d61 (patch) | |
tree | ccb6b71bcc50b61c6671d955fbc409802f0c8d95 /gin/runner.h | |
parent | 1cde19eb7e17b16645fb75a50f3250218d53cd17 (diff) | |
download | chromium_src-a22998a223ecdcd926d152baea8a8703bcb57d61.zip chromium_src-a22998a223ecdcd926d152baea8a8703bcb57d61.tar.gz chromium_src-a22998a223ecdcd926d152baea8a8703bcb57d61.tar.bz2 |
This CL introduces a lightweight bindings system for V8 called gin
Unlike the extensions V8 bindings, gin is based on ObjectTemplates rather than
on evaluating script. Unlike the Blink V8 bindings, gin isn't tightly coupled to
Blink. In fact, gin's only link-time dependency is V8. We plan to use gin to build
the V8 bindings for Mojo (see https://codereview.chromium.org/59153005/ for
an example of how they will be used).
In the long term, gin could serve as a basis for both the Blink and the extension
system bindings, but we don't have any immediate plans to pursue that use of
this code.
This code is largely inspired by a lightweight bindings system designed by
Aaron Boodman.
Review URL: https://codereview.chromium.org/67763002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/runner.h')
-rw-r--r-- | gin/runner.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/gin/runner.h b/gin/runner.h new file mode 100644 index 0000000..c74de16 --- /dev/null +++ b/gin/runner.h @@ -0,0 +1,67 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GIN_RUNNER_H_ +#define GIN_RUNNER_H_ + +#include "base/basictypes.h" +#include "v8/include/v8.h" + +namespace gin { + +class Runner; + +class RunnerDelegate { + public: + // Returns the object that is passed to the script's |main| function. + virtual v8::Handle<v8::Object> CreateRootObject(Runner* runner) = 0; + + protected: + virtual ~RunnerDelegate(); +}; + +class Runner { + public: + Runner(RunnerDelegate* delegate, v8::Isolate* isolate); + ~Runner(); + + void Run(v8::Handle<v8::Script> script); + + v8::Isolate* isolate() const { return isolate_; } + + v8::Handle<v8::Context> context() const { + return v8::Local<v8::Context>::New(isolate_, context_); + } + + v8::Handle<v8::Object> global() const { + return context()->Global(); + } + + class Scope { + public: + explicit Scope(Runner* runner); + ~Scope(); + + private: + v8::HandleScope handle_scope_; + v8::Context::Scope scope_; + + DISALLOW_COPY_AND_ASSIGN(Scope); + }; + + private: + friend class Scope; + + v8::Handle<v8::Function> GetMain(); + + RunnerDelegate* delegate_; + v8::Isolate* isolate_; + v8::Persistent<v8::Context> context_; + + DISALLOW_COPY_AND_ASSIGN(Runner); +}; + +} // namespace gin + +#endif // GIN_RUNNER_H_ |