OLD | NEW |
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 Loading... |
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 static void setExceptionAsReturnValue(const v8::FunctionCallbackInfo<v8::Value>&
info, v8::Local<v8::Object> returnValue, v8::TryCatch& tryCatch) |
| 390 { |
| 391 v8::Isolate* isolate = info.GetIsolate(); |
| 392 returnValue->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.Except
ion()); |
| 393 returnValue->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), JavaS
criptCallFrame::createExceptionDetails(isolate, tryCatch.Message())); |
| 394 v8SetReturnValue(info, returnValue); |
| 395 } |
| 396 |
389 void V8InjectedScriptHost::evaluateWithExceptionDetailsMethodCustom(const v8::Fu
nctionCallbackInfo<v8::Value>& info) | 397 void V8InjectedScriptHost::evaluateWithExceptionDetailsMethodCustom(const v8::Fu
nctionCallbackInfo<v8::Value>& info) |
390 { | 398 { |
391 v8::Isolate* isolate = info.GetIsolate(); | 399 v8::Isolate* isolate = info.GetIsolate(); |
392 if (info.Length() < 1) { | 400 if (info.Length() < 1) { |
393 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); | 401 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "One argument expected."))); |
394 return; | 402 return; |
395 } | 403 } |
396 | 404 |
397 v8::Handle<v8::String> expression = info[0]->ToString(isolate); | 405 v8::Handle<v8::String> expression = info[0]->ToString(isolate); |
398 if (expression.IsEmpty()) { | 406 if (expression.IsEmpty()) { |
399 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); | 407 isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(iso
late, "The argument must be a string."))); |
400 return; | 408 return; |
401 } | 409 } |
402 | 410 |
403 ASSERT(isolate->InContext()); | 411 ASSERT(isolate->InContext()); |
| 412 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate); |
| 413 if (wrappedResult.IsEmpty()) |
| 414 return; |
404 v8::TryCatch tryCatch; | 415 v8::TryCatch tryCatch; |
405 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(expression, St
ring(), String(), TextPosition(), isolate); | 416 v8::Local<v8::Script> script; |
406 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledScript(isolate, sc
ript, currentExecutionContext(isolate)); | 417 v8::Local<v8::Value> result; |
| 418 if (!v8Call(V8ScriptRunner::compileScript(expression, String(), String(), Te
xtPosition(), isolate), script, tryCatch)) { |
| 419 setExceptionAsReturnValue(info, wrappedResult, tryCatch); |
| 420 return; |
| 421 } |
| 422 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate, script, currentExecut
ionContext(isolate)), result, tryCatch)) { |
| 423 setExceptionAsReturnValue(info, wrappedResult, tryCatch); |
| 424 return; |
| 425 } |
407 | 426 |
408 v8::Local<v8::Object> wrappedResult = v8::Object::New(isolate); | 427 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result); |
409 if (tryCatch.HasCaught()) { | 428 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"), v8:
:Undefined(isolate)); |
410 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), tryCatch.
Exception()); | |
411 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"),
JavaScriptCallFrame::createExceptionDetails(isolate, tryCatch.Message())); | |
412 } else { | |
413 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "result"), result); | |
414 wrappedResult->Set(v8::String::NewFromUtf8(isolate, "exceptionDetails"),
v8::Undefined(isolate)); | |
415 } | |
416 v8SetReturnValue(info, wrappedResult); | 429 v8SetReturnValue(info, wrappedResult); |
417 } | 430 } |
418 | 431 |
419 void V8InjectedScriptHost::setFunctionVariableValueMethodCustom(const v8::Functi
onCallbackInfo<v8::Value>& info) | 432 void V8InjectedScriptHost::setFunctionVariableValueMethodCustom(const v8::Functi
onCallbackInfo<v8::Value>& info) |
420 { | 433 { |
421 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i
nfo[2]->IsString()) | 434 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i
nfo[2]->IsString()) |
422 return; | 435 return; |
423 | 436 |
424 v8::Handle<v8::Value> functionValue = info[0]; | 437 v8::Handle<v8::Value> functionValue = info[0]; |
425 int scopeIndex = info[1]->Int32Value(); | 438 int scopeIndex = info[1]->Int32Value(); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); | 598 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec
tedScriptHost(info.Holder()); |
586 if (!injectedScriptNative) | 599 if (!injectedScriptNative) |
587 return; | 600 return; |
588 int id = info[0]->ToInt32(info.GetIsolate())->Value(); | 601 int id = info[0]->ToInt32(info.GetIsolate())->Value(); |
589 String groupName = injectedScriptNative->groupName(id); | 602 String groupName = injectedScriptNative->groupName(id); |
590 if (!groupName.isEmpty()) | 603 if (!groupName.isEmpty()) |
591 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName)); | 604 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName)); |
592 } | 605 } |
593 | 606 |
594 } // namespace blink | 607 } // namespace blink |
OLD | NEW |