v8/test/intl/date-format/property-override-date-style.js
Frank Tang 4c1e09a4e9 [Intl] Only set HourCycle if needed
* Change the logic to reflect the spec change of
  https://github.com/tc39/proposal-intl-datetime-style/pull/37/
* Move enum value of kUndefined to 0 to make unset behavior the same as
  kUndefined.
* Change the expectation of existing tests
* Additional tests - https://github.com/tc39/test262/pull/2385

Bug: v8:9826
Change-Id: Ic437b5f6414aa641ae73766d8c5fd5b9d352a230
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1846722
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64255}
2019-10-11 20:44:17 +00:00

47 lines
1.2 KiB
JavaScript

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Checks for security holes introduced by Object.property overrides.
// For example:
// Object.defineProperty(Array.prototype, 'locale', {
// set: function(value) {
// throw new Error('blah');
// },
// configurable: true,
// enumerable: false
// });
//
// would throw in case of (JS) x.locale = 'us' or (C++) x->Set('locale', 'us').
//
// First get supported properties.
// Some of the properties are optional, so we request them.
var properties = [];
var options = Intl.DateTimeFormat(
'en-US', {dateStyle: 'full'}).resolvedOptions();
for (var prop in options) {
if (options.hasOwnProperty(prop)) {
properties.push(prop);
}
}
// In the order of Table 6 of
// ecma402 #sec-intl.datetimeformat.prototype.resolvedoptions
var expectedProperties = [
'locale',
'calendar',
'numberingSystem',
'timeZone',
'dateStyle',
];
assertEquals(expectedProperties.length, properties.length);
properties.forEach(function(prop) {
assertFalse(expectedProperties.indexOf(prop) === -1);
});
taintProperties(properties);
var locale = Intl.DateTimeFormat().resolvedOptions().locale;