Chromium Code Reviews| 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/dart/DartInjectedScript.h" | |
| 34 | |
| 35 #include "DartInjectedScriptHost.h" | |
| 36 #include "DartNode.h" | |
| 37 #include "bindings/dart/DartHandleProxy.h" | |
| 38 #include "bindings/dart/DartJsInterop.h" | |
| 39 #include "bindings/dart/DartScriptDebugServer.h" | |
| 40 #include "bindings/dart/DartScriptState.h" | |
| 41 #include "bindings/dart/DartUtilities.h" | |
| 42 #include "bindings/dart/V8Converter.h" | |
| 43 #include "bindings/v8/ScriptFunctionCall.h" | |
| 44 #include "core/inspector/InjectedScriptHost.h" | |
| 45 #include "core/inspector/JSONParser.h" | |
| 46 #include "platform/JSONValues.h" | |
| 47 | |
| 48 using WebCore::TypeBuilder::Array; | |
| 49 using WebCore::TypeBuilder::Debugger::CallFrame; | |
| 50 using WebCore::TypeBuilder::Debugger::Location; | |
| 51 using WebCore::TypeBuilder::Debugger::Scope; | |
| 52 using WebCore::TypeBuilder::Runtime::PropertyDescriptor; | |
| 53 using WebCore::TypeBuilder::Runtime::InternalPropertyDescriptor; | |
| 54 using WebCore::TypeBuilder::Debugger::FunctionDetails; | |
| 55 using WebCore::TypeBuilder::Runtime::RemoteObject; | |
| 56 using WebCore::TypeBuilder::Runtime::PropertyPreview; | |
| 57 | |
| 58 namespace WebCore { | |
| 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 type, bool ownProperties, bool access orPropertiesOnly) | |
| 107 { | |
| 108 Dart_Handle args[3] = {type, 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 findThisVariable(Dart_Handle locals) | |
|
rmacnak
2014/06/03 17:32:34
findReceiver
Jacob
2014/06/03 20:23:13
Done.
Jacob
2014/06/03 20:23:13
Done.
| |
| 129 { | |
| 130 intptr_t length = 0; | |
| 131 Dart_Handle ALLOW_UNUSED result = Dart_ListLength(locals, &length); | |
| 132 ASSERT(!Dart_IsError(result)); | |
|
vsm
2014/06/03 14:24:49
ASSERT(length % 2 == 0);
Jacob
2014/06/03 20:23:13
Done.
| |
| 133 String thisStr("this"); | |
| 134 for (intptr_t i = 0; i < length; i+= 2) { | |
| 135 Dart_Handle name = Dart_ListGetAt(locals, i); | |
| 136 if (DartUtilities::toString(name) == thisStr) { | |
| 137 Dart_Handle ret = Dart_ListGetAt(locals, i + 1); | |
| 138 return Dart_IsNull(ret) ? 0 : ret; | |
| 139 } | |
| 140 } | |
| 141 return 0; | |
| 142 } | |
| 143 | |
| 144 Dart_Handle lookupEnclosingType(Dart_Handle functionOwner) | |
| 145 { | |
| 146 // Walk up the chain of function owners until we reach a type or library | |
| 147 // handle. | |
| 148 while (Dart_IsFunction(functionOwner)) | |
| 149 functionOwner = Dart_FunctionOwner(functionOwner); | |
| 150 return functionOwner; | |
| 151 } | |
| 152 | |
| 153 DartDebuggerObject::DartDebuggerObject(Dart_PersistentHandle h, const String& ob jectGroup, Type type) | |
| 154 : m_handle(h) | |
| 155 , m_group(objectGroup) | |
| 156 , m_type(type) | |
| 157 { | |
| 158 } | |
| 159 | |
| 160 DartInjectedScript::DartInjectedScript() | |
| 161 : m_name("DartInjectedScript") | |
| 162 , m_inspectedStateAccessCheck(0) | |
| 163 , m_scriptState(0) | |
| 164 , m_nextObjectId(1) | |
| 165 , m_host(0) | |
| 166 , m_consoleApi(0) | |
| 167 { | |
| 168 } | |
| 169 | |
| 170 DartInjectedScript::DartInjectedScript(DartScriptState* scriptState, InspectedSt ateAccessCheck accessCheck, int injectedScriptId, InjectedScriptHost* host) | |
| 171 : m_name("DartInjectedScript") | |
| 172 , m_inspectedStateAccessCheck(accessCheck) | |
| 173 , m_scriptState(scriptState) | |
| 174 , m_nextObjectId(1) | |
| 175 , m_injectedScriptId(injectedScriptId) | |
| 176 , m_host(host) | |
| 177 , m_consoleApi(0) | |
| 178 { | |
| 179 } | |
| 180 | |
| 181 bool DartInjectedScript::canAccessInspectedWindow() const | |
| 182 { | |
| 183 return m_inspectedStateAccessCheck(scriptState()); | |
| 184 } | |
| 185 | |
| 186 bool DartInjectedScript::validateObjectId(const String& objectId) | |
| 187 { | |
| 188 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); | |
| 189 if (parsedObjectId && parsedObjectId->type() == JSONValue::TypeObject) { | |
| 190 long injectedScriptId = 0; | |
| 191 bool success = parsedObjectId->asObject()->getNumber("injectedScriptId", &injectedScriptId); | |
| 192 return success && injectedScriptId == m_injectedScriptId; | |
| 193 } | |
| 194 return false; | |
| 195 } | |
| 196 | |
| 197 void DartInjectedScript::packageResult(Dart_Handle dartHandle, DartDebuggerObjec t::Type type, const String& objectGroup, ErrorString* errorString, bool returnBy Value, bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 198 { | |
| 199 switch (type) { | |
| 200 case DartDebuggerObject::Object: | |
| 201 packageObjectResult(dartHandle, objectGroup, errorString, returnByValue, generatePreview, result, wasThrown); | |
| 202 return; | |
| 203 case DartDebuggerObject::ObjectClass: | |
| 204 packageObjectClassResult(dartHandle, objectGroup, errorString, returnByV alue, generatePreview, result, wasThrown); | |
| 205 return; | |
| 206 case DartDebuggerObject::Function: | |
| 207 packageFunctionResult(dartHandle, objectGroup, errorString, returnByValu e, generatePreview, result, wasThrown); | |
| 208 return; | |
| 209 case DartDebuggerObject::Method: | |
| 210 packageMethodResult(dartHandle, objectGroup, errorString, returnByValue, generatePreview, result, wasThrown); | |
| 211 return; | |
| 212 case DartDebuggerObject::Class: | |
| 213 case DartDebuggerObject::StaticClass: | |
| 214 packageClassResult(dartHandle, type, objectGroup, errorString, returnByV alue, generatePreview, result, wasThrown); | |
| 215 return; | |
| 216 case DartDebuggerObject::Library: | |
| 217 case DartDebuggerObject::CurrentLibrary: | |
| 218 packageLibraryResult(dartHandle, type, objectGroup, errorString, returnB yValue, generatePreview, result, wasThrown); | |
| 219 return; | |
| 220 case DartDebuggerObject::Libraries: | |
| 221 packageLibrariesResult(dartHandle, objectGroup, errorString, returnByVal ue, generatePreview, result, wasThrown); | |
| 222 return; | |
| 223 case DartDebuggerObject::LocalVariables: | |
| 224 packageLocalVariablesResult(dartHandle, objectGroup, errorString, return ByValue, generatePreview, result, wasThrown); | |
| 225 return; | |
| 226 case DartDebuggerObject::Error: | |
| 227 packageErrorResult(dartHandle, objectGroup, errorString, returnByValue, generatePreview, result, wasThrown); | |
| 228 return; | |
| 229 default: | |
| 230 ASSERT_NOT_REACHED(); | |
| 231 } | |
| 232 } | |
| 233 | |
| 234 DartInjectedScript::~DartInjectedScript() | |
| 235 { | |
| 236 DartIsolateScope scope(m_scriptState->isolate()); | |
| 237 DartApiScope apiScope; | |
| 238 | |
| 239 for (ObjectGroupMap::iterator it = m_objectGroups.begin(); it != m_objectGro ups.end(); ++it) | |
| 240 delete it->value; | |
| 241 | |
| 242 for (DebuggerObjectMap::iterator it = m_objects.begin(); it != m_objects.end (); ++it) { | |
| 243 Dart_DeletePersistentHandle(it->value->persistentHandle()); | |
| 244 delete it->value; | |
| 245 } | |
| 246 | |
| 247 if (m_consoleApi) | |
| 248 Dart_DeletePersistentHandle(m_consoleApi); | |
| 249 } | |
| 250 | |
| 251 Dart_Handle DartInjectedScript::consoleApi() | |
| 252 { | |
| 253 if (!m_consoleApi) { | |
| 254 Dart_Handle host = DartInjectedScriptHost::toDart(m_host); | |
| 255 Dart_SetPeer(host, this); | |
| 256 Dart_Handle consoleApi = DartUtilities::invokeUtilsMethod("consoleApi", 1, &host); | |
| 257 ASSERT(!Dart_IsError(consoleApi)); | |
| 258 m_consoleApi = Dart_NewPersistentHandle(consoleApi); | |
| 259 } | |
| 260 return m_consoleApi; | |
| 261 } | |
| 262 | |
| 263 Dart_Handle DartInjectedScript::evaluateHelper(Dart_Handle target, const String& rawExpression, Dart_Handle localVariables, bool includeCommandLineAPI, Dart_Han dle& exception) | |
| 264 { | |
| 265 DartDOMData* ALLOW_UNUSED domData = DartDOMData::current(); | |
| 266 ASSERT(domData); | |
| 267 ASSERT(Dart_IsList(localVariables) || Dart_IsNull(localVariables)); | |
| 268 | |
| 269 Dart_Handle expression = DartUtilities::stringToDart(rawExpression); | |
| 270 | |
| 271 if (includeCommandLineAPI) { | |
| 272 ASSERT(m_host); | |
| 273 // Vector of local variables and injected console variables. | |
| 274 Vector<Dart_Handle> locals; | |
| 275 if (Dart_IsList(localVariables)) { | |
| 276 DartUtilities::extractListElements(localVariables, exception, locals ); | |
| 277 ASSERT(!exception); | |
| 278 } | |
| 279 | |
| 280 ScriptState* v8ScriptState = DartUtilities::v8ScriptStateForCurrentIsola te(); | |
| 281 for (unsigned i = 0; i < m_host->numInspectedObjects(); i++) { | |
| 282 ScriptValue value = m_host->inspectedObject(i)->get(v8ScriptState); | |
| 283 v8::TryCatch tryCatch; | |
| 284 v8::Handle<v8::Value> v8Value = value.v8Value(); | |
| 285 Dart_Handle dartValue = DartHandleProxy::unwrapValue(v8Value); | |
| 286 ASSERT(!Dart_IsError(dartValue)); | |
| 287 locals.append(DartUtilities::stringToDartString(String::format("$%d" , i))); | |
| 288 locals.append(dartValue); | |
| 289 } | |
| 290 | |
| 291 Dart_Handle list = consoleApi(); | |
| 292 intptr_t length = 0; | |
| 293 ASSERT(Dart_IsList(list)); | |
| 294 Dart_Handle ALLOW_UNUSED ret = Dart_ListLength(list, &length); | |
| 295 ASSERT(!(length % 2)); | |
| 296 ASSERT(!Dart_IsError(ret)); | |
| 297 for (intptr_t i = 0; i < length; i += 2) { | |
| 298 Dart_Handle name = Dart_ListGetAt(list, i); | |
| 299 ASSERT(Dart_IsString(name)); | |
| 300 locals.append(name); | |
| 301 Dart_Handle value = Dart_ListGetAt(list, i+1); | |
| 302 ASSERT(!Dart_IsError(value)); | |
| 303 locals.append(value); | |
| 304 } | |
| 305 localVariables = DartUtilities::toList(locals, exception); | |
| 306 ASSERT(!exception); | |
| 307 } | |
| 308 | |
| 309 Dart_Handle wrapExpressionArgs[3] = { expression, localVariables, DartUtilit ies::boolToDart(includeCommandLineAPI) }; | |
| 310 Dart_Handle wrappedExpressionTuple = | |
| 311 DartUtilities::invokeUtilsMethod("wrapExpressionAsClosure", 3, wrapExpre ssionArgs); | |
| 312 ASSERT(Dart_IsList(wrappedExpressionTuple)); | |
| 313 Dart_Handle wrappedExpression = Dart_ListGetAt(wrappedExpressionTuple, 0); | |
| 314 Dart_Handle wrappedExpressionArgs = Dart_ListGetAt(wrappedExpressionTuple, 1 ); | |
| 315 | |
| 316 ASSERT(Dart_IsString(wrappedExpression)); | |
| 317 Dart_Handle closure = Dart_EvaluateExpr(target, wrappedExpression); | |
| 318 // There was a parse error. FIXME: consider cleaning up the line numbers in | |
| 319 // the error message. | |
| 320 if (Dart_IsError(closure)) { | |
| 321 exception = closure; | |
| 322 return 0; | |
| 323 } | |
| 324 | |
| 325 // Invoke the closure passing in the expression arguments specified by | |
| 326 // wrappedExpressionTuple. | |
| 327 ASSERT(DartUtilities::isFunction(domData, closure)); | |
| 328 intptr_t length = 0; | |
| 329 Dart_ListLength(wrappedExpressionArgs, &length); | |
| 330 Vector<Dart_Handle> dartFunctionArgs; | |
| 331 for (intptr_t i = 0; i < length; i ++) | |
| 332 dartFunctionArgs.append(Dart_ListGetAt(wrappedExpressionArgs, i)); | |
| 333 | |
| 334 return Dart_InvokeClosure(closure, dartFunctionArgs.size(), dartFunctionArgs .data()); | |
| 335 } | |
| 336 | |
| 337 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) | |
| 338 { | |
| 339 Dart_Handle exception = 0; | |
| 340 { | |
| 341 Dart_Handle evalResult = evaluateHelper(target, rawExpression, localVari ables, includeCommandLineAPI, exception); | |
| 342 if (exception) | |
| 343 goto fail; | |
| 344 | |
| 345 packageResult(evalResult, inferType(evalResult), objectGroup, errorStrin g, returnByValue, generatePreview, result, wasThrown); | |
| 346 return; | |
| 347 } | |
| 348 fail: | |
| 349 ASSERT(exception); | |
| 350 packageResult(exception, inferType(exception), objectGroup, errorString, ret urnByValue, generatePreview, result, wasThrown); | |
| 351 } | |
| 352 | |
| 353 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) | |
| 354 { | |
| 355 ASSERT(Dart_IsInstance(dartHandle) || Dart_IsNull(dartHandle)); | |
| 356 | |
| 357 // FIXMEDART: support returnByValue for Dart types that are expressible as J SON. | |
| 358 bool wasThrownVal = false; | |
| 359 Dart_Handle exception = 0; | |
| 360 if (Dart_IsError(dartHandle)) { | |
| 361 wasThrownVal = true; | |
| 362 Dart_Handle exception = Dart_ErrorGetException(dartHandle); | |
| 363 ASSERT(Dart_IsInstance(exception)); | |
| 364 if (!Dart_IsInstance(exception)) { | |
| 365 *errorString = Dart_GetError(dartHandle); | |
| 366 return; | |
| 367 } | |
| 368 dartHandle = exception; | |
| 369 } | |
| 370 | |
| 371 // Primitive value | |
| 372 RefPtr<JSONValue> value = nullptr; | |
| 373 TypeBuilder::Runtime::RemoteObject::Type::Enum remoteObjectType = TypeBuilde r::Runtime::RemoteObject::Type::Object; | |
| 374 ASSERT(Dart_IsInstance(dartHandle) || Dart_IsNull(dartHandle)); | |
| 375 | |
| 376 if (Dart_IsNull(dartHandle)) { | |
| 377 value = JSONValue::null(); | |
| 378 } else { | |
| 379 if (Dart_IsString(dartHandle)) { | |
| 380 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::String; | |
| 381 value = JSONString::create(DartUtilities::toString(dartHandle)); | |
| 382 } else if (Dart_IsDouble(dartHandle)) { | |
| 383 // FIXMEDART: add an extra entry for int? | |
| 384 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::Number; | |
| 385 value = JSONBasicValue::create(DartUtilities::dartToDouble(dartHandl e, exception)); | |
| 386 ASSERT(!exception); | |
| 387 } else if (Dart_IsNumber(dartHandle)) { | |
| 388 // FIXMEDART: handle ints that are larger than 50 bits. | |
| 389 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::Number; | |
| 390 value = JSONBasicValue::create(DartUtilities::dartToDouble(dartHandl e, exception)); | |
| 391 ASSERT(!exception); | |
| 392 } else if (Dart_IsBoolean(dartHandle)) { | |
| 393 remoteObjectType = TypeBuilder::Runtime::RemoteObject::Type::Boolean ; | |
| 394 value = JSONBasicValue::create(DartUtilities::dartToBool(dartHandle, exception)); | |
| 395 ASSERT(!exception); | |
| 396 } | |
| 397 } | |
| 398 | |
| 399 String typeName; | |
| 400 String description; | |
| 401 bool isNode = false; | |
| 402 if (Dart_IsNull(dartHandle)) { | |
| 403 typeName = "null"; | |
| 404 description = "null"; | |
| 405 } else { | |
| 406 ASSERT(!exception); | |
| 407 description = DartUtilities::dartToString(Dart_ToString(dartHandle), exc eption); | |
| 408 Dart_Handle dartType = Dart_InstanceGetType(dartHandle); | |
| 409 Dart_Handle typeNameHandle = Dart_TypeName(dartType); | |
| 410 ASSERT(!Dart_IsError(typeNameHandle)); | |
| 411 typeName = DartUtilities::dartToString(typeNameHandle, exception); | |
| 412 ASSERT(!exception); | |
| 413 if (DartDOMWrapper::subtypeOf(dartHandle, DartNode::dartClassId)) | |
| 414 isNode = true; | |
| 415 } | |
| 416 | |
| 417 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(remoteObjectType).release(); | |
| 418 remoteObject->setLanguage("dart"); | |
| 419 remoteObject->setClassName(typeName); | |
| 420 remoteObject->setDescription(description); | |
| 421 if (value) | |
| 422 remoteObject->setValue(value); | |
| 423 | |
| 424 if (isNode) | |
| 425 remoteObject->setSubtype(RemoteObject::Subtype::Node); | |
| 426 | |
| 427 // FIXMEDART: generate preview if generatePreview is true. | |
| 428 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::O bject); | |
| 429 remoteObject->setObjectId(objectId); | |
| 430 *result = remoteObject; | |
| 431 if (wasThrown) { | |
| 432 *wasThrown = exception || wasThrownVal; | |
| 433 } | |
| 434 } | |
| 435 | |
| 436 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) | |
| 437 { | |
| 438 ASSERT(Dart_IsInstance(dartHandle) || Dart_IsNull(dartHandle)); | |
| 439 bool wasThrownVal = false; | |
| 440 Dart_Handle exception = 0; | |
| 441 | |
| 442 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 443 remoteObject->setLanguage("dart"); | |
| 444 | |
| 445 Dart_Handle typeHandle = Dart_InstanceGetType(dartHandle); | |
| 446 String typeName = DartUtilities::toString(Dart_TypeName(typeHandle)); | |
| 447 | |
| 448 remoteObject->setClassName(typeName); | |
| 449 remoteObject->setDescription(typeName); | |
| 450 | |
| 451 // Don't generate a preview for types. | |
| 452 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::O bjectClass); | |
| 453 remoteObject->setObjectId(objectId); | |
| 454 *result = remoteObject; | |
| 455 if (wasThrown) | |
| 456 *wasThrown = exception || wasThrownVal; | |
| 457 } | |
| 458 | |
| 459 void DartInjectedScript::packageClassResult(Dart_Handle dartHandle, DartDebugger Object::Type type, const String& objectGroup, ErrorString* errorString, bool ret urnByValue, bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* re sult, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 460 { | |
| 461 bool wasThrownVal = false; | |
| 462 Dart_Handle exception = 0; | |
| 463 | |
| 464 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 465 remoteObject->setLanguage("dart"); | |
| 466 String typeName = DartUtilities::toString(Dart_TypeName(dartHandle)); | |
| 467 String typeDescription("class "); | |
| 468 typeDescription.append(typeName); | |
| 469 | |
| 470 remoteObject->setClassName(typeName); | |
| 471 remoteObject->setDescription(typeDescription); | |
| 472 | |
| 473 // Don't generate a preview for types. | |
| 474 String objectId = cacheObject(dartHandle, objectGroup, type); | |
| 475 remoteObject->setObjectId(objectId); | |
| 476 *result = remoteObject; | |
| 477 if (wasThrown) | |
| 478 *wasThrown = exception || wasThrownVal; | |
| 479 } | |
| 480 | |
| 481 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) | |
| 482 { | |
| 483 ASSERT(DartUtilities::isFunction(DartDOMData::current(), dartHandle)); | |
| 484 bool wasThrownVal = false; | |
| 485 Dart_Handle exception = 0; | |
| 486 | |
| 487 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Function).release(); | |
| 488 remoteObject->setLanguage("dart"); | |
| 489 String description = DartUtilities::toString(describeFunction(dartHandle)); | |
| 490 remoteObject->setClassName("<Dart Function>"); | |
| 491 remoteObject->setDescription(description); | |
| 492 | |
| 493 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::F unction); | |
| 494 remoteObject->setObjectId(objectId); | |
| 495 *result = remoteObject; | |
| 496 if (wasThrown) { | |
| 497 *wasThrown = exception || wasThrownVal; | |
| 498 } | |
| 499 } | |
| 500 | |
| 501 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) | |
| 502 { | |
| 503 ASSERT(DartUtilities::isFunction(DartDOMData::current(), dartHandle)); | |
| 504 bool wasThrownVal = false; | |
| 505 Dart_Handle exception = 0; | |
| 506 | |
| 507 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Function).release(); | |
| 508 remoteObject->setLanguage("dart"); | |
| 509 String description = DartUtilities::toString(describeFunction(dartHandle)); | |
| 510 remoteObject->setClassName("<Dart Method>"); | |
| 511 remoteObject->setDescription(description); | |
| 512 | |
| 513 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::M ethod); | |
| 514 remoteObject->setObjectId(objectId); | |
| 515 *result = remoteObject; | |
| 516 if (wasThrown) | |
| 517 *wasThrown = exception || wasThrownVal; | |
| 518 } | |
| 519 | |
| 520 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) | |
| 521 { | |
| 522 bool wasThrownVal = false; | |
| 523 Dart_Handle exception = 0; | |
| 524 | |
| 525 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 526 remoteObject->setLanguage("dart"); | |
| 527 remoteObject->setClassName("Object"); | |
| 528 remoteObject->setDescription("Local Variables"); | |
| 529 | |
| 530 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::L ocalVariables); | |
| 531 remoteObject->setObjectId(objectId); | |
| 532 *result = remoteObject; | |
| 533 if (wasThrown) | |
| 534 *wasThrown = exception || wasThrownVal; | |
| 535 } | |
| 536 | |
| 537 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) | |
| 538 { | |
| 539 ASSERT(Dart_IsError(dartHandle)); | |
| 540 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 541 remoteObject->setLanguage("dart"); | |
| 542 remoteObject->setClassName("Error"); | |
| 543 remoteObject->setDescription(Dart_GetError(dartHandle)); | |
| 544 | |
| 545 Dart_Handle exception = Dart_ErrorGetException(dartHandle); | |
| 546 String objectId = cacheObject(exception, objectGroup, DartDebuggerObject::Er ror); | |
| 547 remoteObject->setObjectId(objectId); | |
| 548 *result = remoteObject; | |
| 549 if (wasThrown) | |
| 550 *wasThrown = true; | |
| 551 } | |
| 552 | |
| 553 void DartInjectedScript::packageLibraryResult(Dart_Handle dartHandle, DartDebugg erObject::Type type, const String& objectGroup, ErrorString* errorString, bool r eturnByValue, bool generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 554 { | |
| 555 ASSERT(Dart_IsLibrary(dartHandle)); | |
| 556 bool wasThrownVal = false; | |
| 557 intptr_t libraryId = 0; | |
| 558 Dart_Handle exception = 0; | |
| 559 Dart_Handle ALLOW_UNUSED ret; | |
| 560 ret = Dart_LibraryId(dartHandle, &libraryId); | |
| 561 ASSERT(!Dart_IsError(ret)); | |
| 562 | |
| 563 String libraryName = DartUtilities::toString(Dart_GetLibraryURL(libraryId)); | |
| 564 | |
| 565 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 566 remoteObject->setLanguage("dart"); | |
| 567 remoteObject->setClassName(libraryName); | |
| 568 remoteObject->setDescription("Dart Library"); | |
| 569 String objectId = cacheObject(dartHandle, objectGroup, type); | |
| 570 remoteObject->setObjectId(objectId); | |
| 571 *result = remoteObject; | |
| 572 if (wasThrown) | |
| 573 *wasThrown = exception || wasThrownVal; | |
| 574 } | |
| 575 | |
| 576 void DartInjectedScript::packageLibrariesResult(Dart_Handle dartHandle, const St ring& objectGroup, ErrorString* errorString, bool returnByValue, bool generatePr eview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuilder::OptOutpu t<bool>* wasThrown) | |
| 577 { | |
| 578 RefPtr<RemoteObject> remoteObject = TypeBuilder::Runtime::RemoteObject::crea te().setType(TypeBuilder::Runtime::RemoteObject::Type::Object).release(); | |
| 579 remoteObject->setLanguage("dart"); | |
| 580 remoteObject->setClassName("Dart Libraries"); | |
|
rmacnak
2014/06/04 00:45:13
"Dart Isolate"?
Jacob
2014/06/04 01:21:41
Good idea. Changed this name to Dart Isolate and r
| |
| 581 remoteObject->setDescription("Dart Libraries"); | |
| 582 String objectId = cacheObject(dartHandle, objectGroup, DartDebuggerObject::L ibraries); | |
| 583 remoteObject->setObjectId(objectId); | |
| 584 *result = remoteObject; | |
| 585 } | |
| 586 | |
| 587 Dart_Handle DartInjectedScript::library() | |
| 588 { | |
| 589 ASSERT(m_scriptState); | |
| 590 return Dart_GetLibraryFromId(m_scriptState->libraryId()); | |
| 591 } | |
| 592 | |
| 593 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) | |
| 594 { | |
| 595 if (!m_scriptState) { | |
| 596 *errorString = "Invalid DartInjectedScript"; | |
| 597 return; | |
| 598 } | |
| 599 DartIsolateScope scope(m_scriptState->isolate()); | |
| 600 DartApiScope apiScope; | |
| 601 V8Scope v8scope(DartDOMData::current()); | |
| 602 evaluateAndPackageResult(library(), expression, Dart_Null(), includeCommandL ineAPI, objectGroup, errorString, returnByValue, generatePreview, result, wasThr own); | |
| 603 } | |
| 604 | |
| 605 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) | |
| 606 { | |
| 607 Dart_Handle exception = 0; | |
| 608 String objectGroup; | |
| 609 { | |
| 610 if (!m_scriptState) { | |
| 611 *errorString = "Invalid DartInjectedScript"; | |
| 612 return; | |
| 613 } | |
| 614 DartIsolateScope scope(m_scriptState->isolate()); | |
| 615 DartApiScope apiScope; | |
| 616 | |
| 617 DartDebuggerObject* object = lookupObject(objectId); | |
| 618 if (!object) { | |
| 619 *errorString = "Object has been deleted"; | |
| 620 return; | |
| 621 } | |
| 622 objectGroup = object->group(); | |
| 623 RefPtr<JSONValue> parsedArguments = parseJSON(arguments); | |
| 624 Vector<Dart_Handle> dartFunctionArgs; | |
| 625 if (!parsedArguments->isNull()) { | |
| 626 if (!parsedArguments->type() == JSONValue::TypeArray) { | |
| 627 *errorString = "Invalid arguments"; | |
| 628 return; | |
| 629 } | |
| 630 RefPtr<JSONArray> argumentsArray = parsedArguments->asArray(); | |
| 631 for (JSONArray::iterator it = argumentsArray->begin(); it != argumen tsArray->end(); ++it) { | |
| 632 RefPtr<JSONObject> arg; | |
| 633 if (!(*it)->asObject(&arg)) { | |
| 634 *errorString = "Invalid argument passed to callFunctionOn"; | |
| 635 return; | |
| 636 } | |
| 637 String argObjectId; | |
| 638 | |
| 639 if (!arg->getString("objectId", &argObjectId)) { | |
| 640 // FIXME: support primitive values passed as arguments as we ll. | |
| 641 *errorString = "Unspecified object id"; | |
| 642 } | |
| 643 | |
| 644 DartDebuggerObject* argObject = lookupObject(argObjectId); | |
| 645 if (!argObject) { | |
| 646 *errorString = "Argument has been deleted"; | |
| 647 return; | |
| 648 } | |
| 649 dartFunctionArgs.append(argObject->handle()); | |
| 650 } | |
| 651 } | |
| 652 | |
| 653 Dart_Handle dartClosure = evaluateHelper(object->handle(), expression, D art_Null(), false, exception); | |
| 654 if (exception) | |
| 655 goto fail; | |
| 656 | |
| 657 if (Dart_IsError(dartClosure)) { | |
| 658 *errorString = Dart_GetError(dartClosure); | |
| 659 return; | |
| 660 } | |
| 661 if (!Dart_IsClosure(dartClosure)) { | |
| 662 *errorString = "Given expression does not evaluate to a closure"; | |
| 663 return; | |
| 664 } | |
| 665 Dart_Handle evalResult = Dart_InvokeClosure(dartClosure, dartFunctionArg s.size(), dartFunctionArgs.data()); | |
| 666 packageResult(evalResult, inferType(evalResult), objectGroup, errorStrin g, returnByValue, generatePreview, result, wasThrown); | |
| 667 return; | |
| 668 } | |
| 669 fail: | |
| 670 ASSERT(exception); | |
| 671 packageResult(exception, inferType(exception), objectGroup, errorString, ret urnByValue, generatePreview, result, wasThrown); | |
| 672 | |
| 673 | |
| 674 } | |
| 675 | |
| 676 void DartInjectedScript::evaluateOnCallFrame(ErrorString* errorString, const Sta ckTrace& callFrames, const Vector<StackTrace>& asyncCallStacks, const String& ca llFrameId, const String& expression, const String& objectGroup, bool includeComm andLineAPI, bool returnByValue, bool generatePreview, RefPtr<RemoteObject>* resu lt, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 677 { | |
| 678 ASSERT(!callFrames.isJavaScript()); | |
| 679 if (!m_scriptState) { | |
| 680 *errorString = "Invalid DartInjectedScript"; | |
| 681 return; | |
| 682 } | |
| 683 DartIsolateScope scope(m_scriptState->isolate()); | |
| 684 DartApiScope apiScope; | |
| 685 // FIXMEDART: add v8Scope calls elsewhere. | |
| 686 V8Scope v8scope(DartDOMData::current()); | |
| 687 | |
| 688 Dart_ActivationFrame frame = callFrameForId(callFrames, asyncCallStacks, cal lFrameId); | |
| 689 ASSERT(frame); | |
| 690 if (!frame) { | |
| 691 *errorString = "Call frame not found"; | |
| 692 return; | |
| 693 } | |
| 694 | |
| 695 Dart_Handle function = 0; | |
| 696 Dart_ActivationFrameGetLocation(frame, 0, &function, 0); | |
| 697 ASSERT(function); | |
| 698 Dart_Handle localVariables = Dart_GetLocalVariables(frame); | |
| 699 Dart_Handle thisHandle = findThisVariable(localVariables); | |
| 700 Dart_Handle context = thisHandle ? thisHandle : lookupEnclosingType(function ); | |
| 701 evaluateAndPackageResult(context, expression, localVariables, includeCommand LineAPI, objectGroup, errorString, returnByValue, generatePreview, result, wasTh rown); | |
| 702 } | |
| 703 | |
| 704 void DartInjectedScript::restartFrame(ErrorString* errorString, const StackTrace & callFrames, const String& callFrameId, RefPtr<JSONObject>* result) | |
| 705 { | |
| 706 ASSERT(!callFrames.isJavaScript()); | |
| 707 *errorString = "Dart does not yet support restarting call frames"; | |
| 708 return; | |
| 709 } | |
| 710 | |
| 711 void DartInjectedScript::getStepInPositions(ErrorString* errorString, const Stac kTrace& callFrames, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugge r::Location> >& positions) | |
| 712 { | |
| 713 ASSERT(!callFrames.isJavaScript()); | |
| 714 if (!m_scriptState) { | |
| 715 *errorString = "Invalid DartInjectedScript"; | |
| 716 return; | |
| 717 } | |
| 718 DartIsolateScope scope(m_scriptState->isolate()); | |
| 719 DartApiScope apiScope; | |
| 720 *errorString = "FIXME: support dart."; | |
| 721 return; | |
| 722 } | |
| 723 | |
| 724 void DartInjectedScript::setVariableValue(ErrorString* errorString, const StackT race& callFrames, const String* callFrameIdOpt, const String* functionObjectIdOp t, int scopeNumber, const String& variableName, const String& newValueStr) | |
| 725 { | |
| 726 if (!m_scriptState) { | |
| 727 *errorString = "Invalid DartInjectedScript"; | |
| 728 return; | |
| 729 } | |
| 730 DartIsolateScope scope(m_scriptState->isolate()); | |
| 731 DartApiScope apiScope; | |
| 732 ASSERT(!callFrames.isJavaScript()); | |
| 733 *errorString = "Not supported by Dart."; | |
| 734 return; | |
| 735 } | |
| 736 | |
| 737 void DartInjectedScript::getFunctionDetails(ErrorString* errorString, const Stri ng& functionId, RefPtr<FunctionDetails>* result) | |
| 738 { | |
| 739 if (!m_scriptState) { | |
| 740 *errorString = "Invalid DartInjectedScript"; | |
| 741 return; | |
| 742 } | |
| 743 DartIsolateScope scope(m_scriptState->isolate()); | |
| 744 DartApiScope apiScope; | |
| 745 DartDebuggerObject* object = lookupObject(functionId); | |
| 746 if (!object) { | |
| 747 *errorString = "Object has been deleted"; | |
| 748 return; | |
| 749 } | |
| 750 | |
| 751 int line = 0; | |
| 752 int column = 0; | |
| 753 DartScriptDebugServer& debugServer = DartScriptDebugServer::shared(); | |
| 754 Dart_Handle url; | |
| 755 Dart_Handle name = 0; | |
| 756 Dart_Handle exception = 0; | |
| 757 | |
| 758 switch (object->type()) { | |
| 759 case DartDebuggerObject::Function: { | |
| 760 Dart_CodeLocation location; | |
| 761 Dart_Handle ret = Dart_GetClosureInfo(object->handle(), &name, 0, &locat ion); | |
| 762 if (Dart_IsError(ret)) { | |
| 763 *errorString = "Unable to determine source location."; | |
| 764 return; | |
| 765 } | |
| 766 | |
| 767 debugServer.resolveCodeLocation(location, &line, &column); | |
| 768 url = location.script_url; | |
| 769 break; | |
| 770 } | |
| 771 case DartDebuggerObject::Method: | |
| 772 { | |
| 773 Dart_Handle ret = getInvocationTrampolineDetails(object->handle()); | |
| 774 | |
| 775 if (Dart_IsError(ret)) { | |
| 776 *errorString = Dart_GetError(ret); | |
| 777 return; | |
| 778 } | |
| 779 ASSERT(Dart_IsList(ret)); | |
| 780 line = DartUtilities::toInteger(Dart_ListGetAt(ret, 0), exception); | |
| 781 column = DartUtilities::toInteger(Dart_ListGetAt(ret, 1), exception) ; | |
| 782 url = Dart_ListGetAt(ret, 2); | |
| 783 name = Dart_ListGetAt(ret, 3); | |
| 784 break; | |
| 785 } | |
| 786 default: | |
| 787 *errorString = "Object is not a function."; | |
| 788 return; | |
| 789 } | |
| 790 | |
| 791 ASSERT(!exception); | |
| 792 | |
| 793 RefPtr<Location> locationJson = Location::create() | |
| 794 .setScriptId(debugServer.getScriptId(DartUtilities::toString(url), Dart_ CurrentIsolate())) | |
| 795 .setLineNumber(line - 1); | |
| 796 locationJson->setColumnNumber(column); | |
| 797 | |
| 798 *result = FunctionDetails::create().setLocation(locationJson).setFunctionNam e(DartUtilities::toString(name)).release(); | |
| 799 } | |
| 800 | |
| 801 void addCompletions(Dart_Handle completions, RefPtr<TypeBuilder::Array<String> > * result) | |
| 802 { | |
| 803 ASSERT(Dart_IsList(completions)); | |
| 804 intptr_t length = 0; | |
| 805 Dart_ListLength(completions, &length); | |
| 806 for (intptr_t i = 0; i < length; ++i) | |
| 807 (*result)->addItem(DartUtilities::toString(Dart_ListGetAt(completions, i ))); | |
| 808 } | |
| 809 | |
| 810 void DartInjectedScript::getCompletionsOnCallFrame(ErrorString* errorString, con st StackTrace& callFrames, const Vector<StackTrace>& asyncCallStacks, const Stri ng& callFrameId, const String& expression, RefPtr<TypeBuilder::Array<String> >* result) | |
| 811 { | |
| 812 ASSERT(!callFrames.isJavaScript()); | |
| 813 *result = TypeBuilder::Array<String>::create(); | |
| 814 if (!m_scriptState) { | |
| 815 *errorString = "Invalid DartInjectedScript"; | |
| 816 return; | |
| 817 } | |
| 818 DartIsolateScope scope(m_scriptState->isolate()); | |
| 819 DartApiScope apiScope; | |
| 820 V8Scope v8scope(DartDOMData::current()); | |
| 821 | |
| 822 Dart_ActivationFrame frame = callFrameForId(callFrames, asyncCallStacks, cal lFrameId); | |
| 823 ASSERT(frame); | |
| 824 if (!frame) { | |
| 825 *errorString = "Call frame not found"; | |
| 826 return; | |
| 827 } | |
| 828 | |
| 829 Dart_Handle function = 0; | |
| 830 Dart_ActivationFrameGetLocation(frame, 0, &function, 0); | |
| 831 ASSERT(function); | |
| 832 Dart_Handle localVariables = Dart_GetLocalVariables(frame); | |
| 833 Dart_Handle thisHandle = findThisVariable(localVariables); | |
| 834 Dart_Handle enclosingType = lookupEnclosingType(function); | |
| 835 Dart_Handle context = thisHandle ? thisHandle : enclosingType; | |
| 836 | |
| 837 if (expression.isEmpty()) { | |
| 838 addCompletions(getLibraryCompletionsIncludingImports(library()), result) ; | |
| 839 if (!Dart_IsLibrary(context)) { | |
| 840 addCompletions(getObjectCompletions(context, library()), result); | |
| 841 } | |
| 842 if (context != enclosingType) { | |
| 843 addCompletions(getObjectCompletions(enclosingType, library()), resul t); | |
| 844 } | |
| 845 intptr_t length = 0; | |
| 846 Dart_ListLength(localVariables, &length); | |
| 847 for (intptr_t i = 0; i < length; i += 2) | |
| 848 (*result)->addItem(DartUtilities::toString(Dart_ListGetAt(localVaria bles, i))); | |
| 849 } else { | |
| 850 // FIXME: we can do better than evaluating the expression and getting | |
| 851 // all completions for that object if an exception is not thrown. For | |
| 852 // example run the Dart Analyzer to get completions of complex | |
| 853 // expressions without triggering side effects or failing for | |
| 854 // expressions that do not evaluate to a first class object. For | |
| 855 // example, the html library is imported with prefix html and the | |
| 856 // expression html is used. | |
| 857 Dart_Handle exception = 0; | |
| 858 Dart_Handle handle = evaluateHelper(context, expression, localVariables, true, exception); | |
| 859 | |
| 860 // No completions if the expression cannot be evaluated. | |
| 861 if (exception) | |
| 862 return; | |
| 863 addCompletions(getObjectCompletions(handle, library()), result); | |
| 864 } | |
| 865 } | |
| 866 | |
| 867 void DartInjectedScript::getCompletions(ErrorString* errorString, const String& expression, RefPtr<TypeBuilder::Array<String> >* result) | |
| 868 { | |
| 869 *result = TypeBuilder::Array<String>::create(); | |
| 870 | |
| 871 if (!m_scriptState) { | |
| 872 *errorString = "Invalid DartInjectedScript"; | |
| 873 return; | |
| 874 } | |
| 875 DartIsolateScope scope(m_scriptState->isolate()); | |
| 876 DartApiScope apiScope; | |
| 877 V8Scope v8scope(DartDOMData::current()); | |
| 878 | |
| 879 Dart_Handle completions; | |
| 880 if (expression.isEmpty()) { | |
| 881 completions = getLibraryCompletionsIncludingImports(library()); | |
| 882 } else { | |
| 883 // FIXME: we can do better than evaluating the expression and getting | |
| 884 // all completions for that object if an exception is not thrown. For | |
| 885 // example run the Dart Analyzer to get completions of complex | |
| 886 // expressions without triggering side effects or failing for | |
| 887 // expressions that do not evaluate to a first class object. For | |
| 888 // example, the html library is imported with prefix html and the | |
| 889 // expression html is used. | |
| 890 Dart_Handle exception = 0; | |
| 891 Dart_Handle handle = evaluateHelper(library(), expression, Dart_Null(), true, exception); | |
| 892 // No completions if the expression cannot be evaluated. | |
| 893 if (exception) | |
| 894 return; | |
| 895 completions = getObjectCompletions(handle, library()); | |
| 896 } | |
| 897 | |
| 898 addCompletions(completions, result); | |
| 899 } | |
| 900 | |
| 901 void DartInjectedScript::getProperties(ErrorString* errorString, const String& o bjectId, bool ownProperties, bool accessorPropertiesOnly, RefPtr<Array<PropertyD escriptor> >* properties) | |
| 902 { | |
| 903 Dart_Handle exception = 0; | |
| 904 if (!m_scriptState) { | |
| 905 *errorString = "Invalid DartInjectedScript"; | |
| 906 return; | |
| 907 } | |
| 908 DartIsolateScope scope(m_scriptState->isolate()); | |
| 909 DartApiScope apiScope; | |
| 910 | |
| 911 DartDebuggerObject* object = lookupObject(objectId); | |
| 912 if (!object) { | |
| 913 *errorString = "Unknown objectId"; | |
| 914 return; | |
| 915 } | |
| 916 Dart_Handle handle = object->handle(); | |
| 917 String objectGroup = object->group(); | |
| 918 | |
| 919 *properties = Array<PropertyDescriptor>::create(); | |
| 920 Dart_Handle propertiesList; | |
| 921 switch (object->type()) { | |
| 922 case DartDebuggerObject::Object: | |
| 923 case DartDebuggerObject::Function: | |
| 924 case DartDebuggerObject::Error: | |
| 925 propertiesList = getObjectProperties(handle, ownProperties, accessorProp ertiesOnly); | |
| 926 break; | |
| 927 case DartDebuggerObject::ObjectClass: | |
| 928 propertiesList = getObjectClassProperties(handle, ownProperties, accesso rPropertiesOnly); | |
| 929 break; | |
| 930 case DartDebuggerObject::Method: | |
| 931 // There aren't any meaningful properties to display for a Dart method. | |
| 932 return; | |
| 933 case DartDebuggerObject::Class: | |
| 934 case DartDebuggerObject::StaticClass: | |
| 935 propertiesList = getClassProperties(handle, ownProperties, accessorPrope rtiesOnly); | |
| 936 break; | |
| 937 case DartDebuggerObject::Library: | |
| 938 case DartDebuggerObject::CurrentLibrary: | |
| 939 propertiesList = getLibraryProperties(handle, ownProperties, accessorPro pertiesOnly); | |
| 940 break; | |
| 941 case DartDebuggerObject::LocalVariables: | |
| 942 { | |
| 943 if (accessorPropertiesOnly) | |
| 944 return; | |
| 945 ASSERT(Dart_IsList(handle)); | |
| 946 intptr_t length = 0; | |
| 947 Dart_Handle ALLOW_UNUSED ret = Dart_ListLength(handle, &length); | |
| 948 ASSERT(!Dart_IsError(ret)); | |
| 949 for (intptr_t i = 0; i < length; i += 2) { | |
| 950 const String& name = DartUtilities::toString(Dart_ListGetAt(hand le, i)); | |
| 951 Dart_Handle value = Dart_ListGetAt(handle, i + 1); | |
| 952 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::crea te().setName(name).setConfigurable(false).setEnumerable(true).release(); | |
| 953 descriptor->setValue(wrapDartHandle(value, inferType(value), obj ectGroup, false)); | |
| 954 descriptor->setWritable(false); | |
| 955 descriptor->setWasThrown(false); | |
| 956 descriptor->setIsOwn(true); | |
| 957 (*properties)->addItem(descriptor); | |
| 958 } | |
| 959 return; | |
| 960 } | |
| 961 case DartDebuggerObject::Libraries: | |
| 962 { | |
| 963 if (accessorPropertiesOnly) | |
| 964 return; | |
| 965 | |
| 966 Dart_Handle libraries = handle; | |
| 967 ASSERT(Dart_IsList(libraries)); | |
| 968 | |
| 969 intptr_t librariesLength = 0; | |
| 970 Dart_Handle ALLOW_UNUSED result = Dart_ListLength(libraries, &librar iesLength); | |
| 971 ASSERT(!Dart_IsError(result)); | |
| 972 for (intptr_t i = 0; i < librariesLength; ++i) { | |
| 973 Dart_Handle libraryIdHandle = Dart_ListGetAt(libraries, i); | |
| 974 ASSERT(!Dart_IsError(libraryIdHandle)); | |
| 975 Dart_Handle exception = 0; | |
| 976 int64_t libraryId = DartUtilities::toInteger(libraryIdHandle, ex ception); | |
| 977 const String& name = DartUtilities::toString(Dart_GetLibraryURL( libraryId)); | |
| 978 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::crea te().setName(name).setConfigurable(false).setEnumerable(true).release(); | |
| 979 descriptor->setValue(wrapDartHandle(Dart_GetLibraryFromId(librar yId), DartDebuggerObject::Library, objectGroup, false)); | |
| 980 descriptor->setWritable(false); | |
| 981 descriptor->setWasThrown(false); | |
| 982 descriptor->setIsOwn(true); | |
| 983 (*properties)->addItem(descriptor); | |
| 984 ASSERT(!exception); | |
| 985 } | |
| 986 return; | |
| 987 } | |
| 988 default: | |
| 989 ASSERT_NOT_REACHED(); | |
| 990 *errorString = "Internal error"; | |
| 991 return; | |
| 992 } | |
| 993 | |
| 994 if (Dart_IsError(propertiesList)) { | |
| 995 *errorString = Dart_GetError(propertiesList); | |
| 996 return; | |
| 997 } | |
| 998 | |
| 999 ASSERT(Dart_IsList(propertiesList)); | |
| 1000 intptr_t length = 0; | |
| 1001 Dart_Handle ALLOW_UNUSED ret = Dart_ListLength(propertiesList, &length); | |
| 1002 ASSERT(!Dart_IsError(ret)); | |
| 1003 ASSERT(!(length % 9)); | |
| 1004 for (intptr_t i = 0; i < length; i += 9) { | |
| 1005 String name = DartUtilities::toString(Dart_ListGetAt(propertiesList, i)) ; | |
| 1006 Dart_Handle setter = Dart_ListGetAt(propertiesList, i + 1); | |
| 1007 Dart_Handle getter = Dart_ListGetAt(propertiesList, i + 2); | |
| 1008 Dart_Handle value = Dart_ListGetAt(propertiesList, i + 3); | |
| 1009 bool hasValue = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList, i + 4), exception); | |
| 1010 ASSERT(!exception); | |
| 1011 bool writable = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList, i + 5), exception); | |
| 1012 ASSERT(!exception); | |
| 1013 bool isMethod = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList, i + 6), exception); | |
| 1014 ASSERT(!exception); | |
| 1015 bool isOwn = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList, i + 7), exception); | |
| 1016 ASSERT(!exception); | |
| 1017 bool wasThrown = DartUtilities::dartToBool(Dart_ListGetAt(propertiesList , i + 8), exception); | |
| 1018 ASSERT(!exception); | |
| 1019 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::create().set Name(name).setConfigurable(false).setEnumerable(true).release(); | |
| 1020 if (isMethod) { | |
| 1021 ASSERT(hasValue); | |
| 1022 descriptor->setValue(wrapDartHandle(value, DartDebuggerObject::Metho d, objectGroup, false)); | |
| 1023 } else { | |
| 1024 if (hasValue) | |
| 1025 descriptor->setValue(wrapDartHandle(value, inferType(value), obj ectGroup, false)); | |
| 1026 if (!Dart_IsNull(setter)) | |
| 1027 descriptor->setSet(wrapDartHandle(setter, DartDebuggerObject::Me thod, objectGroup, false)); | |
| 1028 if (!Dart_IsNull(getter)) | |
| 1029 descriptor->setGet(wrapDartHandle(getter, DartDebuggerObject::Me thod, objectGroup, false)); | |
| 1030 } | |
| 1031 descriptor->setWritable(writable); | |
| 1032 descriptor->setWasThrown(wasThrown); | |
| 1033 descriptor->setIsOwn(isOwn); | |
| 1034 | |
| 1035 (*properties)->addItem(descriptor); | |
| 1036 } | |
| 1037 | |
| 1038 if (object->type() == DartDebuggerObject::Object && !accessorPropertiesOnly && !Dart_IsNull(handle)) { | |
| 1039 RefPtr<PropertyDescriptor> descriptor = PropertyDescriptor::create().set Name("[[class]]").setConfigurable(false).setEnumerable(true).release(); | |
| 1040 descriptor->setValue(wrapDartHandle(handle, DartDebuggerObject::ObjectCl ass, objectGroup, false)); | |
| 1041 descriptor->setWritable(false); | |
| 1042 descriptor->setWasThrown(false); | |
| 1043 descriptor->setIsOwn(true); | |
| 1044 (*properties)->addItem(descriptor); | |
| 1045 } | |
| 1046 } | |
| 1047 | |
| 1048 void DartInjectedScript::getInternalProperties(ErrorString* errorString, const S tring& objectId, RefPtr<Array<InternalPropertyDescriptor> >* properties) | |
| 1049 { | |
| 1050 if (!m_scriptState) { | |
| 1051 *errorString = "Invalid DartInjectedScript"; | |
| 1052 return; | |
| 1053 } | |
| 1054 // FIXME: add internal properties such as [[PrimitiveValue], [[BoundThis]], etc. | |
| 1055 *properties = Array<InternalPropertyDescriptor>::create(); | |
| 1056 } | |
| 1057 | |
| 1058 void DartInjectedScript::getProperty(ErrorString* errorString, const String& obj ectId, const RefPtr<JSONArray>& propertyPath, RefPtr<TypeBuilder::Runtime::Remot eObject>* result, TypeBuilder::OptOutput<bool>* wasThrown) | |
| 1059 { | |
| 1060 if (!m_scriptState) { | |
| 1061 *errorString = "Invalid DartInjectedScript"; | |
| 1062 return; | |
| 1063 } | |
| 1064 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1065 DartApiScope apiScope; | |
| 1066 | |
| 1067 DartDebuggerObject* object = lookupObject(objectId); | |
| 1068 if (!object) { | |
| 1069 *errorString = "Unknown objectId"; | |
| 1070 return; | |
| 1071 } | |
| 1072 Dart_Handle handle = object->handle(); | |
| 1073 const String& objectGroup = object->group(); | |
| 1074 | |
| 1075 | |
| 1076 for (unsigned i = 0; i < propertyPath->length(); i++) { | |
| 1077 RefPtr<JSONValue> value = propertyPath->get(i); | |
| 1078 String propertyName; | |
| 1079 if (!value->asString(&propertyName)) { | |
| 1080 *errorString = "Invalid property name"; | |
| 1081 return; | |
| 1082 } | |
| 1083 | |
| 1084 handle = getObjectPropertySafe(handle, propertyName); | |
| 1085 ASSERT(!Dart_IsError(handle)); | |
| 1086 } | |
| 1087 *result = wrapDartHandle(handle, inferType(handle), objectGroup, false); | |
| 1088 } | |
| 1089 | |
| 1090 Node* DartInjectedScript::nodeForObjectId(const String& objectId) | |
| 1091 { | |
| 1092 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1093 DartApiScope apiScope; | |
| 1094 | |
| 1095 DartDebuggerObject* object = lookupObject(objectId); | |
| 1096 if (!object || object->type() != DartDebuggerObject::Object) | |
| 1097 return 0; | |
| 1098 | |
| 1099 Dart_Handle handle = object->handle(); | |
| 1100 if (DartDOMWrapper::subtypeOf(handle, DartNode::dartClassId)) { | |
| 1101 Dart_Handle exception = 0; | |
| 1102 Node* node = DartNode::toNative(handle, exception); | |
| 1103 ASSERT(!exception); | |
| 1104 return node; | |
| 1105 } | |
| 1106 return 0; | |
| 1107 } | |
| 1108 | |
| 1109 String DartInjectedScript::cacheObject(Dart_Handle handle, const String& objectG roup, DartDebuggerObject::Type type) | |
| 1110 { | |
| 1111 Dart_PersistentHandle persistentHandle = Dart_NewPersistentHandle(handle); | |
| 1112 String objectId = String::format("{\"injectedScriptId\":%d,\"id\":%lu}", m_i njectedScriptId, m_nextObjectId); | |
| 1113 m_nextObjectId++; | |
| 1114 | |
| 1115 if (!objectGroup.isNull()) { | |
| 1116 ObjectGroupMap::iterator groupIterator = m_objectGroups.find(objectGroup ); | |
| 1117 Vector<String>* groupMembers; | |
| 1118 if (groupIterator == m_objectGroups.end()) { | |
| 1119 groupMembers = new Vector<String>(); | |
| 1120 m_objectGroups.set(objectGroup, groupMembers); | |
| 1121 } else { | |
| 1122 groupMembers = groupIterator->value; | |
| 1123 } | |
| 1124 groupMembers->append(objectId); | |
| 1125 } | |
| 1126 | |
| 1127 m_objects.set(objectId, new DartDebuggerObject(persistentHandle, objectGroup , type)); | |
| 1128 return objectId; | |
| 1129 } | |
| 1130 | |
| 1131 void DartInjectedScript::releaseObject(const String& objectId) | |
| 1132 { | |
| 1133 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1134 DartApiScope apiScope; | |
| 1135 ASSERT(validateObjectId(objectId)); | |
| 1136 DebuggerObjectMap::iterator it = m_objects.find(objectId); | |
| 1137 if (it != m_objects.end()) { | |
| 1138 Dart_DeletePersistentHandle(it->value->persistentHandle()); | |
| 1139 m_objects.remove(objectId); | |
| 1140 } | |
| 1141 } | |
| 1142 | |
| 1143 String DartInjectedScript::getCallFrameId(int ordinal, int asyncOrdinal) | |
| 1144 { | |
| 1145 // FIXME: what if the stack trace contains frames from multiple | |
| 1146 // injectedScripts? | |
| 1147 return String::format("{\"ordinal\":%d,\"injectedScriptId\":%d,\"asyncOrdina l\":%d}", ordinal, m_injectedScriptId, asyncOrdinal); | |
| 1148 } | |
| 1149 | |
| 1150 Dart_ActivationFrame DartInjectedScript::callFrameForId(const StackTrace& callFr ames, const Vector<StackTrace>& asyncCallStacks, const String& callFrameId) | |
| 1151 { | |
| 1152 ASSERT(!callFrames.isJavaScript()); | |
| 1153 if (callFrames.isJavaScript()) | |
| 1154 return 0; | |
| 1155 Dart_StackTrace trace = callFrames.asDart(); | |
| 1156 Dart_ActivationFrame frame = 0; | |
| 1157 int ordinal = 0; | |
| 1158 int asyncOrdinal = 0; | |
| 1159 RefPtr<JSONValue> json = parseJSON(callFrameId); | |
| 1160 if (json && json->type() == JSONValue::TypeObject) { | |
| 1161 bool ALLOW_UNUSED success = json->asObject()->getNumber("ordinal", &ordi nal); | |
| 1162 ASSERT(success); | |
| 1163 success = json->asObject()->getNumber("asyncOrdinal", &asyncOrdinal); | |
| 1164 ASSERT(success); | |
| 1165 } else { | |
| 1166 ASSERT(json && json->type() == JSONValue::TypeObject); | |
| 1167 return 0; | |
| 1168 } | |
| 1169 Dart_Handle ALLOW_UNUSED result; | |
| 1170 if (asyncOrdinal > 0) { // 1-based index | |
| 1171 ASSERT(asyncOrdinal <= (int)asyncCallStacks.size()); | |
| 1172 if (asyncOrdinal <= (int)asyncCallStacks.size()) { | |
| 1173 ASSERT(!asyncCallStacks[asyncOrdinal-1].isJavaScript()); | |
| 1174 result = Dart_GetActivationFrame(asyncCallStacks[asyncOrdinal-1].asD art(), ordinal, &frame); | |
| 1175 } else { | |
| 1176 return 0; | |
| 1177 } | |
| 1178 } else { | |
| 1179 Dart_GetActivationFrame(trace, ordinal, &frame); | |
| 1180 } | |
| 1181 ASSERT(result); | |
| 1182 return frame; | |
| 1183 } | |
| 1184 | |
| 1185 PassRefPtr<Array<CallFrame> > DartInjectedScript::wrapCallFrames(const StackTrac e& callFrames, int asyncOrdinal) | |
| 1186 { | |
| 1187 ASSERT(!callFrames.isJavaScript()); | |
| 1188 if (callFrames.isJavaScript()) | |
| 1189 return nullptr; | |
| 1190 Dart_StackTrace trace = callFrames.asDart(); | |
| 1191 intptr_t length = 0; | |
| 1192 Dart_Handle ALLOW_UNUSED result; | |
| 1193 RefPtr<Array<CallFrame> > ret = Array<CallFrame>::create(); | |
| 1194 result = Dart_StackTraceLength(trace, &length); | |
| 1195 ASSERT(!Dart_IsError(result)); | |
| 1196 DartScriptDebugServer& debugServer = DartScriptDebugServer::shared(); | |
| 1197 Dart_Handle libraries = Dart_GetLibraryIds(); | |
| 1198 for (intptr_t i = 0; i < length; i++) { | |
| 1199 Dart_ActivationFrame frame = 0; | |
| 1200 result = Dart_GetActivationFrame(trace, i, &frame); | |
| 1201 ASSERT(!Dart_IsError(result)); | |
| 1202 Dart_Handle functionName = 0; | |
| 1203 Dart_Handle function = 0; | |
| 1204 Dart_CodeLocation location; | |
| 1205 Dart_ActivationFrameGetLocation(frame, &functionName, &function, &locati on); | |
| 1206 const String& url = DartUtilities::toString(location.script_url); | |
| 1207 int line = 0; | |
| 1208 int column = 0; | |
| 1209 debugServer.resolveCodeLocation(location, &line, &column); | |
| 1210 RefPtr<Location> locationJson = Location::create() | |
| 1211 .setScriptId(debugServer.getScriptId(url, Dart_CurrentIsolate())) | |
| 1212 .setLineNumber(line - 1); | |
| 1213 locationJson->setColumnNumber(column); | |
| 1214 Dart_Handle localVariables = Dart_GetLocalVariables(frame); | |
| 1215 Dart_Handle thisHandle = findThisVariable(localVariables); | |
| 1216 Dart_Handle enclosingType = lookupEnclosingType(function); | |
| 1217 RefPtr<TypeBuilder::Array<Scope> > scopeChain = TypeBuilder::Array<Scope >::create(); | |
| 1218 RefPtr<TypeBuilder::Runtime::RemoteObject> thisObject = | |
| 1219 wrapDartHandle(thisHandle ? thisHandle : Dart_Null(), DartDebuggerOb ject::Object, "backtrace", false); | |
| 1220 | |
| 1221 intptr_t localVariablesLength = 0; | |
| 1222 result = Dart_ListLength(localVariables, &localVariablesLength); | |
| 1223 ASSERT(!Dart_IsError(result)); | |
| 1224 if (localVariablesLength > 0) { | |
| 1225 scopeChain->addItem(Scope::create() | |
| 1226 .setType(Scope::Type::Local) | |
| 1227 .setObject(wrapDartHandle(localVariables, DartDebuggerObject::Lo calVariables, "backtrace", false)) | |
| 1228 .release()); | |
| 1229 } | |
| 1230 | |
| 1231 if (thisHandle) { | |
| 1232 scopeChain->addItem(Scope::create() | |
| 1233 .setType(Scope::Type::Instance) | |
| 1234 .setObject(thisObject) | |
| 1235 .release()); | |
| 1236 } | |
| 1237 | |
| 1238 if (Dart_IsType(enclosingType)) { | |
| 1239 scopeChain->addItem(Scope::create() | |
| 1240 .setType(Scope::Type::Class) | |
| 1241 .setObject(wrapDartHandle(enclosingType, DartDebuggerObject::Sta ticClass, "backtrace", false)) | |
| 1242 .release()); | |
| 1243 } | |
| 1244 | |
| 1245 Dart_Handle library = Dart_GetLibraryFromId(location.library_id); | |
| 1246 ASSERT(Dart_IsLibrary(library)); | |
| 1247 if (Dart_IsLibrary(library)) { | |
| 1248 scopeChain->addItem(Scope::create() | |
| 1249 .setType(Scope::Type::Global) | |
| 1250 .setObject(wrapDartHandle(library, DartDebuggerObject::CurrentLi brary, "backtrace", false)) | |
| 1251 .release()); | |
| 1252 } | |
| 1253 | |
| 1254 scopeChain->addItem(Scope::create() | |
| 1255 .setType(Scope::Type::Library) | |
| 1256 .setObject(wrapDartHandle(libraries, DartDebuggerObject::Libraries, "backtrace", false)) | |
| 1257 .release()); | |
| 1258 | |
| 1259 ret->addItem(CallFrame::create() | |
| 1260 .setCallFrameId(getCallFrameId(i, asyncOrdinal)) | |
| 1261 .setFunctionName(DartUtilities::toString(functionName)) | |
| 1262 .setLocation(locationJson) | |
| 1263 .setScopeChain(scopeChain) | |
| 1264 .setThis(thisObject) | |
| 1265 .release()); | |
| 1266 } | |
| 1267 return ret; | |
| 1268 } | |
| 1269 | |
| 1270 DartDebuggerObject::Type DartInjectedScript::inferType(Dart_Handle handle) | |
| 1271 { | |
| 1272 DartDOMData* domData = DartDOMData::current(); | |
| 1273 ASSERT(domData); | |
| 1274 if (Dart_IsType(handle)) | |
| 1275 return DartDebuggerObject::Class; | |
| 1276 if (Dart_IsError(handle)) | |
| 1277 return DartDebuggerObject::Error; | |
| 1278 if (Dart_IsNull(handle)) | |
| 1279 return DartDebuggerObject::Object; | |
| 1280 if (DartUtilities::isFunction(domData, handle)) | |
| 1281 return DartDebuggerObject::Function; | |
| 1282 if (Dart_IsInstance(handle)) | |
| 1283 return DartDebuggerObject::Object; | |
| 1284 ASSERT(Dart_IsLibrary(handle)); | |
| 1285 return DartDebuggerObject::Library; | |
| 1286 } | |
| 1287 | |
| 1288 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapDartObjec t(Dart_Handle dartHandle, const String& groupName, bool generatePreview) | |
| 1289 { | |
| 1290 return wrapDartHandle(dartHandle, inferType(dartHandle), groupName, generate Preview); | |
| 1291 } | |
| 1292 | |
| 1293 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapDartHandl e(Dart_Handle dartHandle, DartDebuggerObject::Type type, const String& groupName , bool generatePreview) | |
| 1294 { | |
| 1295 RefPtr<TypeBuilder::Runtime::RemoteObject> remoteObject; | |
| 1296 packageResult(dartHandle, type, groupName, 0, false, generatePreview, &remot eObject, 0); | |
| 1297 return remoteObject; | |
| 1298 } | |
| 1299 | |
| 1300 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapObject(co nst ScriptValue& value, const String& groupName, bool generatePreview) | |
| 1301 { | |
| 1302 if (!m_scriptState) { | |
| 1303 return nullptr; | |
| 1304 } | |
| 1305 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1306 DartApiScope apiScope; | |
| 1307 // FIXME: should we use the ScriptValue's isolate instead? | |
| 1308 V8Scope v8scope(DartDOMData::current()); | |
| 1309 | |
| 1310 v8::TryCatch tryCatch; | |
| 1311 v8::Handle<v8::Value> v8Value = value.v8Value(); | |
| 1312 return wrapDartObject(DartHandleProxy::unwrapValue(v8Value), groupName, gene ratePreview); | |
| 1313 } | |
| 1314 | |
| 1315 PassRefPtr<TypeBuilder::Runtime::RemoteObject> DartInjectedScript::wrapTable(con st ScriptValue& table, const ScriptValue& columns) | |
| 1316 { | |
| 1317 if (!m_scriptState) | |
| 1318 return nullptr; | |
| 1319 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1320 DartApiScope apiScope; | |
| 1321 // FIXME: implement this rarely used method or call out to the JS version. | |
| 1322 ASSERT_NOT_REACHED(); | |
| 1323 return nullptr; | |
| 1324 } | |
| 1325 | |
| 1326 ActivationFrame DartInjectedScript::findCallFrameById(ErrorString* errorString, const StackTrace& topCallFrame, const String& callFrameId) | |
| 1327 { | |
| 1328 if (!m_scriptState) { | |
| 1329 *errorString = "Internal error"; | |
| 1330 return ActivationFrame(); | |
| 1331 } | |
| 1332 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1333 DartApiScope apiScope; | |
| 1334 ASSERT_NOT_REACHED(); | |
| 1335 return ActivationFrame(); | |
| 1336 } | |
| 1337 | |
| 1338 void DartInjectedScript::releaseObjectGroup(const String& objectGroup) | |
| 1339 { | |
| 1340 if (!m_scriptState) | |
| 1341 return; | |
| 1342 DartIsolateScope scope(m_scriptState->isolate()); | |
| 1343 DartApiScope apiScope; | |
| 1344 ObjectGroupMap::iterator it = m_objectGroups.find(objectGroup); | |
| 1345 if (it != m_objectGroups.end()) { | |
| 1346 Vector<String>* ids = it->value; | |
| 1347 for (Vector<String>::iterator it = ids->begin(); it != ids->end(); ++it) { | |
| 1348 const String& id = *it; | |
| 1349 DebuggerObjectMap::iterator objectIt = m_objects.find(id); | |
| 1350 if (objectIt != m_objects.end()) { | |
| 1351 Dart_DeletePersistentHandle(objectIt->value->handle()); | |
| 1352 delete objectIt->value; | |
| 1353 m_objects.remove(id); | |
| 1354 } | |
| 1355 } | |
| 1356 delete ids; | |
| 1357 m_objectGroups.remove(objectGroup); | |
| 1358 } | |
| 1359 } | |
| 1360 | |
| 1361 ScriptState* DartInjectedScript::scriptState() const | |
| 1362 { | |
| 1363 return m_scriptState; | |
| 1364 } | |
| 1365 | |
| 1366 DartDebuggerObject* DartInjectedScript::lookupObject(const String& objectId) | |
| 1367 { | |
| 1368 ASSERT(validateObjectId(objectId)); | |
| 1369 DebuggerObjectMap::iterator it = m_objects.find(objectId); | |
| 1370 return it != m_objects.end() ? it->value : 0; | |
| 1371 } | |
| 1372 | |
| 1373 } // namespace WebCore | |
| OLD | NEW |