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