Skip to content

Commit 21624b8

Browse files
committed
[MERGE #5731 @yullin-ms] Implemented Math min and max as JsBuiltIns
Merge pull request #5731 from yullin-ms:mathMinMax Implemented Math min and max as JsBuiltIns
2 parents eeba684 + 6c42b34 commit 21624b8

17 files changed

+7405
-6469
lines changed

lib/Runtime/Base/JnDirectFields.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ ENTRY(Array_every)
659659
ENTRY(Array_includes)
660660
ENTRY(Array_reduce)
661661
ENTRY(Object_fromEntries)
662+
ENTRY(Math_min)
663+
ENTRY(Math_max)
662664
ENTRY(FunctionKind)
663665

664666
// EngineInterfaceObject built-ins
@@ -668,6 +670,8 @@ ENTRY(builtInJavascriptArrayEntryIndexOf)
668670
ENTRY(builtInJavascriptArrayEntrySome)
669671
ENTRY(builtInJavascriptArrayEntryEvery)
670672
ENTRY(builtInJavascriptArrayEntryIncludes)
673+
ENTRY(builtInMathMin)
674+
ENTRY(builtInMathMax)
671675
ENTRY(EngineInterface)
672676
ENTRY(builtInCallInstanceFunction)
673677

lib/Runtime/ByteCode/ByteCodeCacheReleaseFileVersion.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
55
// NOTE: If there is a merge conflict the correct fix is to make a new GUID.
6-
// This file was generated with tools\update_bytecode_version.ps1
76

8-
// {9FAAF688-ACBA-4092-BA5B-77D97D3CD53A}
7+
// {D8913E7E-E430-4B28-81DD-EDD3EE5F263B}
98
const GUID byteCodeCacheReleaseFileVersion =
10-
{ 0x9FAAF688, 0xACBA, 0x4092, { 0xBA, 0x5B, 0x77, 0xD9, 0x7D, 0x3C, 0xD5, 0x3A } };
9+
{ 0xD8913E7E, 0xE430, 0x4B28, { 0x81, 0xDD, 0xED, 0xD3, 0xEE, 0x5F, 0x26, 0x3B } };

lib/Runtime/Language/AsmJsBuiltInNames.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
//-------------------------------------------------------------------------------------------------------
55

66
// Default all macros to nothing
7+
8+
#ifndef ASMJS_JSBUILTIN_MATH_FUNC_NAMES
9+
#define ASMJS_JSBUILTIN_MATH_FUNC_NAMES(propertyId, funcName)
10+
#endif
11+
712
#ifndef ASMJS_MATH_FUNC_NAMES
813
#define ASMJS_MATH_FUNC_NAMES(name, propertyName, funcInfo)
914
#endif
@@ -24,6 +29,11 @@
2429
#define ASMJS_TYPED_ARRAY_NAMES(name, propertyName) ASMJS_ARRAY_NAMES(name, propertyName)
2530
#endif
2631

32+
#ifdef ENABLE_JS_BUILTINS
33+
ASMJS_JSBUILTIN_MATH_FUNC_NAMES(Js::PropertyIds::min, Min )
34+
ASMJS_JSBUILTIN_MATH_FUNC_NAMES(Js::PropertyIds::max, Max )
35+
#endif
36+
2737
ASMJS_MATH_FUNC_NAMES(sin, sin, Math::EntryInfo::Sin )
2838
ASMJS_MATH_FUNC_NAMES(cos, cos, Math::EntryInfo::Cos )
2939
ASMJS_MATH_FUNC_NAMES(tan, tan, Math::EntryInfo::Tan )
@@ -66,6 +76,7 @@ ASMJS_TYPED_ARRAY_NAMES(Float64Array, Float64Array)
6676
ASMJS_ARRAY_NAMES(byteLength, byteLength)
6777

6878
// help the caller to undefine all the macros
79+
#undef ASMJS_JSBUILTIN_MATH_FUNC_NAMES
6980
#undef ASMJS_MATH_FUNC_NAMES
7081
#undef ASMJS_MATH_CONST_NAMES
7182
#undef ASMJS_MATH_DOUBLE_CONST_NAMES

lib/Runtime/Language/AsmJsLink.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ namespace Js{
191191
bool ASMLink::CheckIsBuiltinFunction(ScriptContext* scriptContext, const Var object, PropertyId propertyId, const FunctionInfo& funcInfo)
192192
{
193193
Var mathFuncObj = JavascriptOperators::OP_GetProperty(object, propertyId, scriptContext);
194+
#ifdef ENABLE_JS_BUILTINS
195+
if (scriptContext->IsJsBuiltInEnabled())
196+
{
197+
switch (propertyId)
198+
{
199+
#define ASMJS_JSBUILTIN_MATH_FUNC_NAMES(propertyId, funcName) case propertyId: \
200+
return VarIs<JavascriptFunction>(mathFuncObj) && \
201+
VarTo<JavascriptFunction>(mathFuncObj) == scriptContext->GetLibrary()->GetMath##funcName##Function();
202+
#include "AsmJsBuiltInNames.h"
203+
}
204+
}
205+
#endif
194206
return VarIs<JavascriptFunction>(mathFuncObj) &&
195207
VarTo<JavascriptFunction>(mathFuncObj)->GetFunctionInfo()->GetOriginalEntryPoint() == funcInfo.GetOriginalEntryPoint();
196208
}

lib/Runtime/Library/EngineInterfaceObjectBuiltIns.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ GlobalBuiltInConstructor(Symbol)
5656

5757
GlobalMathBuiltIn(Abs)
5858
GlobalMathBuiltIn(Floor)
59-
GlobalMathBuiltIn(Max)
6059
GlobalMathBuiltIn(Pow)
6160

6261
GlobalBuiltIn(JavascriptObject, DefineProperty)

lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h

Lines changed: 785 additions & 785 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h

Lines changed: 788 additions & 788 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h

Lines changed: 793 additions & 793 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h

Lines changed: 772 additions & 772 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,6 @@ namespace Js
18761876

18771877
/* No inlining Array_Fill */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::fill, &JavascriptArray::EntryInfo::Fill, 1);
18781878
/* No inlining Array_CopyWithin */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::copyWithin, &JavascriptArray::EntryInfo::CopyWithin, 2);
1879-
18801879
DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
18811880

18821881
arrayPrototype->SetHasNoEnumerableProperties(true);
@@ -2860,6 +2859,18 @@ namespace Js
28602859

28612860
Field(JavascriptFunction*)* builtinFuncs = library->GetBuiltinFunctions();
28622861

2862+
#ifdef ENABLE_JS_BUILTINS
2863+
if (scriptContext->IsJsBuiltInEnabled())
2864+
{
2865+
library->EnsureBuiltInEngineIsReady();
2866+
}
2867+
else
2868+
#endif
2869+
{
2870+
builtinFuncs[BuiltinFunction::Math_Max] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::max, &Math::EntryInfo::Max, 2);
2871+
builtinFuncs[BuiltinFunction::Math_Min] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::min, &Math::EntryInfo::Min, 2);
2872+
}
2873+
28632874
builtinFuncs[BuiltinFunction::Math_Abs] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::abs, &Math::EntryInfo::Abs, 1);
28642875
builtinFuncs[BuiltinFunction::Math_Acos] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::acos, &Math::EntryInfo::Acos, 1);
28652876
builtinFuncs[BuiltinFunction::Math_Asin] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::asin, &Math::EntryInfo::Asin, 1);
@@ -2870,8 +2881,6 @@ namespace Js
28702881
builtinFuncs[BuiltinFunction::Math_Exp] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::exp, &Math::EntryInfo::Exp, 1);
28712882
builtinFuncs[BuiltinFunction::Math_Floor] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::floor, &Math::EntryInfo::Floor, 1);
28722883
builtinFuncs[BuiltinFunction::Math_Log] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::log, &Math::EntryInfo::Log, 1);
2873-
builtinFuncs[BuiltinFunction::Math_Max] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::max, &Math::EntryInfo::Max, 2);
2874-
builtinFuncs[BuiltinFunction::Math_Min] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::min, &Math::EntryInfo::Min, 2);
28752884
builtinFuncs[BuiltinFunction::Math_Pow] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::pow, &Math::EntryInfo::Pow, 2);
28762885
builtinFuncs[BuiltinFunction::Math_Random] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::random, &Math::EntryInfo::Random, 0);
28772886
builtinFuncs[BuiltinFunction::Math_Round] = library->AddFunctionToLibraryObject(mathObject, PropertyIds::round, &Math::EntryInfo::Round, 1);

0 commit comments

Comments
 (0)