| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |