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

Side by Side Diff: gin/runner.cc

Issue 74753002: Introduce gin_shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style nits 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gin/runner.h" 5 #include "gin/runner.h"
6 6
7 #include "gin/converter.h" 7 #include "gin/converter.h"
8 #include "gin/try_catch.h"
8 9
9 using v8::Context; 10 using v8::Context;
10 using v8::Handle;
11 using v8::HandleScope; 11 using v8::HandleScope;
12 using v8::Isolate; 12 using v8::Isolate;
13 using v8::Object; 13 using v8::Object;
14 using v8::ObjectTemplate; 14 using v8::ObjectTemplate;
15 using v8::Script; 15 using v8::Script;
16 16
17 namespace gin { 17 namespace gin {
18 18
19 RunnerDelegate::RunnerDelegate() { 19 RunnerDelegate::RunnerDelegate() {
20 } 20 }
21 21
22 RunnerDelegate::~RunnerDelegate() { 22 RunnerDelegate::~RunnerDelegate() {
23 } 23 }
24 24
25 Handle<ObjectTemplate> RunnerDelegate::GetGlobalTemplate(Runner* runner) { 25 v8::Handle<ObjectTemplate> RunnerDelegate::GetGlobalTemplate(Runner* runner) {
26 return Handle<ObjectTemplate>(); 26 return v8::Handle<ObjectTemplate>();
27 } 27 }
28 28
29 void RunnerDelegate::DidCreateContext(Runner* runner) { 29 void RunnerDelegate::DidCreateContext(Runner* runner) {
30 } 30 }
31 31
32 void RunnerDelegate::WillRunScript(Runner* runner, v8::Handle<Script> script) {
33 }
34
35 void RunnerDelegate::DidRunScript(Runner* runner, v8::Handle<Script> script) {
36 }
37
38 void RunnerDelegate::UnhandledException(Runner* runner, TryCatch& try_catch) {
39 }
40
32 Runner::Runner(RunnerDelegate* delegate, Isolate* isolate) 41 Runner::Runner(RunnerDelegate* delegate, Isolate* isolate)
33 : ContextHolder(isolate), 42 : ContextHolder(isolate),
34 delegate_(delegate) { 43 delegate_(delegate),
44 weak_factory_(this) {
35 HandleScope handle_scope(isolate); 45 HandleScope handle_scope(isolate);
36 SetContext(Context::New(isolate, NULL, delegate_->GetGlobalTemplate(this))); 46 SetContext(Context::New(isolate, NULL, delegate_->GetGlobalTemplate(this)));
37 47
38 v8::Context::Scope scope(context()); 48 v8::Context::Scope scope(context());
39 delegate_->DidCreateContext(this); 49 delegate_->DidCreateContext(this);
40 } 50 }
41 51
42 Runner::~Runner() { 52 Runner::~Runner() {
43 } 53 }
44 54
45 void Runner::Run(const std::string& script) { 55 void Runner::Run(const std::string& script) {
46 Run(Script::New(StringToV8(isolate(), script))); 56 Run(Script::New(StringToV8(isolate(), script)));
47 } 57 }
48 58
49 void Runner::Run(Handle<Script> script) { 59 void Runner::Run(v8::Handle<Script> script) {
50 script->Run(); 60 delegate_->WillRunScript(this, script);
61 {
62 TryCatch try_catch;
63 script->Run();
jochen (gone - plz use gerrit) 2013/11/18 12:46:05 consider locking the isolate and entering before r
abarth-chromium 2013/11/18 15:33:06 Done. Is there some way to enable an ASSERT in V8
abarth-chromium 2013/11/18 15:36:40 Adding a v8::Locker causes an ASSERT. I've left i
64 if (try_catch.HasCaught())
65 delegate_->UnhandledException(this, try_catch);
66 }
67 delegate_->DidRunScript(this, script);
51 } 68 }
52 69
53 Runner::Scope::Scope(Runner* runner) 70 Runner::Scope::Scope(Runner* runner)
54 : handle_scope_(runner->isolate()), 71 : handle_scope_(runner->isolate()),
55 scope_(runner->context()) { 72 scope_(runner->context()) {
56 } 73 }
57 74
58 Runner::Scope::~Scope() { 75 Runner::Scope::~Scope() {
59 } 76 }
60 77
61 } // namespace gin 78 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698