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

Side by Side Diff: Source/bindings/core/v8/custom/V8InjectedScriptHostCustom.cpp

Issue 289423002: DevTools: added injectedScript.evaluateWithDetails, that return exception details if it occured (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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 /* 1 /*
2 * Copyright (C) 2007-2011 Google Inc. All rights reserved. 2 * Copyright (C) 2007-2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/core/v8/V8InjectedScriptHost.h" 32 #include "bindings/core/v8/V8InjectedScriptHost.h"
33 33
34 #include "bindings/core/v8/BindingSecurity.h" 34 #include "bindings/core/v8/BindingSecurity.h"
35 #include "bindings/core/v8/EvaluateExceptionDetailsFactory.h"
35 #include "bindings/core/v8/ExceptionState.h" 36 #include "bindings/core/v8/ExceptionState.h"
36 #include "bindings/core/v8/ScriptDebugServer.h" 37 #include "bindings/core/v8/ScriptDebugServer.h"
37 #include "bindings/core/v8/ScriptValue.h" 38 #include "bindings/core/v8/ScriptValue.h"
38 #include "bindings/core/v8/V8AbstractEventListener.h" 39 #include "bindings/core/v8/V8AbstractEventListener.h"
39 #include "bindings/core/v8/V8Binding.h" 40 #include "bindings/core/v8/V8Binding.h"
40 #include "bindings/core/v8/V8EventTarget.h" 41 #include "bindings/core/v8/V8EventTarget.h"
41 #include "bindings/core/v8/V8HTMLAllCollection.h" 42 #include "bindings/core/v8/V8HTMLAllCollection.h"
42 #include "bindings/core/v8/V8HTMLCollection.h" 43 #include "bindings/core/v8/V8HTMLCollection.h"
43 #include "bindings/core/v8/V8Node.h" 44 #include "bindings/core/v8/V8Node.h"
44 #include "bindings/core/v8/V8NodeList.h" 45 #include "bindings/core/v8/V8NodeList.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if (info.Length() < 2) 307 if (info.Length() < 2)
307 return; 308 return;
308 309
309 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); 310 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder());
310 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); 311 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
311 ScriptValue object(scriptState, info[0]); 312 ScriptValue object(scriptState, info[0]);
312 ScriptValue hints(scriptState, info[1]); 313 ScriptValue hints(scriptState, info[1]);
313 host->inspectImpl(object.toJSONValue(scriptState), hints.toJSONValue(scriptS tate)); 314 host->inspectImpl(object.toJSONValue(scriptState), hints.toJSONValue(scriptS tate));
314 } 315 }
315 316
316 void V8InjectedScriptHost::evaluateMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& info) 317 void V8InjectedScriptHost::evaluateMethodCustom(const v8::FunctionCallbackInfo<v 8::Value>& info)
pfeldman 2014/07/05 20:11:06 InjectedScriptHost.evaluate is just a raw window.e
317 { 318 {
318 v8::Isolate* isolate = info.GetIsolate(); 319 v8::Isolate* isolate = info.GetIsolate();
319 if (info.Length() < 1) { 320 if (info.Length() < 1) {
320 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "One argument expected."))); 321 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "One argument expected.")));
321 return; 322 return;
322 } 323 }
323 324
324 v8::Handle<v8::String> expression = info[0]->ToString(); 325 v8::Handle<v8::String> expression = info[0]->ToString();
325 if (expression.IsEmpty()) { 326 if (expression.IsEmpty()) {
326 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string."))); 327 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string.")));
327 return; 328 return;
328 } 329 }
329 330
330 ASSERT(isolate->InContext()); 331 ASSERT(isolate->InContext());
331 v8::TryCatch tryCatch; 332 v8::TryCatch tryCatch;
332 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(e xpression, info.GetIsolate()); 333 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(e xpression, info.GetIsolate());
334
335 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate);
333 if (tryCatch.HasCaught()) { 336 if (tryCatch.HasCaught()) {
334 v8SetReturnValue(info, tryCatch.ReThrow()); 337 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch. Exception());
335 return; 338 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), createEvaluateExceptionDetails(tryCatch.Message(), isolate));
339 } else {
340 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result);
341 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8::Undefined(isolate));
336 } 342 }
337 v8SetReturnValue(info, result); 343 v8SetReturnValue(info, wrappedResult);
338 } 344 }
339 345
340 void V8InjectedScriptHost::setFunctionVariableValueMethodCustom(const v8::Functi onCallbackInfo<v8::Value>& info) 346 void V8InjectedScriptHost::setFunctionVariableValueMethodCustom(const v8::Functi onCallbackInfo<v8::Value>& info)
341 { 347 {
342 v8::Handle<v8::Value> functionValue = info[0]; 348 v8::Handle<v8::Value> functionValue = info[0];
343 int scopeIndex = info[1]->Int32Value(); 349 int scopeIndex = info[1]->Int32Value();
344 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]); 350 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]);
345 v8::Handle<v8::Value> newValue = info[3]; 351 v8::Handle<v8::Value> newValue = info[3];
346 352
347 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder()); 353 InjectedScriptHost* host = V8InjectedScriptHost::toNative(info.Holder());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 OwnPtr<v8::Handle<v8::Value>[]> argv = adoptArrayPtr(new v8::Handle<v8::Valu e>[argc]); 442 OwnPtr<v8::Handle<v8::Value>[]> argv = adoptArrayPtr(new v8::Handle<v8::Valu e>[argc]);
437 for (size_t i = 0; i < argc; ++i) 443 for (size_t i = 0; i < argc; ++i)
438 argv[i] = info[i + 2]; 444 argv[i] = info[i + 2];
439 445
440 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get()); 446 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get());
441 debugServer.unmuteWarningsAndDeprecations(); 447 debugServer.unmuteWarningsAndDeprecations();
442 v8SetReturnValue(info, result); 448 v8SetReturnValue(info, result);
443 } 449 }
444 450
445 } // namespace WebCore 451 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698