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

Commit 0bdb2b1

Browse files
jackhortonchakrabot
authored andcommitted
deps: update ChakraCore to chakra-core/ChakraCore@172bac86e0
[MERGE #4614 @jackhorton] Fix error messages on errors created through the JSRT Merge pull request #4614 from jackhorton:jsrt_error_message This will unblock the 01/14/18 node merge pump Reviewed-By: Jack Horton <jahorto@microsoft.com>
1 parent 25a3ac8 commit 0bdb2b1

File tree

14 files changed

+214
-21
lines changed

14 files changed

+214
-21
lines changed

deps/chakrashim/core/lib/Backend/GlobOpt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5195,6 +5195,7 @@ GlobOpt::ValueNumberDst(IR::Instr **pInstr, Value *src1Val, Value *src2Val)
51955195
break;
51965196

51975197
case Js::OpCode::Typeof:
5198+
case Js::OpCode::TypeofElem:
51985199
return this->NewGenericValue(ValueType::String, dst);
51995200
case Js::OpCode::InitLocalClosure:
52005201
Assert(instr->GetDst());

deps/chakrashim/core/lib/Jsrt/Jsrt.cpp

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,27 @@ JsErrorCode CreateContextCore(_In_ JsRuntimeHandle runtimeHandle, _In_ TTDRecord
178178

179179
if(jsrtDebugManager != nullptr)
180180
{
181+
// JsDiagStartDebugging was called
182+
threadContext->GetDebugManager()->SetLocalsDisplayFlags(Js::DebugManager::LocalsDisplayFlags::LocalsDisplayFlags_NoGroupMethods);
183+
181184
Js::ScriptContext* scriptContext = context->GetScriptContext();
182-
scriptContext->InitializeDebugging();
183185

184186
Js::DebugContext* debugContext = scriptContext->GetDebugContext();
185187
debugContext->SetHostDebugContext(jsrtDebugManager);
186188

187-
Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
188-
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
189-
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
190-
191-
threadContext->GetDebugManager()->SetLocalsDisplayFlags(Js::DebugManager::LocalsDisplayFlags::LocalsDisplayFlags_NoGroupMethods);
189+
if (!jsrtDebugManager->IsDebugEventCallbackSet())
190+
{
191+
// JsDiagStopDebugging was called so we need to be in SourceRunDownMode
192+
debugContext->SetDebuggerMode(Js::DebuggerMode::SourceRundown);
193+
}
194+
else
195+
{
196+
// Set Debugging mode
197+
scriptContext->InitializeDebugging();
198+
Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
199+
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
200+
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
201+
}
192202
}
193203
#endif
194204

@@ -2880,9 +2890,28 @@ CHAKRA_API JsCreateNamedFunction(_In_ JsValueRef name, _In_ JsNativeFunction nat
28802890
return JsCreateEnhancedFunctionHelper<true>(nativeFunction, name, callbackState, function);
28812891
}
28822892

2883-
void SetErrorMessage(Js::ScriptContext *scriptContext, JsValueRef newError, JsValueRef message)
2893+
void SetErrorMessage(Js::ScriptContext *scriptContext, Js::JavascriptError *newError, JsValueRef message)
28842894
{
2885-
Js::JavascriptOperators::OP_SetProperty(newError, Js::PropertyIds::message, message, scriptContext);
2895+
// ECMA262 #sec-error-message
2896+
if (!Js::JavascriptOperators::IsUndefined(message))
2897+
{
2898+
Js::JavascriptString *messageStr = nullptr;
2899+
if (Js::JavascriptString::Is(message))
2900+
{
2901+
messageStr = Js::JavascriptString::FromVar(message);
2902+
}
2903+
else
2904+
{
2905+
messageStr = Js::JavascriptConversion::ToString(message, scriptContext);
2906+
}
2907+
2908+
Js::PropertyDescriptor desc;
2909+
desc.SetValue(messageStr);
2910+
desc.SetWritable(true);
2911+
desc.SetEnumerable(false);
2912+
desc.SetConfigurable(true);
2913+
Js::JavascriptOperators::SetPropertyDescriptor(newError, Js::PropertyIds::message, desc);
2914+
}
28862915
}
28872916

28882917
CHAKRA_API JsCreateError(_In_ JsValueRef message, _Out_ JsValueRef *error)
@@ -2894,7 +2923,7 @@ CHAKRA_API JsCreateError(_In_ JsValueRef message, _Out_ JsValueRef *error)
28942923
PARAM_NOT_NULL(error);
28952924
*error = nullptr;
28962925

2897-
JsValueRef newError = scriptContext->GetLibrary()->CreateError();
2926+
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateError();
28982927
SetErrorMessage(scriptContext, newError, message);
28992928
*error = newError;
29002929

@@ -2913,7 +2942,7 @@ CHAKRA_API JsCreateRangeError(_In_ JsValueRef message, _Out_ JsValueRef *error)
29132942
PARAM_NOT_NULL(error);
29142943
*error = nullptr;
29152944

2916-
JsValueRef newError = scriptContext->GetLibrary()->CreateRangeError();
2945+
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateRangeError();
29172946
SetErrorMessage(scriptContext, newError, message);
29182947
*error = newError;
29192948

@@ -2932,7 +2961,7 @@ CHAKRA_API JsCreateReferenceError(_In_ JsValueRef message, _Out_ JsValueRef *err
29322961
PARAM_NOT_NULL(error);
29332962
*error = nullptr;
29342963

2935-
JsValueRef newError = scriptContext->GetLibrary()->CreateReferenceError();
2964+
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateReferenceError();
29362965
SetErrorMessage(scriptContext, newError, message);
29372966
*error = newError;
29382967

@@ -2951,7 +2980,7 @@ CHAKRA_API JsCreateSyntaxError(_In_ JsValueRef message, _Out_ JsValueRef *error)
29512980
PARAM_NOT_NULL(error);
29522981
*error = nullptr;
29532982

2954-
JsValueRef newError = scriptContext->GetLibrary()->CreateSyntaxError();
2983+
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateSyntaxError();
29552984
SetErrorMessage(scriptContext, newError, message);
29562985
*error = newError;
29572986

@@ -2970,7 +2999,7 @@ CHAKRA_API JsCreateTypeError(_In_ JsValueRef message, _Out_ JsValueRef *error)
29702999
PARAM_NOT_NULL(error);
29713000
*error = nullptr;
29723001

2973-
JsValueRef newError = scriptContext->GetLibrary()->CreateTypeError();
3002+
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateTypeError();
29743003
SetErrorMessage(scriptContext, newError, message);
29753004
*error = newError;
29763005

@@ -2989,7 +3018,7 @@ CHAKRA_API JsCreateURIError(_In_ JsValueRef message, _Out_ JsValueRef *error)
29893018
PARAM_NOT_NULL(error);
29903019
*error = nullptr;
29913020

2992-
JsValueRef newError = scriptContext->GetLibrary()->CreateURIError();
3021+
Js::JavascriptError *newError = scriptContext->GetLibrary()->CreateURIError();
29933022
SetErrorMessage(scriptContext, newError, message);
29943023
*error = newError;
29953024

deps/chakrashim/core/lib/Jsrt/JsrtDiag.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ CHAKRA_API JsDiagStartDebugging(
9999
return JsErrorFatal;
100100
}
101101

102-
Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
103-
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
104-
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
102+
// ScriptContext might get closed in OnDebuggerAttached
103+
if (!scriptContext->IsClosed())
104+
{
105+
Js::ProbeContainer* probeContainer = debugContext->GetProbeContainer();
106+
probeContainer->InitializeInlineBreakEngine(jsrtDebugManager);
107+
probeContainer->InitializeDebuggerScriptOptionCallback(jsrtDebugManager);
108+
}
105109
}
106110

107111
return JsNoError;

deps/chakrashim/core/lib/Runtime/Library/JavascriptRegExpConstructor.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Js
1717
JavascriptRegExpConstructor::JavascriptRegExpConstructor(DynamicType * type) :
1818
RuntimeFunction(type, &JavascriptRegExp::EntryInfo::NewInstance),
1919
reset(false),
20+
invalidatedLastMatch(false),
2021
lastPattern(nullptr),
2122
lastMatch() // undefined
2223
{
@@ -53,17 +54,44 @@ namespace Js
5354
this->lastInput = lastInput;
5455
this->lastMatch = lastMatch;
5556
this->reset = true;
57+
this->invalidatedLastMatch = false;
58+
}
59+
60+
void JavascriptRegExpConstructor::InvalidateLastMatch(UnifiedRegex::RegexPattern* lastPattern, JavascriptString* lastInput)
61+
{
62+
AssertMsg(lastPattern != nullptr, "lastPattern should not be null");
63+
AssertMsg(lastInput != nullptr, "lastInput should not be null");
64+
AssertMsg(JavascriptOperators::GetTypeId(lastInput) != TypeIds_Null, "lastInput should not be JavaScript null");
65+
66+
this->lastPattern = lastPattern;
67+
this->lastInput = lastInput;
68+
this->lastMatch.Reset();
69+
this->reset = true;
70+
this->invalidatedLastMatch = true;
5671
}
5772

5873
void JavascriptRegExpConstructor::EnsureValues()
5974
{
6075
if (reset)
6176
{
62-
Assert(!lastMatch.IsUndefined());
6377
ScriptContext* scriptContext = this->GetScriptContext();
78+
const CharCount lastInputLen = lastInput->GetLength();
79+
const char16* lastInputStr = lastInput->GetString();
6480
UnifiedRegex::RegexPattern* pattern = lastPattern;
81+
82+
// When we perform a regex test operation it's possible the result of the operation will be loaded from a cache and the match will not be computed and updated in the ctor.
83+
// In that case we invalidate the last match stored in the ctor and will need to compute it before it will be accessible via $1 etc.
84+
// Since we only do this for the case of RegExp.prototype.test cache hit, we know several things:
85+
// - The regex is not global or sticky
86+
// - There was a match (test returned true)
87+
if (invalidatedLastMatch)
88+
{
89+
this->lastMatch = RegexHelper::SimpleMatch(scriptContext, pattern, lastInputStr, lastInputLen, 0);
90+
invalidatedLastMatch = false;
91+
}
92+
93+
Assert(!lastMatch.IsUndefined());
6594
JavascriptString* emptyString = scriptContext->GetLibrary()->GetEmptyString();
66-
const CharCount lastInputLen = lastInput->GetLength();
6795
// IE8 quirk: match of length 0 is regarded as length 1
6896
CharCount lastIndexVal = lastMatch.EndOffset();
6997
this->index = JavascriptNumber::ToVar(lastMatch.offset, scriptContext);
@@ -82,7 +110,7 @@ namespace Js
82110
// every match is prohibitively slow. Instead, run the match again using the known last input string.
83111
if (!pattern->WasLastMatchSuccessful())
84112
{
85-
RegexHelper::SimpleMatch(scriptContext, pattern, lastInput->GetString(), lastInputLen, lastMatch.offset);
113+
RegexHelper::SimpleMatch(scriptContext, pattern, lastInputStr, lastInputLen, lastMatch.offset);
86114
}
87115
Assert(pattern->WasLastMatchSuccessful());
88116
for (int groupId = 1; groupId < min(numGroups, NumCtorCaptures); groupId++)
@@ -100,6 +128,11 @@ namespace Js
100128
captures[groupId] = emptyString;
101129
reset = false;
102130
}
131+
else
132+
{
133+
// If we are not resetting the values, the last match cannot be invalidated.
134+
Assert(!invalidatedLastMatch);
135+
}
103136
}
104137

105138
/*static*/

deps/chakrashim/core/lib/Runtime/Library/JavascriptRegExpConstructor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ namespace Js
5353
bool GetPropertyBuiltIns(PropertyId propertyId, Var* value, BOOL* result);
5454
bool SetPropertyBuiltIns(PropertyId propertyId, Var value, BOOL* result);
5555
void SetLastMatch(UnifiedRegex::RegexPattern* lastPattern, JavascriptString* lastInput, UnifiedRegex::GroupInfo lastMatch);
56+
void InvalidateLastMatch(UnifiedRegex::RegexPattern* lastPattern, JavascriptString* lastInput);
5657

5758
void EnsureValues();
5859

5960
Field(UnifiedRegex::RegexPattern*) lastPattern;
6061
Field(JavascriptString*) lastInput;
6162
Field(UnifiedRegex::GroupInfo) lastMatch;
63+
Field(bool) invalidatedLastMatch; // true if last match must be recalculated before use
6264
Field(bool) reset; // true if following fields must be recalculated from above before first use
6365
Field(Var) lastParen;
6466
Field(Var) lastIndex;

deps/chakrashim/core/lib/Runtime/Library/RegexHelper.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,20 @@ namespace Js
691691
{
692692
Assert(useCache);
693693
cachedResult = (cache->resultBV.Test(cacheIndex) != 0);
694+
695+
// If our cache says this test should produce a match (which we aren't going to compute),
696+
// notify the Ctor to invalidate the last match so it must be recomputed before access.
697+
if (cachedResult)
698+
{
699+
InvalidateLastMatchOnCtor(scriptContext, regularExpression, input);
700+
}
701+
694702
// for debug builds, let's still do the real test so we can validate values in the cache
695703
#if !DBG
696704
return JavascriptBoolean::ToVar(cachedResult, scriptContext);
697705
#endif
698706
}
699707

700-
701708
CharCount offset;
702709
if (!GetInitialOffset(isGlobal, isSticky, regularExpression, inputLength, offset))
703710
{
@@ -2087,6 +2094,16 @@ namespace Js
20872094
}
20882095
}
20892096

2097+
void RegexHelper::InvalidateLastMatchOnCtor(ScriptContext* scriptContext, JavascriptRegExp* regularExpression, JavascriptString* lastInput, bool useSplitPattern)
2098+
{
2099+
Assert(lastInput);
2100+
2101+
UnifiedRegex::RegexPattern* pattern = useSplitPattern
2102+
? regularExpression->GetSplitPattern()
2103+
: regularExpression->GetPattern();
2104+
scriptContext->GetLibrary()->GetRegExpConstructor()->InvalidateLastMatch(pattern, lastInput);
2105+
}
2106+
20902107
bool RegexHelper::GetInitialOffset(bool isGlobal, bool isSticky, JavascriptRegExp* regularExpression, CharCount inputLength, CharCount& offset)
20912108
{
20922109
if (isGlobal || isSticky)

deps/chakrashim/core/lib/Runtime/Library/RegexHelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace Js
5858
, UnifiedRegex::GroupInfo lastSuccessfulMatch
5959
, bool useSplitPattern );
6060

61+
static void InvalidateLastMatchOnCtor(ScriptContext* scriptContext, JavascriptRegExp* regularExpression, JavascriptString* lastInput, bool useSplitPattern = false);
62+
6163
static bool GetInitialOffset(bool isGlobal, bool isSticky, JavascriptRegExp* regularExpression, CharCount inputLength, CharCount& offset);
6264
static JavascriptArray* CreateMatchResult(void *const stackAllocationPointer, ScriptContext* scriptContext, bool isGlobal, int numGroups, JavascriptString* input);
6365
static void FinalizeMatchResult(ScriptContext* scriptContext, bool isGlobal, JavascriptArray* arr, UnifiedRegex::GroupInfo match);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
6+
function bar(x)
7+
{
8+
if (x != x)
9+
{
10+
return;
11+
}
12+
}
13+
14+
function foo()
15+
{
16+
bar(typeof arguments[0]);
17+
};
18+
19+
foo();
20+
foo();
21+
foo();
22+
23+
WScript.Echo("Passed");

deps/chakrashim/core/test/Bugs/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,9 @@
428428
<baseline>bug13830477.baseline</baseline>
429429
</default>
430430
</test>
431+
<test>
432+
<default>
433+
<files>bug15490382.js</files>
434+
</default>
435+
</test>
431436
</regress-exe>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)