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(); |
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)); |
(...skipping 20 matching lines...) Expand all Loading... |
70 Run(script); | 71 Run(script); |
71 } | 72 } |
72 | 73 |
73 void Runner::Run(v8::Handle<Script> script) { | 74 void Runner::Run(v8::Handle<Script> script) { |
74 TryCatch try_catch; | 75 TryCatch try_catch; |
75 delegate_->WillRunScript(this); | 76 delegate_->WillRunScript(this); |
76 | 77 |
77 script->Run(); | 78 script->Run(); |
78 | 79 |
79 delegate_->DidRunScript(this); | 80 delegate_->DidRunScript(this); |
80 if (try_catch.HasCaught()) | 81 if (try_catch.HasCaught()) { |
81 delegate_->UnhandledException(this, try_catch); | 82 delegate_->UnhandledException(this, try_catch); |
| 83 } |
82 } | 84 } |
83 | 85 |
84 v8::Handle<v8::Value> Runner::Call(v8::Handle<v8::Function> function, | 86 v8::Handle<v8::Value> Runner::Call(v8::Handle<v8::Function> function, |
85 v8::Handle<v8::Value> receiver, | 87 v8::Handle<v8::Value> receiver, |
86 int argc, | 88 int argc, |
87 v8::Handle<v8::Value> argv[]) { | 89 v8::Handle<v8::Value> argv[]) { |
88 TryCatch try_catch; | 90 TryCatch try_catch; |
89 delegate_->WillRunScript(this); | 91 delegate_->WillRunScript(this); |
90 | 92 |
91 v8::Handle<v8::Value> result = function->Call(receiver, argc, argv); | 93 v8::Handle<v8::Value> result = function->Call(receiver, argc, argv); |
92 | 94 |
93 delegate_->DidRunScript(this); | 95 delegate_->DidRunScript(this); |
94 if (try_catch.HasCaught()) { | 96 if (try_catch.HasCaught()) { |
95 delegate_->UnhandledException(this, try_catch); | 97 delegate_->UnhandledException(this, try_catch); |
96 } | 98 } |
97 | 99 |
98 return result; | 100 return result; |
99 } | 101 } |
100 | 102 |
101 Runner::Scope::Scope(Runner* runner) | 103 Runner::Scope::Scope(Runner* runner) |
102 : isolate_scope_(runner->isolate()), | 104 : isolate_scope_(runner->isolate()), |
103 handle_scope_(runner->isolate()), | 105 handle_scope_(runner->isolate()), |
104 scope_(runner->context()) { | 106 scope_(runner->context()) { |
105 } | 107 } |
106 | 108 |
107 Runner::Scope::~Scope() { | 109 Runner::Scope::~Scope() { |
108 } | 110 } |
109 | 111 |
110 } // namespace gin | 112 } // namespace gin |
OLD | NEW |