Chromium Code Reviews| 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/per_context_data.h" | 8 #include "gin/per_context_data.h" |
| 9 #include "gin/try_catch.h" | 9 #include "gin/try_catch.h" |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 void RunnerDelegate::DidCreateContext(Runner* runner) { | 30 void RunnerDelegate::DidCreateContext(Runner* runner) { |
| 31 } | 31 } |
| 32 | 32 |
| 33 void RunnerDelegate::WillRunScript(Runner* runner) { | 33 void RunnerDelegate::WillRunScript(Runner* runner) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 void RunnerDelegate::DidRunScript(Runner* runner) { | 36 void RunnerDelegate::DidRunScript(Runner* runner) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 void RunnerDelegate::UnhandledException(Runner* runner, TryCatch& try_catch) { | 39 void RunnerDelegate::UnhandledException(Runner* runner, TryCatch& try_catch) { |
| 40 CHECK(false) << try_catch.GetStackTrace(); | |
|
Aaron Boodman
2013/12/21 01:44:30
This seems like a better default behavior than wha
| |
| 40 } | 41 } |
| 41 | 42 |
| 42 Runner::Runner(RunnerDelegate* delegate, Isolate* isolate) | 43 Runner::Runner(RunnerDelegate* delegate, Isolate* isolate) |
| 43 : ContextHolder(isolate), | 44 : ContextHolder(isolate), |
| 44 delegate_(delegate), | 45 delegate_(delegate), |
| 45 weak_factory_(this) { | 46 weak_factory_(this) { |
| 46 v8::Isolate::Scope isolate_scope(isolate); | 47 v8::Isolate::Scope isolate_scope(isolate); |
| 47 HandleScope handle_scope(isolate); | 48 HandleScope handle_scope(isolate); |
| 48 v8::Handle<v8::Context> context = | 49 v8::Handle<v8::Context> context = |
| 49 Context::New(isolate, NULL, delegate_->GetGlobalTemplate(this)); | 50 Context::New(isolate, NULL, delegate_->GetGlobalTemplate(this)); |
| 50 | 51 |
| 51 SetContext(context); | 52 SetContext(context); |
| 52 PerContextData::From(context)->set_runner(this); | 53 PerContextData::From(context)->set_runner(this); |
| 53 | 54 |
| 54 v8::Context::Scope scope(context); | 55 v8::Context::Scope scope(context); |
| 55 delegate_->DidCreateContext(this); | 56 delegate_->DidCreateContext(this); |
| 56 } | 57 } |
| 57 | 58 |
| 58 Runner::~Runner() { | 59 Runner::~Runner() { |
| 59 } | 60 } |
| 60 | 61 |
| 61 void Runner::Run(const std::string& source, const std::string& resource_name) { | 62 void Runner::Run(const std::string& source, const std::string& resource_name) { |
| 63 TryCatch try_catch; | |
| 62 Run(Script::New(StringToV8(isolate(), source), | 64 Run(Script::New(StringToV8(isolate(), source), |
| 63 StringToV8(isolate(), resource_name))); | 65 StringToV8(isolate(), resource_name))); |
| 66 if (try_catch.HasCaught()) { | |
| 67 delegate_->UnhandledException(this, try_catch); | |
| 68 } | |
| 64 } | 69 } |
| 65 | 70 |
| 66 void Runner::Run(v8::Handle<Script> script) { | 71 void Runner::Run(v8::Handle<Script> script) { |
| 67 TryCatch try_catch; | 72 TryCatch try_catch; |
| 68 delegate_->WillRunScript(this); | 73 delegate_->WillRunScript(this); |
| 69 | 74 |
| 70 script->Run(); | 75 script->Run(); |
| 71 | 76 |
| 72 delegate_->DidRunScript(this); | 77 delegate_->DidRunScript(this); |
| 73 if (try_catch.HasCaught()) | 78 if (try_catch.HasCaught()) { |
| 74 delegate_->UnhandledException(this, try_catch); | 79 delegate_->UnhandledException(this, try_catch); |
| 80 } | |
| 75 } | 81 } |
| 76 | 82 |
| 77 v8::Handle<v8::Value> Runner::Call(v8::Handle<v8::Function> function, | 83 v8::Handle<v8::Value> Runner::Call(v8::Handle<v8::Function> function, |
| 78 v8::Handle<v8::Value> receiver, | 84 v8::Handle<v8::Value> receiver, |
| 79 int argc, | 85 int argc, |
| 80 v8::Handle<v8::Value> argv[]) { | 86 v8::Handle<v8::Value> argv[]) { |
| 81 TryCatch try_catch; | 87 TryCatch try_catch; |
| 82 delegate_->WillRunScript(this); | 88 delegate_->WillRunScript(this); |
| 83 | 89 |
| 84 v8::Handle<v8::Value> result = function->Call(receiver, argc, argv); | 90 v8::Handle<v8::Value> result = function->Call(receiver, argc, argv); |
| 85 | 91 |
| 86 delegate_->DidRunScript(this); | 92 delegate_->DidRunScript(this); |
| 87 if (try_catch.HasCaught()) | 93 if (try_catch.HasCaught()) |
| 88 delegate_->UnhandledException(this, try_catch); | 94 delegate_->UnhandledException(this, try_catch); |
| 89 | 95 |
| 90 return result; | 96 return result; |
| 91 } | 97 } |
| 92 | 98 |
| 93 Runner::Scope::Scope(Runner* runner) | 99 Runner::Scope::Scope(Runner* runner) |
| 94 : isolate_scope_(runner->isolate()), | 100 : isolate_scope_(runner->isolate()), |
| 95 handle_scope_(runner->isolate()), | 101 handle_scope_(runner->isolate()), |
| 96 scope_(runner->context()) { | 102 scope_(runner->context()) { |
| 97 } | 103 } |
| 98 | 104 |
| 99 Runner::Scope::~Scope() { | 105 Runner::Scope::~Scope() { |
| 100 } | 106 } |
| 101 | 107 |
| 102 } // namespace gin | 108 } // namespace gin |
| OLD | NEW |