Skip to content

Commit ff1fc68

Browse files
committed
[MERGE #1455 @obastemur] CH embeds platform details to enable/disable some tests
Merge pull request #1455 from obastemur:ch_platform See comments on disabled test case Attempt to fix #1397
2 parents 545dd6c + 8f9d334 commit ff1fc68

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

bin/ch/WScriptJsrt.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@
44
//-------------------------------------------------------------------------------------------------------
55
#include "stdafx.h"
66

7+
#if defined(_X86_) || defined(_M_IX86)
8+
#define CPU_ARCH_TEXT "x86"
9+
#elif defined(_AMD64_) || defined(_IA64_) || defined(_M_AMD64) || defined(_M_IA64)
10+
#define CPU_ARCH_TEXT "x86_64"
11+
#elif defined(_ARM_) || defined(_M_ARM)
12+
#define CPU_ARCH_TEXT "ARM"
13+
#elif defined(_ARM64_) || defined(_M_ARM64)
14+
#define CPU_ARCH_TEXT "ARM64"
15+
#endif
16+
17+
// do not change the order below
18+
// otherwise, i.e. android system can be marked as posix? etc..
19+
#ifdef _WIN32
20+
#define DEST_PLATFORM_TEXT "win32"
21+
#elif defined(__APPLE__)
22+
#ifdef __IOS__
23+
#define DEST_PLATFORM_TEXT "ios"
24+
#else
25+
#define DEST_PLATFORM_TEXT "darwin"
26+
#endif
27+
#elif defined(__ANDROID__)
28+
#define DEST_PLATFORM_TEXT "android"
29+
#elif defined(__linux__)
30+
#define DEST_PLATFORM_TEXT "posix"
31+
#elif defined(__FreeBSD__) || defined(__unix__)
32+
#define DEST_PLATFORM_TEXT "bsd"
33+
#endif
34+
735
MessageQueue* WScriptJsrt::messageQueue = nullptr;
836
std::map<std::string, JsModuleRecord> WScriptJsrt::moduleRecordMap;
937
DWORD_PTR WScriptJsrt::sourceContext = 0;
@@ -322,7 +350,7 @@ JsErrorCode WScriptJsrt::LoadModuleFromString(LPCSTR fileName, LPCSTR fileConten
322350
JsValueRef errorObject = JS_INVALID_REFERENCE;
323351

324352
// ParseModuleSource is sync, while additional fetch & evaluation are async.
325-
errorCode = ChakraRTInterface::JsParseModuleSource(requestModule, dwSourceCookie, (LPBYTE)fileContent,
353+
errorCode = ChakraRTInterface::JsParseModuleSource(requestModule, dwSourceCookie, (LPBYTE)fileContent,
326354
(unsigned int)strlen(fileContent), JsParseModuleSourceFlags_DataIsUTF8, &errorObject);
327355
if ((errorCode != JsNoError) && errorObject != JS_INVALID_REFERENCE)
328356
{
@@ -708,6 +736,28 @@ bool WScriptJsrt::Initialize()
708736
// ToDo Remove
709737
IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Edit", EmptyCallback));
710738

739+
// Platform
740+
JsValueRef platformObject;
741+
IfJsrtErrorFail(ChakraRTInterface::JsCreateObject(&platformObject), false);
742+
JsPropertyIdRef platformProperty;
743+
IfJsrtErrorFail(ChakraRTInterface::JsGetPropertyIdFromNameUtf8("Platform", &platformProperty), false);
744+
745+
// Set CPU arch
746+
JsPropertyIdRef archProperty;
747+
IfJsrtErrorFail(ChakraRTInterface::JsGetPropertyIdFromNameUtf8("ARCH", &archProperty), false);
748+
JsValueRef archValue;
749+
IfJsrtErrorFail(ChakraRTInterface::JsPointerToStringUtf8(CPU_ARCH_TEXT, strlen(CPU_ARCH_TEXT), &archValue), false);
750+
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, archProperty, archValue, true), false);
751+
752+
// Set destination OS
753+
JsPropertyIdRef osProperty;
754+
IfJsrtErrorFail(ChakraRTInterface::JsGetPropertyIdFromNameUtf8("OS", &osProperty), false);
755+
JsValueRef osValue;
756+
IfJsrtErrorFail(ChakraRTInterface::JsPointerToStringUtf8(DEST_PLATFORM_TEXT, strlen(DEST_PLATFORM_TEXT), &osValue), false);
757+
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, osProperty, osValue, true), false);
758+
759+
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(wscript, platformProperty, platformObject, true), false);
760+
711761
JsValueRef argsObject;
712762

713763
if (!CreateArgumentsObject(&argsObject))
@@ -993,7 +1043,7 @@ JsErrorCode WScriptJsrt::FetchImportedModule(_In_ JsModuleRecord referencingModu
9931043
return errorCode;
9941044
}
9951045

996-
// Callback from chakraCore when the module resolution is finished, either successfuly or unsuccessfully.
1046+
// Callback from chakraCore when the module resolution is finished, either successfuly or unsuccessfully.
9971047
JsErrorCode WScriptJsrt::NotifyModuleReadyCallback(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar)
9981048
{
9991049
if (exceptionVar != nullptr)

test/es6/ES6TypedArrayExtensions.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,16 @@ var tests = [
14311431
assert.areEqual([1,2,3,4,5,6,7,8,9,10], getTypedArray(10).sort(sortCallback), "%TypedArrayPrototype%.sort basic behavior with a non-lying sort callback");
14321432
assert.areEqual([10,9,8,7,6,5,4,3,2,1], getTypedArray(10).sort(sortCallbackReverse), "%TypedArrayPrototype%.sort with a sort callback function which reverses elements");
14331433
assert.areEqual([5,1,2,3,4,6,7,8,9,10], getTypedArray(10).sort(sortCallbackHate5), "%TypedArrayPrototype%.sort basic behavior with a lying sort callback which hates the number 5");
1434-
assert.areEqual([9,8,7,2,10,5,4,3,1,6], getTypedArray(10).sort(sortCallbackMalformed), "%TypedArrayPrototype%.sort basic behavior with a sort callback which returns random values");
1434+
1435+
// exclude this particular test from xplat
1436+
// posix / bsd implementations of qsort is incompatible with the one on Windows
1437+
// result from the test below is strictly related to how qsort is implemented
1438+
// TODO (maybe) : implement consistent re-entrant qsort ?
1439+
// ChakraFull test host does not implements `Platform` below.
1440+
// So, consider that as Windows too
1441+
if (!WScript.Platform || WScript.Platform.OS == "win32") {
1442+
assert.areEqual([9,8,7,2,10,5,4,3,1,6], getTypedArray(10).sort(sortCallbackMalformed), "%TypedArrayPrototype%.sort basic behavior with a sort callback which returns random values");
1443+
}
14351444

14361445
assert.throws(function() { sort.call(); }, TypeError, "Calling %TypedArrayPrototype%.sort with no this throws TypeError", "'this' is not a typed array object");
14371446
assert.throws(function() { sort.call(undefined); }, TypeError, "Calling %TypedArrayPrototype%.sort with undefined this throws TypeError", "'this' is not a typed array object");

test/fieldopts/objtypespec-add.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ test5();
180180
test5();
181181
test5();
182182
function printAll(n, v) {
183-
for (var c in v)
184-
printAll(n, v[c]);
183+
for (var c in v) {
184+
if (typeof v != "string")
185+
printAll(c, v[c]);
186+
}
185187
}
186188
printAll('this', this);

0 commit comments

Comments
 (0)