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

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

Issue 1003043002: bindings: Use Maybe APIs in V8ScriptRunner (part 1) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 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 | Annotate | Revision Log
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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 371 }
372 372
373 v8::Handle<v8::String> expression = info[0]->ToString(isolate); 373 v8::Handle<v8::String> expression = info[0]->ToString(isolate);
374 if (expression.IsEmpty()) { 374 if (expression.IsEmpty()) {
375 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string."))); 375 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string.")));
376 return; 376 return;
377 } 377 }
378 378
379 ASSERT(isolate->InContext()); 379 ASSERT(isolate->InContext());
380 v8::TryCatch tryCatch; 380 v8::TryCatch tryCatch;
381 v8::Handle<v8::Value> result = V8ScriptRunner::compileAndRunInternalScript(e xpression, info.GetIsolate()); 381 v8::Local<v8::Value> result;
382 if (tryCatch.HasCaught()) { 382 if (!v8Call(V8ScriptRunner::compileAndRunInternalScript(expression, info.Get Isolate()), result, tryCatch)) {
383 v8SetReturnValue(info, tryCatch.ReThrow()); 383 v8SetReturnValue(info, tryCatch.ReThrow());
384 return; 384 return;
385 } 385 }
386 v8SetReturnValue(info, result); 386 v8SetReturnValue(info, result);
387 } 387 }
388 388
389 void V8InjectedScriptHost::evaluateWithExceptionDetailsMethodCustom(const v8::Fu nctionCallbackInfo<v8::Value>& info) 389 void V8InjectedScriptHost::evaluateWithExceptionDetailsMethodCustom(const v8::Fu nctionCallbackInfo<v8::Value>& info)
390 { 390 {
391 v8::Isolate* isolate = info.GetIsolate(); 391 v8::Isolate* isolate = info.GetIsolate();
392 if (info.Length() < 1) { 392 if (info.Length() < 1) {
393 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "One argument expected."))); 393 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "One argument expected.")));
394 return; 394 return;
395 } 395 }
396 396
397 v8::Handle<v8::String> expression = info[0]->ToString(isolate); 397 v8::Handle<v8::String> expression = info[0]->ToString(isolate);
398 if (expression.IsEmpty()) { 398 if (expression.IsEmpty()) {
399 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string."))); 399 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso late, "The argument must be a string.")));
400 return; 400 return;
401 } 401 }
402 402
403 ASSERT(isolate->InContext()); 403 ASSERT(isolate->InContext());
404 v8::TryCatch tryCatch; 404 v8::TryCatch tryCatch;
405 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(expression, St ring(), String(), TextPosition(), isolate); 405 v8::Local<v8::Script> script;
406 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledScript(isolate, sc ript, currentExecutionContext(isolate)); 406 v8::MaybeLocal<v8::Value> result;
407 if (v8Call(V8ScriptRunner::compileScript(expression, String(), String(), Tex tPosition(), isolate), script, tryCatch))
408 result = V8ScriptRunner::runCompiledScript(isolate, script, currentExecu tionContext(isolate));
407 409
410 if (!tryCatch.CanContinue())
haraken 2015/03/18 01:58:51 Sorry for a repeated question, but when do we need
bashi 2015/03/18 02:33:12 Other places return immediately on failure, but th
haraken 2015/03/18 08:27:37 Hmm, I'm not sure of how helpful the CanContinue c
bashi 2015/03/20 01:16:07 OK, removed.
411 return;
408 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate); 412 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate);
409 if (tryCatch.HasCaught()) { 413 if (tryCatch.HasCaught()) {
haraken 2015/03/18 08:27:37 Also this HasCaught check is a bit too late. The O
bashi 2015/03/20 01:16:06 Changed the current implementation so that we don'
410 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch. Exception()); 414 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch. Exception());
411 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), JavaScriptCallFrame::createExceptionDetails(isolate, tryCatch.Message())); 415 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), JavaScriptCallFrame::createExceptionDetails(isolate, tryCatch.Message()));
412 } else { 416 } else {
haraken 2015/03/18 01:58:51 Is it possible to hit this branch? Given that you
bashi 2015/03/18 02:33:12 If v8ScriptRunner::runCompiledScript() succeeds, w
413 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result); 417 ASSERT(!result.IsEmpty());
418 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result.To LocalChecked());
414 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8::Undefined(isolate)); 419 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8::Undefined(isolate));
415 } 420 }
416 v8SetReturnValue(info, wrappedResult); 421 v8SetReturnValue(info, wrappedResult);
417 } 422 }
418 423
419 void V8InjectedScriptHost::setFunctionVariableValueMethodCustom(const v8::Functi onCallbackInfo<v8::Value>& info) 424 void V8InjectedScriptHost::setFunctionVariableValueMethodCustom(const v8::Functi onCallbackInfo<v8::Value>& info)
420 { 425 {
421 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i nfo[2]->IsString()) 426 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i nfo[2]->IsString())
422 return; 427 return;
423 428
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec tedScriptHost(info.Holder()); 590 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec tedScriptHost(info.Holder());
586 if (!injectedScriptNative) 591 if (!injectedScriptNative)
587 return; 592 return;
588 int id = info[0]->ToInt32(info.GetIsolate())->Value(); 593 int id = info[0]->ToInt32(info.GetIsolate())->Value();
589 String groupName = injectedScriptNative->groupName(id); 594 String groupName = injectedScriptNative->groupName(id);
590 if (!groupName.isEmpty()) 595 if (!groupName.isEmpty())
591 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName)); 596 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName));
592 } 597 }
593 598
594 } // namespace blink 599 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698