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

Side by Side Diff: gin/runner.cc

Issue 76353002: Introduce a Gin class instead of using global functions to control gin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 #include "gin/try_catch.h"
9 9
10 using v8::Context; 10 using v8::Context;
(...skipping 24 matching lines...) Expand all
35 void RunnerDelegate::DidRunScript(Runner* runner, v8::Handle<Script> script) { 35 void RunnerDelegate::DidRunScript(Runner* runner, v8::Handle<Script> script) {
36 } 36 }
37 37
38 void RunnerDelegate::UnhandledException(Runner* runner, TryCatch& try_catch) { 38 void RunnerDelegate::UnhandledException(Runner* runner, TryCatch& try_catch) {
39 } 39 }
40 40
41 Runner::Runner(RunnerDelegate* delegate, Isolate* isolate) 41 Runner::Runner(RunnerDelegate* delegate, Isolate* isolate)
42 : ContextHolder(isolate), 42 : ContextHolder(isolate),
43 delegate_(delegate), 43 delegate_(delegate),
44 weak_factory_(this) { 44 weak_factory_(this) {
45 v8::Isolate::Scope isolate_scope(isolate);
45 HandleScope handle_scope(isolate); 46 HandleScope handle_scope(isolate);
46 SetContext(Context::New(isolate, NULL, delegate_->GetGlobalTemplate(this))); 47 SetContext(Context::New(isolate, NULL, delegate_->GetGlobalTemplate(this)));
47 48
48 v8::Context::Scope scope(context()); 49 v8::Context::Scope scope(context());
49 delegate_->DidCreateContext(this); 50 delegate_->DidCreateContext(this);
50 } 51 }
51 52
52 Runner::~Runner() { 53 Runner::~Runner() {
53 } 54 }
54 55
55 void Runner::Run(const std::string& script) { 56 void Runner::Run(const std::string& script) {
56 Run(Script::New(StringToV8(isolate(), script))); 57 Run(Script::New(StringToV8(isolate(), script)));
57 } 58 }
58 59
59 void Runner::Run(v8::Handle<Script> script) { 60 void Runner::Run(v8::Handle<Script> script) {
60 TryCatch try_catch; 61 TryCatch try_catch;
61 delegate_->WillRunScript(this, script); 62 delegate_->WillRunScript(this, script);
62 script->Run(); 63 script->Run();
63 delegate_->DidRunScript(this, script); 64 delegate_->DidRunScript(this, script);
64 if (try_catch.HasCaught()) 65 if (try_catch.HasCaught())
65 delegate_->UnhandledException(this, try_catch); 66 delegate_->UnhandledException(this, try_catch);
66 } 67 }
67 68
68 Runner::Scope::Scope(Runner* runner) 69 Runner::Scope::Scope(Runner* runner)
69 : handle_scope_(runner->isolate()), 70 : isolate_scope_(runner->isolate()),
71 handle_scope_(runner->isolate()),
70 scope_(runner->context()) { 72 scope_(runner->context()) {
71 } 73 }
72 74
73 Runner::Scope::~Scope() { 75 Runner::Scope::~Scope() {
74 } 76 }
75 77
76 } // namespace gin 78 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698