浏览代码

Fix failing unit tests

Jack Horton 8 年之前
父节点
当前提交
a9e69c5c33
共有 3 个文件被更改,包括 23 次插入15 次删除
  1. 21 6
      lib/Runtime/Library/InJavascript/Intl.js
  2. 2 1
      lib/Runtime/PlatformAgnostic/Platform/Common/Intl.cpp
  3. 0 8
      test/Intl/rlexe.xml

+ 21 - 6
lib/Runtime/Library/InJavascript/Intl.js

@@ -692,17 +692,19 @@
             ? BestFitSupportedLocales(isAvailableLocale, requestedLocales)
             : LookupSupportedLocales(isAvailableLocale, requestedLocales);
 
+        // make sure property descriptor is null-prototyped to avoid tainting of Object.prototype.{get|set}
+        const descriptor = _.setPrototypeOf({ configurable: false, writable: false });
         for (let i = 0; i < supportedLocales.length; i++) {
-            _.defineProperty(supportedLocales, Internal.ToString(i), { configurable: false, writable: false });
+            _.defineProperty(supportedLocales, Internal.ToString(i), descriptor);
         }
 
         // test262 supportedLocalesOf-returned-array-elements-are-frozen.js:
         // Property length of object returned by SupportedLocales should not be writable
-        _.defineProperty(supportedLocales, "length", {
+        _.defineProperty(supportedLocales, "length", _.setPrototypeOf({
             writable: false,
             configurable: false,
             enumerable: false,
-        });
+        }));
 
         return supportedLocales;
     };
@@ -771,11 +773,14 @@
      *
      * @param {String[]} props The list of properties to extract from hiddenObject and add to the final resolved options
      * @param {Object} hiddenObject The hiddenObject of the calling constructor that contains values for each prop in props
+     * @param {Function} func An optional custom function(prop, resolved) run for each prop; if omitted, default logic will be used
      */
-    const createResolvedOptions = function (props, hiddenObject) {
+    const createResolvedOptions = function (props, hiddenObject, func = null) {
         const resolved = _.create();
         _.forEach(props, function (prop) {
-            if (typeof hiddenObject[prop] !== undefined) {
+            if (func !== null) {
+                func(prop, resolved);
+            } else if (typeof hiddenObject[prop] !== "undefined") {
                 resolved[prop] = hiddenObject[prop];
             }
         });
@@ -1790,7 +1795,17 @@
                     "timeZoneName",
                 ];
 
-                return createResolvedOptions(options, hiddenObject);
+                return createResolvedOptions(options, hiddenObject, function (prop, resolved) {
+                    if (prop === "hourCycle") {
+                        const hc = hiddenObject.hourCycle;
+                        if (hiddenObject.hour !== undefined && hc !== null) {
+                            resolved.hourCycle = hc;
+                            resolved.hour12 = hc === "h11" || hc === "h12";
+                        }
+                    } else if (hiddenObject[prop] !== undefined && hiddenObject[prop] !== null) {
+                        resolved[prop] = hiddenObject[prop];
+                    }
+                });
             },
             writable: true,
             enumerable: false,

+ 2 - 1
lib/Runtime/PlatformAgnostic/Platform/Common/Intl.cpp

@@ -534,6 +534,7 @@ namespace Intl
             -1,
             &status
         );
+        ICU_ASSERT(status, true);
 
         // DateTimeFormat is expected to use the "proleptic Gregorian calendar", which means that the Julian calendar should never be used.
         // To accomplish this, we can set the switchover date between julian/gregorian
@@ -543,7 +544,7 @@ namespace Intl
 
         // status can be U_UNSUPPORTED_ERROR if the calendar isn't gregorian, which
         // there does not seem to be a way to check for ahead of time in the C API
-        AssertOrFailFast(status == U_ZERO_ERROR || status == U_UNSUPPORTED_ERROR);
+        AssertOrFailFastMsg(U_SUCCESS(status) || status == U_UNSUPPORTED_ERROR, u_errorName(status));
 
         IPlatformAgnosticResource *formatterResource = new IcuCObject<UDateFormat>(dtf, &udat_close);
         AssertOrFailFast(formatterResource);

+ 0 - 8
test/Intl/rlexe.xml

@@ -91,14 +91,6 @@
       <tags>Intl,exclude_drt</tags>
     </default>
   </test>
-  <test>
-    <default>
-      <compile-flags>-Intl -JsBuiltIn-</compile-flags>
-      <files>IntlTaintingTests.js</files>
-      <baseline>IntlTaintingTests.baseline</baseline>
-      <tags>Intl,exclude_winglob</tags>
-    </default>
-  </test>
   <test>
     <default>
       <files>IntlBuiltIns.js</files>