| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shell_runner.h" | 5 #include "gin/shell_runner.h" |
| 6 | 6 |
| 7 #include "gin/converter.h" | 7 #include "gin/converter.h" |
| 8 #include "gin/modules/module_registry.h" | 8 #include "gin/modules/module_registry.h" |
| 9 #include "gin/per_context_data.h" | 9 #include "gin/per_context_data.h" |
| 10 #include "gin/public/context_holder.h" | 10 #include "gin/public/context_holder.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 v8::Context::Scope scope(context); | 59 v8::Context::Scope scope(context); |
| 60 delegate_->DidCreateContext(this); | 60 delegate_->DidCreateContext(this); |
| 61 } | 61 } |
| 62 | 62 |
| 63 ShellRunner::~ShellRunner() { | 63 ShellRunner::~ShellRunner() { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ShellRunner::Run(const std::string& source, | 66 void ShellRunner::Run(const std::string& source, |
| 67 const std::string& resource_name) { | 67 const std::string& resource_name) { |
| 68 TryCatch try_catch; |
| 68 v8::Isolate* isolate = GetContextHolder()->isolate(); | 69 v8::Isolate* isolate = GetContextHolder()->isolate(); |
| 69 TryCatch try_catch(isolate); | 70 v8::Local<Script> script = Script::Compile( |
| 70 v8::ScriptOrigin origin(StringToV8(isolate, resource_name)); | 71 StringToV8(isolate, source), StringToV8(isolate, resource_name)); |
| 71 auto maybe_script = Script::Compile(GetContextHolder()->context(), | 72 if (try_catch.HasCaught()) { |
| 72 StringToV8(isolate, source), &origin); | |
| 73 v8::Local<Script> script; | |
| 74 if (!maybe_script.ToLocal(&script)) { | |
| 75 delegate_->UnhandledException(this, try_catch); | 73 delegate_->UnhandledException(this, try_catch); |
| 76 return; | 74 return; |
| 77 } | 75 } |
| 78 | 76 |
| 79 Run(script); | 77 Run(script); |
| 80 } | 78 } |
| 81 | 79 |
| 82 v8::Local<v8::Value> ShellRunner::Call(v8::Local<v8::Function> function, | 80 v8::Local<v8::Value> ShellRunner::Call(v8::Local<v8::Function> function, |
| 83 v8::Local<v8::Value> receiver, | 81 v8::Local<v8::Value> receiver, |
| 84 int argc, | 82 int argc, |
| 85 v8::Local<v8::Value> argv[]) { | 83 v8::Local<v8::Value> argv[]) { |
| 86 TryCatch try_catch(GetContextHolder()->isolate()); | 84 TryCatch try_catch; |
| 87 delegate_->WillRunScript(this); | 85 delegate_->WillRunScript(this); |
| 88 | 86 |
| 89 auto maybe_result = | 87 v8::Local<v8::Value> result = function->Call(receiver, argc, argv); |
| 90 function->Call(GetContextHolder()->context(), receiver, argc, argv); | |
| 91 | 88 |
| 92 delegate_->DidRunScript(this); | 89 delegate_->DidRunScript(this); |
| 93 v8::Local<v8::Value> result; | 90 if (try_catch.HasCaught()) |
| 94 if (!maybe_result.ToLocal(&result)) | |
| 95 delegate_->UnhandledException(this, try_catch); | 91 delegate_->UnhandledException(this, try_catch); |
| 96 | 92 |
| 97 return result; | 93 return result; |
| 98 } | 94 } |
| 99 | 95 |
| 100 ContextHolder* ShellRunner::GetContextHolder() { | 96 ContextHolder* ShellRunner::GetContextHolder() { |
| 101 return context_holder_.get(); | 97 return context_holder_.get(); |
| 102 } | 98 } |
| 103 | 99 |
| 104 void ShellRunner::Run(v8::Local<Script> script) { | 100 void ShellRunner::Run(v8::Local<Script> script) { |
| 105 TryCatch try_catch(GetContextHolder()->isolate()); | 101 TryCatch try_catch; |
| 106 delegate_->WillRunScript(this); | 102 delegate_->WillRunScript(this); |
| 107 | 103 |
| 108 auto maybe = script->Run(GetContextHolder()->context()); | 104 script->Run(); |
| 109 | 105 |
| 110 delegate_->DidRunScript(this); | 106 delegate_->DidRunScript(this); |
| 111 v8::Local<v8::Value> result; | 107 if (try_catch.HasCaught()) { |
| 112 if (!maybe.ToLocal(&result)) { | |
| 113 delegate_->UnhandledException(this, try_catch); | 108 delegate_->UnhandledException(this, try_catch); |
| 114 } | 109 } |
| 115 } | 110 } |
| 116 | 111 |
| 117 } // namespace gin | 112 } // namespace gin |
| OLD | NEW |