diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-17 17:46:07 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-17 17:46:07 +0000 |
commit | 97f21cad04bb80834a8cc84bfc3dd24a96531a16 (patch) | |
tree | 4e49aa68b49f90e4e68c220cc9d9b04be95a6a5d /gin/runner.h | |
parent | 00509a3ac0c1c11e97852d2331d116df6754eb5d (diff) | |
download | chromium_src-97f21cad04bb80834a8cc84bfc3dd24a96531a16.zip chromium_src-97f21cad04bb80834a8cc84bfc3dd24a96531a16.tar.gz chromium_src-97f21cad04bb80834a8cc84bfc3dd24a96531a16.tar.bz2 |
This CL implements the Asynchronous Module Definition (AMD)
API, which we plan to use for JavaScript in Mojo. We don't
yet implement every feature in the AMD spec
<https://github.com/amdjs/amdjs-api/wiki/AMD>, but we
implement the basic framework, which will let us get started
writing and testing JavaScript modules in Mojo.
The two other leading choices for a modules system are
CommonJS and ES6 modules. We decided not to use CommonJS,
despite its popularity, because it implies the ability to
load modules synchronously. That works well in server
environments like node.js, but it won't work well for Mojo
where modules might be loaded across a network.
I would really like to have used ES6 modules, but the spec
isn't finalized yet and V8 doesn't yet implement them. It's
likely that we'll replace this AMD module system with ES6
modules once ES6 modules are ready.
Structurally, I've implemented AMD in the ModuleRegistry
class in a new "modules" directory in Gin. Nothing else in
Gin (except the tests) depends on ModuleRegistry, which
means folks are free to use Gin without AMD. At the Mojo
layer, I've added a dependency on AMD.
BUG=317398
Review URL: https://codereview.chromium.org/62333018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235543 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/runner.h')
-rw-r--r-- | gin/runner.h | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/gin/runner.h b/gin/runner.h index c74de16..3e999e1f 100644 --- a/gin/runner.h +++ b/gin/runner.h @@ -5,8 +5,8 @@ #ifndef GIN_RUNNER_H_ #define GIN_RUNNER_H_ -#include "base/basictypes.h" -#include "v8/include/v8.h" +#include <string> +#include "gin/context_holder.h" namespace gin { @@ -14,26 +14,23 @@ 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: + RunnerDelegate(); virtual ~RunnerDelegate(); + + // Returns the template for the global object. + virtual v8::Handle<v8::ObjectTemplate> GetGlobalTemplate(Runner* runner); + + virtual void DidCreateContext(Runner* runner); }; -class Runner { +class Runner : public ContextHolder { public: Runner(RunnerDelegate* delegate, v8::Isolate* isolate); ~Runner(); + void Run(const std::string& script); 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(); } @@ -53,11 +50,7 @@ class Runner { private: friend class Scope; - v8::Handle<v8::Function> GetMain(); - RunnerDelegate* delegate_; - v8::Isolate* isolate_; - v8::Persistent<v8::Context> context_; DISALLOW_COPY_AND_ASSIGN(Runner); }; |