JsrtDebugUtils.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "JsrtPch.h"
  6. #ifdef ENABLE_SCRIPT_DEBUGGING
  7. #include "JsrtDebugUtils.h"
  8. #include "RuntimeDebugPch.h"
  9. #include "screrror.h" // For CompileScriptException
  10. void JsrtDebugUtils::AddScriptIdToObject(Js::DynamicObject* object, Js::Utf8SourceInfo* utf8SourceInfo)
  11. {
  12. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::scriptId, utf8SourceInfo->GetSourceInfoId(), utf8SourceInfo->GetScriptContext());
  13. Js::Utf8SourceInfo* callerUtf8SourceInfo = utf8SourceInfo->GetCallerUtf8SourceInfo();
  14. if (callerUtf8SourceInfo != nullptr)
  15. {
  16. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::parentScriptId, callerUtf8SourceInfo->GetSourceInfoId(), callerUtf8SourceInfo->GetScriptContext());
  17. }
  18. }
  19. void JsrtDebugUtils::AddFileNameOrScriptTypeToObject(Js::DynamicObject* object, Js::Utf8SourceInfo* utf8SourceInfo)
  20. {
  21. if (utf8SourceInfo->IsDynamic())
  22. {
  23. AssertMsg(utf8SourceInfo->GetSourceContextInfo()->url == nullptr, "How come dynamic code have a url?");
  24. Js::FunctionBody* anyFunctionBody = utf8SourceInfo->GetAnyParsedFunction();
  25. LPCWSTR sourceName = (anyFunctionBody != nullptr) ? anyFunctionBody->GetSourceName() : Js::Constants::UnknownScriptCode;
  26. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::scriptType, sourceName, wcslen(sourceName), utf8SourceInfo->GetScriptContext());
  27. }
  28. else
  29. {
  30. // url can be nullptr if JsParseScript/JsRunScript didn't passed any
  31. const char16* url = utf8SourceInfo->GetSourceContextInfo()->url == nullptr ? _u("") : utf8SourceInfo->GetSourceContextInfo()->url;
  32. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::fileName, url, wcslen(url), utf8SourceInfo->GetScriptContext());
  33. }
  34. }
  35. void JsrtDebugUtils::AddLineColumnToObject(Js::DynamicObject* object, Js::FunctionBody* functionBody, int byteCodeOffset)
  36. {
  37. if (functionBody != nullptr)
  38. {
  39. ULONG line = 0;
  40. LONG col = 0;
  41. if (functionBody->GetLineCharOffset(byteCodeOffset, &line, &col, false))
  42. {
  43. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::line, (uint32) line, functionBody->GetScriptContext());
  44. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::column, (int32) col, functionBody->GetScriptContext());
  45. }
  46. }
  47. }
  48. void JsrtDebugUtils::AddSourceLengthAndTextToObject(Js::DynamicObject* object, Js::FunctionBody* functionBody, int byteCodeOffset)
  49. {
  50. Js::FunctionBody::StatementMap* statementMap = functionBody->GetEnclosingStatementMapFromByteCode(byteCodeOffset);
  51. Assert(statementMap != nullptr);
  52. LPCUTF8 source = functionBody->GetStartOfDocument(_u("Source for debugging"));
  53. size_t cbLength = functionBody->GetUtf8SourceInfo()->GetCbLength();
  54. size_t startByte = utf8::CharacterIndexToByteIndex(source, cbLength, (const charcount_t)statementMap->sourceSpan.begin);
  55. size_t endByte = utf8::CharacterIndexToByteIndex(source, cbLength, (const charcount_t)statementMap->sourceSpan.end);
  56. int cch = statementMap->sourceSpan.end - statementMap->sourceSpan.begin;
  57. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::sourceLength, (double)cch, functionBody->GetScriptContext());
  58. AutoArrayPtr<char16> sourceContent(HeapNewNoThrowArray(char16, cch + 1), cch + 1);
  59. if (sourceContent != nullptr)
  60. {
  61. LPCUTF8 pbStart = source + startByte;
  62. LPCUTF8 pbEnd = pbStart + (endByte - startByte);
  63. utf8::DecodeOptions options = functionBody->GetUtf8SourceInfo()->IsCesu8() ? utf8::doAllowThreeByteSurrogates : utf8::doDefault;
  64. utf8::DecodeUnitsIntoAndNullTerminate(sourceContent, pbStart, pbEnd, options);
  65. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::sourceText, sourceContent, cch, functionBody->GetScriptContext());
  66. }
  67. else
  68. {
  69. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::sourceText, _u(""), 1, functionBody->GetScriptContext());
  70. }
  71. }
  72. void JsrtDebugUtils::AddLineCountToObject(Js::DynamicObject * object, Js::Utf8SourceInfo * utf8SourceInfo)
  73. {
  74. utf8SourceInfo->EnsureLineOffsetCache();
  75. Assert(utf8SourceInfo->GetLineCount() < UINT32_MAX);
  76. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::lineCount, (uint32)utf8SourceInfo->GetLineCount(), utf8SourceInfo->GetScriptContext());
  77. }
  78. void JsrtDebugUtils::AddSourceToObject(Js::DynamicObject * object, Js::Utf8SourceInfo * utf8SourceInfo)
  79. {
  80. int32 cchLength = utf8SourceInfo->GetCchLength();
  81. AutoArrayPtr<char16> sourceContent(HeapNewNoThrowArray(char16, cchLength + 1), cchLength + 1);
  82. if (sourceContent != nullptr)
  83. {
  84. LPCUTF8 source = utf8SourceInfo->GetSource();
  85. size_t cbLength = utf8SourceInfo->GetCbLength();
  86. utf8::DecodeOptions options = utf8SourceInfo->IsCesu8() ? utf8::doAllowThreeByteSurrogates : utf8::doDefault;
  87. utf8::DecodeUnitsIntoAndNullTerminate(sourceContent, source, source + cbLength, options);
  88. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::source, sourceContent, cchLength, utf8SourceInfo->GetScriptContext());
  89. }
  90. else
  91. {
  92. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::source, _u(""), 1, utf8SourceInfo->GetScriptContext());
  93. }
  94. }
  95. void JsrtDebugUtils::AddSourceMetadataToObject(Js::DynamicObject * object, Js::Utf8SourceInfo * utf8SourceInfo)
  96. {
  97. JsrtDebugUtils::AddFileNameOrScriptTypeToObject(object, utf8SourceInfo);
  98. JsrtDebugUtils::AddLineCountToObject(object, utf8SourceInfo);
  99. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::sourceLength, utf8SourceInfo->GetCchLength(), utf8SourceInfo->GetScriptContext());
  100. if (utf8SourceInfo->HasDebugDocument())
  101. {
  102. // Only add the script ID in cases where a debug document exists
  103. JsrtDebugUtils::AddScriptIdToObject(object, utf8SourceInfo);
  104. }
  105. }
  106. void JsrtDebugUtils::AddVarPropertyToObject(Js::DynamicObject * object, const char16 * propertyName, Js::Var value, Js::ScriptContext * scriptContext)
  107. {
  108. const Js::PropertyRecord* propertyRecord;
  109. // propertyName is the DEBUGOBJECTPROPERTY from JsrtDebugPropertiesEnum so it can't have embedded null, ok to use wcslen
  110. scriptContext->GetOrAddPropertyRecord(propertyName, static_cast<int>(wcslen(propertyName)), &propertyRecord);
  111. Js::Var marshaledObj = Js::CrossSite::MarshalVar(scriptContext, value);
  112. if (FALSE == Js::JavascriptOperators::InitProperty(object, propertyRecord->GetPropertyId(), marshaledObj))
  113. {
  114. Assert("Failed to add property to debugger object");
  115. }
  116. }
  117. void JsrtDebugUtils::AddPropertyType(Js::DynamicObject * object, Js::IDiagObjectModelDisplay* objectDisplayRef, Js::ScriptContext * scriptContext, bool forceSetValueProp)
  118. {
  119. Assert(objectDisplayRef != nullptr);
  120. Assert(scriptContext != nullptr);
  121. bool addDisplay = false;
  122. bool addValue = false;
  123. Js::Var varValue = objectDisplayRef->GetVarValue(FALSE);
  124. Js::IDiagObjectAddress* varAddress = objectDisplayRef->GetDiagAddress();
  125. if (varValue != nullptr)
  126. {
  127. Js::TypeId typeId = Js::JavascriptOperators::GetTypeId(varValue);
  128. switch (typeId)
  129. {
  130. case Js::TypeIds_Undefined:
  131. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetUndefinedDisplayString(), scriptContext);
  132. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, scriptContext->GetLibrary()->GetUndefined(), scriptContext);
  133. addDisplay = true;
  134. break;
  135. case Js::TypeIds_Null:
  136. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetObjectTypeDisplayString(), scriptContext);
  137. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, scriptContext->GetLibrary()->GetNull(), scriptContext);
  138. addDisplay = true;
  139. break;
  140. case Js::TypeIds_Boolean:
  141. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetBooleanTypeDisplayString(), scriptContext);
  142. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, Js::VarTo<Js::JavascriptBoolean>(varValue)->GetValue() == TRUE ? true : false, scriptContext);
  143. break;
  144. case Js::TypeIds_Integer:
  145. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetNumberTypeDisplayString(), scriptContext);
  146. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, Js::TaggedInt::ToDouble(varValue), scriptContext);
  147. break;
  148. case Js::TypeIds_Number:
  149. {
  150. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetNumberTypeDisplayString(), scriptContext);
  151. double numberValue = Js::JavascriptNumber::GetValue(varValue);
  152. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, numberValue, scriptContext);
  153. // If number is not finite (NaN, Infinity, -Infinity) or is -0 add display as well so that we can display special strings
  154. if (!Js::NumberUtilities::IsFinite(numberValue) || Js::JavascriptNumber::IsNegZero(numberValue))
  155. {
  156. addDisplay = true;
  157. }
  158. break;
  159. }
  160. case Js::TypeIds_Int64Number:
  161. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetNumberTypeDisplayString(), scriptContext);
  162. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, (double)Js::VarTo<Js::JavascriptInt64Number>(varValue)->GetValue(), scriptContext);
  163. break;
  164. case Js::TypeIds_UInt64Number:
  165. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetNumberTypeDisplayString(), scriptContext);
  166. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, (double)Js::VarTo<Js::JavascriptUInt64Number>(varValue)->GetValue(), scriptContext);
  167. break;
  168. case Js::TypeIds_String:
  169. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetStringTypeDisplayString(), scriptContext);
  170. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, Js::VarTo<Js::JavascriptString>(varValue), scriptContext);
  171. break;
  172. case Js::TypeIds_Symbol:
  173. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetSymbolTypeDisplayString(), scriptContext);
  174. addDisplay = true;
  175. break;
  176. case Js::TypeIds_Function:
  177. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetFunctionTypeDisplayString(), scriptContext);
  178. addDisplay = true;
  179. break;
  180. case Js::TypeIds_Enumerator:
  181. case Js::TypeIds_HostDispatch:
  182. case Js::TypeIds_UnscopablesWrapperObject:
  183. case Js::TypeIds_UndeclBlockVar:
  184. case Js::TypeIds_EngineInterfaceObject:
  185. AssertMsg(false, "Not valid types");
  186. break;
  187. case Js::TypeIds_ModuleRoot:
  188. case Js::TypeIds_HostObject:
  189. case Js::TypeIds_ActivationObject:
  190. AssertMsg(false, "Are these valid types for debugger?");
  191. break;
  192. case Js::TypeIds_NativeIntArray:
  193. #if ENABLE_COPYONACCESS_ARRAY
  194. case Js::TypeIds_CopyOnAccessNativeIntArray:
  195. #endif
  196. case Js::TypeIds_NativeFloatArray:
  197. case Js::TypeIds_ES5Array:
  198. case Js::TypeIds_CharArray:
  199. case Js::TypeIds_BoolArray:
  200. case Js::TypeIds_ArrayIterator:
  201. case Js::TypeIds_MapIterator:
  202. case Js::TypeIds_SetIterator:
  203. case Js::TypeIds_StringIterator:
  204. case Js::TypeIds_Object:
  205. case Js::TypeIds_Array:
  206. case Js::TypeIds_Date:
  207. case Js::TypeIds_RegEx:
  208. case Js::TypeIds_Error:
  209. case Js::TypeIds_BooleanObject:
  210. case Js::TypeIds_NumberObject:
  211. case Js::TypeIds_StringObject:
  212. case Js::TypeIds_Arguments:
  213. case Js::TypeIds_ArrayBuffer:
  214. case Js::TypeIds_Int8Array:
  215. case Js::TypeIds_Uint8Array:
  216. case Js::TypeIds_Uint8ClampedArray:
  217. case Js::TypeIds_Int16Array:
  218. case Js::TypeIds_Uint16Array:
  219. case Js::TypeIds_Int32Array:
  220. case Js::TypeIds_Uint32Array:
  221. case Js::TypeIds_Float32Array:
  222. case Js::TypeIds_Float64Array:
  223. case Js::TypeIds_Int64Array:
  224. case Js::TypeIds_Uint64Array:
  225. case Js::TypeIds_DataView:
  226. case Js::TypeIds_Map:
  227. case Js::TypeIds_Set:
  228. case Js::TypeIds_WeakMap:
  229. case Js::TypeIds_WeakSet:
  230. case Js::TypeIds_SymbolObject:
  231. case Js::TypeIds_Generator:
  232. case Js::TypeIds_AsyncGenerator:
  233. case Js::TypeIds_AsyncFromSyncIterator:
  234. case Js::TypeIds_Promise:
  235. case Js::TypeIds_GlobalObject:
  236. case Js::TypeIds_SpreadArgument:
  237. #ifdef ENABLE_WASM
  238. case Js::TypeIds_WebAssemblyModule:
  239. case Js::TypeIds_WebAssemblyInstance:
  240. case Js::TypeIds_WebAssemblyMemory:
  241. case Js::TypeIds_WebAssemblyTable:
  242. #endif
  243. case Js::TypeIds_Proxy:
  244. {
  245. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetObjectTypeDisplayString(), scriptContext);
  246. addDisplay = true;
  247. const char16* className = JsrtDebugUtils::GetClassName(typeId);
  248. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::className, className, wcslen(className), scriptContext);
  249. break;
  250. }
  251. default:
  252. AssertMsg(false, "Unhandled type");
  253. break;
  254. }
  255. }
  256. else
  257. {
  258. if (objectDisplayRef->HasChildren())
  259. {
  260. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetObjectTypeDisplayString(), scriptContext);
  261. addDisplay = true;
  262. const char16* className = JsrtDebugUtils::GetClassName(Js::TypeIds_Object);
  263. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::className, className, wcslen(className), scriptContext);
  264. }
  265. else
  266. {
  267. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::type, scriptContext->GetLibrary()->GetStringTypeDisplayString(), scriptContext);
  268. addValue = true;
  269. }
  270. }
  271. if (addDisplay || addValue)
  272. {
  273. LPCWSTR value = nullptr;
  274. // Getting value might call getter which can throw so wrap in try catch
  275. try
  276. {
  277. value = objectDisplayRef->Value(10);
  278. }
  279. catch (const Js::JavascriptException& err)
  280. {
  281. err.GetAndClear(); // discard exception object
  282. value = _u("");
  283. }
  284. JsrtDebugUtils::AddPropertyToObject(object, addDisplay ? JsrtDebugPropertyId::display : JsrtDebugPropertyId::value, value, wcslen(value), scriptContext);
  285. }
  286. if (forceSetValueProp && varValue != nullptr && !JsrtDebugUtils::HasProperty(object, JsrtDebugPropertyId::value, scriptContext))
  287. {
  288. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::value, varValue, scriptContext);
  289. }
  290. DBGPROP_ATTRIB_FLAGS dbPropAttrib = objectDisplayRef->GetTypeAttribute();
  291. JsrtDebugPropertyAttribute propertyAttributes = JsrtDebugPropertyAttribute::NONE;
  292. if ((dbPropAttrib & DBGPROP_ATTRIB_VALUE_READONLY) == DBGPROP_ATTRIB_VALUE_READONLY)
  293. {
  294. propertyAttributes |= JsrtDebugPropertyAttribute::READ_ONLY_VALUE;
  295. }
  296. if (objectDisplayRef->HasChildren())
  297. {
  298. propertyAttributes |= JsrtDebugPropertyAttribute::HAVE_CHILDRENS;
  299. }
  300. if (varAddress != nullptr && varAddress->IsInDeadZone())
  301. {
  302. propertyAttributes |= JsrtDebugPropertyAttribute::IN_TDZ;
  303. }
  304. JsrtDebugUtils::AddPropertyToObject(object, JsrtDebugPropertyId::propertyAttributes, (UINT)propertyAttributes, scriptContext);
  305. }
  306. void JsrtDebugUtils::AddVarPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, Js::Var value, Js::ScriptContext * scriptContext)
  307. {
  308. JsrtDebugUtils::AddVarPropertyToObject(object, JsrtDebugUtils::GetDebugPropertyName(propertyId), value, scriptContext);
  309. }
  310. void JsrtDebugUtils::AddPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, double value, Js::ScriptContext * scriptContext)
  311. {
  312. JsrtDebugUtils::AddVarPropertyToObject(object, propertyId, Js::JavascriptNumber::ToVarNoCheck(value, scriptContext), scriptContext);
  313. }
  314. void JsrtDebugUtils::AddPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, uint32 value, Js::ScriptContext * scriptContext)
  315. {
  316. JsrtDebugUtils::AddVarPropertyToObject(object, propertyId, Js::JavascriptNumber::ToVarNoCheck(value, scriptContext), scriptContext);
  317. }
  318. void JsrtDebugUtils::AddPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, int32 value, Js::ScriptContext * scriptContext)
  319. {
  320. JsrtDebugUtils::AddVarPropertyToObject(object, propertyId, Js::JavascriptNumber::ToVarNoCheck(value, scriptContext), scriptContext);
  321. }
  322. void JsrtDebugUtils::AddPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, const char16 * value, size_t len, Js::ScriptContext * scriptContext)
  323. {
  324. charcount_t charCount = static_cast<charcount_t>(len);
  325. Assert(charCount == len);
  326. if (charCount == len)
  327. {
  328. JsrtDebugUtils::AddVarPropertyToObject(object, propertyId, Js::JavascriptString::NewCopyBuffer(value, charCount, scriptContext), scriptContext);
  329. }
  330. }
  331. void JsrtDebugUtils::AddPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, Js::JavascriptString* jsString, Js::ScriptContext * scriptContext)
  332. {
  333. JsrtDebugUtils::AddPropertyToObject(object, propertyId, jsString->GetSz(), jsString->GetLength(), scriptContext);
  334. }
  335. void JsrtDebugUtils::AddPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, bool value, Js::ScriptContext * scriptContext)
  336. {
  337. JsrtDebugUtils::AddVarPropertyToObject(object, propertyId, Js::JavascriptBoolean::ToVar(value, scriptContext), scriptContext);
  338. }
  339. void JsrtDebugUtils::AddPropertyToObject(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, Js::Var value, Js::ScriptContext * scriptContext)
  340. {
  341. JsrtDebugUtils::AddVarPropertyToObject(object, propertyId, value, scriptContext);
  342. }
  343. bool JsrtDebugUtils::HasProperty(Js::DynamicObject * object, JsrtDebugPropertyId propertyId, Js::ScriptContext * scriptContext)
  344. {
  345. const char16* propertyName = GetDebugPropertyName(propertyId);
  346. const Js::PropertyRecord* propertyRecord;
  347. scriptContext->FindPropertyRecord(propertyName, static_cast<int>(wcslen(propertyName)), &propertyRecord);
  348. if (propertyRecord == nullptr)
  349. {
  350. // No property record exists, there must be no property with that name in the script context.
  351. return false;
  352. }
  353. return !!Js::JavascriptOperators::HasProperty(object, propertyRecord->GetPropertyId());
  354. }
  355. const char16 * JsrtDebugUtils::GetClassName(Js::TypeId typeId)
  356. {
  357. switch (typeId)
  358. {
  359. case Js::TypeIds_Object:
  360. case Js::TypeIds_ArrayIterator:
  361. case Js::TypeIds_MapIterator:
  362. case Js::TypeIds_SetIterator:
  363. case Js::TypeIds_StringIterator:
  364. return _u("Object");
  365. case Js::TypeIds_Proxy: return _u("Proxy");
  366. case Js::TypeIds_Array:
  367. case Js::TypeIds_NativeIntArray:
  368. #if ENABLE_COPYONACCESS_ARRAY
  369. case Js::TypeIds_CopyOnAccessNativeIntArray:
  370. #endif
  371. case Js::TypeIds_NativeFloatArray:
  372. case Js::TypeIds_ES5Array:
  373. case Js::TypeIds_CharArray:
  374. case Js::TypeIds_BoolArray:
  375. return _u("Array");
  376. case Js::TypeIds_Date:
  377. return _u("Date");
  378. case Js::TypeIds_RegEx: return _u("RegExp");
  379. case Js::TypeIds_Error: return _u("Error");
  380. case Js::TypeIds_BooleanObject: return _u("Boolean");
  381. case Js::TypeIds_NumberObject: return _u("Number");
  382. case Js::TypeIds_StringObject: return _u("String");
  383. case Js::TypeIds_Arguments: return _u("Object");
  384. case Js::TypeIds_ArrayBuffer: return _u("ArrayBuffer");
  385. case Js::TypeIds_Int8Array: return _u("Int8Array");
  386. case Js::TypeIds_Uint8Array: return _u("Uint8Array");
  387. case Js::TypeIds_Uint8ClampedArray: return _u("Uint8ClampedArray");
  388. case Js::TypeIds_Int16Array: return _u("Int16Array");
  389. case Js::TypeIds_Uint16Array: return _u("Uint16Array");
  390. case Js::TypeIds_Int32Array: return _u("Int32Array");
  391. case Js::TypeIds_Uint32Array: return _u("Uint32Array");
  392. case Js::TypeIds_Float32Array: return _u("Float32Array");
  393. case Js::TypeIds_Float64Array: return _u("Float64Array");
  394. case Js::TypeIds_Int64Array: return _u("Int64Array");
  395. case Js::TypeIds_Uint64Array: return _u("Uint64Array");
  396. case Js::TypeIds_DataView: return _u("DataView");
  397. case Js::TypeIds_Map: return _u("Map");
  398. case Js::TypeIds_Set: return _u("Set");
  399. case Js::TypeIds_WeakMap: return _u("WeakMap");
  400. case Js::TypeIds_WeakSet: return _u("WeakSet");
  401. case Js::TypeIds_SymbolObject: return _u("Symbol");
  402. case Js::TypeIds_Generator: return _u("Generator");
  403. case Js::TypeIds_AsyncGenerator: return _u("AsyncGenerator");
  404. case Js::TypeIds_AsyncFromSyncIterator: return _u("AsyncFromSyncIterator");
  405. case Js::TypeIds_Promise: return _u("Promise");
  406. case Js::TypeIds_GlobalObject: return _u("Object");
  407. case Js::TypeIds_SpreadArgument: return _u("Spread");
  408. #ifdef ENABLE_WASM
  409. case Js::TypeIds_WebAssemblyModule: return _u("WebAssembly.Module");
  410. case Js::TypeIds_WebAssemblyInstance: return _u("WebAssembly.Instance");
  411. case Js::TypeIds_WebAssemblyMemory: return _u("WebAssembly.Memory");
  412. case Js::TypeIds_WebAssemblyTable: return _u("WebAssembly.Table");
  413. #endif
  414. default:
  415. Assert(false);
  416. }
  417. return _u("");
  418. }
  419. const char16 * JsrtDebugUtils::GetDebugPropertyName(JsrtDebugPropertyId propertyId)
  420. {
  421. switch (propertyId)
  422. {
  423. #define DEBUGOBJECTPROPERTY(name) case JsrtDebugPropertyId::##name: return _u(###name);
  424. #include "JsrtDebugPropertiesEnum.h"
  425. }
  426. Assert(false);
  427. return _u("");
  428. }
  429. #endif