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

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

Issue 2819683002: [Extenisons Bindings] Don't throw unchecked errors; add console errors (Closed)
Patch Set: jbroman's Created 3 years, 8 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 | « extensions/renderer/api_last_error.h ('k') | extensions/renderer/api_last_error_unittest.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 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 std::string error_; 46 std::string error_;
47 bool accessed_ = false; 47 bool accessed_ = false;
48 48
49 DISALLOW_COPY_AND_ASSIGN(LastErrorObject); 49 DISALLOW_COPY_AND_ASSIGN(LastErrorObject);
50 }; 50 };
51 51
52 gin::WrapperInfo LastErrorObject::kWrapperInfo = {gin::kEmbedderNativeGin}; 52 gin::WrapperInfo LastErrorObject::kWrapperInfo = {gin::kEmbedderNativeGin};
53 53
54 } // namespace 54 } // namespace
55 55
56 APILastError::APILastError(const GetParent& get_parent) 56 APILastError::APILastError(const GetParent& get_parent,
57 : get_parent_(get_parent) {} 57 const AddConsoleError& add_console_error)
58 : get_parent_(get_parent), add_console_error_(add_console_error) {}
58 APILastError::APILastError(APILastError&& other) = default; 59 APILastError::APILastError(APILastError&& other) = default;
59 APILastError::~APILastError() = default; 60 APILastError::~APILastError() = default;
60 61
61 void APILastError::SetError(v8::Local<v8::Context> context, 62 void APILastError::SetError(v8::Local<v8::Context> context,
62 const std::string& error) { 63 const std::string& error) {
63 v8::Isolate* isolate = context->GetIsolate(); 64 v8::Isolate* isolate = context->GetIsolate();
64 DCHECK(isolate); 65 DCHECK(isolate);
65 v8::HandleScope handle_scope(isolate); 66 v8::HandleScope handle_scope(isolate);
66 67
67 // The various accesses/sets on an object could potentially fail if script has 68 // The various accesses/sets on an object could potentially fail if script has
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 v8::Local<v8::Value> error; 127 v8::Local<v8::Value> error;
127 if (!parent->Get(context, key).ToLocal(&error)) 128 if (!parent->Get(context, key).ToLocal(&error))
128 return; 129 return;
129 if (!gin::Converter<LastErrorObject*>::FromV8(context->GetIsolate(), error, 130 if (!gin::Converter<LastErrorObject*>::FromV8(context->GetIsolate(), error,
130 &last_error)) { 131 &last_error)) {
131 return; 132 return;
132 } 133 }
133 } 134 }
134 135
135 if (report_if_unchecked && !last_error->accessed()) { 136 if (report_if_unchecked && !last_error->accessed()) {
136 isolate->ThrowException( 137 add_console_error_.Run(
137 v8::Exception::Error(gin::StringToV8(isolate, last_error->error()))); 138 context, "Unchecked runtime.lastError: " + last_error->error());
138 } 139 }
139 140
140 // See comment in SetError(). 141 // See comment in SetError().
141 v8::TryCatch try_catch(isolate); 142 v8::TryCatch try_catch(isolate);
142 try_catch.SetVerbose(true); 143 try_catch.SetVerbose(true);
143 144
144 // This Delete() can fail, but there's nothing to do if it does (the exception 145 // This Delete() can fail, but there's nothing to do if it does (the exception
145 // will be caught by the TryCatch above). 146 // will be caught by the TryCatch above).
146 parent->Delete(context, key).ToChecked(); 147 parent->Delete(context, key).ToChecked();
147 } 148 }
(...skipping 14 matching lines...) Expand all
162 .ToLocal(&error)) { 163 .ToLocal(&error)) {
163 return false; 164 return false;
164 } 165 }
165 166
166 LastErrorObject* last_error = nullptr; 167 LastErrorObject* last_error = nullptr;
167 return gin::Converter<LastErrorObject*>::FromV8(context->GetIsolate(), error, 168 return gin::Converter<LastErrorObject*>::FromV8(context->GetIsolate(), error,
168 &last_error); 169 &last_error);
169 } 170 }
170 171
171 } // namespace extensions 172 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api_last_error.h ('k') | extensions/renderer/api_last_error_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698