Skip to content

Commit f299a99

Browse files
author
Suwei Chen
committed
Bugfix:OS5553123:Freeze while comparing valueOf()-injected null
Chakra implementation of Abstract Relational Comparison operation fails to handle 'null'. Specifically, it cause a browser tab to freeze when a comparison ("<") is done with the left value being 'null' injected by valueOf() call through a prototype. Add 'null' checking to fix this problem. Add unit test.
1 parent bf0f4fe commit f299a99

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ namespace Js
708708
dblRight = JavascriptConversion::ToNumber(aRight, scriptContext);
709709
break;
710710
case TypeIds_Boolean:
711+
case TypeIds_Null:
712+
case TypeIds_Undefined:
713+
case TypeIds_Symbol:
711714
dblLeft = JavascriptConversion::ToNumber(aLeft, scriptContext);
712715
dblRight = JavascriptConversion::ToNumber(aRight, scriptContext);
713716
break;

test/Bugs/OS_5553123.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
7+
8+
function testRelationalComparison (retVal)
9+
{
10+
var ObjectV = function ObjectV(v){ }
11+
12+
ObjectV.prototype = {
13+
valueOf : function(){ return retVal; }
14+
};
15+
16+
function f()
17+
{
18+
var x = new ObjectV(0);
19+
x<"1";
20+
}
21+
22+
f();
23+
f();
24+
f();
25+
}
26+
27+
testRelationalComparison(null);
28+
testRelationalComparison(undefined);
29+
assert.throws(function() { testRelationalComparison(Symbol("abc")); }, TypeError, "Number expected");
30+
31+
WScript.Echo("Passed");

test/Bugs/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,9 @@
235235
<compile-flags>-maxinterpretCount:2 -off:simplejit -off:dynamicProfile -args summary -endargs</compile-flags>
236236
</default>
237237
</test>
238+
<test>
239+
<default>
240+
<files>OS_5553123.js</files>
241+
</default>
242+
</test>
238243
</regress-exe>

0 commit comments

Comments
 (0)