Skip to content

Commit

Permalink
[MERGE #4742 @jackhorton] Add Intl/ICU/WinGlob information to WScript…
Browse files Browse the repository at this point in the history
… to simplify tests

Merge pull request #4742 from jackhorton:icu/wscript-platform

This is in preparation for ChakraFull + ICU and ICU in CI
  • Loading branch information
jackhorton committed Feb 28, 2018
2 parents acea7d0 + 5e16db1 commit 5720cdb
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 65 deletions.
1 change: 1 addition & 0 deletions bin/ch/ChakraRtInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ bool ChakraRTInterface::LoadChakraDll(ArgInfo* argInfo, HINSTANCE *outLibrary)
m_jsApiHooks.pfJsrtCallFunction = (JsAPIHooks::JsrtCallFunctionPtr)GetChakraCoreSymbol(library, "JsCallFunction");
m_jsApiHooks.pfJsrtNumberToDouble = (JsAPIHooks::JsrtNumberToDoublePtr)GetChakraCoreSymbol(library, "JsNumberToDouble");
m_jsApiHooks.pfJsrtNumberToInt = (JsAPIHooks::JsrtNumberToIntPtr)GetChakraCoreSymbol(library, "JsNumberToInt");
m_jsApiHooks.pfJsrtIntToNumber = (JsAPIHooks::JsrtIntToNumberPtr)GetChakraCoreSymbol(library, "JsIntToNumber");
m_jsApiHooks.pfJsrtDoubleToNumber = (JsAPIHooks::JsrtDoubleToNumberPtr)GetChakraCoreSymbol(library, "JsDoubleToNumber");
m_jsApiHooks.pfJsrtGetExternalData = (JsAPIHooks::JsrtGetExternalDataPtr)GetChakraCoreSymbol(library, "JsGetExternalData");
m_jsApiHooks.pfJsrtSetExternalData = (JsAPIHooks::JsrtSetExternalDataPtr)GetChakraCoreSymbol(library, "JsSetExternalData");
Expand Down
3 changes: 3 additions & 0 deletions bin/ch/ChakraRtInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct JsAPIHooks
typedef JsErrorCode (WINAPI *JsrtCallFunctionPtr)(JsValueRef function, JsValueRef* arguments, unsigned short argumentCount, JsValueRef *result);
typedef JsErrorCode (WINAPI *JsrtNumberToDoublePtr)(JsValueRef value, double *doubleValue);
typedef JsErrorCode (WINAPI *JsrtNumberToIntPtr)(JsValueRef value, int *intValue);
typedef JsErrorCode (WINAPI *JsrtIntToNumberPtr)(int intValue, JsValueRef *value);
typedef JsErrorCode (WINAPI *JsrtDoubleToNumberPtr)(double doubleValue, JsValueRef* value);
typedef JsErrorCode (WINAPI *JsrtGetExternalDataPtr)(JsValueRef object, void **data);
typedef JsErrorCode (WINAPI *JsrtSetExternalDataPtr)(JsValueRef object, void *data);
Expand Down Expand Up @@ -136,6 +137,7 @@ struct JsAPIHooks
JsrtCallFunctionPtr pfJsrtCallFunction;
JsrtNumberToDoublePtr pfJsrtNumberToDouble;
JsrtNumberToIntPtr pfJsrtNumberToInt;
JsrtIntToNumberPtr pfJsrtIntToNumber;
JsrtDoubleToNumberPtr pfJsrtDoubleToNumber;
JsrtGetExternalDataPtr pfJsrtGetExternalData;
JsrtSetExternalDataPtr pfJsrtSetExternalData;
Expand Down Expand Up @@ -341,6 +343,7 @@ class ChakraRTInterface
static JsErrorCode WINAPI JsCallFunction(JsValueRef function, JsValueRef* arguments, unsigned short argumentCount, JsValueRef *result) { return HOOK_JS_API(CallFunction(function, arguments, argumentCount, result)); }
static JsErrorCode WINAPI JsNumberToDouble(JsValueRef value, double* doubleValue) { return HOOK_JS_API(NumberToDouble(value, doubleValue)); }
static JsErrorCode WINAPI JsNumberToInt(JsValueRef value, int* intValue) { return HOOK_JS_API(NumberToInt(value, intValue)); }
static JsErrorCode WINAPI JsIntToNumber(int intValue, JsValueRef *value) { return HOOK_JS_API(IntToNumber(intValue, value)); }
static JsErrorCode WINAPI JsDoubleToNumber(double doubleValue, JsValueRef* value) { return HOOK_JS_API(DoubleToNumber(doubleValue, value)); }
static JsErrorCode WINAPI JsGetExternalData(JsValueRef object, void **data) { return HOOK_JS_API(GetExternalData(object, data)); }
static JsErrorCode WINAPI JsSetExternalData(JsValueRef object, void *data) { return HOOK_JS_API(SetExternalData(object, data)); }
Expand Down
26 changes: 26 additions & 0 deletions bin/ch/WScriptJsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//-------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include <vector>
#ifdef HAS_ICU
#include "unicode/uvernum.h"
#endif

#if defined(_X86_) || defined(_M_IX86)
#define CPU_ARCH_TEXT "x86"
Expand Down Expand Up @@ -35,6 +38,17 @@
#endif // FreeBSD or unix ?
#endif // _WIN32 ?

#ifdef HAS_ICU
#define INTL_LIBRARY_TEXT "icu"
#define ICU_VERSION U_ICU_VERSION_MAJOR_NUM
#elif defined(_WIN32)
#define INTL_LIBRARY_TEXT "winglob"
#define ICU_VERSION -1
#else
#define INTL_LIBRARY_TEXT ""
#define ICU_VERSION -1
#endif

MessageQueue* WScriptJsrt::messageQueue = nullptr;
std::map<std::string, JsModuleRecord> WScriptJsrt::moduleRecordMap;
std::map<JsModuleRecord, std::string> WScriptJsrt::moduleDirMap;
Expand Down Expand Up @@ -988,6 +1002,18 @@ bool WScriptJsrt::Initialize()
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, osProperty,
osValue, true), false);

// set Internationalization library
JsPropertyIdRef intlLibraryProp;
IfJsrtErrorFail(CreatePropertyIdFromString("INTL_LIBRARY", &intlLibraryProp), false);
JsValueRef intlLibraryStr;
IfJsrtErrorFail(ChakraRTInterface::JsCreateString(INTL_LIBRARY_TEXT, strlen(INTL_LIBRARY_TEXT), &intlLibraryStr), false);
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, intlLibraryProp, intlLibraryStr, true), false);
JsPropertyIdRef icuVersionProp;
IfJsrtErrorFail(CreatePropertyIdFromString("ICU_VERSION", &icuVersionProp), false);
JsValueRef icuVersionNum;
IfJsrtErrorFail(ChakraRTInterface::JsIntToNumber(ICU_VERSION, &icuVersionNum), false);
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, icuVersionProp, icuVersionNum, true), false);

IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(wscript, platformProperty,
platformObject, true), false);

Expand Down
54 changes: 23 additions & 31 deletions test/Intl/DateTimeFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function ascii (str) {
return str.replace(nonAsciiRegex, "");
}

const isICU = WScript.Arguments.includes("icu");
const isWinGlob = WScript.Arguments.includes("winglob");
const isICU = WScript.Platform.INTL_LIBRARY === "icu";
const isWinGlob = WScript.Platform.INTL_LIBRARY === "winglob";

const tests = [
{
Expand Down Expand Up @@ -293,7 +293,7 @@ const tests = [

assert.isTrue(isICU, "This test requires an ICU implementation of Intl");

function test(date, timeZone, timeZoneName, expectedPart, expectedTimeZone) {
function innerTest(date, timeZone, timeZoneName, expectedPart, expectedTimeZone) {
const options = {
hour: "numeric",
timeZone,
Expand All @@ -312,39 +312,31 @@ const tests = [
assert.areEqual(expectedPart, actualPart.value, `Incorrect timeZoneName for ${date.toString()} with options ${JSON.stringify(options)}`);
}

function date(str) {
return new Date(Date.parse(str));
function test(date, timeZone, expectedShortPart, expectedLongPart, expectedTimeZone) {
innerTest(date, timeZone, "short", expectedShortPart, expectedTimeZone);
innerTest(date, timeZone, "long", expectedLongPart, expectedTimeZone);
}

const newYears = date("2018-01-01T00:00:00.000Z");
const juneFirst = date("2018-06-01T00:00:00.000Z");
const newYears = new Date(Date.parse("2018-01-01T00:00:00.000Z"));
const juneFirst = new Date(Date.parse("2018-06-01T00:00:00.000Z"));

// see https://github.com/tc39/ecma402/issues/121 for edge cases here
// TODO(jahorto): re-enable the commented out GMT/UTC tests once we have a way
// to assert different expected values depending on CLDR version
// ICU ~55 formats GMT-like time zones as GMT, but ICU ~60 formats them as UTC
// test(newYears, "GMT", "short", "UTC", "UTC");
// test(newYears, "GMT", "long", "Coordinated Universal Time", "UTC");
// test(newYears, "Etc/GMT", "short", "UTC", "UTC");
// test(newYears, "Etc/GMT", "long", "Coordinated Universal Time", "UTC");
// test(newYears, "Etc/UTC", "short", "UTC", "UTC");
// test(newYears, "Etc/UTC", "long", "Coordinated Universal Time", "UTC");
// test(newYears, "Etc/UCT", "short", "UTC", "UTC");
// test(newYears, "Etc/UCT", "long", "Coordinated Universal Time", "UTC");
test(newYears, "US/Pacific", "short", "PST", "America/Los_Angeles");
test(newYears, "US/Pacific", "long", "Pacific Standard Time", "America/Los_Angeles");
test(newYears, "Etc/GMT-2", "short", "GMT+2", "Etc/GMT-2");
test(newYears, "Etc/GMT-2", "long", "GMT+02:00", "Etc/GMT-2");

test(newYears, "America/New_York", "short", "EST", "America/New_York");
test(newYears, "America/New_York", "long", "Eastern Standard Time", "America/New_York");
test(newYears, "America/Los_Angeles", "short", "PST", "America/Los_Angeles");
test(newYears, "America/Los_Angeles", "long", "Pacific Standard Time","America/Los_Angeles");

test(juneFirst, "America/New_York", "short", "EDT", "America/New_York");
test(juneFirst, "America/New_York", "long", "Eastern Daylight Time", "America/New_York");
test(juneFirst, "America/Los_Angeles", "short", "PDT", "America/Los_Angeles");
test(juneFirst, "America/Los_Angeles", "long", "Pacific Daylight Time", "America/Los_Angeles");
const UTCshort = WScript.Platform.ICU_VERSION >= 59 ? "UTC" : "GMT";
const UTClong = WScript.Platform.ICU_VERSION >= 59 ? "Coordinated Universal Time" : "GMT";
test(newYears, "GMT", UTCshort, UTClong, "UTC");
test(newYears, "Etc/GMT", UTCshort, UTClong, "UTC");
test(newYears, "Etc/UTC", UTCshort, UTClong, "UTC");
test(newYears, "Etc/UCT", UTCshort, UTClong, "UTC");

test(newYears, "US/Pacific", "PST", "Pacific Standard Time", "America/Los_Angeles");
test(newYears, "Etc/GMT-2", "GMT+2", "GMT+02:00", "Etc/GMT-2");

test(newYears, "America/New_York", "EST", "Eastern Standard Time", "America/New_York");
test(newYears, "America/Los_Angeles", "PST", "Pacific Standard Time","America/Los_Angeles");

test(juneFirst, "America/New_York", "EDT", "Eastern Daylight Time", "America/New_York");
test(juneFirst, "America/Los_Angeles", "PDT", "Pacific Daylight Time", "America/Los_Angeles");
}
},
];
Expand Down
6 changes: 3 additions & 3 deletions test/Intl/GetCanonicalLocales.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ function testRangeError(tag) {
* @param {String} message
*/
const equal = (function () {
if (WScript.Arguments.includes("icu")) {
if (WScript.Platform.INTL_LIBRARY === "icu") {
return function (_, expectedICU, actual, message) {
assert.areEqual(expectedICU, actual, message);
}
} else {
assert.isTrue(WScript.Arguments.includes("winglob"));
assert.isTrue(WScript.Platform.INTL_LIBRARY === "winglob");
return function (expectedWinGlob, _, actual, message) {
assert.areEqual(expectedWinGlob, actual, message);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ var tests = [
const duplicateSingletons = ['cmn-hans-cn-u-u', 'cmn-hans-cn-t-u-ca-u'];
const duplicateUnicodeExtensionKeys = ['de-de-u-kn-true-co-phonebk-co-phonebk'];

if (WScript.Arguments.includes("icu")) {
if (WScript.Platform.INTL_LIBRARY === "icu") {
const duplicateTags = ['de-gregory-gregory'];
duplicateTags.forEach(testRangeError);
}
Expand Down
22 changes: 4 additions & 18 deletions test/Intl/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@
<test>
<default>
<files>DateTimeFormat.js</files>
<compile-flags>-args summary winglob -endargs</compile-flags>
<tags>Intl,require_winglob</tags>
</default>
</test>
<test>
<default>
<files>DateTimeFormat.js</files>
<compile-flags>-args summary icu -endargs</compile-flags>
<tags>Intl,require_icu</tags>
<compile-flags>-args summary -endargs</compile-flags>
<tags>Intl</tags>
</default>
</test>
<test>
Expand All @@ -48,15 +41,8 @@
<test>
<default>
<files>GetCanonicalLocales.js</files>
<compile-flags>-args summary winglob -endargs</compile-flags>
<tags>Intl,require_winglob</tags>
</default>
</test>
<test>
<default>
<files>GetCanonicalLocales.js</files>
<compile-flags>-args summary icu -endargs</compile-flags>
<tags>Intl,require_icu</tags>
<compile-flags>-args summary -endargs</compile-flags>
<tags>Intl</tags>
</default>
</test>
<test>
Expand Down
2 changes: 1 addition & 1 deletion test/es6/ES6TypedArrayExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ var tests = [
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");

// we have a consistent qsort_r impl. on xplat.
if (!WScript.Platform || WScript.Platform.OS == "win32") { // Windows
if (!WScript.Platform || !WScript.Platform.OS || WScript.Platform.OS == "win32") { // Windows
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");
} else { // xplat
assert.areEqual([2,9,8,7,10,4,1,3,5,6], getTypedArray(10).sort(sortCallbackMalformed), "%TypedArrayPrototype%.sort basic behavior with a sort callback which returns random values");
Expand Down
6 changes: 0 additions & 6 deletions test/runtests.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,6 @@ goto :main
set _TAGS=%_TAGS% -tags:Slow
)

if "%IntlICU%" == "true" (
set _NOTTAGS=%_NOTTAGS% -nottags:require_winglob
) else (
set _NOTTAGS=%_NOTTAGS% -nottags:require_icu
)

if not "%NUM_RL_THREADS%" == "" (
set _RL_THREAD_FLAGS=-threads:%NUM_RL_THREADS%
)
Expand Down
6 changes: 0 additions & 6 deletions test/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@
not_tags.add('require_winglob')
not_tags.add('require_simd')

if sys.platform == 'win32':
if os.environ.get('IntlICU') == 'true':
not_tags.add('require_winglob')
else:
not_tags.add('require_icu')

if args.sanitize != None:
not_tags.add('exclude_sanitize_'+args.sanitize)

Expand Down

0 comments on commit 5720cdb

Please sign in to comment.