Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1229)

Unified Diff: gin/runner.h

Issue 67763002: Add gin, a lightweight bindings system for V8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Aaron's comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gin/per_isolate_data.cc ('k') | gin/runner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/runner.h
diff --git a/gin/runner.h b/gin/runner.h
new file mode 100644
index 0000000000000000000000000000000000000000..c74de16c72067e7b226d26d8c2ebb6a156327d3d
--- /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_
« no previous file with comments | « gin/per_isolate_data.cc ('k') | gin/runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698