From 65515ebf39fc458ea6743feea6053143c943b691 Mon Sep 17 00:00:00 2001 From: chakrabot Date: Mon, 31 Jul 2017 16:47:52 -0700 Subject: [PATCH] [Merge Microsoft/Chakracore@fdba5f1f9b] [1.6>1.7] [MERGE #3435 @suwc] 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. --- deps/chakrashim/core/lib/Jsrt/JsrtDiag.cpp | 51 +++++++++++-------- .../core/lib/Runtime/Base/FunctionBody.h | 2 +- .../test/DebuggerCommon/bug_OS12814968.js | 13 +++++ .../core/test/DebuggerCommon/rlexe.xml | 7 +++ 4 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 deps/chakrashim/core/test/DebuggerCommon/bug_OS12814968.js diff --git a/deps/chakrashim/core/lib/Jsrt/JsrtDiag.cpp b/deps/chakrashim/core/lib/Jsrt/JsrtDiag.cpp index 1dcc32cace9..c9a0970912e 100644 --- a/deps/chakrashim/core/lib/Jsrt/JsrtDiag.cpp +++ b/deps/chakrashim/core/lib/Jsrt/JsrtDiag.cpp @@ -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; + } } } } diff --git a/deps/chakrashim/core/lib/Runtime/Base/FunctionBody.h b/deps/chakrashim/core/lib/Runtime/Base/FunctionBody.h index bd16bc66d75..1998e47a3fd 100644 --- a/deps/chakrashim/core/lib/Runtime/Base/FunctionBody.h +++ b/deps/chakrashim/core/lib/Runtime/Base/FunctionBody.h @@ -1763,7 +1763,7 @@ namespace Js inline FunctionBody * FunctionProxy::GetFunctionBody() const { - Assert(IsFunctionBody()); + AssertOrFailFast(IsFunctionBody()); return (FunctionBody*)this; } diff --git a/deps/chakrashim/core/test/DebuggerCommon/bug_OS12814968.js b/deps/chakrashim/core/test/DebuggerCommon/bug_OS12814968.js new file mode 100644 index 00000000000..2495a8ab6fc --- /dev/null +++ b/deps/chakrashim/core/test/DebuggerCommon/bug_OS12814968.js @@ -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"); diff --git a/deps/chakrashim/core/test/DebuggerCommon/rlexe.xml b/deps/chakrashim/core/test/DebuggerCommon/rlexe.xml index a8c0d59c573..414d4a03411 100644 --- a/deps/chakrashim/core/test/DebuggerCommon/rlexe.xml +++ b/deps/chakrashim/core/test/DebuggerCommon/rlexe.xml @@ -1356,6 +1356,13 @@ -debuglaunch -dbgbaseline:promisedisplay.js.dbg.baseline + + + bug_OS12814968.js + -forcedeferparse + BugFix + + AsyncDynamicAttach.js