@@ -61,17 +61,19 @@ void JsrtDebugUtils::AddSourceLengthAndTextToObject(Js::DynamicObject* object, J
6161 LPCUTF8 source = functionBody->GetStartOfDocument (_u (" Source for debugging" ));
6262 size_t cbLength = functionBody->GetUtf8SourceInfo ()->GetCbLength ();
6363 size_t startByte = utf8::CharacterIndexToByteIndex (source, cbLength, (const charcount_t )statementMap->sourceSpan .begin );
64+ size_t endByte = utf8::CharacterIndexToByteIndex (source, cbLength, (const charcount_t )statementMap->sourceSpan .end );
65+ int cch = statementMap->sourceSpan .end - statementMap->sourceSpan .begin ;
6466
65- int byteLength = statementMap-> sourceSpan . end - statementMap-> sourceSpan . begin ;
67+ JsrtDebugUtils::AddPropertyToObject (object, JsrtDebugPropertyId::sourceLength, ( double )cch, functionBody-> GetScriptContext ()) ;
6668
67- JsrtDebugUtils::AddPropertyToObject (object, JsrtDebugPropertyId::sourceLength, (double )byteLength, functionBody->GetScriptContext ());
68-
69- AutoArrayPtr<char16> sourceContent (HeapNewNoThrowArray (char16, byteLength + 1 ), byteLength + 1 );
69+ AutoArrayPtr<char16> sourceContent (HeapNewNoThrowArray (char16, cch + 1 ), cch + 1 );
7070 if (sourceContent != nullptr )
7171 {
72+ LPCUTF8 pbStart = source + startByte;
73+ LPCUTF8 pbEnd = pbStart + (endByte - startByte);
7274 utf8::DecodeOptions options = functionBody->GetUtf8SourceInfo ()->IsCesu8 () ? utf8::doAllowThreeByteSurrogates : utf8::doDefault;
73- utf8::DecodeIntoAndNullTerminate (sourceContent, source + startByte, source + startByte + cbLength, byteLength , options);
74- JsrtDebugUtils::AddPropertyToObject (object, JsrtDebugPropertyId::sourceText, sourceContent, byteLength , functionBody->GetScriptContext ());
75+ utf8::DecodeUnitsIntoAndNullTerminate (sourceContent, pbStart, pbEnd , options);
76+ JsrtDebugUtils::AddPropertyToObject (object, JsrtDebugPropertyId::sourceText, sourceContent, cch , functionBody->GetScriptContext ());
7577 }
7678 else
7779 {
@@ -96,7 +98,7 @@ void JsrtDebugUtils::AddSouceToObject(Js::DynamicObject * object, Js::Utf8Source
9698 LPCUTF8 source = utf8SourceInfo->GetSource ();
9799 size_t cbLength = utf8SourceInfo->GetCbLength ();
98100 utf8::DecodeOptions options = utf8SourceInfo->IsCesu8 () ? utf8::doAllowThreeByteSurrogates : utf8::doDefault;
99- utf8::DecodeIntoAndNullTerminate (sourceContent, source, source + cbLength, cchLength , options);
101+ utf8::DecodeUnitsIntoAndNullTerminate (sourceContent, source, source + cbLength, options);
100102 JsrtDebugUtils::AddPropertyToObject (object, JsrtDebugPropertyId::source, sourceContent, cchLength, utf8SourceInfo->GetScriptContext ());
101103 }
102104 else
0 commit comments