Skip to content

Commit 7c94e25

Browse files
committed
Merge branch 'master' into build/arunetm/wasm.simd-merge
2 parents f70f51c + c54e9a6 commit 7c94e25

File tree

410 files changed

+31844
-24114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+31844
-24114
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,14 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
346346
add_compile_options(
347347
-fasm-blocks
348348
-fms-extensions
349-
-fwrapv # Treat signed integer overflow as two's complement
349+
-fwrapv # Treat signed integer overflow as two's complement
350350
)
351351

352+
# Only disable RTTI in release builds so that TrackAlloc works for debug and test builds
353+
if(CMAKE_BUILD_TYPE STREQUAL Release)
354+
add_compile_options(-fno-rtti)
355+
endif()
356+
352357
# Clang -fsanitize.
353358
if (CLANG_SANITIZE_SH)
354359
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${CLANG_SANITIZE_SH}")

RegenAllByteCode.cmd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ if %errorlevel% neq 0 (
3838
)
3939
popd
4040

41+
pushd lib\Runtime\Library\JsBuiltIn
42+
call GenByteCode.cmd
43+
if %errorlevel% neq 0 (
44+
echo There was an error when regenerating bytecode header.
45+
exit /b 1
46+
)
47+
popd
48+
4149
:: ch.exe x64_debug (NoJIT)
4250
:: ch.exe x86_debug (NoJIT)
4351
call jenkins\buildone.cmd x64 debug "/p:BuildJIT=false"
@@ -61,6 +69,15 @@ if %errorlevel% neq 0 (
6169
)
6270
popd
6371

72+
:: Generate BuiltIn NoJIT Bytecodes using ch.exe (NoJIT)
73+
pushd lib\Runtime\Library\JsBuiltIn
74+
call GenByteCode.cmd -nojit
75+
if %errorlevel% neq 0 (
76+
echo There was an error when regenerating bytecode header for NoJIT.
77+
exit /b 1
78+
)
79+
popd
80+
6481
popd
6582

6683
endlocal

bin/NativeTests/JsRTApiTest.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,7 @@ namespace JsRTApiTest
20632063
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, ReentrantParseModuleTest);
20642064
}
20652065

2066+
20662067
ModuleResponseData reentrantNoErrorParseData;
20672068
static JsErrorCode CALLBACK reentrantNoErrorParse_FIMC(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord)
20682069
{
@@ -2131,6 +2132,50 @@ namespace JsRTApiTest
21312132
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, ReentrantNoErrorParseModuleTest);
21322133
}
21332134

2135+
static JsErrorCode CALLBACK FIMC1(_In_ JsModuleRecord referencingModule, _In_ JsValueRef specifier, _Outptr_result_maybenull_ JsModuleRecord* dependentModuleRecord)
2136+
{
2137+
JsModuleRecord moduleRecord = JS_INVALID_REFERENCE;
2138+
LPCWSTR specifierStr;
2139+
size_t length;
2140+
JsErrorCode errorCode = JsStringToPointer(specifier, &specifierStr, &length);
2141+
REQUIRE(errorCode == JsNoError);
2142+
2143+
if (wcscmp(specifierStr, _u("foo.js")) == 0)
2144+
{
2145+
errorCode = JsInitializeModuleRecord(referencingModule, specifier, &moduleRecord);
2146+
REQUIRE(errorCode == JsNoError);
2147+
}
2148+
2149+
*dependentModuleRecord = moduleRecord;
2150+
return JsNoError;
2151+
}
2152+
2153+
static JsErrorCode CALLBACK NMRC1(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar)
2154+
{
2155+
// NotifyModuleReadyCallback handling.
2156+
2157+
return JsNoError;
2158+
}
2159+
2160+
void SomebugTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
2161+
{
2162+
JsModuleRecord rec;
2163+
JsInitializeModuleRecord(nullptr, nullptr, &rec);
2164+
JsSetModuleHostInfo(rec, JsModuleHostInfo_FetchImportedModuleCallback, FIMC1);
2165+
JsSetModuleHostInfo(rec, JsModuleHostInfo_FetchImportedModuleFromScriptCallback, FIMC1);
2166+
JsSetModuleHostInfo(rec, JsModuleHostInfo_NotifyModuleReadyCallback, NMRC1);
2167+
2168+
JsValueRef F = JS_INVALID_REFERENCE;
2169+
JsErrorCode err = JsRunScript(_u("var j = import('foo.js').then(mod => { mod.bar(); })"), 0, _u(""), &F);
2170+
2171+
CHECK(err == JsNoError);
2172+
}
2173+
2174+
TEST_CASE("ApiTest_SomebugTest", "[ApiTest]")
2175+
{
2176+
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, SomebugTest);
2177+
2178+
}
21342179
void ObjectHasOwnPropertyMethodTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
21352180
{
21362181
JsValueRef proto = JS_INVALID_REFERENCE;

bin/ch/WScriptJsrt.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ JsValueRef WScriptJsrt::LoadScriptFileHelper(JsValueRef callee, JsValueRef *argu
205205
}
206206
else
207207
{
208-
returnValue = LoadScript(callee, *fileName, fileContent, *scriptInjectType ? *scriptInjectType : "self", isSourceModule, WScriptJsrt::FinalizeFree);
208+
returnValue = LoadScript(callee, *fileName, fileContent, *scriptInjectType ? *scriptInjectType : "self", isSourceModule, WScriptJsrt::FinalizeFree, true);
209209
}
210210
}
211211
}
@@ -258,6 +258,7 @@ JsValueRef WScriptJsrt::LoadScriptHelper(JsValueRef callee, bool isConstructCall
258258
AutoString fileName;
259259
AutoString scriptInjectType;
260260
char fileNameBuffer[MAX_PATH];
261+
bool isFile = true;
261262

262263
IfJsrtErrorSetGo(fileContent.Initialize(arguments[1]));
263264
// ExternalArrayBuffer Finalize will clean this up
@@ -275,17 +276,21 @@ JsValueRef WScriptJsrt::LoadScriptHelper(JsValueRef callee, bool isConstructCall
275276
}
276277
}
277278

278-
if (!fileNameNarrow && isSourceModule)
279+
if (!fileNameNarrow)
279280
{
280-
sprintf_s(fileNameBuffer, MAX_PATH, "moduleScript%i.js", (int)sourceContext);
281-
fileNameNarrow = fileNameBuffer;
281+
isFile = false;
282+
if (isSourceModule)
283+
{
284+
sprintf_s(fileNameBuffer, MAX_PATH, "moduleScript%i.js", (int)sourceContext);
285+
fileNameNarrow = fileNameBuffer;
286+
}
282287
}
283288

284289
if (*fileContent)
285290
{
286291
// TODO: This is CESU-8. How to tell the engine?
287292
// TODO: How to handle this source (script) life time?
288-
returnValue = LoadScript(callee, fileNameNarrow, *fileContent, *scriptInjectType ? *scriptInjectType : "self", isSourceModule, WScriptJsrt::FinalizeFree);
293+
returnValue = LoadScript(callee, fileNameNarrow, *fileContent, *scriptInjectType ? *scriptInjectType : "self", isSourceModule, WScriptJsrt::FinalizeFree, isFile);
289294
}
290295
}
291296

@@ -347,7 +352,7 @@ void WScriptJsrt::GetDir(LPCSTR fullPathNarrow, std::string *fullDirNarrow)
347352
*fullDirNarrow = result;
348353
}
349354

350-
JsErrorCode WScriptJsrt::LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent, LPCSTR fullName)
355+
JsErrorCode WScriptJsrt::LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent, LPCSTR fullName, bool isFile)
351356
{
352357
DWORD_PTR dwSourceCookie = WScriptJsrt::GetNextSourceContext();
353358
JsModuleRecord requestModule = JS_INVALID_REFERENCE;
@@ -390,6 +395,15 @@ JsErrorCode WScriptJsrt::LoadModuleFromString(LPCSTR fileName, LPCSTR fileConten
390395

391396
// ParseModuleSource is sync, while additional fetch & evaluation are async.
392397
unsigned int fileContentLength = (fileContent == nullptr) ? 0 : (unsigned int)strlen(fileContent);
398+
399+
if (isFile && fullName)
400+
{
401+
JsValueRef moduleUrl;
402+
ChakraRTInterface::JsCreateString(fullName, strlen(fullName), &moduleUrl);
403+
errorCode = ChakraRTInterface::JsSetModuleHostInfo(requestModule, JsModuleHostInfo_Url, moduleUrl);
404+
IfJsrtErrorFail(errorCode, errorCode);
405+
}
406+
393407
errorCode = ChakraRTInterface::JsParseModuleSource(requestModule, dwSourceCookie, (LPBYTE)fileContent,
394408
fileContentLength, JsParseModuleSourceFlags_DataIsUTF8, &errorObject);
395409
if ((errorCode != JsNoError) && errorObject != JS_INVALID_REFERENCE && fileContent != nullptr && !HostConfigFlags::flags.IgnoreScriptErrorCode)
@@ -402,7 +416,7 @@ JsErrorCode WScriptJsrt::LoadModuleFromString(LPCSTR fileName, LPCSTR fileConten
402416

403417

404418
JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
405-
LPCSTR fileContent, LPCSTR scriptInjectType, bool isSourceModule, JsFinalizeCallback finalizeCallback)
419+
LPCSTR fileContent, LPCSTR scriptInjectType, bool isSourceModule, JsFinalizeCallback finalizeCallback, bool isFile)
406420
{
407421
HRESULT hr = E_FAIL;
408422
JsErrorCode errorCode = JsNoError;
@@ -419,7 +433,7 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
419433
IfJsrtErrorSetGo(ChakraRTInterface::JsGetRuntime(currentContext, &runtime));
420434

421435
if (fileName == nullptr)
422-
{
436+
{
423437
fileName = "script.js";
424438
}
425439

@@ -432,7 +446,7 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
432446
// treated as a module source text instead of opening a new file.
433447
if (isSourceModule || (strcmp(scriptInjectType, "module") == 0))
434448
{
435-
errorCode = LoadModuleFromString(fileName, fileContent, fullPath);
449+
errorCode = LoadModuleFromString(fileName, fileContent, fullPath, isFile);
436450
}
437451
else if (strcmp(scriptInjectType, "self") == 0)
438452
{
@@ -1350,7 +1364,7 @@ bool WScriptJsrt::PrintException(LPCSTR fileName, JsErrorCode jsErrorCode)
13501364

13511365
int line;
13521366
int column;
1353-
1367+
13541368
IfJsrtErrorFail(CreatePropertyIdFromString("line", &linePropertyId), false);
13551369
IfJsrtErrorFail(ChakraRTInterface::JsGetProperty(exception, linePropertyId, &lineProperty), false);
13561370
IfJsrtErrorFail(ChakraRTInterface::JsNumberToInt(lineProperty, &line), false);
@@ -1558,11 +1572,11 @@ HRESULT WScriptJsrt::ModuleMessage::Call(LPCSTR fileName)
15581572
fprintf(stderr, "Couldn't load file.\n");
15591573
}
15601574

1561-
LoadScript(nullptr, fullPath, nullptr, "module", true, WScriptJsrt::FinalizeFree);
1575+
LoadScript(nullptr, fullPath, nullptr, "module", true, WScriptJsrt::FinalizeFree, false);
15621576
}
15631577
else
15641578
{
1565-
LoadScript(nullptr, fullPath, fileContent, "module", true, WScriptJsrt::FinalizeFree);
1579+
LoadScript(nullptr, fullPath, fileContent, "module", true, WScriptJsrt::FinalizeFree, true);
15661580
}
15671581
}
15681582
}

bin/ch/WScriptJsrt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class WScriptJsrt
9090
#endif
9191

9292
static bool PrintException(LPCSTR fileName, JsErrorCode jsErrorCode);
93-
static JsValueRef LoadScript(JsValueRef callee, LPCSTR fileName, LPCSTR fileContent, LPCSTR scriptInjectType, bool isSourceModule, JsFinalizeCallback finalizeCallback);
93+
static JsValueRef LoadScript(JsValueRef callee, LPCSTR fileName, LPCSTR fileContent, LPCSTR scriptInjectType, bool isSourceModule, JsFinalizeCallback finalizeCallback, bool isFile);
9494
static DWORD_PTR GetNextSourceContext();
9595
static JsValueRef LoadScriptFileHelper(JsValueRef callee, JsValueRef *arguments, unsigned short argumentCount, bool isSourceModule);
9696
static JsValueRef LoadScriptHelper(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState, bool isSourceModule);
@@ -114,7 +114,7 @@ class WScriptJsrt
114114
static JsValueRef CALLBACK RequestAsyncBreakCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
115115

116116
static JsValueRef CALLBACK EmptyCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
117-
static JsErrorCode CALLBACK LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent, LPCSTR fullName = nullptr);
117+
static JsErrorCode CALLBACK LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent, LPCSTR fullName = nullptr, bool isFile = false);
118118
static JsErrorCode CALLBACK InitializeModuleInfo(JsValueRef specifier, JsModuleRecord moduleRecord);
119119

120120
static JsValueRef CALLBACK LoadBinaryFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);

bin/ch/ch.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#include <fcntl.h>
1111
#endif
1212

13+
#ifdef __linux__
14+
#include <sys/sysinfo.h>
15+
#elif defined(__APPLE__)
16+
#include <sys/sysctl.h>
17+
#endif
18+
1319
unsigned int MessageBase::s_messageCount = 0;
1420
Debugger* Debugger::debugger = nullptr;
1521

@@ -525,20 +531,52 @@ HRESULT RunScript(const char* fileName, LPCSTR fileContents, JsFinalizeCallback
525531
static HRESULT CreateRuntime(JsRuntimeHandle *runtime)
526532
{
527533
HRESULT hr = E_FAIL;
528-
IfJsErrorFailLog(ChakraRTInterface::JsCreateRuntime(jsrtAttributes, nullptr, runtime));
529534

530535
#ifndef _WIN32
531-
// On Posix, malloc may not return NULL even if there is no
532-
// memory left. However, kernel will send SIGKILL to process
533-
// in case we use that `not actually available` memory address.
534-
// (See posix man malloc and OOM)
535-
536+
// On Posix, malloc optimistically returns a non-null address without
537+
// checking if it's actually able to back that allocation in memory
538+
// Upon use of that address however, if the address space for that allocation
539+
// can't be committed, the process is killed
540+
// See the man page for malloc
541+
//
542+
// In order to avoid having to deal with this, we set the memory limit for the
543+
// runtime to the size of the physical memory on the system
544+
// TODO:
545+
// We could move the following into its own platform agnostic API
546+
// but in this case, this is a one-time call thats not applicable
547+
// on Windows so decided to leave as is
548+
// Additionally, we can probably do better than just limit to the physical memory
549+
// size
550+
551+
#if defined(__APPLE__) || defined(__linux__)
536552
size_t memoryLimit;
537-
if (PlatformAgnostic::SystemInfo::GetTotalRam(&memoryLimit))
553+
#ifdef __APPLE__
554+
int totalRamHW[] = { CTL_HW, HW_MEMSIZE };
555+
size_t length = sizeof(memoryLimit);
556+
if (sysctl(totalRamHW, 2, &memoryLimit, &length, NULL, 0) == -1)
538557
{
539-
IfJsErrorFailLog(ChakraRTInterface::JsSetRuntimeMemoryLimit(*runtime, memoryLimit));
558+
memoryLimit = 0;
540559
}
560+
#else
561+
struct sysinfo sysInfo;
562+
if (sysinfo(&sysInfo) == -1)
563+
{
564+
memoryLimit = 0;
565+
}
566+
else
567+
{
568+
memoryLimit = sysInfo.totalram;
569+
}
570+
#endif // __APPLE__
571+
#endif // __APPLE__ || __linux
572+
#endif // !_WIN32
573+
574+
IfJsErrorFailLog(ChakraRTInterface::JsCreateRuntime(jsrtAttributes, nullptr, runtime));
575+
576+
#ifndef _WIN32
577+
IfJsErrorFailLog(ChakraRTInterface::JsSetRuntimeMemoryLimit(*runtime, memoryLimit));
541578
#endif
579+
542580
hr = S_OK;
543581
Error:
544582
return hr;

bin/rl/rl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ unsigned NumberOfThreads = 0;
367367
TestList DirList, ExcludeDirList;
368368
BOOL FUserSpecifiedFiles = FALSE;
369369
BOOL FUserSpecifiedDirs = TRUE;
370+
BOOL FNoProgramOutput = FALSE;
371+
BOOL FOnlyAssertOutput = FALSE;
370372
BOOL FExcludeDirs = FALSE;
371373
BOOL FGenLst = FALSE;
372374
char *ResumeDir, *MatchDir;
@@ -2878,6 +2880,16 @@ ParseArg(
28782880
break;
28792881
}
28802882

2883+
if (!_stricmp(&arg[1], "noprogramoutput")) {
2884+
FNoProgramOutput = TRUE;
2885+
break;
2886+
}
2887+
2888+
if (!_stricmp(&arg[1], "onlyassertoutput")) {
2889+
FOnlyAssertOutput = TRUE;
2890+
break;
2891+
}
2892+
28812893
#ifndef NODEBUG
28822894
if (!_stricmp(&arg[1], "debug")) {
28832895
FDebug = FVerbose = TRUE;

bin/rl/rl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ extern BOOL FSyncEnumDirs;
870870
extern BOOL FNogpfnt;
871871
extern BOOL FTest;
872872
extern BOOL FAppendTestNameToExtraCCFlags;
873+
extern BOOL FNoProgramOutput;
874+
extern BOOL FOnlyAssertOutput;
873875

874876
#define MAXOPTIONS 60
875877
extern const char *OptFlags[MAXOPTIONS + 1], *PogoOptFlags[MAXOPTIONS + 1];

0 commit comments

Comments
 (0)