|
4 | 4 | //------------------------------------------------------------------------------------------------------- |
5 | 5 | #include "stdafx.h" |
6 | 6 |
|
| 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 | + |
7 | 35 | MessageQueue* WScriptJsrt::messageQueue = nullptr; |
8 | 36 | std::map<std::string, JsModuleRecord> WScriptJsrt::moduleRecordMap; |
9 | 37 | DWORD_PTR WScriptJsrt::sourceContext = 0; |
@@ -322,7 +350,7 @@ JsErrorCode WScriptJsrt::LoadModuleFromString(LPCSTR fileName, LPCSTR fileConten |
322 | 350 | JsValueRef errorObject = JS_INVALID_REFERENCE; |
323 | 351 |
|
324 | 352 | // 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, |
326 | 354 | (unsigned int)strlen(fileContent), JsParseModuleSourceFlags_DataIsUTF8, &errorObject); |
327 | 355 | if ((errorCode != JsNoError) && errorObject != JS_INVALID_REFERENCE) |
328 | 356 | { |
@@ -708,6 +736,28 @@ bool WScriptJsrt::Initialize() |
708 | 736 | // ToDo Remove |
709 | 737 | IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Edit", EmptyCallback)); |
710 | 738 |
|
| 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 | + |
711 | 761 | JsValueRef argsObject; |
712 | 762 |
|
713 | 763 | if (!CreateArgumentsObject(&argsObject)) |
@@ -993,7 +1043,7 @@ JsErrorCode WScriptJsrt::FetchImportedModule(_In_ JsModuleRecord referencingModu |
993 | 1043 | return errorCode; |
994 | 1044 | } |
995 | 1045 |
|
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. |
997 | 1047 | JsErrorCode WScriptJsrt::NotifyModuleReadyCallback(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar) |
998 | 1048 | { |
999 | 1049 | if (exceptionVar != nullptr) |
|
0 commit comments