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

Side by Side Diff: gin/shell_runner.cc

Issue 1152653004: Re-land: gin: Use V8 Maybe APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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
« no previous file with comments | « gin/shell/gin_main.cc ('k') | gin/test/file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
69 v8::Isolate* isolate = GetContextHolder()->isolate(); 68 v8::Isolate* isolate = GetContextHolder()->isolate();
70 v8::Local<Script> script = Script::Compile( 69 TryCatch try_catch(isolate);
71 StringToV8(isolate, source), StringToV8(isolate, resource_name)); 70 v8::ScriptOrigin origin(StringToV8(isolate, resource_name));
72 if (try_catch.HasCaught()) { 71 auto maybe_script = Script::Compile(GetContextHolder()->context(),
72 StringToV8(isolate, source), &origin);
73 v8::Local<Script> script;
74 if (!maybe_script.ToLocal(&script)) {
73 delegate_->UnhandledException(this, try_catch); 75 delegate_->UnhandledException(this, try_catch);
74 return; 76 return;
75 } 77 }
76 78
77 Run(script); 79 Run(script);
78 } 80 }
79 81
80 v8::Local<v8::Value> ShellRunner::Call(v8::Local<v8::Function> function, 82 v8::Local<v8::Value> ShellRunner::Call(v8::Local<v8::Function> function,
81 v8::Local<v8::Value> receiver, 83 v8::Local<v8::Value> receiver,
82 int argc, 84 int argc,
83 v8::Local<v8::Value> argv[]) { 85 v8::Local<v8::Value> argv[]) {
84 TryCatch try_catch; 86 TryCatch try_catch(GetContextHolder()->isolate());
85 delegate_->WillRunScript(this); 87 delegate_->WillRunScript(this);
86 88
87 v8::Local<v8::Value> result = function->Call(receiver, argc, argv); 89 auto maybe_result =
90 function->Call(GetContextHolder()->context(), receiver, argc, argv);
88 91
89 delegate_->DidRunScript(this); 92 delegate_->DidRunScript(this);
90 if (try_catch.HasCaught()) 93 v8::Local<v8::Value> result;
94 if (!maybe_result.ToLocal(&result))
91 delegate_->UnhandledException(this, try_catch); 95 delegate_->UnhandledException(this, try_catch);
92 96
93 return result; 97 return result;
94 } 98 }
95 99
96 ContextHolder* ShellRunner::GetContextHolder() { 100 ContextHolder* ShellRunner::GetContextHolder() {
97 return context_holder_.get(); 101 return context_holder_.get();
98 } 102 }
99 103
100 void ShellRunner::Run(v8::Local<Script> script) { 104 void ShellRunner::Run(v8::Local<Script> script) {
101 TryCatch try_catch; 105 TryCatch try_catch(GetContextHolder()->isolate());
102 delegate_->WillRunScript(this); 106 delegate_->WillRunScript(this);
103 107
104 script->Run(); 108 auto maybe = script->Run(GetContextHolder()->context());
105 109
106 delegate_->DidRunScript(this); 110 delegate_->DidRunScript(this);
107 if (try_catch.HasCaught()) { 111 v8::Local<v8::Value> result;
112 if (!maybe.ToLocal(&result)) {
108 delegate_->UnhandledException(this, try_catch); 113 delegate_->UnhandledException(this, try_catch);
109 } 114 }
110 } 115 }
111 116
112 } // namespace gin 117 } // namespace gin
OLDNEW
« no previous file with comments | « gin/shell/gin_main.cc ('k') | gin/test/file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698