| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 | |
| 33 #include "bindings/core/dart/DartInjectedScript.h" | |
| 34 | |
| 35 #include "bindings/core/dart/DartHandleProxy.h" | |
| 36 #include "bindings/core/dart/DartInjectedScriptHost.h" | |
| 37 #include "bindings/core/dart/DartJsInterop.h" | |
| 38 #include "bindings/core/dart/DartNode.h" | |
| 39 #include "bindings/core/dart/DartScriptDebugServer.h" | |
| 40 #include "bindings/core/dart/DartScriptState.h" | |
| 41 #include "bindings/core/dart/DartUtilities.h" | |
| 42 #include "bindings/core/dart/V8Converter.h" | |
| 43 #include "bindings/core/v8/ScriptFunctionCall.h" | |
| 44 #include "core/inspector/InjectedScriptHost.h" | |
| 45 #include "core/inspector/JSONParser.h" | |
| 46 #include "platform/JSONValues.h" | |
| 47 | |
| 48 using blink::TypeBuilder::Array; | |
| 49 using blink::TypeBuilder::Debugger::CallFrame; | |
| 50 using blink::TypeBuilder::Debugger::Location; | |
| 51 using blink::TypeBuilder::Debugger::Scope; | |
| 52 using blink::TypeBuilder::Runtime::PropertyDescriptor; | |
| 53 using blink::TypeBuilder::Runtime::InternalPropertyDescriptor; | |
| 54 using blink::TypeBuilder::Debugger::FunctionDetails; | |
| 55 using blink::TypeBuilder::Runtime::RemoteObject; | |
| 56 using blink::TypeBuilder::Runtime::PropertyPreview; | |
| 57 | |
| 58 namespace blink { | |
| 59 | |
| 60 Dart_Handle getLibraryUrl(Dart_Handle handle) | |
| 61 { | |
| 62 intptr_t libraryId = 0; | |
| 63 Dart_Handle ALLOW_UNUSED result = Dart_LibraryId(handle, &libraryId); | |
| 64 ASSERT(!Dart_IsError(result)); | |
| 65 Dart_Handle libraryUrl = Dart_GetLibraryURL(libraryId); | |
| 66 ASSERT(Dart_IsString(libraryUrl)); | |
| 67 return libraryUrl; | |
| 68 } | |
| 69 | |
| 70 Dart_Handle getObjectCompletions(Dart_Handle object, Dart_Handle library) | |
| 71 { | |
| 72 Dart_Handle args[2] = {object, getLibraryUrl(library)}; | |
| 73 return DartUtilities::invokeUtilsMethod("getObjectCompletions", 2, args); | |
| 74 } | |
| 75 | |
| 76 Dart_Handle getLibraryCompletions(Dart_Handle library) | |
| 77 { | |
| 78 Dart_Handle libraryUrl = getLibraryUrl(library); | |
| 79 return DartUtilities::invokeUtilsMethod("getLibraryCompletions", 1, &library
Url); | |
| 80 } | |
| 81 | |
| 82 Dart_Handle getLibraryCompletionsIncludingImports(Dart_Handle library) | |
| 83 { | |
| 84 Dart_Handle libraryUrl = getLibraryUrl(library); | |
| 85 return DartUtilities::invokeUtilsMethod("getLibraryCompletionsIncludingImpor
ts", 1, &libraryUrl); | |
| 86 } | |
| 87 | |
| 88 Dart_Handle getObjectProperties(Dart_Handle object, bool ownProperties, bool acc
essorPropertiesOnly) | |
| 89 { | |
| 90 Dart_Handle args[3] = {object, DartUtilities::boolToDart(ownProperties), Dar
tUtilities::boolToDart(accessorPropertiesOnly)}; | |
| 91 return DartUtilities::invokeUtilsMethod("getObjectProperties", 3, args); | |
| 92 } | |
| 93 | |
| 94 Dart_Handle getObjectPropertySafe(Dart_Handle object, const String& propertyName
) | |
| 95 { | |
| 96 Dart_Handle args[2] = {object, DartUtilities::stringToDartString(propertyNam
e)}; | |
| 97 return DartUtilities::invokeUtilsMethod("getObjectPropertySafe", 2, args); | |
| 98 } | |
| 99 | |
| 100 Dart_Handle getObjectClassProperties(Dart_Handle object, bool ownProperties, boo
l accessorPropertiesOnly) | |
| 101 { | |
| 102 Dart_Handle args[3] = {object, DartUtilities::boolToDart(ownProperties), Dar
tUtilities::boolToDart(accessorPropertiesOnly)}; | |
| 103 return DartUtilities::invokeUtilsMethod("getObjectClassProperties", 3, args)
; | |
| 104 } | |
| 105 | |
| 106 Dart_Handle getClassProperties(Dart_Handle kind, bool ownProperties, bool access
orPropertiesOnly) | |
| 107 { | |
| 108 Dart_Handle args[3] = {kind, DartUtilities::boolToDart(ownProperties), DartU
tilities::boolToDart(accessorPropertiesOnly)}; | |
| 109 return DartUtilities::invokeUtilsMethod("getClassProperties", 3, args); | |
| 110 } | |
| 111 | |
| 112 Dart_Handle getLibraryProperties(Dart_Handle library, bool ownProperties, bool a
ccessorPropertiesOnly) | |
| 113 { | |
| 114 Dart_Handle args[3] = {getLibraryUrl(library), DartUtilities::boolToDart(own
Properties), DartUtilities::boolToDart(accessorPropertiesOnly)}; | |
| 115 return DartUtilities::invokeUtilsMethod("getLibraryProperties", 3, args); | |
| 116 } | |
| 117 | |
| 118 Dart_Handle describeFunction(Dart_Handle function) | |
| 119 { | |
| 120 return DartUtilities::invokeUtilsMethod("describeFunction", 1, &function); | |
| 121 } | |
| 122 | |
| 123 Dart_Handle getInvocationTrampolineDetails(Dart_Handle function) | |
| 124 { | |
| 125 return DartUtilities::invokeUtilsMethod("getInvocationTrampolineDetails", 1,
&function); | |
| 126 } | |
| 127 | |
| 128 Dart_Handle findReceiver(Dart_Handle locals) | |
| 129 { | |
| 130 intptr_t length = 0; | |
| 131 Dart_Handle ALLOW_UNUSED result = Dart_ListLength(locals, &length); | |
| 132 ASSERT(!Dart_IsError(result)); | |
| 133 ASSERT(length % 2 == 0); | |
| 134 String thisStr("this"); | |
| 135 for (intptr_t i = 0; i < length; i+= 2) { | |
| 136 Dart_Handle name = Dart_ListGetAt(locals, i); | |
| 137 if (DartUtilities::toString(name) == thisStr) { | |
| 138 Dart_Handle ret = Dart_ListGetAt(locals, i + 1); | |
| 139 return Dart_IsNull(ret) ? 0 : ret; | |
| 140 } | |
| 141 } | |
| 142 return 0; | |
| 143 } | |
| 144 | |
| 145 Dart_Handle lookupEnclosingType(Dart_Handle functionOwner) | |
| 146 { | |
| 147 // Walk up the chain of function owners until we reach a type or library | |
| 148 // handle. | |
| 149 while (Dart_IsFunction(functionOwner)) | |
| 150 functionOwner = Dart_FunctionOwner(functionOwner); | |
| 151 return functionOwner; | |
| 152 } | |
| 153 | |
| 154 String stripVariableName(const String& name) | |
| 155 { | |
| 156 size_t index = name.find('@'); | |
| 157 return index == kNotFound ? name : name.left(index); | |
| 158 } | |
| 159 | |
| 160 String stripFunctionDescription(const String& description) | |
| 161 { | |
| 162 size_t index = description.find('{'); | |
| 163 if (index != kNotFound) | |
| 164 return description.left(index); | |
| 165 index = description.find(';'); | |
| 166 if (index != kNotFound) | |
| 167 return description.left(index); | |
| 168 return description; | |
| 169 } | |
| 170 | |
| 171 DartDebuggerObject::DartDebuggerObject(Dart_PersistentHandle h, const String& ob
jectGroup, Kind kind) | |
| 172 : m_handle(h) | |
| 173 , m_group(objectGroup) | |
| 174 , m_kind(kind) | |
| 175 { | |
| 176 } | |
| 177 | |
| 178 DartDebuggerObject::~DartDebuggerObject() | |
| 179 { | |
| 180 Dart_DeletePersistentHandle(m_handle); | |
| 181 } | |
| 182 | |
| 183 DartInjectedScript::DartInjectedScript() | |
| 184 : m_name("DartInjectedScript") | |
| 185 , m_inspectedStateAccessCheck(0) | |
| 186 , m_scriptState(0) | |
| 187 , m_nextObjectId(1) | |
| 188 , m_host(0) | |
| 189 , m_consoleApi(0) | |
| 190 { | |
| 191 } | |
| 192 | |
| 193 DartInjectedScript::DartInjectedScript(DartScriptState* scriptState, InjectedScr
iptManager::InspectedStateAccessCheck accessCheck, int injectedScriptId, Injecte
dScriptHost* host, InjectedScriptManager* injectedScriptManager) | |
| 194 : m_name("DartInjectedScript") | |
| 195 , m_inspectedStateAccessCheck(accessCheck) | |
| 196 , m_scriptState(scriptState) | |
| 197 , m_nextObjectId(1) | |
| 198 , m_injectedScriptId(injectedScriptId) | |
| 199 , m_host(host) | |
| 200 , m_injectedScriptManager(injectedScriptManager) | |
| 201 , m_consoleApi(0) | |
| 202 { | |
| 203 } | |
| 204 | |
| 205 bool DartInjectedScript::canAccessInspectedWindow() const | |
| 206 { | |
| 207 return m_inspectedStateAccessCheck(scriptState()); | |
| 208 } | |
| 209 | |
| 210 bool DartInjectedScript::validateObjectId(const String& objectId) | |
| 211 { | |
| 212 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); | |
| 213 if (parsedObjectId && parsedObjectId->type() == JSONValue::TypeObject) { | |
| 214 long injectedScriptId = 0; | |
| 215 bool success = parsedObjectId->asObject()->getNumber("injectedScriptId",
&injectedScriptId); | |
| 216 return success && injectedScriptId == m_injectedScriptId; | |
| 217 } | |
| 218 return false; | |
| 219 } | |
| 220 | |
| 221 void DartInjectedScript::packageResult(Dart_Handle dartHandle, DartDebuggerObjec
t::Kind kind, const String& objectGroup, ErrorString* errorString, bool returnBy
Value, bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result,
TypeBuilder::OptOutput<bool>* wasThrown) | |
| 222 { | |
| 223 switch (kind) { | |
| 224 case DartDebuggerObject::Object: | |
| 225 packageObjectResult(dartHandle, objectGroup, errorString, returnByValue,
generatePreview, result, wasThrown); | |
| 226 return; | |
| 227 case DartDebuggerObject::ObjectClass: | |
| 228 packageObjectClassResult(dartHandle, objectGroup, errorString, returnByV
alue, generatePreview, result, wasThrown); | |
| 229 return; | |
| 230 case DartDebuggerObject::Function: | |
| 231 packageFunctionResult(dartHandle, objectGroup, errorString, returnByValu
e, generatePreview, result, wasThrown); | |
| 232 return; | |
| 233 case DartDebuggerObject::Method: | |
| 234 packageMethodResult(dartHandle, objectGroup, errorString, returnByValue,
generatePreview, result, wasThrown); | |
| 235 return; | |
| 236 case DartDebuggerObject::Class: | |
| 237 case DartDebuggerObject::StaticClass: | |
| 238 packageClassResult(dartHandle, kind, objectGroup, errorString, returnByV
alue, generatePreview, result, wasThrown); | |
| 239 return; | |
| 240 case DartDebuggerObject::Library: | |
| 241 case DartDebuggerObject::CurrentLibrary: | |
| 242 packageLibraryResult(dartHandle, kind, objectGroup, errorString, returnB
yValue, generatePreview, result, wasThrown); | |
| 243 return; | |
| 244 case DartDebuggerObject::Isolate: | |
| 245 packageIsolateResult(dartHandle, objectGroup, errorString, returnByValue
, generatePreview, result, wasThrown); | |
| 246 return; | |
| 247 case DartDebuggerObject::LocalVariables: | |
| 248 packageLocalVariablesResult(dartHandle, objectGroup, errorString, return
ByValue, generatePreview, result, wasThrown); | |
| 249 return; | |
| 250 case DartDebuggerObject::Error: | |
| 251 packageErrorResult(dartHandle, objectGroup, errorString, returnByValue,
generatePreview, result, wasThrown); | |
| 252 return; | |
| 253 default: | |
| 254 ASSERT_NOT_REACHED(); | |
| 255 } | |
| 256 } | |
| 257 | |
| 258 DartInjectedScript::~DartInjectedScript() | |
| 259 { | |
| 260 DartIsolateScope scope(m_scriptState->isolate()); | |
| 261 DartApiScope apiScope; | |
| 262 | |
| 263 for (DebuggerObjectMap::iterator it = m_objects.begin(); it != m_objects.end
(); ++it) { | |
| 264 delete it->value; | |
| 265 } | |
| 266 | |
| 267 if (m_consoleApi) | |
| 268 Dart_DeletePersistentHandle(m_consoleApi); | |
| 269 } | |
| 270 | |
| 271 Dart_Handle DartInjectedScript::consoleApi() | |
| 272 { | |
| 273 if (!m_consoleApi) { | |
| 274 Dart_Handle host = DartInjectedScriptHost::toDart(m_host); | |
| 275 Dart_SetPeer(host, this); | |
| 276 Dart_Handle consoleApi = DartUtilities::invokeUtilsMethod("consoleApi",
1, &host); | |
| 277 ASSERT(!Dart_IsError(consoleApi)); | |
| 278 m_consoleApi = Dart_NewPersistentHandle(consoleApi); | |
| 279 } | |
| 280 return m_consoleApi; | |
| 281 } | |
| 282 | |
| 283 Dart_Handle DartInjectedScript::evaluateHelper(Dart_Handle target, const String&
rawExpression, Dart_Handle localVariables, bool includeCommandLineAPI, Dart_Han
dle& exception) | |
| 284 { | |
| 285 DartDOMData* ALLOW_UNUSED domData = DartDOMData::current(); | |
| 286 ASSERT(domData); | |
| 287 ASSERT(Dart_IsList(localVariables) || Dart_IsNull(localVariables)); | |
| 288 | |
| 289 Dart_Handle expression = DartUtilities::stringToDart(rawExpression); | |
| 290 | |
| 291 if (includeCommandLineAPI) { | |
| 292 ASSERT(m_host); | |
| 293 // Vector of local variables and injected console variables. | |
| 294 Vector<Dart_Handle> locals; | |
| 295 if (Dart_IsList(localVariables)) { | |
| 296 DartUtilities::extractListElements(localVariables, exception, locals
); | |
| 297 ASSERT(!exception); | |
| 298 } | |
| 299 | |
| 300 ScriptState* v8ScriptState = DartUtilities::v8ScriptStateForCurrentIsola
te(); | |
| 301 for (unsigned i = 0; i < 6; i++) { | |
| 302 ScriptValue value = m_host->inspectedObject(i)->get(v8ScriptState); | |
| 303 v8::TryCatch tryCatch; | |
| 304 v8::Handle<v8::Value> v8Value = value.v8Value(); | |
| 305 if (v8Value.IsEmpty()) | |
| 306 break; | |
| 307 Dart_Handle dartValue = DartHandleProxy::unwrapValue(v8Value); | |
| 308 ASSERT(!Dart_IsError(dartValue)); | |
| 309 if (Dart_IsNull(dartValue)) | |
| 310 continue; | |
| 311 locals.append(DartUtilities::stringToDartString(String::format("$%d"
, i))); | |
| 312 locals.append(dartValue); | |
| 313 } | |
| 314 | |
| 315 Dart_Handle list = consoleApi(); | |
| 316 intptr_t length = 0; | |
| 317 ASSERT(Dart_IsList(list)); | |
| 318 Dart_Handle ALLOW_UNUSED ret = Dart_ListLength(list, &length); | |
| 319 ASSERT(!(length % 2)); | |
| 320 ASSERT(!Dart_IsError(ret)); | |
| 321 for (intptr_t i = 0; i < length; i += 2) { | |
| 322 Dart_Handle name = Dart_ListGetAt(list, i); | |
| 323 ASSERT(Dart_IsString(name)); | |
| 324 locals.append(name); | |
| 325 Dart_Handle value = Dart_ListGetAt(list, i+1); | |
| 326 ASSERT(!Dart_IsError(value)); | |
| 327 locals.append(value); | |
| 328 } | |
| 329 localVariables = DartUtilities::toList(locals, exception); | |
| 330 ASSERT(!exception); | |
| 331 } | |
| 332 | |
| 333 Dart_Handle wrapExpressionArgs[3] = { expression, localVariables, DartUtilit
ies::boolToDart(includeCommandLineAPI) }; | |
| 334 Dart_Handle wrappedExpressionTuple = | |
| 335 DartUtilities::invokeUtilsMethod("wrapExpressionAsClosure", 3, wrapExpre
ssionArgs); | |
| 336 ASSERT(Dart_IsList(wrappedExpressionTuple)); | |
| 337 Dart_Handle wrappedExpression = Dart_ListGetAt(wrappedExpressionTuple, 0); | |
| 338 Dart_Handle wrappedExpressionArgs = Dart_ListGetAt(wrappedExpressionTuple, 1
); | |
| 339 // TODO(jacobr): replace most of this logic with Dart_ActivationFrameEvaluat
e. | |
| 340 | |
| 341 ASSERT(Dart_IsString(wrappedExpression)); | |
| 342 Dart_Handle closure = Dart_EvaluateExpr(target, wrappedExpression); | |
| 343 // There was a parse error. FIXME: consider cleaning up the line numbers in | |
| 344 // the error message. | |
| 345 if (Dart_IsError(closure)) { | |
| 346 exception = closure; | |
| 347 return 0; | |
| 348 } | |
| 349 | |
| 350 // Invoke the closure passing in the expression arguments specified by | |
| 351 // wrappedExpressionTuple. | |
| 352 ASSERT(DartUtilities::isFunction(domData, closure)); | |
| 353 intptr_t length = 0; | |
| 354 Dart_ListLength(wrappedExpressionArgs, &length); | |
| 355 Vector<Dart_Handle> dartFunctionArgs; | |
| 356 for (intptr_t i = 0; i < length; i ++) | |
| 357 dartFunctionArgs.append(Dart_ListGetAt(wrappedExpressionArgs, i)); | |
| 358 | |
| 359 Dart_Handle result = Dart_InvokeClosure(closure, dartFunctionArgs.size(), da
rtFunctionArgs.data()); | |
| 360 if (Dart_IsError(result)) { | |
| 361 exception = result; | |
| 362 return Dart_Null(); | |
| 363 } | |
| 364 return result; | |
| 365 } | |
| 366 | |
| 367 void DartInjectedScript::evaluateAndPackageResult(Dart_Handle target, const Stri
ng& rawExpression, Dart_Handle localVariables, bool includeCommandLineAPI, const
String& objectGroup, ErrorString* errorString, bool returnByValue, bool generat
ePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOu
tput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exceptio
nDetails) | |
| 368 { | |
| 369 Dart_Handle exception = 0; | |
| 370 { | |
| 371 Dart_Handle evalResult = evaluateHelper(target, rawExpression, localVari
ables, includeCommandLineAPI, exception); | |
| 372 if (exception) | |
| 373 goto fail; | |
| 374 packageResult(evalResult, inferKind(evalResult), objectGroup, errorStrin
g, returnByValue, generatePreview, result, wasThrown); | |
| 375 return; | |
| 376 } | |
| 377 fail: | |
| 378 ASSERT(exception); | |
| 379 packageResult(exception, DartDebuggerObject::Error, objectGroup, errorString
, returnByValue, generatePreview, result, wasThrown); | |
| 380 ASSERT(Dart_IsError(exception)); | |
| 381 if (exceptionDetails) { | |
| 382 *exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().se
tText(Dart_GetError(exception)).release(); | |
| 383 Dart_StackTrace trace; | |
| 384 Dart_Handle ALLOW_UNUSED ret = Dart_GetStackTraceFromError(exception, &t
race); | |
| 385 if (Dart_IsInstance(ret)) { | |
| 386 // Only unhandled exception error handles have stacktraces. | |
| 387 (*exceptionDetails)->setStackTrace(consoleCallFrames(trace)); | |
| 388 } | |
| 389 } | |
| 390 } | |
| 391 | |
| 392 PassRefPtr<Array<TypeBuilder::Console::CallFrame> > DartInjectedScript::consoleC
allFrames(Dart_StackTrace trace) | |
| 393 { | |
| 394 intptr_t length = 0; | |
| 395 Dart_Handle ALLOW_UNUSED result; | |
| 396 RefPtr<Array<TypeBuilder::Console::CallFrame> > ret = Array<TypeBuilder::Con
sole::CallFrame>::create(); | |
| 397 result = Dart_StackTraceLength(trace, &length); | |
| 398 ASSERT(!Dart_IsError(result)); | |
| 399 DartScriptDebugServer& debugServer = DartScriptDebugServer::shared(); | |
| 400 for (intptr_t i = 0; i < length; i++) { | |
| 401 Dart_ActivationFrame frame = 0; | |
| 402 result = Dart_GetActivationFrame(trace, i, &frame); | |
| 403 ASSERT(!Dart_IsError(result)); | |
| 404 Dart_Handle functionName = 0; | |
| 405 Dart_CodeLocation location; | |
| 406 Dart_ActivationFrameGetLocation(frame, &functionName, 0, &location); | |
| 407 const String& url = DartUtilities::toString(location.script_url); | |
| 408 intptr_t line = 0; | |
| 409 intptr_t column = 0; | |
| 410 Dart_ActivationFrameInfo(frame, 0, 0, &line, &column); | |
| 411 | |
| 412 ret->addItem(TypeBuilder::Console::CallFrame::create() | |
| 413 .setFunctionName(DartUtilities::toString(functionName)) | |
| 414 .setScriptId(debugServer.getScriptId(url, Dart_CurrentIsolate())) | |
| 415 .setUrl(url) | |
| 416 .setLineNumber(line-1) | |
| 417 .setColumnNumber(column) | |
| 418 .release()); | |
| 419 } | |
| 420 return ret; | |
| 421 } | |
| 422 | |
| 423 void DartInjectedScript::packageObjectResult(Dart_Handle dartHandle, const Strin
g& objectGroup, ErrorString* errorString, bool returnByValue, bool generatePrevi
ew, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<b
ool>* wasThrown) | |
| 424 { | |
| 425 ASSERT(Dart_IsInstance(dartHandle) || Dart_IsNull(dartHandle)); | |
| 426 | |
| 427 // FIXMEDART: support returnByValue for Dart types that are expressible as J
SON. | |
| 428 bool wasThrownVal = false; | |
| 429 Dart_Handle exception = 0; | |
| 430 if (Dart_IsError(dartHandle)) { | |
| 431 wasThrownVal = true; | |
| 432 Dart_Handle exception = Dart_ErrorGetException(dartHandle); | |
| 433 ASSERT(Dart_IsInstance(exception)); | |
| 434 if (!Dart_IsInstance(exception)) { | |
| 435 *errorString = Dart_GetError(dartHandle); | |
| 436 return; | |
| 437 } | |
| 438 dartHandle = exception; | |
| 439 } | |
| 440 | |
| 441 // Primitive value | |
| 442 RefPtr<JSONValue> value = nullptr; | |
| 443 TypeBuilder::Runtime::RemoteObject::Type::Enum remoteObjectType = TypeBuilde
r::Runtime::RemoteObject::Type::Object; | |
| 444 ASSERT(Dart_IsInstance(dartHandle) || Dart_IsNull(dartHandle)); | |
| 445 | |
| 446 if (Dart_IsNull(dartHandle)) { | |
| 447 value = JSONValue::null(); | |
| 448 } else { | |
| 449 if (Dart_IsString(dartHandle)) { | |
| 450 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::String; | |
| 451 value = JSONString::create(DartUtilities::toString(dartHandle)); | |
| 452 } else if (Dart_IsDouble(dartHandle)) { | |
| 453 // FIXMEDART: add an extra entry for int? | |
| 454 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::Number; | |
| 455 value = JSONBasicValue::create(DartUtilities::dartToDouble(dartHandl
e, exception)); | |
| 456 ASSERT(!exception); | |
| 457 } else if (Dart_IsNumber(dartHandle)) { | |
| 458 // FIXMEDART: handle ints that are larger than 50 bits. | |
| 459 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::Number; | |
| 460 value = JSONBasicValue::create(DartUtilities::dartToDouble(dartHandl
e, exception)); | |
| 461 ASSERT(!exception); | |
| 462 } else if (Dart_IsBoolean(dartHandle)) { | |
| 463 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::Boolean
; | |
| 464 value = JSONBasicValue::create(DartUtilities::dartToBool(dartHandle,
exception)); | |
| 465 ASSERT(!exception); | |
| 466 } | |
| 467 } | |
| 468 | |
| 469 String typeName; | |
| 470 String description; | |
| 471 bool isNode = false; | |
| 472 if (Dart_IsNull(dartHandle)) { | |
| 473 typeName = "null"; | |
| 474 description = "null"; | |
| 475 } else { | |
| 476 Dart_Handle dartType = Dart_InstanceGetType(dartHandle); | |
| 477 Dart_Handle typeNameHandle = Dart_TypeName(dartType); | |
| 478 ASSERT(!Dart_IsError(typeNameHandle)); | |
| 479 typeName = DartUtilities::dartToString(typeNameHandle, exception); | |
| 480 description = DartUtilities::dartToString(Dart_ToString(dartHandle), exc
eption); | |
| 481 if (exception) { | |
| 482 description = String::format("Instance of '%s'", typeName.utf8().dat
a()); | |
| 483 exception = 0; | |
| 484 } | |
| 485 ASSERT(!exception); | |
| 486 if (DartDOMWrapper::subtypeOf(dartHandle, DartNode::dartClassId)) | |
| 487 isNode = true; | |
| 488 } | |
| 489 | |
| 490 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(remoteObjectType).release(); | |
| 491 remoteObject->setLanguage("Dart"); | |
| 492 remoteObject->setClassName(typeName); | |
| 493 remoteObject->setDescription(description); | |
| 494 if (value) | |
| 495 remoteObject->setValue(value); | |
| 496 | |
| 497 if (isNode) | |
| 498 remoteObject->setSubtype(RemoteObject::Subtype::Node); | |
| 499 | |
| 500 // FIXMEDART: generate preview if generatePreview is true. | |
| 501 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::O
bject); | |
| 502 remoteObject->setObjectId(objectId); | |
| 503 *result = remoteObject; | |
| 504 if (wasThrown) { | |
| 505 *wasThrown = exception || wasThrownVal; | |
| 506 } | |
| 507 } | |
| 508 | |
| 509 void DartInjectedScript::packageObjectClassResult(Dart_Handle dartHandle, const
String& objectGroup, ErrorString* errorString, bool returnByValue, bool generate
Preview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOut
put<bool>* wasThrown) | |
| 510 { | |
| 511 ASSERT(Dart_IsInstance(dartHandle) || Dart_IsNull(dartHandle)); | |
| 512 bool wasThrownVal = false; | |
| 513 Dart_Handle exception = 0; | |
| 514 | |
| 515 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 516 remoteObject->setLanguage("Dart"); | |
| 517 | |
| 518 Dart_Handle typeHandle = Dart_InstanceGetType(dartHandle); | |
| 519 String typeName = DartUtilities::toString(Dart_TypeName(typeHandle)); | |
| 520 | |
| 521 remoteObject->setClassName(typeName); | |
| 522 remoteObject->setDescription(typeName); | |
| 523 | |
| 524 // Don't generate a preview for types. | |
| 525 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::O
bjectClass); | |
| 526 remoteObject->setObjectId(objectId); | |
| 527 *result = remoteObject; | |
| 528 if (wasThrown) | |
| 529 *wasThrown = exception || wasThrownVal; | |
| 530 } | |
| 531 | |
| 532 void DartInjectedScript::packageClassResult(Dart_Handle dartHandle, DartDebugger
Object::Kind kind, const String& objectGroup, ErrorString* errorString, bool ret
urnByValue, bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* re
sult, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 533 { | |
| 534 bool wasThrownVal = false; | |
| 535 Dart_Handle exception = 0; | |
| 536 | |
| 537 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 538 remoteObject->setLanguage("Dart"); | |
| 539 String typeName = DartUtilities::toString(Dart_TypeName(dartHandle)); | |
| 540 String typeDescription("class "); | |
| 541 typeDescription.append(typeName); | |
| 542 | |
| 543 remoteObject->setClassName(typeName); | |
| 544 remoteObject->setDescription(typeDescription); | |
| 545 | |
| 546 // Don't generate a preview for types. | |
| 547 String objectId = cacheObject(dartHandle, objectGroup, kind); | |
| 548 remoteObject->setObjectId(objectId); | |
| 549 *result = remoteObject; | |
| 550 if (wasThrown) | |
| 551 *wasThrown = exception || wasThrownVal; | |
| 552 } | |
| 553 | |
| 554 void DartInjectedScript::packageFunctionResult(Dart_Handle dartHandle, const Str
ing& objectGroup, ErrorString* errorString, bool returnByValue, bool generatePre
view, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput
<bool>* wasThrown) | |
| 555 { | |
| 556 ASSERT(DartUtilities::isFunction(DartDOMData::current(), dartHandle)); | |
| 557 bool wasThrownVal = false; | |
| 558 Dart_Handle exception = 0; | |
| 559 | |
| 560 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Function).release(); | |
| 561 remoteObject->setLanguage("Dart"); | |
| 562 remoteObject->setClassName("<Dart Function>"); | |
| 563 remoteObject->setDescription(stripFunctionDescription(DartUtilities::toStrin
g(describeFunction(dartHandle)))); | |
| 564 | |
| 565 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::F
unction); | |
| 566 remoteObject->setObjectId(objectId); | |
| 567 *result = remoteObject; | |
| 568 if (wasThrown) { | |
| 569 *wasThrown = exception || wasThrownVal; | |
| 570 } | |
| 571 } | |
| 572 | |
| 573 void DartInjectedScript::packageMethodResult(Dart_Handle dartHandle, const Strin
g& objectGroup, ErrorString* errorString, bool returnByValue, bool generatePrevi
ew, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<b
ool>* wasThrown) | |
| 574 { | |
| 575 ASSERT(DartUtilities::isFunction(DartDOMData::current(), dartHandle)); | |
| 576 bool wasThrownVal = false; | |
| 577 Dart_Handle exception = 0; | |
| 578 | |
| 579 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Function).release(); | |
| 580 remoteObject->setLanguage("Dart"); | |
| 581 remoteObject->setClassName("<Dart Method>"); | |
| 582 remoteObject->setDescription(stripFunctionDescription(DartUtilities::toStrin
g(describeFunction(dartHandle)))); | |
| 583 | |
| 584 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::M
ethod); | |
| 585 remoteObject->setObjectId(objectId); | |
| 586 *result = remoteObject; | |
| 587 if (wasThrown) | |
| 588 *wasThrown = exception || wasThrownVal; | |
| 589 } | |
| 590 | |
| 591 void DartInjectedScript::packageLocalVariablesResult(Dart_Handle dartHandle, con
st String& objectGroup, ErrorString* errorString, bool returnByValue, bool gener
atePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::Opt
Output<bool>* wasThrown) | |
| 592 { | |
| 593 bool wasThrownVal = false; | |
| 594 Dart_Handle exception = 0; | |
| 595 | |
| 596 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 597 remoteObject->setLanguage("Dart"); | |
| 598 remoteObject->setClassName("Object"); | |
| 599 remoteObject->setDescription("Local Variables"); | |
| 600 | |
| 601 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::L
ocalVariables); | |
| 602 remoteObject->setObjectId(objectId); | |
| 603 *result = remoteObject; | |
| 604 if (wasThrown) | |
| 605 *wasThrown = exception || wasThrownVal; | |
| 606 } | |
| 607 | |
| 608 void DartInjectedScript::packageErrorResult(Dart_Handle dartHandle, const String
& objectGroup, ErrorString* errorString, bool returnByValue, bool generatePrevie
w, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bo
ol>* wasThrown) | |
| 609 { | |
| 610 ASSERT(Dart_IsError(dartHandle)); | |
| 611 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 612 remoteObject->setLanguage("Dart"); | |
| 613 remoteObject->setClassName("Error"); | |
| 614 remoteObject->setDescription(Dart_GetError(dartHandle)); | |
| 615 | |
| 616 Dart_Handle exception = Dart_ErrorGetException(dartHandle); | |
| 617 String objectId = cacheObject(exception, objectGroup, DartDebuggerObject::Er
ror); | |
| 618 remoteObject->setObjectId(objectId); | |
| 619 *result = remoteObject; | |
| 620 if (wasThrown) | |
| 621 *wasThrown = true; | |
| 622 } | |
| 623 | |
| 624 void DartInjectedScript::packageLibraryResult(Dart_Handle dartHandle, DartDebugg
erObject::Kind kind, const String& objectGroup, ErrorString* errorString, bool r
eturnByValue, bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>*
result, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 625 { | |
| 626 ASSERT(Dart_IsLibrary(dartHandle)); | |
| 627 bool wasThrownVal = false; | |
| 628 intptr_t libraryId = 0; | |
| 629 Dart_Handle exception = 0; | |
| 630 Dart_Handle ALLOW_UNUSED ret; | |
| 631 ret = Dart_LibraryId(dartHandle, &libraryId); | |
| 632 ASSERT(!Dart_IsError(ret)); | |
| 633 | |
| 634 // FIXMEDART: Demangle library name. | |
| 635 String libraryName = DartUtilities::toString(Dart_LibraryName(dartHandle)); | |
| 636 String libraryUri = DartUtilities::toString(Dart_GetLibraryURL(libraryId)); | |
| 637 if (libraryName == "") | |
| 638 libraryName = libraryUri; | |
| 639 | |
| 640 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 641 remoteObject->setLanguage("Dart"); | |
| 642 remoteObject->setClassName(libraryUri); | |
| 643 remoteObject->setDescription(libraryName); | |
| 644 String objectId = cacheObject(dartHandle, objectGroup, kind); | |
| 645 remoteObject->setObjectId(objectId); | |
| 646 *result = remoteObject; | |
| 647 if (wasThrown) | |
| 648 *wasThrown = exception || wasThrownVal; | |
| 649 } | |
| 650 | |
| 651 void DartInjectedScript::packageIsolateResult(Dart_Handle dartHandle, const Stri
ng& objectGroup, ErrorString* errorString, bool returnByValue, bool generatePrev
iew, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<
bool>* wasThrown) | |
| 652 { | |
| 653 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea
te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 654 | |
| 655 String isolateName = DartUtilities::toString(Dart_DebugName()); | |
| 656 | |
| 657 remoteObject->setLanguage("Dart"); | |
| 658 remoteObject->setClassName("Dart Isolate"); | |
| 659 remoteObject->setDescription(isolateName); | |
| 660 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::I
solate); | |
| 661 remoteObject->setObjectId(objectId); | |
| 662 *result = remoteObject; | |
| 663 } | |
| 664 | |
| 665 Dart_Handle DartInjectedScript::library() | |
| 666 { | |
| 667 ASSERT(m_scriptState); | |
| 668 return Dart_GetLibraryFromId(m_scriptState->libraryId()); | |
| 669 } | |
| 670 | |
| 671 void DartInjectedScript::evaluate(ErrorString* errorString, const String& expres
sion, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue,
bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeB
uilder::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetai
ls>* exceptionDetails) | |
| 672 { | |
| 673 if (!m_scriptState) { | |
| 674 *errorString = "Invalid DartInjectedScript"; | |
| 675 return; | |
| 676 } | |
| 677 DartIsolateScope scope(m_scriptState->isolate()); | |
| 678 DartApiScope apiScope; | |
| 679 V8Scope v8scope(DartDOMData::current()); | |
| 680 evaluateAndPackageResult(library(), expression, Dart_Null(), includeCommandL
ineAPI, objectGroup, errorString, returnByValue, generatePreview, result, wasThr
own, exceptionDetails); | |
| 681 } | |
| 682 | |
| 683 void DartInjectedScript::callFunctionOn(ErrorString* errorString, const String&
objectId, const String& expression, const String& arguments, bool returnByValue,
bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeB
uilder::OptOutput<bool>* wasThrown) | |
| 684 { | |
| 685 Dart_Handle exception = 0; | |
| 686 String objectGroup; | |
| 687 if (!m_scriptState) { | |
| 688 *errorString = "Invalid DartInjectedScript"; | |
| 689 return; | |
| 690 } | |
| 691 DartIsolateScope scope(m_scriptState->isolate()); | |
| 692 DartApiScope apiScope; | |
| 693 { | |
| 694 DartDebuggerObject* object = lookupObject(objectId); | |
| 695 if (!object) { | |
| 696 *errorString = "Object has been deleted"; | |
| 697 return; | |
| 698 } | |
| 699 objectGroup = object->group(); | |
| 700 Vector<Dart_Handle> dartFunctionArgs; | |
| 701 if (arguments.length()) { | |
| 702 RefPtr<JSONValue> parsedArguments = parseJSON(arguments); | |
| 703 if (!parsedArguments.get()) { | |
| 704 *errorString = "Unable to parse arguments json"; | |
| 705 return; | |
| 706 } | |
| 707 if (!parsedArguments->isNull()) { | |
| 708 if (parsedArguments->type() != JSONValue::TypeArray) { | |
| 709 *errorString = "Invalid arguments"; | |
| 710 return; | |
| 711 } | |
| 712 RefPtr<JSONArray> argumentsArray = parsedArguments->asArray(); | |
| 713 for (JSONArray::iterator it = argumentsArray->begin(); it != arg
umentsArray->end(); ++it) { | |
| 714 RefPtr<JSONObject> arg; | |
| 715 if (!(*it)->asObject(&arg)) { | |
| 716 *errorString = "Invalid argument passed to callFunctionO
n"; | |
| 717 return; | |
| 718 } | |
| 719 String argObjectId; | |
| 720 | |
| 721 if (!arg->getString("objectId", &argObjectId)) { | |
| 722 // FIXME: support primitive values passed as arguments a
s well. | |
| 723 *errorString = "Unspecified object id"; | |
| 724 } | |
| 725 | |
| 726 DartDebuggerObject* argObject = lookupObject(argObjectId); | |
| 727 if (!argObject) { | |
| 728 *errorString = "Argument has been deleted"; | |
| 729 return; | |
| 730 } | |
| 731 dartFunctionArgs.append(argObject->handle()); | |
| 732 } | |
| 733 } | |
| 734 } | |
| 735 | |
| 736 Dart_Handle dartClosure = evaluateHelper(object->handle(), expression, D
art_Null(), false, exception); | |
| 737 if (exception) | |
| 738 goto fail; | |
| 739 | |
| 740 if (Dart_IsError(dartClosure)) { | |
| 741 *errorString = Dart_GetError(dartClosure); | |
| 742 return; | |
| 743 } | |
| 744 if (!Dart_IsClosure(dartClosure)) { | |
| 745 *errorString = "Given expression does not evaluate to a closure"; | |
| 746 return; | |
| 747 } | |
| 748 Dart_Handle evalResult = Dart_InvokeClosure(dartClosure, dartFunctionArg
s.size(), dartFunctionArgs.data()); | |
| 749 packageResult(evalResult, inferKind(evalResult), objectGroup, errorStrin
g, returnByValue, generatePreview, result, wasThrown); | |
| 750 return; | |
| 751 } | |
| 752 fail: | |
| 753 ASSERT(exception); | |
| 754 packageResult(exception, DartDebuggerObject::Error, objectGroup, errorString
, returnByValue, generatePreview, result, wasThrown); | |
| 755 | |
| 756 | |
| 757 } | |
| 758 | |
| 759 void DartInjectedScript::evaluateOnCallFrame(ErrorString* errorString, const Dar
t_StackTrace callFrames, const String& callFrameId, const String& expression, co
nst String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool ge
neratePreview, RefPtr<RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasTh
rown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exceptionDetails) | |
| 760 { | |
| 761 DartIsolateScope scope(m_scriptState->isolate()); | |
| 762 DartApiScope apiScope; | |
| 763 // FIXMEDART: add v8Scope calls elsewhere. | |
| 764 V8Scope v8scope(DartDOMData::current()); | |
| 765 | |
| 766 Dart_ActivationFrame frame = callFrameForId(callFrames, callFrameId); | |
| 767 ASSERT(frame); | |
| 768 if (!frame) { | |
| 769 *errorString = "Call frame not found"; | |
| 770 return; | |
| 771 } | |
| 772 | |
| 773 Dart_Handle function = 0; | |
| 774 Dart_ActivationFrameGetLocation(frame, 0, &function, 0); | |
| 775 ASSERT(function); | |
| 776 Dart_Handle localVariables = Dart_GetLocalVariables(frame); | |
| 777 Dart_Handle thisHandle = findReceiver(localVariables); | |
| 778 Dart_Handle context = thisHandle ? thisHandle : lookupEnclosingType(function
); | |
| 779 evaluateAndPackageResult(context, expression, localVariables, includeCommand
LineAPI, objectGroup, errorString, returnByValue, generatePreview, result, wasTh
rown, exceptionDetails); | |
| 780 } | |
| 781 | |
| 782 void DartInjectedScript::restartFrame(ErrorString* errorString, const Dart_Stack
Trace callFrames, const String& callFrameId, RefPtr<JSONObject>* result) | |
| 783 { | |
| 784 *errorString = "Dart does not yet support restarting call frames"; | |
| 785 return; | |
| 786 } | |
| 787 | |
| 788 void DartInjectedScript::setVariableValue(ErrorString* errorString, const Dart_S
tackTrace callFrames, const String* callFrameIdOpt, const String* functionObject
IdOpt, int scopeNumber, const String& variableName, const String& newValueStr) | |
| 789 { | |
| 790 if (!m_scriptState) { | |
| 791 *errorString = "Invalid DartInjectedScript"; | |
| 792 return; | |
| 793 } | |
| 794 DartIsolateScope scope(m_scriptState->isolate()); | |
| 795 DartApiScope apiScope; | |
| 796 *errorString = "Not supported by Dart."; | |
| 797 return; | |
| 798 } | |
| 799 | |
| 800 void DartInjectedScript::getFunctionDetails(ErrorString* errorString, const Stri
ng& functionId, RefPtr<FunctionDetails>* result) | |
| 801 { | |
| 802 if (!m_scriptState) { | |
| 803 *errorString = "Invalid DartInjectedScript"; | |
| 804 return; | |
| 805 } | |
| 806 DartIsolateScope scope(m_scriptState->isolate()); | |
| 807 DartApiScope apiScope; | |
| 808 DartDebuggerObject* object = lookupObject(functionId); | |
| 809 if (!object) { | |
| 810 *errorString = "Object has been deleted"; | |
| 811 return; | |
| 812 } | |
| 813 | |
| 814 int line = 0; | |
| 815 int column = 0; | |
| 816 DartScriptDebugServer& debugServer = DartScriptDebugServer::shared(); | |
| 817 Dart_Handle url; | |
| 818 Dart_Handle name = 0; | |
| 819 Dart_Handle exception = 0; | |
| 820 | |
| 821 switch (object->kind()) { | |
| 822 case DartDebuggerObject::Function: { | |
| 823 Dart_CodeLocation location; | |
| 824 Dart_Handle ret = Dart_GetClosureInfo(object->handle(), &name, 0, &locat
ion); | |
| 825 if (Dart_IsError(ret) || !debugServer.resolveCodeLocation(location, &lin
e, &column)) { | |
| 826 // Avoid returning an error for this case which can legitimately | |
| 827 // occur if the function was the result of calling Dart_EvaluateExpr
. | |
| 828 RefPtr<Location> locationJson = Location::create() | |
| 829 .setScriptId("INVALID_SCRIPT_ID") | |
| 830 .setLineNumber(0); | |
| 831 *result = FunctionDetails::create().setLocation(locationJson).setFun
ctionName("DartClosure").release(); | |
| 832 return; | |
| 833 } | |
| 834 url = location.script_url; | |
| 835 break; | |
| 836 } | |
| 837 case DartDebuggerObject::Method: | |
| 838 { | |
| 839 Dart_Handle ret = getInvocationTrampolineDetails(object->handle()); | |
| 840 | |
| 841 if (Dart_IsError(ret)) { | |
| 842 *errorString = Dart_GetError(ret); | |
| 843 return; | |
| 844 } | |
| 845 ASSERT(Dart_IsList(ret)); | |
| 846 line = DartUtilities::toInteger(Dart_ListGetAt(ret, 0), exception); | |
| 847 column = DartUtilities::toInteger(Dart_ListGetAt(ret, 1), exception)
; | |
| 848 url = Dart_ListGetAt(ret, 2); | |
| 849 name = Dart_ListGetAt(ret, 3); | |
| 850 break; | |
| 851 } | |
| 852 default: | |
| 853 *errorString = "Object is not a function."; | |
| 854 return; | |
| 855 } | |
| 856 | |
| 857 ASSERT(!exception); | |
| 858 | |
| 859 RefPtr<Location> locationJson = Location::create() | |
| 860 .setScriptId(debugServer.getScriptId(DartUtilities::toString(url), Dart_
CurrentIsolate())) | |
| 861 .setLineNumber(line - 1); | |
| 862 locationJson->setColumnNumber(column); | |
| 863 | |
| 864 *result = FunctionDetails::create().setLocation(locationJson).setFunctionNam
e(DartUtilities::toString(name)).release(); | |
| 865 } | |
| 866 | |
| 867 void addCompletions(Dart_Handle completions, RefPtr<TypeBuilder::Array<String> >
* result) | |
| 868 { | |
| 869 ASSERT(Dart_IsList(completions)); | |
| 870 intptr_t length = 0; | |
| 871 Dart_ListLength(completions, &length); | |
| 872 for (intptr_t i = 0; i < length; ++i) | |
| 873 (*result)->addItem(DartUtilities::toString(Dart_ListGetAt(completions, i
))); | |
| 874 } | |
| 875 | |
| 876 void DartInjectedScript::getCompletionsOnCallFrame(ErrorString* errorString, con
st Dart_StackTrace callFrames, const String& callFrameId, const String& expressi
on, RefPtr<TypeBuilder::Array<String> >* result) | |
| 877 { | |
| 878 *result = TypeBuilder::Array<String>::create(); | |
| 879 if (!m_scriptState) { | |
| 880 *errorString = "Invalid DartInjectedScript"; | |
| 881 return; | |
| 882 } | |
| 883 DartIsolateScope scope(m_scriptState->isolate()); | |
| 884 DartApiScope apiScope; | |
| 885 V8Scope v8scope(DartDOMData::current()); | |
| 886 | |
| 887 Dart_ActivationFrame frame = callFrameForId(callFrames, callFrameId); | |
| 888 ASSERT(frame); | |
| 889 if (!frame) { | |
| 890 *errorString = "Call frame not found"; | |
| 891 return; | |
| 892 } | |
| 893 | |
| 894 Dart_Handle function = 0; | |
| 895 Dart_ActivationFrameGetLocation(frame, 0, &function, 0); | |
| 896 ASSERT(function); | |
| 897 Dart_Handle localVariables = Dart_GetLocalVariables(frame); | |
| 898 Dart_Handle thisHandle = findReceiver(localVariables); | |
| 899 Dart_Handle enclosingType = lookupEnclosingType(function); | |
| 900 Dart_Handle context = thisHandle ? thisHandle : enclosingType; | |
| 901 | |
| 902 if (expression.isEmpty()) { | |
| 903 addCompletions(getLibraryCompletionsIncludingImports(library()), result)
; | |
| 904 if (!Dart_IsLibrary(context)) { | |
| 905 addCompletions(getObjectCompletions(context, library()), result); | |
| 906 } | |
| 907 if (context != enclosingType) { | |
| 908 addCompletions(getObjectCompletions(enclosingType, library()), resul
t); | |
| 909 } | |
| 910 intptr_t length = 0; | |
| 911 Dart_ListLength(localVariables, &length); | |
| 912 for (intptr_t i = 0; i < length; i += 2) | |
| 913 (*result)->addItem(stripVariableName(DartUtilities::toString(Dart_Li
stGetAt(localVariables, i)))); | |
| 914 } else { | |
| 915 // FIXME: we can do better than evaluating the expression and getting | |
| 916 // all completions for that object if an exception is not thrown. For | |
| 917 // example run the Dart Analyzer to get completions of complex | |
| 918 // expressions without triggering side effects or failing for | |
| 919 // expressions that do not evaluate to a first class object. For | |
| 920 // example, the html library is imported with prefix html and the | |
| 921 // expression html is used. | |
| 922 Dart_Handle exception = 0; | |
| 923 Dart_Handle handle = evaluateHelper(context, expression, localVariables,
true, exception); | |
| 924 | |
| 925 // No completions if the expression cannot be evaluated. | |
| 926 if (exception) | |
| 927 return; | |
| 928 addCompletions(getObjectCompletions(handle, library()), result); | |
| 929 } | |
| 930 } | |
| 931 | |
| 932 void DartInjectedScript::getCompletions(ErrorString* errorString, const String&
expression, RefPtr<TypeBuilder::Array<String> >* result) | |
| 933 { | |
| 934 *result = TypeBuilder::Array<String>::create(); | |
| 935 | |
| 936 if (!m_scriptState) { | |
| 937 *errorString = "Invalid DartInjectedScript"; | |
| 938 return; | |
| 939 } | |
| 940 DartIsolateScope scope(m_scriptState->isolate()); | |
| 941 DartApiScope apiScope; | |
| 942 V8Scope v8scope(DartDOMData::current()); | |
| 943 | |
| 944 Dart_Handle completions; | |
| 945 if (expression.isEmpty()) { | |
| 946 completions = getLibraryCompletionsIncludingImports(library()); | |
| 947 } else { | |
| 948 // FIXME: we can do better than evaluating the expression and getting | |
| 949 // all completions for that object if an exception is not thrown. For | |
| 950 // example run the Dart Analyzer to get completions of complex | |
| 951 // expressions without triggering side effects or failing for | |
| 952 // expressions that do not evaluate to a first class object. For | |
| 953 // example, the html library is imported with prefix html and the | |
| 954 // expression html is used. | |
| 955 Dart_Handle exception = 0; | |
| 956 Dart_Handle handle = evaluateHelper(library(), expression, Dart_Null(),
true, exception); | |
| 957 // No completions if the expression cannot be evaluated. | |
| 958 if (exception) | |
| 959 return; | |
| 960 completions = getObjectCompletions(handle, library()); | |
| 961 } | |
| 962 | |
| 963 addCompletions(completions, result); | |
| 964 } | |
| 965 | |
| 966 void DartInjectedScript::getProperties(ErrorString* errorString, const String& o
bjectId, bool ownProperties, bool accessorPropertiesOnly, RefPtr<Array<PropertyD
escriptor> >* properties) | |
| 967 { | |
| 968 Dart_Handle exception = 0; | |
| 969 if (!m_scriptState) { | |
| 970 *errorString = "Invalid DartInjectedScript"; | |
| 971 return; | |
| 972 } | |
| 973 DartIsolateScope scope(m_scriptState->isolate()); | |
| 974 DartApiScope apiScope; | |
| 975 | |
| 976 DartDebuggerObject* object = lookupObject(objectId); | |
| 977 if (!object) { | |
| 978 *errorString = "Unknown objectId"; | |
| 979 return; | |
| 980 } | |
| 981 Dart_Handle handle = object->handle(); | |
| 982 String objectGroup = object->group(); | |
| 983 | |
| 984 *properties = Array<PropertyDescriptor>::create(); | |
| 985 Dart_Handle propertiesList; | |
| 986 switch (object->kind()) { | |
| 987 case DartDebuggerObject::Object: | |
| 988 case DartDebuggerObject::Function: | |
| 989 case DartDebuggerObject::Error: | |
| 990 propertiesList = getObjectProperties(handle, ownProperties, accessorProp
ertiesOnly); | |
| 991 break; | |
| 992 case DartDebuggerObject::ObjectClass: | |
| 993 propertiesList = getObjectClassProperties(handle, ownProperties, accesso
rPropertiesOnly); | |
| 994 break; | |
| 995 case DartDebuggerObject::Method: | |
| 996 // There aren't any meaningful properties to display for a Dart method. | |
| 997 return; | |
| 998 case DartDebuggerObject::Class: | |
| 999 case DartDebuggerObject::StaticClass: | |
| 1000 propertiesList = getClassProperties(handle, ownProperties, accessorPrope
rtiesOnly); | |
| 1001 break; | |
| 1002 case DartDebuggerObject::Library: | |
| 1003 case DartDebuggerObject::CurrentLibrary: | |
| 1004 propertiesList = getLibraryProperties(handle, ownProperties, accessorPro
pertiesOnly); | |
| 1005 break; | |
| 1006 case DartDebuggerObject::LocalVariables: | |
| 1007 { | |
| 1008 if (accessorPropertiesOnly) | |
| 1009 return; | |
| 1010 ASSERT(Dart_IsList(handle)); | |
| 1011 intptr_t length = 0; | |
| 1012 Dart_Handle ALLOW_UNUSED ret = Dart_ListLength(handle, &length); | |
| 1013 ASSERT(!Dart_IsError(ret)); | |
| 1014 for (intptr_t i = 0; i < length; i += 2) { | |
| 1015 const String& name = stripVariableName(DartUtilities::toString(D
art_ListGetAt(handle, i))); | |
| 1016 Dart_Handle value = Dart_ListGetAt(handle, i + 1); | |
| 1017 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::crea
te().setName(name).setConfigurable(false).setEnumerable(true).release(); | |
| 1018 descriptor->setValue(wrapDartHandle(value, inferKind(value), obj
ectGroup, false)); | |
| 1019 descriptor->setWritable(false); | |
| 1020 descriptor->setWasThrown(false); | |
| 1021 descriptor->setIsOwn(true); | |
| 1022 (*properties)->addItem(descriptor); | |
| 1023 } | |
| 1024 return; | |
| 1025 } | |
| 1026 case DartDebuggerObject::Isolate: | |
| 1027 { | |
| 1028 if (accessorPropertiesOnly) | |
| 1029 return; | |
| 1030 | |
| 1031 Dart_Handle libraries = handle; | |
| 1032 ASSERT(Dart_IsList(libraries)); | |
| 1033 | |
| 1034 intptr_t librariesLength = 0; | |
| 1035 Dart_Handle ALLOW_UNUSED result = Dart_ListLength(libraries, &librar
iesLength); | |
| 1036 ASSERT(!Dart_IsError(result)); | |
| 1037 for (intptr_t i = 0; i < librariesLength; ++i) { | |
| 1038 Dart_Handle libraryIdHandle = Dart_ListGetAt(libraries, i); | |
| 1039 ASSERT(!Dart_IsError(libraryIdHandle)); | |
| 1040 Dart_Handle exception = 0; | |
| 1041 int64_t libraryId = DartUtilities::toInteger(libraryIdHandle, ex
ception); | |
| 1042 const String& name = DartUtilities::toString(Dart_GetLibraryURL(
libraryId)); | |
| 1043 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::crea
te().setName(name).setConfigurable(false).setEnumerable(true).release(); | |
| 1044 descriptor->setValue(wrapDartHandle(Dart_GetLibraryFromId(librar
yId), DartDebuggerObject::Library, objectGroup, false)); | |
| 1045 descriptor->setWritable(false); | |
| 1046 descriptor->setWasThrown(false); | |
| 1047 descriptor->setIsOwn(true); | |
| 1048 (*properties)->addItem(descriptor); | |
| 1049 ASSERT(!exception); | |
| 1050 } | |
| 1051 return; | |
| 1052 } | |
| 1053 default: | |
| 1054 ASSERT_NOT_REACHED(); | |
| 1055 *errorString = "Internal error"; | |
| 1056 return; | |
| 1057 } | |
| 1058 | |
| 1059 if (Dart_IsError(propertiesList)) { | |
| 1060 *errorString = Dart_GetError(propertiesList); | |
| 1061 return; | |
| 1062 } | |
| 1063 | |
| 1064 ASSERT(Dart_IsList(propertiesList)); | |
| 1065 intptr_t length = 0; | |
| 1066 Dart_Handle ALLOW_UNUSED ret = Dart_ListLength(propertiesList, &length); | |
| 1067 ASSERT(!Dart_IsError(ret)); | |
| 1068 ASSERT(!(length % 9)); | |
| 1069 for (intptr_t i = 0; i < length; i += 9) { | |
| 1070 String name = DartUtilities::toString(Dart_ListGetAt(propertiesList, i))
; | |
| 1071 Dart_Handle setter = Dart_ListGetAt(propertiesList, i + 1); | |
| 1072 Dart_Handle getter = Dart_ListGetAt(propertiesList, i + 2); | |
| 1073 Dart_Handle value = Dart_ListGetAt(propertiesList, i + 3); | |
| 1074 bool hasValue = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList,
i + 4), exception); | |
| 1075 ASSERT(!exception); | |
| 1076 bool writable = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList,
i + 5), exception); | |
| 1077 ASSERT(!exception); | |
| 1078 bool isMethod = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList,
i + 6), exception); | |
| 1079 ASSERT(!exception); | |
| 1080 bool isOwn = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList, i
+ 7), exception); | |
| 1081 ASSERT(!exception); | |
| 1082 bool wasThrown = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList
, i + 8), exception); | |
| 1083 ASSERT(!exception); | |
| 1084 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::create().set
Name(name).setConfigurable(false).setEnumerable(true).release(); | |
| 1085 if (isMethod) { | |
| 1086 ASSERT(hasValue); | |
| 1087 descriptor->setValue(wrapDartHandle(value, DartDebuggerObject::Metho
d, objectGroup, false)); | |
| 1088 } else { | |
| 1089 if (hasValue) | |
| 1090 descriptor->setValue(wrapDartHandle(value, inferKind(value), obj
ectGroup, false)); | |
| 1091 if (!Dart_IsNull(setter)) | |
| 1092 descriptor->setSet(wrapDartHandle(setter, DartDebuggerObject::Me
thod, objectGroup, false)); | |
| 1093 if (!Dart_IsNull(getter)) | |
| 1094 descriptor->setGet(wrapDartHandle(getter, DartDebuggerObject::Me
thod, objectGroup, false)); | |
| 1095 } | |
| 1096 descriptor->setWritable(writable); | |
| 1097 descriptor->setWasThrown(wasThrown); | |
| 1098 descriptor->setIsOwn(isOwn); | |
| 1099 | |
| 1100 (*properties)->addItem(descriptor); | |
| 1101 } | |
| 1102 | |
| 1103 if (object->kind() == DartDebuggerObject::Object && !accessorPropertiesOnly
&& !Dart_IsNull(handle)) { | |
| 1104 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::create().set
Name("[[class]]").setConfigurable(false).setEnumerable(true).release(); | |
| 1105 descriptor->setValue(wrapDartHandle(handle, DartDebuggerObject::ObjectCl
ass, objectGroup, false)); | |
| 1106 descriptor->setWritable(false); | |
| 1107 descriptor->setWasThrown(false); | |
| 1108 descriptor->setIsOwn(true); | |
| 1109 (*properties)->addItem(descriptor); | |
| 1110 | |
| 1111 if (DartDOMWrapper::subtypeOf(handle, JsObject::dartClassId)) { | |
| 1112 DartDOMData* domData = DartDOMData::current(); | |
| 1113 JsObject* object = DartDOMWrapper::unwrapDartWrapper<JsObject>(domDa
ta, handle, exception); | |
| 1114 if (!exception) { | |
| 1115 descriptor = PropertyDescriptor::create().setName("[[JavaScript
View]]").setConfigurable(false).setEnumerable(true).release(); | |
| 1116 | |
| 1117 V8ScriptState* v8ScriptState = DartUtilities::v8ScriptStateForCu
rrentIsolate(); | |
| 1118 InjectedScript v8InjectedScript = m_injectedScriptManager->injec
tedScriptFor(v8ScriptState); | |
| 1119 ScriptValue v8ScriptValue(v8ScriptState, object->localV8Object()
); | |
| 1120 descriptor->setValue(v8InjectedScript.wrapObject(v8ScriptValue,
objectGroup, false)); | |
| 1121 descriptor->setWritable(false); | |
| 1122 descriptor->setWasThrown(false); | |
| 1123 descriptor->setIsOwn(true); | |
| 1124 (*properties)->addItem(descriptor); | |
| 1125 } | |
| 1126 } | |
| 1127 } | |
| 1128 } | |
| 1129 | |
| 1130 void DartInjectedScript::getInternalProperties(ErrorString* errorString, const S
tring& objectId, RefPtr<Array<InternalPropertyDescriptor> >* properties) | |
| 1131 { | |
| 1132 if (!m_scriptState) { | |
| 1133 *errorString = "Invalid DartInjectedScript"; | |
| 1134 return; | |
| 1135 } | |
| 1136 // FIXME: add internal properties such as [[PrimitiveValue], [[BoundThis]],
etc. | |
| 1137 *properties = Array<InternalPropertyDescriptor>::create(); | |
| 1138 } | |
| 1139 | |
| 1140 void DartInjectedScript::getProperty(ErrorString* errorString, const String& obj
ectId, const RefPtr<JSONArray>& propertyPath, RefPtr<TypeBuilder::Runtime::Remot
eObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 1141 { | |
| 1142 if (!m_scriptState) { | |
| 1143 *errorString = "Invalid DartInjectedScript"; | |
| 1144 return; | |
| 1145 } | |
| 1146 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1147 DartApiScope apiScope; | |
| 1148 | |
| 1149 DartDebuggerObject* object = lookupObject(objectId); | |
| 1150 if (!object) { | |
| 1151 *errorString = "Unknown objectId"; | |
| 1152 return; | |
| 1153 } | |
| 1154 Dart_Handle handle = object->handle(); | |
| 1155 const String& objectGroup = object->group(); | |
| 1156 | |
| 1157 | |
| 1158 for (unsigned i = 0; i < propertyPath->length(); i++) { | |
| 1159 RefPtr<JSONValue> value = propertyPath->get(i); | |
| 1160 String propertyName; | |
| 1161 if (!value->asString(&propertyName)) { | |
| 1162 *errorString = "Invalid property name"; | |
| 1163 return; | |
| 1164 } | |
| 1165 | |
| 1166 handle = getObjectPropertySafe(handle, propertyName); | |
| 1167 ASSERT(!Dart_IsError(handle)); | |
| 1168 } | |
| 1169 *result = wrapDartHandle(handle, inferKind(handle), objectGroup, false); | |
| 1170 } | |
| 1171 | |
| 1172 Node* DartInjectedScript::nodeForObjectId(const String& objectId) | |
| 1173 { | |
| 1174 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1175 DartApiScope apiScope; | |
| 1176 | |
| 1177 DartDebuggerObject* object = lookupObject(objectId); | |
| 1178 if (!object || object->kind() != DartDebuggerObject::Object) | |
| 1179 return 0; | |
| 1180 | |
| 1181 Dart_Handle handle = object->handle(); | |
| 1182 if (DartDOMWrapper::subtypeOf(handle, DartNode::dartClassId)) { | |
| 1183 Dart_Handle exception = 0; | |
| 1184 Node* node = DartNode::toNative(handle, exception); | |
| 1185 ASSERT(!exception); | |
| 1186 return node; | |
| 1187 } | |
| 1188 return 0; | |
| 1189 } | |
| 1190 | |
| 1191 String DartInjectedScript::cacheObject(Dart_Handle handle, const String& objectG
roup, DartDebuggerObject::Kind kind) | |
| 1192 { | |
| 1193 Dart_PersistentHandle persistentHandle = Dart_NewPersistentHandle(handle); | |
| 1194 String objectId = String::format("{\"injectedScriptId\":%d,\"id\":%ld,\"isDa
rt\":true}", m_injectedScriptId, m_nextObjectId); | |
| 1195 m_nextObjectId++; | |
| 1196 | |
| 1197 if (!objectGroup.isNull()) { | |
| 1198 ObjectGroupMap::AddResult addResult = m_objectGroups.add(objectGroup, Ve
ctor<String>()); | |
| 1199 Vector<String>& groupMembers = addResult.storedValue->value; | |
| 1200 groupMembers.append(objectId); | |
| 1201 } | |
| 1202 | |
| 1203 m_objects.set(objectId, new DartDebuggerObject(persistentHandle, objectGroup
, kind)); | |
| 1204 return objectId; | |
| 1205 } | |
| 1206 | |
| 1207 void DartInjectedScript::releaseObject(const String& objectId) | |
| 1208 { | |
| 1209 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1210 DartApiScope apiScope; | |
| 1211 ASSERT(validateObjectId(objectId)); | |
| 1212 DebuggerObjectMap::iterator it = m_objects.find(objectId); | |
| 1213 if (it != m_objects.end()) { | |
| 1214 delete it->value; | |
| 1215 m_objects.remove(objectId); | |
| 1216 } | |
| 1217 } | |
| 1218 | |
| 1219 String DartInjectedScript::getCallFrameId(int ordinal, int asyncOrdinal) | |
| 1220 { | |
| 1221 // FIXME: what if the stack trace contains frames from multiple | |
| 1222 // injectedScripts? | |
| 1223 return String::format("{\"ordinal\":%d,\"injectedScriptId\":%d,\"asyncOrdina
l\":%d,\"isDart\":true}", ordinal, m_injectedScriptId, asyncOrdinal); | |
| 1224 } | |
| 1225 | |
| 1226 Dart_ActivationFrame DartInjectedScript::callFrameForId(const Dart_StackTrace tr
ace, const String& callFrameId) | |
| 1227 { | |
| 1228 Dart_ActivationFrame frame = 0; | |
| 1229 int ordinal = 0; | |
| 1230 int asyncOrdinal = 0; | |
| 1231 RefPtr<JSONValue> json = parseJSON(callFrameId); | |
| 1232 if (json && json->type() == JSONValue::TypeObject) { | |
| 1233 bool ALLOW_UNUSED success = json->asObject()->getNumber("ordinal", &ordi
nal); | |
| 1234 ASSERT(success); | |
| 1235 success = json->asObject()->getNumber("asyncOrdinal", &asyncOrdinal); | |
| 1236 ASSERT(success); | |
| 1237 } else { | |
| 1238 ASSERT(json && json->type() == JSONValue::TypeObject); | |
| 1239 return 0; | |
| 1240 } | |
| 1241 Dart_Handle ALLOW_UNUSED result; | |
| 1242 if (asyncOrdinal > 0) { // 1-based index | |
| 1243 // FIXMEDART: we never really supported async stacks for dart anyway. | |
| 1244 return 0; | |
| 1245 } | |
| 1246 result = Dart_GetActivationFrame(trace, ordinal, &frame); | |
| 1247 ASSERT(result); | |
| 1248 return frame; | |
| 1249 } | |
| 1250 | |
| 1251 PassRefPtr<Array<CallFrame> > DartInjectedScript::wrapCallFrames(const Dart_Stac
kTrace trace, int asyncOrdinal) | |
| 1252 { | |
| 1253 intptr_t length = 0; | |
| 1254 Dart_Handle ALLOW_UNUSED result; | |
| 1255 RefPtr<Array<CallFrame> > ret = Array<CallFrame>::create(); | |
| 1256 result = Dart_StackTraceLength(trace, &length); | |
| 1257 ASSERT(!Dart_IsError(result)); | |
| 1258 DartScriptDebugServer& debugServer = DartScriptDebugServer::shared(); | |
| 1259 Dart_Handle libraries = Dart_GetLibraryIds(); | |
| 1260 for (intptr_t i = 0; i < length; i++) { | |
| 1261 Dart_ActivationFrame frame = 0; | |
| 1262 result = Dart_GetActivationFrame(trace, i, &frame); | |
| 1263 ASSERT(!Dart_IsError(result)); | |
| 1264 Dart_Handle functionName = 0; | |
| 1265 Dart_Handle function = 0; | |
| 1266 Dart_CodeLocation location; | |
| 1267 Dart_ActivationFrameGetLocation(frame, &functionName, &function, &locati
on); | |
| 1268 const String& url = DartUtilities::toString(location.script_url); | |
| 1269 intptr_t line = 0; | |
| 1270 intptr_t column = 0; | |
| 1271 Dart_ActivationFrameInfo(frame, 0, 0, &line, &column); | |
| 1272 RefPtr<Location> locationJson = Location::create() | |
| 1273 .setScriptId(debugServer.getScriptId(url, Dart_CurrentIsolate())) | |
| 1274 .setLineNumber(line - 1); | |
| 1275 locationJson->setColumnNumber(column); | |
| 1276 Dart_Handle localVariables = Dart_GetLocalVariables(frame); | |
| 1277 Dart_Handle thisHandle = findReceiver(localVariables); | |
| 1278 Dart_Handle enclosingType = lookupEnclosingType(function); | |
| 1279 RefPtr<TypeBuilder::Array<Scope> > scopeChain = TypeBuilder::Array<Scope
>::create(); | |
| 1280 RefPtr<TypeBuilder::Runtime::RemoteObject> thisObject = | |
| 1281 wrapDartHandle(thisHandle ? thisHandle : Dart_Null(), DartDebuggerOb
ject::Object, "backtrace", false); | |
| 1282 | |
| 1283 intptr_t localVariablesLength = 0; | |
| 1284 result = Dart_ListLength(localVariables, &localVariablesLength); | |
| 1285 ASSERT(!Dart_IsError(result)); | |
| 1286 if (localVariablesLength > 0) { | |
| 1287 scopeChain->addItem(Scope::create() | |
| 1288 .setType(Scope::Type::Local) | |
| 1289 .setObject(wrapDartHandle(localVariables, DartDebuggerObject::Lo
calVariables, "backtrace", false)) | |
| 1290 .release()); | |
| 1291 } | |
| 1292 | |
| 1293 if (thisHandle) { | |
| 1294 scopeChain->addItem(Scope::create() | |
| 1295 .setType(Scope::Type::Instance) | |
| 1296 .setObject(thisObject) | |
| 1297 .release()); | |
| 1298 } | |
| 1299 | |
| 1300 if (Dart_IsType(enclosingType)) { | |
| 1301 scopeChain->addItem(Scope::create() | |
| 1302 .setType(Scope::Type::Class) | |
| 1303 .setObject(wrapDartHandle(enclosingType, DartDebuggerObject::Sta
ticClass, "backtrace", false)) | |
| 1304 .release()); | |
| 1305 } | |
| 1306 | |
| 1307 Dart_Handle library = Dart_GetLibraryFromId(location.library_id); | |
| 1308 ASSERT(Dart_IsLibrary(library)); | |
| 1309 ASSERT(!Dart_IsNull(library)); | |
| 1310 if (Dart_IsLibrary(library)) { | |
| 1311 scopeChain->addItem(Scope::create() | |
| 1312 .setType(Scope::Type::Library) | |
| 1313 .setObject(wrapDartHandle(library, DartDebuggerObject::CurrentLi
brary, "backtrace", false)) | |
| 1314 .release()); | |
| 1315 } | |
| 1316 | |
| 1317 scopeChain->addItem(Scope::create() | |
| 1318 .setType(Scope::Type::Isolate) | |
| 1319 .setObject(wrapDartHandle(libraries, DartDebuggerObject::Isolate, "b
acktrace", false)) | |
| 1320 .release()); | |
| 1321 | |
| 1322 ret->addItem(CallFrame::create() | |
| 1323 .setCallFrameId(getCallFrameId(i, asyncOrdinal)) | |
| 1324 .setFunctionName(DartUtilities::toString(functionName)) | |
| 1325 .setLocation(locationJson) | |
| 1326 .setScopeChain(scopeChain) | |
| 1327 .setThis(thisObject) | |
| 1328 .release()); | |
| 1329 } | |
| 1330 return ret; | |
| 1331 } | |
| 1332 | |
| 1333 DartDebuggerObject::Kind DartInjectedScript::inferKind(Dart_Handle handle) | |
| 1334 { | |
| 1335 DartDOMData* domData = DartDOMData::current(); | |
| 1336 ASSERT(domData); | |
| 1337 if (Dart_IsType(handle)) | |
| 1338 return DartDebuggerObject::Class; | |
| 1339 if (Dart_IsError(handle)) | |
| 1340 return DartDebuggerObject::Error; | |
| 1341 if (Dart_IsNull(handle)) | |
| 1342 return DartDebuggerObject::Object; | |
| 1343 if (DartUtilities::isFunction(domData, handle)) | |
| 1344 return DartDebuggerObject::Function; | |
| 1345 if (Dart_IsInstance(handle)) | |
| 1346 return DartDebuggerObject::Object; | |
| 1347 ASSERT(Dart_IsLibrary(handle)); | |
| 1348 return DartDebuggerObject::Library; | |
| 1349 } | |
| 1350 | |
| 1351 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapDartObjec
t(Dart_Handle dartHandle, const String& groupName, bool generatePreview) | |
| 1352 { | |
| 1353 return wrapDartHandle(dartHandle, inferKind(dartHandle), groupName, generate
Preview); | |
| 1354 } | |
| 1355 | |
| 1356 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapDartHandl
e(Dart_Handle dartHandle, DartDebuggerObject::Kind kind, const String& groupName
, bool generatePreview) | |
| 1357 { | |
| 1358 RefPtr<TypeBuilder::Runtime::RemoteObject> remoteObject; | |
| 1359 packageResult(dartHandle, kind, groupName, 0, false, generatePreview, &remot
eObject, 0); | |
| 1360 return remoteObject; | |
| 1361 } | |
| 1362 | |
| 1363 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapObject(co
nst ScriptValue& value, const String& groupName, bool generatePreview) | |
| 1364 { | |
| 1365 if (!m_scriptState) | |
| 1366 return nullptr; | |
| 1367 | |
| 1368 AbstractScriptValue* scriptValue = value.scriptValue(); | |
| 1369 if (scriptValue->isEmpty()) | |
| 1370 return wrapDartObject(Dart_Null(), groupName, generatePreview); | |
| 1371 | |
| 1372 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1373 DartApiScope apiScope; | |
| 1374 ASSERT(!scriptValue->isV8()); | |
| 1375 if (scriptValue->isV8()) { | |
| 1376 return wrapDartObject(Dart_NewStringFromCString("JavaScript value when D
art value expected"), groupName, generatePreview); | |
| 1377 } | |
| 1378 return wrapDartObject(static_cast<DartScriptValue*>(scriptValue)->dartValue(
), groupName, generatePreview); | |
| 1379 } | |
| 1380 | |
| 1381 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapTable(con
st ScriptValue& table, const ScriptValue& columns) | |
| 1382 { | |
| 1383 if (!m_scriptState) | |
| 1384 return nullptr; | |
| 1385 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1386 DartApiScope apiScope; | |
| 1387 // FIXME: implement this rarely used method or call out to the JS version. | |
| 1388 ASSERT_NOT_REACHED(); | |
| 1389 return nullptr; | |
| 1390 } | |
| 1391 | |
| 1392 ScriptValue DartInjectedScript::findObjectById(const String& objectId) const | |
| 1393 { | |
| 1394 // FIXMEDART: Implement this. | |
| 1395 RELEASE_ASSERT(0); | |
| 1396 return ScriptValue(); | |
| 1397 } | |
| 1398 | |
| 1399 void DartInjectedScript::inspectNode(Node* node) | |
| 1400 { | |
| 1401 // FIXMEDART: Implement this. | |
| 1402 RELEASE_ASSERT(0); | |
| 1403 } | |
| 1404 | |
| 1405 void DartInjectedScript::releaseObjectGroup(const String& objectGroup) | |
| 1406 { | |
| 1407 if (!m_scriptState) | |
| 1408 return; | |
| 1409 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1410 DartApiScope apiScope; | |
| 1411 ObjectGroupMap::iterator it = m_objectGroups.find(objectGroup); | |
| 1412 if (it != m_objectGroups.end()) { | |
| 1413 Vector<String>& ids = it->value; | |
| 1414 for (Vector<String>::iterator it = ids.begin(); it != ids.end(); ++it) { | |
| 1415 const String& id = *it; | |
| 1416 DebuggerObjectMap::iterator objectIt = m_objects.find(id); | |
| 1417 if (objectIt != m_objects.end()) { | |
| 1418 delete objectIt->value; | |
| 1419 m_objects.remove(id); | |
| 1420 } | |
| 1421 } | |
| 1422 m_objectGroups.remove(objectGroup); | |
| 1423 } | |
| 1424 } | |
| 1425 | |
| 1426 DartScriptState* DartInjectedScript::scriptState() const | |
| 1427 { | |
| 1428 return m_scriptState; | |
| 1429 } | |
| 1430 | |
| 1431 DartDebuggerObject* DartInjectedScript::lookupObject(const String& objectId) | |
| 1432 { | |
| 1433 ASSERT(validateObjectId(objectId)); | |
| 1434 DebuggerObjectMap::iterator it = m_objects.find(objectId); | |
| 1435 return it != m_objects.end() ? it->value : 0; | |
| 1436 } | |
| 1437 | |
| 1438 bool DartInjectedScript::isDartObjectId(const String& objectId) | |
| 1439 { | |
| 1440 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); | |
| 1441 if (parsedObjectId && parsedObjectId->type() == JSONValue::TypeObject) { | |
| 1442 bool isDart = false; | |
| 1443 bool success = parsedObjectId->asObject()-> getBoolean("isDart", &isDart
); | |
| 1444 return success && isDart; | |
| 1445 } | |
| 1446 return false; | |
| 1447 } | |
| 1448 | |
| 1449 } // namespace blink | |
| OLD | NEW |