OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 ASSERT(length); | 208 ASSERT(length); |
209 ASSERT(Dart_CurrentIsolate()); | 209 ASSERT(Dart_CurrentIsolate()); |
210 int isolateHandle = isolateMap().getByValue(Dart_CurrentIsolate()); | 210 int isolateHandle = isolateMap().getByValue(Dart_CurrentIsolate()); |
211 | 211 |
212 v8::Local<v8::Array> callFrames = v8::Array::New(length); | 212 v8::Local<v8::Array> callFrames = v8::Array::New(length); |
213 for (int i = length - 1; i >=0; --i) { | 213 for (int i = length - 1; i >=0; --i) { |
214 Dart_ActivationFrame frame = 0; | 214 Dart_ActivationFrame frame = 0; |
215 result = Dart_GetActivationFrame(trace, i, &frame); | 215 result = Dart_GetActivationFrame(trace, i, &frame); |
216 ASSERT(!Dart_IsError(result)); | 216 ASSERT(!Dart_IsError(result)); |
217 Dart_Handle functionName = 0; | 217 Dart_Handle functionName = 0; |
218 Dart_Handle function = 0; | |
218 Dart_Handle scriptURL = 0; | 219 Dart_Handle scriptURL = 0; |
219 intptr_t lineNumber = 0; | 220 intptr_t lineNumber = 0; |
220 intptr_t libraryId = 0; | 221 intptr_t libraryId = 0; |
221 | 222 |
222 result = Dart_ActivationFrameInfo(frame, &functionName, &scriptURL, &lin eNumber, &libraryId); | 223 result = Dart_ActivationFrameInfo(frame, &functionName, &function, &scri ptURL, &lineNumber, &libraryId); |
223 ASSERT(!Dart_IsError(result)); | 224 ASSERT(!Dart_IsError(result)); |
224 Dart_Handle libraryURL = Dart_GetLibraryURL(libraryId); | 225 Dart_Handle libraryURL = Dart_GetLibraryURL(libraryId); |
225 ASSERT(!Dart_IsError(libraryURL)); | 226 ASSERT(!Dart_IsError(libraryURL)); |
226 Dart_Handle library = Dart_LookupLibrary(libraryURL); | 227 Dart_Handle library = Dart_LookupLibrary(libraryURL); |
228 Dart_Handle localVariablesHandle = Dart_GetLocalVariables(frame); | |
227 | 229 |
228 v8::Local<v8::Object> callFrame = v8::Object::New(); | 230 v8::Local<v8::Object> callFrame = v8::Object::New(); |
229 callFrame->Set(v8::String::New("functionName"), V8Converter::stringToV8( functionName)); | 231 callFrame->Set(v8::String::New("functionName"), V8Converter::stringToV8( functionName)); |
232 callFrame->Set(v8::String::New("functionProxy"), DartHandleProxy::create (function)); | |
230 callFrame->Set(v8::String::New("scriptURL"), V8Converter::stringToV8(scr iptURL)); | 233 callFrame->Set(v8::String::New("scriptURL"), V8Converter::stringToV8(scr iptURL)); |
231 callFrame->Set(v8::String::New("lineNumber"), v8::Number::New(lineNumber - 1)); | 234 callFrame->Set(v8::String::New("lineNumber"), v8::Number::New(lineNumber - 1)); |
232 callFrame->Set(v8::String::New("libraryProxy"), DartHandleProxy::createL ibraryProxy(library, libraryId, Dart_Null())); | 235 callFrame->Set(v8::String::New("libraryProxy"), DartHandleProxy::createL ibraryProxy(library, libraryId, Dart_Null())); |
233 callFrame->Set(v8::String::New("localScopeProxy"), DartHandleProxy::crea teLocalScopeProxy( | 236 callFrame->Set(v8::String::New("localScopeProxy"), DartHandleProxy::crea teLocalScopeProxy( |
234 Dart_GetLocalVariables(frame))); | 237 localVariablesHandle)); |
238 callFrame->Set(v8::String::New("localVariables"), DartHandleProxy::creat e(localVariablesHandle)); | |
235 callFrame->Set(v8::String::New("isolateHandle"), v8::Number::New(isolate Handle)); | 239 callFrame->Set(v8::String::New("isolateHandle"), v8::Number::New(isolate Handle)); |
236 callFrames->Set(i, callFrame); | 240 callFrames->Set(i, callFrame); |
237 } | 241 } |
238 | 242 |
239 ASSERT(!m_dartDebugObject.isEmpty()); | 243 ASSERT(!m_dartDebugObject.isEmpty()); |
240 v8::Handle<v8::Function> executionStateConstructor = v8::Local<v8::Function> ::Cast(dartDebugObject()->Get(v8::String::New("ExecutionState"))); | 244 v8::Handle<v8::Function> executionStateConstructor = v8::Local<v8::Function> ::Cast(dartDebugObject()->Get(v8::String::New("ExecutionState"))); |
241 v8::Handle<v8::Value> args[] = { callFrames }; | 245 v8::Handle<v8::Value> args[] = { callFrames }; |
242 return v8::Local<v8::Object>::Cast(executionStateConstructor->CallAsConstruc tor(1, args)); | 246 return v8::Local<v8::Object>::Cast(executionStateConstructor->CallAsConstruc tor(1, args)); |
243 } | 247 } |
244 | 248 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 } | 403 } |
400 | 404 |
401 static void stepOut(const v8::FunctionCallbackInfo<v8::Value>& args) | 405 static void stepOut(const v8::FunctionCallbackInfo<v8::Value>& args) |
402 { | 406 { |
403 Dart_SetStepOut(); | 407 Dart_SetStepOut(); |
404 } | 408 } |
405 | 409 |
406 static void evaluateInScope(const v8::FunctionCallbackInfo<v8::Value>& args) | 410 static void evaluateInScope(const v8::FunctionCallbackInfo<v8::Value>& args) |
407 { | 411 { |
408 v8::Handle<v8::String> expression = args[0]->ToString(); | 412 v8::Handle<v8::String> expression = args[0]->ToString(); |
409 v8::Handle<v8::Object> receiver = args[1].As<v8::Object>(); | 413 v8::Handle<v8::Value> receiver = args[1]; |
410 v8::Handle<v8::Value> scopeObjectGlobal = args[2]; | 414 v8::Handle<v8::Object> functionProxy = args[2].As<v8::Object>(); |
411 v8::Handle<v8::Value> scopeObjectLocal = args[3]; | 415 v8::Handle<v8::Value> localVariablesProxy = args[3]; |
412 v8::Handle<v8::Value> scopes[] = { scopeObjectGlobal, scopeObjectLocal }; | |
413 | 416 |
417 DartScopes scopes(functionProxy); | |
418 Dart_Handle target = 0; | |
414 if (receiver->IsNull() || receiver->IsUndefined()) { | 419 if (receiver->IsNull() || receiver->IsUndefined()) { |
415 // There is no receiver which indicates we are in a static method | 420 Dart_Handle functionHandle = scopes.handle; |
416 // scope in Dart. We should ignore the receiver for this case. | 421 ASSERT(Dart_IsFunction(functionHandle)); |
417 // Using null or undefined as the receiver for a function triggers | 422 target = Dart_FunctionOwner(functionHandle); |
418 // asserts in V8 while running in Debug mode if an exception occurs. | |
419 receiver = v8::Object::New(); | |
420 expression = v8::String::Concat(v8::String::New( | |
421 "(function($$scopeObjectGlobal, $$scopeObjectLocal) { " | |
422 "with ($$scopeObjectGlobal) with($$scopeObjectLocal) { " | |
423 "return "), | |
424 expression); | |
425 expression = v8::String::Concat(expression, v8::String::New("} })")); | |
426 } else { | 423 } else { |
427 expression = v8::String::Concat(v8::String::New( | 424 target = DartHandleProxy::unwrapValue(receiver); |
428 "(function($$scopeObjectGlobal, $$scopeObjectLocal) { " | |
429 "with ($$scopeObjectGlobal) with (this) with($$scopeObjectLocal) { " | |
430 "return "), | |
431 expression); | |
432 expression = v8::String::Concat(expression, v8::String::New("} })")); | |
433 } | 425 } |
426 ASSERT(!Dart_IsError(target)); | |
427 Dart_Handle localVariables = DartHandleProxy::unwrapValue(localVariablesProx y); | |
428 ASSERT(Dart_IsList(localVariables)); | |
429 intptr_t localVariablesLength = 0; | |
430 Dart_ListLength(localVariables, &localVariablesLength); | |
434 | 431 |
435 v8::TryCatch tryCatch; | 432 Dart_Handle wrapExpressionArgs[2] = { V8Converter::stringToDart(expression), localVariables }; |
436 v8::Handle<v8::Function> function = V8ScriptRunner::compileAndRunInternalScr ipt(expression, args.GetIsolate()).As<v8::Function>(); | |
437 | 433 |
438 if (tryCatch.HasCaught()) { | 434 Dart_Handle wrappedExpressionTuple = |
439 v8SetReturnValue(args, tryCatch.ReThrow()); | 435 DartUtilities::invokeUtilsMethod("wrapExpressionAsClosure", 2, wrapExpre ssionArgs); |
440 return; | 436 ASSERT(Dart_IsList(wrappedExpressionTuple)); |
437 Dart_Handle wrappedExpression = Dart_ListGetAt(wrappedExpressionTuple, 0); | |
438 Dart_Handle wrappedExpressionArgs = Dart_ListGetAt(wrappedExpressionTuple, 1 ); | |
439 | |
440 ASSERT(Dart_IsString(wrappedExpression)); | |
441 Dart_Handle closure = Dart_EvaluateExpr(target, wrappedExpression); | |
442 if (Dart_IsError(closure)) { | |
443 // There was a parse error. FIXME: consider cleaning up the line | |
444 // numbers in the error message. | |
445 V8ThrowException::throwError(v8::String::New(Dart_GetError(closure))); | |
446 } else { | |
447 // Invoke the closure passing in the | |
vsm
2013/09/12 00:17:23
Finish the comment. :-)
Jacob
2013/09/17 21:44:43
Done.
| |
448 ASSERT(Dart_IsClosure(closure)); | |
449 intptr_t length = 0; | |
450 Dart_ListLength(wrappedExpressionArgs, &length); | |
451 Vector<Dart_Handle> dartFunctionArgs; | |
452 for (uint32_t i = 0; i < length; i ++) { | |
453 dartFunctionArgs.append(Dart_ListGetAt(wrappedExpressionArgs, i)); | |
454 } | |
455 | |
456 Dart_Handle result = Dart_InvokeClosure(closure, dartFunctionArgs.size() , dartFunctionArgs.data()); | |
457 if (Dart_IsError(result)) { | |
458 V8ThrowException::throwError(v8::String::New(Dart_GetError(result))) ; | |
459 } else { | |
460 v8SetReturnValue(args, DartHandleProxy::create(result)); | |
461 } | |
441 } | 462 } |
442 | |
443 v8::Local<v8::Value> result = V8ScriptRunner::callFunction( | |
444 function, getScriptExecutionContext(), | |
445 receiver, | |
446 2, scopes); | |
447 | |
448 if (tryCatch.HasCaught()) { | |
449 v8SetReturnValue(args, tryCatch.ReThrow()); | |
450 return; | |
451 } | |
452 crashIfV8IsDead(); | |
453 v8SetReturnValue(args, result); | |
454 } | 463 } |
455 | 464 |
456 void DartDebugServer::ensureHooksInstalled() | 465 void DartDebugServer::ensureHooksInstalled() |
457 { | 466 { |
458 DEFINE_STATIC_LOCAL(bool, hooksInstalled, (false)); | 467 DEFINE_STATIC_LOCAL(bool, hooksInstalled, (false)); |
459 | 468 |
460 if (hooksInstalled) | 469 if (hooksInstalled) |
461 return; | 470 return; |
462 | 471 |
463 hooksInstalled = true; | 472 hooksInstalled = true; |
(...skipping 16 matching lines...) Expand all Loading... | |
480 nativeCallbacks->Set(v8::String::New("handleDebugEvent"), v8::FunctionTempla te::New(&handleDebugEvent)->GetFunction()); | 489 nativeCallbacks->Set(v8::String::New("handleDebugEvent"), v8::FunctionTempla te::New(&handleDebugEvent)->GetFunction()); |
481 nativeCallbacks->Set(v8::String::New("scriptsForIsolate"), v8::FunctionTempl ate::New(&scriptsForIsolate)->GetFunction()); | 490 nativeCallbacks->Set(v8::String::New("scriptsForIsolate"), v8::FunctionTempl ate::New(&scriptsForIsolate)->GetFunction()); |
482 nativeCallbacks->Set(v8::String::New("setBreakpoint"), v8::FunctionTemplate: :New(&setBreakpoint)->GetFunction()); | 491 nativeCallbacks->Set(v8::String::New("setBreakpoint"), v8::FunctionTemplate: :New(&setBreakpoint)->GetFunction()); |
483 nativeCallbacks->Set(v8::String::New("removeBreakpoint"), v8::FunctionTempla te::New(&removeBreakpoint)->GetFunction()); | 492 nativeCallbacks->Set(v8::String::New("removeBreakpoint"), v8::FunctionTempla te::New(&removeBreakpoint)->GetFunction()); |
484 nativeCallbacks->Set(v8::String::New("getBreakpointLine"), v8::FunctionTempl ate::New(&getBreakpointLine)->GetFunction()); | 493 nativeCallbacks->Set(v8::String::New("getBreakpointLine"), v8::FunctionTempl ate::New(&getBreakpointLine)->GetFunction()); |
485 nativeCallbacks->Set(v8::String::New("setExceptionPauseInfo"), v8::FunctionT emplate::New(&setExceptionPauseInfo)->GetFunction()); | 494 nativeCallbacks->Set(v8::String::New("setExceptionPauseInfo"), v8::FunctionT emplate::New(&setExceptionPauseInfo)->GetFunction()); |
486 nativeCallbacks->Set(v8::String::New("stepInto"), v8::FunctionTemplate::New( &stepInto)->GetFunction()); | 495 nativeCallbacks->Set(v8::String::New("stepInto"), v8::FunctionTemplate::New( &stepInto)->GetFunction()); |
487 nativeCallbacks->Set(v8::String::New("stepOver"), v8::FunctionTemplate::New( &stepOver)->GetFunction()); | 496 nativeCallbacks->Set(v8::String::New("stepOver"), v8::FunctionTemplate::New( &stepOver)->GetFunction()); |
488 nativeCallbacks->Set(v8::String::New("stepOut"), v8::FunctionTemplate::New(& stepOut)->GetFunction()); | 497 nativeCallbacks->Set(v8::String::New("stepOut"), v8::FunctionTemplate::New(& stepOut)->GetFunction()); |
489 nativeCallbacks->Set(v8::String::New("evaluateInScope"), evaluateInScopeFunc tion); | 498 nativeCallbacks->Set(v8::String::New("evaluateInScope"), evaluateInScopeFunc tion); |
499 { | |
500 // Trampoline script is required to properly set calling context before | |
501 // invoking Dart code because of security checks in console.log | |
502 // implementation (see InjectedScriptManager::canAccessInspectedWindow). | |
503 V8Scope v8scope; | |
504 v8::Handle<v8::String> trampolineScript = v8::String::New("(function (fu nc, args) { return func.apply(this, args); })"); | |
505 v8::Local<v8::Function> trampoline = v8::Local<v8::Function>::Cast(v8::S cript::Compile(trampolineScript)->Run()); | |
506 nativeCallbacks->Set(v8::String::New("invocationTrampoline"), trampoline ); | |
507 } | |
490 dartDebugObject()->Set(v8::String::New("nativeCallbacks"), nativeCallbacks); | 508 dartDebugObject()->Set(v8::String::New("nativeCallbacks"), nativeCallbacks); |
491 } | 509 } |
492 | 510 |
493 v8::Local<v8::Object> DartDebugServer::dartDebugObject() | 511 v8::Local<v8::Object> DartDebugServer::dartDebugObject() |
494 { | 512 { |
495 return m_dartDebugObject.newLocal(v8::Isolate::GetCurrent()); | 513 return m_dartDebugObject.newLocal(v8::Isolate::GetCurrent()); |
496 } | 514 } |
497 | 515 |
498 } | 516 } |
OLD | NEW |