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

Side by Side Diff: Source/bindings/core/v8/PrivateScriptRunner.cpp

Issue 594213002: Inline exception handling code into PrivateScriptRunner helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 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 | « Source/bindings/core/v8/PrivateScriptRunner.h ('k') | Source/bindings/templates/attributes.cpp » ('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 "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/PrivateScriptRunner.h" 6 #include "bindings/core/v8/PrivateScriptRunner.h"
7 7
8 #include "bindings/core/v8/DOMWrapperWorld.h" 8 #include "bindings/core/v8/DOMWrapperWorld.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 if (context.IsEmpty()) 179 if (context.IsEmpty())
180 return v8::Handle<v8::Value>(); 180 return v8::Handle<v8::Value>();
181 ScriptState* scriptState = ScriptState::from(context); 181 ScriptState* scriptState = ScriptState::from(context);
182 if (!scriptState->executionContext()) 182 if (!scriptState->executionContext())
183 return v8::Handle<v8::Value>(); 183 return v8::Handle<v8::Value>();
184 184
185 ScriptState::Scope scope(scriptState); 185 ScriptState::Scope scope(scriptState);
186 return classObjectOfPrivateScript(scriptState, className); 186 return classObjectOfPrivateScript(scriptState, className);
187 } 187 }
188 188
189 v8::Handle<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(ScriptState* sc riptState, String className, String attributeName, v8::Handle<v8::Value> holder) 189 namespace {
190 {
191 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
192 v8::Handle<v8::Value> descriptor = classObject->GetOwnPropertyDescriptor(v8S tring(scriptState->isolate(), attributeName));
193 if (descriptor.IsEmpty() || !descriptor->IsObject()) {
194 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className.utf8().data(), at tributeName.utf8().data());
195 RELEASE_ASSERT_NOT_REACHED();
196 }
197 v8::Handle<v8::Value> getter = v8::Handle<v8::Object>::Cast(descriptor)->Get (v8String(scriptState->isolate(), "get"));
198 if (getter.IsEmpty() || !getter->IsFunction()) {
199 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className.utf8().data(), at tributeName.utf8().data());
200 RELEASE_ASSERT_NOT_REACHED();
201 }
202 initializeHolderIfNeeded(scriptState, classObject, holder);
203 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(getter), scriptState->executionContext(), holder, 0, 0, scriptState->isolate());
204 }
205 190
206 void PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, String className, String attributeName, v8::Handle<v8::Value> holder, v8::Handle<v8::V alue> v8Value) 191 void rethrowExceptionInPrivateScript(v8::Isolate* isolate, v8::TryCatch& block, ScriptState* scriptStateInUserScript, ExceptionState::Context errorContext, cons t char* propertyName, const char* interfaceName)
207 {
208 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
209 v8::Handle<v8::Value> descriptor = classObject->GetOwnPropertyDescriptor(v8S tring(scriptState->isolate(), attributeName));
210 if (descriptor.IsEmpty() || !descriptor->IsObject()) {
211 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className.utf8().data(), at tributeName.utf8().data());
212 RELEASE_ASSERT_NOT_REACHED();
213 }
214 v8::Handle<v8::Value> setter = v8::Handle<v8::Object>::Cast(descriptor)->Get (v8String(scriptState->isolate(), "set"));
215 if (setter.IsEmpty() || !setter->IsFunction()) {
216 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className.utf8().data(), at tributeName.utf8().data());
217 RELEASE_ASSERT_NOT_REACHED();
218 }
219 initializeHolderIfNeeded(scriptState, classObject, holder);
220 v8::Handle<v8::Value> argv[] = { v8Value };
221 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(setter), scriptS tate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, scriptState->iso late());
222 }
223
224 v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState , String className, String methodName, v8::Handle<v8::Value> holder, int argc, v 8::Handle<v8::Value> argv[])
225 {
226 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
227 v8::Handle<v8::Value> method = classObject->Get(v8String(scriptState->isolat e(), methodName));
228 if (method.IsEmpty() || !method->IsFunction()) {
229 fprintf(stderr, "Private script error: Target DOM method was not found. (Class name = %s, Method name = %s)\n", className.utf8().data(), methodName.utf8 ().data());
230 RELEASE_ASSERT_NOT_REACHED();
231 }
232 initializeHolderIfNeeded(scriptState, classObject, holder);
233 return V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(method), scriptState->executionContext(), holder, argc, argv, scriptState->isolate());
234 }
235
236 void PrivateScriptRunner::rethrowExceptionInPrivateScript(v8::Isolate* isolate, v8::TryCatch& block, ScriptState* scriptStateInUserScript, ExceptionState::Conte xt errorContext, const char* propertyName, const char* interfaceName)
237 { 192 {
238 v8::Handle<v8::Value> exception = block.Exception(); 193 v8::Handle<v8::Value> exception = block.Exception();
239 RELEASE_ASSERT(!exception.IsEmpty() && exception->IsObject()); 194 RELEASE_ASSERT(!exception.IsEmpty() && exception->IsObject());
240 195
241 v8::Handle<v8::Object> exceptionObject = v8::Handle<v8::Object>::Cast(except ion); 196 v8::Handle<v8::Object> exceptionObject = v8::Handle<v8::Object>::Cast(except ion);
242 v8::Handle<v8::Value> name = exceptionObject->Get(v8String(isolate, "name")) ; 197 v8::Handle<v8::Value> name = exceptionObject->Get(v8String(isolate, "name")) ;
243 RELEASE_ASSERT(!name.IsEmpty() && name->IsString()); 198 RELEASE_ASSERT(!name.IsEmpty() && name->IsString());
244 199
245 v8::Handle<v8::Message> tryCatchMessage = block.Message(); 200 v8::Handle<v8::Message> tryCatchMessage = block.Message();
246 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "mess age")); 201 v8::Handle<v8::Value> message = exceptionObject->Get(v8String(isolate, "mess age"));
(...skipping 22 matching lines...) Expand all
269 exceptionState.throwDOMException(V8RangeError, messageString); 224 exceptionState.throwDOMException(V8RangeError, messageString);
270 exceptionState.throwIfNeeded(); 225 exceptionState.throwIfNeeded();
271 return; 226 return;
272 } 227 }
273 228
274 fprintf(stderr, "Private script error: %s was thrown.\n", exceptionName.utf8 ().data()); 229 fprintf(stderr, "Private script error: %s was thrown.\n", exceptionName.utf8 ().data());
275 dumpV8Message(tryCatchMessage); 230 dumpV8Message(tryCatchMessage);
276 RELEASE_ASSERT_NOT_REACHED(); 231 RELEASE_ASSERT_NOT_REACHED();
277 } 232 }
278 233
234 } // namespace
235
236 v8::Handle<v8::Value> PrivateScriptRunner::runDOMAttributeGetter(ScriptState* sc riptState, ScriptState* scriptStateInUserScript, const char* className, const ch ar* attributeName, v8::Handle<v8::Value> holder)
237 {
238 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
239 v8::Handle<v8::Value> descriptor = classObject->GetOwnPropertyDescriptor(v8S tring(scriptState->isolate(), attributeName));
240 if (descriptor.IsEmpty() || !descriptor->IsObject()) {
241 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
242 RELEASE_ASSERT_NOT_REACHED();
243 }
244 v8::Handle<v8::Value> getter = v8::Handle<v8::Object>::Cast(descriptor)->Get (v8String(scriptState->isolate(), "get"));
245 if (getter.IsEmpty() || !getter->IsFunction()) {
246 fprintf(stderr, "Private script error: Target DOM attribute getter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
247 RELEASE_ASSERT_NOT_REACHED();
248 }
249 initializeHolderIfNeeded(scriptState, classObject, holder);
250 v8::TryCatch block;
251 v8::Handle<v8::Value> result = V8ScriptRunner::callFunction(v8::Handle<v8::F unction>::Cast(getter), scriptState->executionContext(), holder, 0, 0, scriptSta te->isolate());
252 if (block.HasCaught()) {
253 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::GetterContext, attributeName, className);
254 block.ReThrow();
255 return v8::Handle<v8::Value>();
256 }
257 return result;
258 }
259
260 bool PrivateScriptRunner::runDOMAttributeSetter(ScriptState* scriptState, Script State* scriptStateInUserScript, const char* className, const char* attributeName , v8::Handle<v8::Value> holder, v8::Handle<v8::Value> v8Value)
261 {
262 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
263 v8::Handle<v8::Value> descriptor = classObject->GetOwnPropertyDescriptor(v8S tring(scriptState->isolate(), attributeName));
264 if (descriptor.IsEmpty() || !descriptor->IsObject()) {
265 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
266 RELEASE_ASSERT_NOT_REACHED();
267 }
268 v8::Handle<v8::Value> setter = v8::Handle<v8::Object>::Cast(descriptor)->Get (v8String(scriptState->isolate(), "set"));
269 if (setter.IsEmpty() || !setter->IsFunction()) {
270 fprintf(stderr, "Private script error: Target DOM attribute setter was n ot found. (Class name = %s, Attribute name = %s)\n", className, attributeName);
271 RELEASE_ASSERT_NOT_REACHED();
272 }
273 initializeHolderIfNeeded(scriptState, classObject, holder);
274 v8::Handle<v8::Value> argv[] = { v8Value };
275 v8::TryCatch block;
276 V8ScriptRunner::callFunction(v8::Handle<v8::Function>::Cast(setter), scriptS tate->executionContext(), holder, WTF_ARRAY_LENGTH(argv), argv, scriptState->iso late());
277 if (block.HasCaught()) {
278 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::SetterContext, attributeName, className);
279 block.ReThrow();
280 return false;
281 }
282 return true;
283 }
284
285 v8::Handle<v8::Value> PrivateScriptRunner::runDOMMethod(ScriptState* scriptState , ScriptState* scriptStateInUserScript, const char* className, const char* metho dName, v8::Handle<v8::Value> holder, int argc, v8::Handle<v8::Value> argv[])
286 {
287 v8::Handle<v8::Object> classObject = classObjectOfPrivateScript(scriptState, className);
288 v8::Handle<v8::Value> method = classObject->Get(v8String(scriptState->isolat e(), methodName));
289 if (method.IsEmpty() || !method->IsFunction()) {
290 fprintf(stderr, "Private script error: Target DOM method was not found. (Class name = %s, Method name = %s)\n", className, methodName);
291 RELEASE_ASSERT_NOT_REACHED();
292 }
293 initializeHolderIfNeeded(scriptState, classObject, holder);
294 v8::TryCatch block;
295 v8::Handle<v8::Value> result = V8ScriptRunner::callFunction(v8::Handle<v8::F unction>::Cast(method), scriptState->executionContext(), holder, argc, argv, scr iptState->isolate());
296 if (block.HasCaught()) {
297 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className);
298 block.ReThrow();
299 return v8::Handle<v8::Value>();
300 }
301 return result;
302 }
303
279 } // namespace blink 304 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/PrivateScriptRunner.h ('k') | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698