Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@fdba5f1f9b] [1.6>1.7] [MERGE #3435 @suwc]…
Browse files Browse the repository at this point in the history
… OS12814968: ASSERTION:(lib\runtime\Base/FunctionBody.h) IsFunctionBody()

Merge pull request #3435 from suwc:build/suwc/OS12814968

Function body not available for deferred-parse function.
Add additional checking.
  • Loading branch information
chakrabot authored and kfarnung committed Aug 10, 2017
1 parent 2e92601 commit 65515eb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
51 changes: 30 additions & 21 deletions deps/chakrashim/core/lib/Jsrt/JsrtDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,34 +499,43 @@ CHAKRA_API JsDiagGetFunctionPosition(

Js::ScriptFunction* jsFunction = Js::ScriptFunction::FromVar(function);

Js::FunctionBody* functionBody = jsFunction->GetFunctionBody();
if (functionBody != nullptr)
BOOL fParsed = jsFunction->GetParseableFunctionInfo()->IsFunctionParsed();
if (!fParsed)
{
Js::Utf8SourceInfo* utf8SourceInfo = functionBody->GetUtf8SourceInfo();
if (utf8SourceInfo != nullptr && !utf8SourceInfo->GetIsLibraryCode())
{
ULONG lineNumber = functionBody->GetLineNumber();
ULONG columnNumber = functionBody->GetColumnNumber();
uint startOffset = functionBody->GetStatementStartOffset(0);
ULONG firstStatementLine;
LONG firstStatementColumn;
Js::JavascriptFunction::DeferredParseCore(&jsFunction, fParsed);
}

if (functionBody->GetLineCharOffsetFromStartChar(startOffset, &firstStatementLine, &firstStatementColumn))
if (fParsed)
{
Js::FunctionBody* functionBody = jsFunction->GetFunctionBody();
if (functionBody != nullptr)
{
Js::Utf8SourceInfo* utf8SourceInfo = functionBody->GetUtf8SourceInfo();
if (utf8SourceInfo != nullptr && !utf8SourceInfo->GetIsLibraryCode())
{
Js::DynamicObject* funcPositionObject = (Js::DynamicObject*)Js::CrossSite::MarshalVar(utf8SourceInfo->GetScriptContext(), scriptContext->GetLibrary()->CreateObject());
ULONG lineNumber = functionBody->GetLineNumber();
ULONG columnNumber = functionBody->GetColumnNumber();
uint startOffset = functionBody->GetStatementStartOffset(0);
ULONG firstStatementLine;
LONG firstStatementColumn;

if (funcPositionObject != nullptr)
if (functionBody->GetLineCharOffsetFromStartChar(startOffset, &firstStatementLine, &firstStatementColumn))
{
JsrtDebugUtils::AddScriptIdToObject(funcPositionObject, utf8SourceInfo);
JsrtDebugUtils::AddFileNameOrScriptTypeToObject(funcPositionObject, utf8SourceInfo);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::line, (uint32) lineNumber, scriptContext);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::column, (uint32) columnNumber, scriptContext);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::firstStatementLine, (uint32) firstStatementLine, scriptContext);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::firstStatementColumn, (int32) firstStatementColumn, scriptContext);
Js::DynamicObject* funcPositionObject = (Js::DynamicObject*)Js::CrossSite::MarshalVar(utf8SourceInfo->GetScriptContext(), scriptContext->GetLibrary()->CreateObject());

if (funcPositionObject != nullptr)
{
JsrtDebugUtils::AddScriptIdToObject(funcPositionObject, utf8SourceInfo);
JsrtDebugUtils::AddFileNameOrScriptTypeToObject(funcPositionObject, utf8SourceInfo);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::line, (uint32)lineNumber, scriptContext);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::column, (uint32)columnNumber, scriptContext);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::firstStatementLine, (uint32)firstStatementLine, scriptContext);
JsrtDebugUtils::AddPropertyToObject(funcPositionObject, JsrtDebugPropertyId::firstStatementColumn, (int32)firstStatementColumn, scriptContext);

*functionPosition = funcPositionObject;
*functionPosition = funcPositionObject;

return JsNoError;
return JsNoError;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion deps/chakrashim/core/lib/Runtime/Base/FunctionBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ namespace Js

inline FunctionBody * FunctionProxy::GetFunctionBody() const
{
Assert(IsFunctionBody());
AssertOrFailFast(IsFunctionBody());
return (FunctionBody*)this;
}

Expand Down
13 changes: 13 additions & 0 deletions deps/chakrashim/core/test/DebuggerCommon/bug_OS12814968.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

// repro flags: -forcedeferparse

var obj = {
func : function () { }
};

WScript.DumpFunctionPosition(obj.func);
console.log("PASS");
7 changes: 7 additions & 0 deletions deps/chakrashim/core/test/DebuggerCommon/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,13 @@
<compile-flags>-debuglaunch -dbgbaseline:promisedisplay.js.dbg.baseline</compile-flags>
</default>
</test>
<test>
<default>
<files>bug_OS12814968.js</files>
<compile-flags>-forcedeferparse</compile-flags>
<tags>BugFix</tags>
</default>
</test>
<test>
<default>
<files>AsyncDynamicAttach.js</files>
Expand Down

0 comments on commit 65515eb

Please sign in to comment.