Skip to content

Commit

Permalink
Merge branch 'main' into promise-with-resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
peetklecha authored Sep 8, 2023
2 parents 8453477 + e04e1c1 commit 1b697d1
Show file tree
Hide file tree
Showing 966 changed files with 12,999 additions and 3,009 deletions.
2 changes: 2 additions & 0 deletions harness/regExpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ function testPropertyOfStrings(args) {
}
}

if (!nonMatchStrings) return;

const allNonMatchStrings = nonMatchStrings.join('');
if (regExp.test(allNonMatchStrings)) {
for (const string of nonMatchStrings) {
Expand Down
21 changes: 20 additions & 1 deletion harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,25 @@ var TemporalHelpers = {
return new CalendarMergeFieldsPrimitive(primitive);
},

/*
* A custom calendar whose fields() method returns the same value as the
* iso8601 calendar, with the addition of extraFields provided as parameter.
*/
calendarWithExtraFields(fields) {
class CalendarWithExtraFields extends Temporal.Calendar {
constructor(extraFields) {
super("iso8601");
this._extraFields = extraFields;
}

fields(fieldNames) {
return super.fields(fieldNames).concat(this._extraFields);
}
}

return new CalendarWithExtraFields(fields);
},

/*
* crossDateLineTimeZone():
*
Expand Down Expand Up @@ -1715,7 +1734,7 @@ var TemporalHelpers = {
}

getPossibleInstantsFor(plainDateTime) {
this.getPossibleInstantsForCalledWith.push(plainDateTime.toString());
this.getPossibleInstantsForCalledWith.push(plainDateTime.toString({ calendarName: "never" }));
const [instant] = super.getPossibleInstantsFor(plainDateTime);
if (this._shiftNanoseconds > 0) {
if (this._isBeforeShift(instant)) return [instant];
Expand Down
215 changes: 215 additions & 0 deletions harness/testIntl.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ defines:
- getDateTimeComponents
- getDateTimeComponentValues
- isCanonicalizedStructurallyValidTimeZoneName
- partitionDurationFormatPattern
- formatDurationFormatPattern
---*/
/**
*/
Expand Down Expand Up @@ -2138,6 +2140,7 @@ function allNumberingSystems() {
"jpanfin",
"jpanyear",
"kali",
"kawi",
"khmr",
"knda",
"lana",
Expand All @@ -2159,6 +2162,7 @@ function allNumberingSystems() {
"mymr",
"mymrshan",
"mymrtlng",
"nagm",
"native",
"newa",
"nkoo",
Expand Down Expand Up @@ -2242,6 +2246,7 @@ var numberingSystemDigits = {
hmnp: "𞅀𞅁𞅂𞅃𞅄𞅅𞅆𞅇𞅈𞅉",
java: "꧐꧑꧒꧓꧔꧕꧖꧗꧘꧙",
kali: "꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉",
kawi: "\u{11F50}\u{11F51}\u{11F52}\u{11F53}\u{11F54}\u{11F55}\u{11F56}\u{11F57}\u{11F58}\u{11F59}",
khmr: "០១២៣៤៥៦៧៨៩",
knda: "೦೧೨೩೪೫೬೭೮೯",
lana: "᪀᪁᪂᪃᪄᪅᪆᪇᪈᪉",
Expand All @@ -2250,6 +2255,7 @@ var numberingSystemDigits = {
latn: "0123456789",
lepc: "᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉",
limb: "\u1946\u1947\u1948\u1949\u194A\u194B\u194C\u194D\u194E\u194F",
nagm: "\u{1E4F0}\u{1E4F1}\u{1E4F2}\u{1E4F3}\u{1E4F4}\u{1E4F5}\u{1E4F6}\u{1E4F7}\u{1E4F8}\u{1E4F9}",
mathbold: "𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗",
mathdbl: "𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡",
mathmono: "𝟶𝟷𝟸𝟹𝟺𝟻𝟼𝟽𝟾𝟿",
Expand Down Expand Up @@ -2498,3 +2504,212 @@ function isCanonicalizedStructurallyValidTimeZoneName(timeZone) {
}
return zoneNamePattern.test(timeZone);
}


/**
* @description Simplified PartitionDurationFormatPattern implementation which
* only supports the "en" locale.
* @param {Object} duration the duration record
* @param {String} style the duration format style
* @result {Array} an array with formatted duration parts
*/

function partitionDurationFormatPattern(duration, style = "short") {
const units = [
"years",
"months",
"weeks",
"days",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds",
];

function durationToFractionalSeconds(duration) {
let {
seconds = 0,
milliseconds = 0,
microseconds = 0,
nanoseconds = 0,
} = duration;

// Directly return seconds when no sub-seconds are present.
if (milliseconds === 0 && microseconds === 0 && nanoseconds === 0) {
return seconds;
}

// Otherwise compute the overall amount of nanoseconds using BigInt to avoid
// loss of precision.
let ns_sec = BigInt(seconds) * 1_000_000_000n;
let ns_ms = BigInt(milliseconds) * 1_000_000n;
let ns_us = BigInt(microseconds) * 1_000n;
let ns = ns_sec + ns_ms + ns_us + BigInt(nanoseconds);

// Split the nanoseconds amount into seconds and sub-seconds.
let q = ns / 1_000_000_000n;
let r = ns % 1_000_000_000n;

// Pad sub-seconds, without any leading negative sign, to nine digits.
if (r < 0) {
r = -r;
}
r = String(r).padStart(9, "0");

// Return seconds with fractional part as a decimal string.
return `${q}.${r}`;
}

// Only "en" is supported.
const locale = "en";
const numberingSystem = "latn";
const timeSeparator = ":";

let result = [];
let separated = false;

for (let unit of units) {
// Absent units default to zero.
let value = duration[unit] ?? 0;

let display = "auto";
if (style === "digital") {
// Always display numeric units per GetDurationUnitOptions.
if (unit === "hours" || unit === "minutes" || unit === "seconds") {
display = "always";
}

// Numeric seconds and sub-seconds are combined into a single value.
if (unit === "seconds") {
value = durationToFractionalSeconds(duration);
}
}

// "auto" display omits zero units.
if (value !== 0 || display !== "auto") {
// Map the DurationFormat style to a NumberFormat style.
let unitStyle = style;
if (style === "digital") {
if (unit === "hours") {
unitStyle = "numeric";
} else if (unit === "minutes" || unit === "seconds") {
unitStyle = "2-digit";
} else {
unitStyle = "short";
}
}

// NumberFormat requires singular unit names.
let numberFormatUnit = unit.slice(0, -1);

// Compute the matching NumberFormat options.
let nfOpts;
if (unitStyle !== "numeric" && unitStyle !== "2-digit") {
// The value is formatted as a standalone unit.
nfOpts = {
numberingSystem,
style: "unit",
unit: numberFormatUnit,
unitDisplay: unitStyle,
};
} else {
let roundingMode = undefined;
let minimumFractionDigits = undefined;
let maximumFractionDigits = undefined;

// Numeric seconds include any sub-seconds.
if (style === "digital" && unit === "seconds") {
roundingMode = "trunc";
minimumFractionDigits = 0;
maximumFractionDigits = 9;
}

// The value is formatted as a numeric unit.
nfOpts = {
numberingSystem,
minimumIntegerDigits: (unitStyle === "2-digit" ? 2 : 1),
roundingMode,
minimumFractionDigits,
maximumFractionDigits,
};
}

let nf = new Intl.NumberFormat(locale, nfOpts);
let formatted = nf.formatToParts(value);

// Add |numberFormatUnit| to the formatted number.
let list = [];
for (let {value, type} of formatted) {
list.push({type, value, unit: numberFormatUnit});
}

if (!separated) {
// Prepend the separator before the next numeric unit.
if (unitStyle === "2-digit" || unitStyle === "numeric") {
separated = true;
}

// Append the formatted number to |result|.
result.push(list);
} else {
let last = result[result.length - 1];

// Prepend the time separator before the formatted number.
last.push({
type: "literal",
value: timeSeparator,
});

// Concatenate |last| and the formatted number.
last.push(...list);
}
} else {
separated = false;
}

// No further units possible after "seconds" when style is "digital".
if (style === "digital" && unit === "seconds") {
break;
}
}

let lf = new Intl.ListFormat(locale, {
type: "unit",
style: (style !== "digital" ? style : "short"),
});

// Collect all formatted units into a list of strings.
let strings = [];
for (let parts of result) {
let string = "";
for (let {value} of parts) {
string += value;
}
strings.push(string);
}

// Format the list of strings and compute the overall result.
let flattened = [];
for (let {type, value} of lf.formatToParts(strings)) {
if (type === "element") {
flattened.push(...result.shift());
} else {
flattened.push({type, value});
}
}
return flattened;
}


/**
* @description Return the formatted string from partitionDurationFormatPattern.
* @param {Object} duration the duration record
* @param {String} style the duration format style
* @result {String} a string containing the formatted duration
*/

function formatDurationFormatPattern(duration, style) {
return partitionDurationFormatPattern(duration, style).reduce((acc, e) => acc + e.value, "");
}
8 changes: 3 additions & 5 deletions test/built-ins/ArrayBuffer/prototype/resize/nonconstructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ info: |
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified
in the description of a particular function.
features: [resizable-arraybuffer]
includes: [isConstructor.js]
features: [resizable-arraybuffer, Reflect.construct]
---*/

assert.sameValue(
Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.resize, 'prototype'),
false
);
assert(!isConstructor(ArrayBuffer.prototype.resize), "ArrayBuffer.prototype.resize is not a constructor");

var arrayBuffer = new ArrayBuffer(8);
assert.throws(TypeError, function() {
Expand Down
4 changes: 3 additions & 1 deletion test/built-ins/ArrayBuffer/prototype/slice/nonconstructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ info: |
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified
in the description of a particular function.
includes: [isConstructor.js]
features: [Reflect.construct]
---*/

assert.sameValue(Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.slice, "prototype"), false);
assert(!isConstructor(ArrayBuffer.prototype.slice), "ArrayBuffer.prototype.slice is not a constructor");

var arrayBuffer = new ArrayBuffer(8);
assert.throws(TypeError, function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ info: |
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified
in the description of a particular function.
features: [arraybuffer-transfer]
includes: [isConstructor.js]
features: [arraybuffer-transfer, Reflect.construct]
---*/

assert.sameValue(
Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.transfer, 'prototype'),
false
);
assert(!isConstructor(ArrayBuffer.prototype.transfer), "ArrayBuffer.prototype.transfer is not a constructor");

var arrayBuffer = new ArrayBuffer(8);
assert.throws(TypeError, function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ info: |
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified
in the description of a particular function.
features: [arraybuffer-transfer]
includes: [isConstructor.js]
features: [arraybuffer-transfer, Reflect.construct]
---*/

assert.sameValue(
Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.transferToFixedLength, 'prototype'),
false
);
assert(!isConstructor(ArrayBuffer.prototype.transferToFixedLength), "ArrayBuffer.prototype.transferToFixedLength is not a constructor");

var arrayBuffer = new ArrayBuffer(8);
assert.throws(TypeError, function() {
Expand Down
14 changes: 14 additions & 0 deletions test/built-ins/Iterator/from/iterable-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ assert.throws(TypeError, function () {
assert.compareArray(Array.from(Iterator.from(new Number(5))), [0, 1, 2, 3, 4]);

assert.compareArray(Array.from(Iterator.from('string')), ['s', 't', 'r', 'i', 'n', 'g']);

const originalStringIterator = String.prototype[Symbol.iterator];
let observedType;
Object.defineProperty(String.prototype, Symbol.iterator, {
get() {
'use strict';
observedType = typeof this;
return originalStringIterator;
}
});
Iterator.from('');
assert.sameValue(observedType, 'string');
Iterator.from(new String(''));
assert.sameValue(observedType, 'object');
1 change: 1 addition & 0 deletions test/built-ins/Iterator/from/supports-iterable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ features: [iterator-helpers]
flags: []
---*/
assert.compareArray(Array.from(Iterator.from([0, 1, 2, 3])), [0, 1, 2, 3]);
assert.compareArray(Array.from(Iterator.from(new String('str'))), ['s', 't', 'r']);
Loading

0 comments on commit 1b697d1

Please sign in to comment.