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

Unified Diff: gin/runner.cc

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/runner.h ('k') | gin/runner_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/runner.cc
diff --git a/gin/runner.cc b/gin/runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf9839951f5381a6f6fcb0d186fbf437c7e2cee2
--- /dev/null
+++ b/gin/runner.cc
@@ -0,0 +1,64 @@
+// 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.
+
+#include "gin/runner.h"
+
+#include "gin/converter.h"
+
+using v8::Context;
+using v8::Function;
+using v8::Handle;
+using v8::HandleScope;
+using v8::Isolate;
+using v8::Local;
+using v8::Object;
+using v8::Script;
+using v8::String;
+using v8::Value;
+
+namespace gin {
+
+RunnerDelegate::~RunnerDelegate() {
+}
+
+Runner::Runner(RunnerDelegate* delegate, Isolate* isolate)
+ : delegate_(delegate),
+ isolate_(isolate) {
+ HandleScope handle_scope(isolate_);
+ context_.Reset(isolate_, Context::New(isolate_));
+}
+
+Runner::~Runner() {
+ // TODO(abarth): Figure out how to set kResetInDestructor to true.
+ context_.Reset();
+}
+
+void Runner::Run(Handle<Script> script) {
+ script->Run();
+ Handle<Function> main = GetMain();
+ if (main.IsEmpty())
+ return;
+ Handle<Value> argv[] = { delegate_->CreateRootObject(this) };
+ main->Call(global(), 1, argv);
+}
+
+v8::Handle<v8::Function> Runner::GetMain() {
+ Handle<Value> property = global()->Get(StringToV8(isolate_, "main"));
+ if (property.IsEmpty())
+ return v8::Handle<v8::Function>();
+ Handle<Function> main;
+ if (!ConvertFromV8(property, &main))
+ return v8::Handle<v8::Function>();
+ return main;
+}
+
+Runner::Scope::Scope(Runner* runner)
+ : handle_scope_(runner->isolate_),
+ scope_(Local<Context>::New(runner->isolate_, runner->context_)) {
+}
+
+Runner::Scope::~Scope() {
+}
+
+} // namespace gin
« no previous file with comments | « gin/runner.h ('k') | gin/runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698