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

Side by Side Diff: extensions/renderer/api_last_error.cc

Issue 2762623003: [Extensions Bindings] Add lastError utilities to APIBindingJSUtil (Closed)
Patch Set: . Created 3 years, 9 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "extensions/renderer/api_last_error.h" 5 #include "extensions/renderer/api_last_error.h"
6 6
7 #include "gin/converter.h" 7 #include "gin/converter.h"
8 #include "gin/handle.h" 8 #include "gin/handle.h"
9 #include "gin/object_template_builder.h" 9 #include "gin/object_template_builder.h"
10 #include "gin/wrappable.h" 10 #include "gin/wrappable.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 // See comment in SetError(). 140 // See comment in SetError().
141 v8::TryCatch try_catch(isolate); 141 v8::TryCatch try_catch(isolate);
142 try_catch.SetVerbose(true); 142 try_catch.SetVerbose(true);
143 143
144 // This Delete() can fail, but there's nothing to do if it does (the exception 144 // This Delete() can fail, but there's nothing to do if it does (the exception
145 // will be caught by the TryCatch above). 145 // will be caught by the TryCatch above).
146 parent->Delete(context, key); 146 parent->Delete(context, key);
147 } 147 }
148 148
149 bool APILastError::HasError(v8::Local<v8::Context> context) {
150 v8::Isolate* isolate = context->GetIsolate();
151 v8::HandleScope handle_scope(isolate);
152
153 // See comment in SetError().
154 v8::TryCatch try_catch(isolate);
155 try_catch.SetVerbose(true);
156
157 v8::Local<v8::Object> parent = get_parent_.Run(context);
158 if (parent.IsEmpty())
159 return false;
160 v8::Local<v8::Value> error;
161 if (!parent->Get(context, gin::StringToSymbol(isolate, kLastErrorProperty))
162 .ToLocal(&error)) {
163 return false;
164 }
165
166 LastErrorObject* last_error = nullptr;
167 return gin::Converter<LastErrorObject*>::FromV8(context->GetIsolate(), error,
168 &last_error);
169 }
170
149 } // namespace extensions 171 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698