Merge pull request #2064 from test262-automation/v8-test262-automation-export-6bb8f41e0a

Import test changes from V8
This commit is contained in:
Leo Balter 2019-07-21 21:17:21 -04:00 committed by GitHub
commit deb5d07a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
213 changed files with 4512 additions and 1039 deletions

View File

@ -1,5 +1,5 @@
{
"sourceRevisionAtLastExport": "f85a3554",
"targetRevisionAtLastExport": "6bb8f41e0a",
"sourceRevisionAtLastExport": "ddf72e4b",
"targetRevisionAtLastExport": "8d9f7690f8",
"curatedFiles": {}
}

View File

@ -0,0 +1,61 @@
// 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.
// Flags: --harmony-intl-bigint
var locales = [
"en", // "1,234,567,890,123,456"
"de", // "1.234.567.890.123.456"
"fr", // "1234567890123456"
"hi", // "1,23,45,67,89,01,23,456"
"fa", // "۱٬۲۳۴٬۵۶۷٬۸۹۰٬۱۲۳٬۴۵۶"
"th-u-nu-thai", // "๑,๒๓๔,๕๖๗,๘๙๐,๑๒๓,๔๕๖"
];
var data = [
Number.MAX_SAFE_INTEGER,
-Number.MAX_SAFE_INTEGER,
Math.floor(Number.MAX_SAFE_INTEGER / 2),
0,
/// -0, // this case is broken now.
];
for (var locale of locales) {
let nf = new Intl.NumberFormat(locale);
let percentOption = {style: "percent"};
let nfPercent = new Intl.NumberFormat(locale, percentOption);
for (var n of data) {
let bigint = BigInt(n);
// Test NumberFormat w/ number output the same as
// BigInt.prototype.toLocaleString()
assertEquals(nf.format(n), bigint.toLocaleString(locale));
// Test NumberFormat output the same regardless pass in as number or BigInt
assertEquals(nf.format(n), nf.format(bigint));
// Test formatToParts
assertEquals(nf.formatToParts(n), nf.formatToParts(bigint));
// Test output with option
// Test NumberFormat w/ number output the same as
// BigInt.prototype.toLocaleString()
assertEquals(nfPercent.format(n),
bigint.toLocaleString(locale, percentOption));
// Test NumberFormat output the same regardless pass in as number or BigInt
assertEquals(nfPercent.format(n), nfPercent.format(bigint));
assertEquals(nfPercent.formatToParts(n), nfPercent.formatToParts(bigint));
}
// Test very big BigInt
let veryBigInt = BigInt(Number.MAX_SAFE_INTEGER) *
BigInt(Number.MAX_SAFE_INTEGER) *
BigInt(Number.MAX_SAFE_INTEGER);
assertEquals(nf.format(veryBigInt), veryBigInt.toLocaleString(locale));
// It should output different than toString
assertFalse(veryBigInt.toLocaleString(locale) == veryBigInt.toString());
assertTrue(veryBigInt.toLocaleString(locale).length >
veryBigInt.toString().length);
}

View File

@ -26,7 +26,8 @@ let locales = [
];
invalid_hc.forEach(function(hc) {
let df = new Intl.DateTimeFormat(["en-u-hc-" + hc + "-fo-obar"]);
let df = new Intl.DateTimeFormat(
["en-u-hc-" + hc + "-fo-obar"], {hour: "2-digit"});
assertEquals("en", df.resolvedOptions().locale);
}
);
@ -34,7 +35,8 @@ invalid_hc.forEach(function(hc) {
valid_hc.forEach(function(hc) {
locales.forEach(function(base) {
let l = base + "-u-hc-" + hc;
let df = new Intl.DateTimeFormat([l + "-fo-obar"]);
let df = new Intl.DateTimeFormat(
[l + "-fo-obar"], {hour: "2-digit"});
assertEquals(l, df.resolvedOptions().locale);
});
}

View File

@ -0,0 +1,108 @@
// 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.
// Flags: --harmony-intl-datetime-style
// Throws only once during construction.
// Check for all getters to prevent regression.
// Preserve the order of getter initialization.
let getCount = 0;
let weekday = new Array();
let year = new Array();
let month = new Array();
let day = new Array();
let hour = new Array();
let minute = new Array();
let second = new Array();
let localeMatcher = new Array();
let hour12 = new Array();
let hourCycle = new Array();
let dateStyle = new Array();
let timeStyle = new Array();
let timeZone = new Array();
let era = new Array();
let timeZoneName = new Array();
let formatMatcher = new Array();
new Intl.DateTimeFormat(['en-US'], {
get weekday() {
weekday.push(++getCount);
},
get year() {
year.push(++getCount);
},
get month() {
month.push(++getCount);
},
get day() {
day.push(++getCount);
},
get hour() {
hour.push(++getCount);
},
get minute() {
minute.push(++getCount);
},
get second() {
second.push(++getCount);
},
get localeMatcher() {
localeMatcher.push(++getCount);
},
get hour12() {
hour12.push(++getCount);
},
get hourCycle() {
hourCycle.push(++getCount);
},
get timeZone() {
timeZone.push(++getCount);
},
get dateStyle() {
dateStyle.push(++getCount);
return "full";
},
get timeStyle() {
timeStyle.push(++getCount);
},
get era() {
era.push(++getCount);
},
get timeZoneName() {
timeZoneName.push(++getCount);
},
get formatMatcher() {
formatMatcher.push(++getCount);
}
});
assertEquals(1, weekday.length);
assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]);
assertEquals(1, hour.length);
assertEquals(5, hour[0]);
assertEquals(1, minute.length);
assertEquals(6, minute[0]);
assertEquals(1, second.length);
assertEquals(7, second[0]);
assertEquals(1, localeMatcher.length);
assertEquals(8, localeMatcher[0]);
assertEquals(1, hour12.length);
assertEquals(9, hour12[0]);
assertEquals(1, hourCycle.length);
assertEquals(10, hourCycle[0]);
assertEquals(1, timeZone.length);
assertEquals(11, timeZone[0]);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]);
assertEquals(1, timeStyle.length);
assertEquals(13, timeStyle[0]);
assertEquals(0, era.length);
assertEquals(0, timeZoneName.length);
assertEquals(0, formatMatcher.length);

View File

@ -0,0 +1,109 @@
// 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.
// Flags: --harmony-intl-datetime-style
// Throws only once during construction.
// Check for all getters to prevent regression.
// Preserve the order of getter initialization.
let getCount = 0;
let weekday = new Array();
let year = new Array();
let month = new Array();
let day = new Array();
let hour = new Array();
let minute = new Array();
let second = new Array();
let localeMatcher = new Array();
let hour12 = new Array();
let hourCycle = new Array();
let dateStyle = new Array();
let timeStyle = new Array();
let timeZone = new Array();
let era = new Array();
let timeZoneName = new Array();
let formatMatcher = new Array();
new Intl.DateTimeFormat(['en-US'], {
get weekday() {
weekday.push(++getCount);
},
get year() {
year.push(++getCount);
},
get month() {
month.push(++getCount);
},
get day() {
day.push(++getCount);
},
get hour() {
hour.push(++getCount);
},
get minute() {
minute.push(++getCount);
},
get second() {
second.push(++getCount);
},
get localeMatcher() {
localeMatcher.push(++getCount);
},
get hour12() {
hour12.push(++getCount);
},
get hourCycle() {
hourCycle.push(++getCount);
},
get timeZone() {
timeZone.push(++getCount);
},
get dateStyle() {
dateStyle.push(++getCount);
return "full";
},
get timeStyle() {
timeStyle.push(++getCount);
return "full";
},
get era() {
era.push(++getCount);
},
get timeZoneName() {
timeZoneName.push(++getCount);
},
get formatMatcher() {
formatMatcher.push(++getCount);
}
});
assertEquals(1, weekday.length);
assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]);
assertEquals(1, hour.length);
assertEquals(5, hour[0]);
assertEquals(1, minute.length);
assertEquals(6, minute[0]);
assertEquals(1, second.length);
assertEquals(7, second[0]);
assertEquals(1, localeMatcher.length);
assertEquals(8, localeMatcher[0]);
assertEquals(1, hour12.length);
assertEquals(9, hour12[0]);
assertEquals(1, hourCycle.length);
assertEquals(10, hourCycle[0]);
assertEquals(1, timeZone.length);
assertEquals(11, timeZone[0]);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]);
assertEquals(1, timeStyle.length);
assertEquals(13, timeStyle[0]);
assertEquals(0, era.length);
assertEquals(0, timeZoneName.length);
assertEquals(0, formatMatcher.length);

View File

@ -0,0 +1,33 @@
// 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.
// Flags: --harmony-intl-datetime-style
var validStyle = ["full", "long", "medium", "short", undefined];
var invalidStyle = ["narrow", "numeric"];
validStyle.forEach(function(dateStyle) {
validStyle.forEach(function(timeStyle) {
assertDoesNotThrow(() =>
new Intl.DateTimeFormat("en", {dateStyle, timeStyle}));
});
invalidStyle.forEach(function(timeStyle) {
assertThrows(() =>
new Intl.DateTimeFormat("en", {dateStyle, timeStyle}), RangeError);
});
}
);
invalidStyle.forEach(function(dateStyle) {
validStyle.forEach(function(timeStyle) {
assertThrows(() =>
new Intl.DateTimeFormat("en", {dateStyle, timeStyle}), RangeError);
});
invalidStyle.forEach(function(timeStyle) {
assertThrows(() =>
new Intl.DateTimeFormat("en", {dateStyle, timeStyle}), RangeError);
});
}
);

View File

@ -0,0 +1,114 @@
// 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.
// Flags: --harmony-intl-datetime-style
// Throws only once during construction.
// Check for all getters to prevent regression.
// Preserve the order of getter initialization.
let getCount = 0;
let weekday = new Array();
let year = new Array();
let month = new Array();
let day = new Array();
let hour = new Array();
let minute = new Array();
let second = new Array();
let localeMatcher = new Array();
let hour12 = new Array();
let hourCycle = new Array();
let dateStyle = new Array();
let timeStyle = new Array();
let timeZone = new Array();
let era = new Array();
let timeZoneName = new Array();
let formatMatcher = new Array();
new Intl.DateTimeFormat(['en-US'], {
get weekday() {
weekday.push(++getCount);
},
get year() {
year.push(++getCount);
},
get month() {
month.push(++getCount);
},
get day() {
day.push(++getCount);
},
get hour() {
hour.push(++getCount);
},
get minute() {
minute.push(++getCount);
},
get second() {
second.push(++getCount);
},
get localeMatcher() {
localeMatcher.push(++getCount);
},
get hour12() {
hour12.push(++getCount);
},
get hourCycle() {
hourCycle.push(++getCount);
},
get timeZone() {
timeZone.push(++getCount);
},
get dateStyle() {
dateStyle.push(++getCount);
},
get timeStyle() {
timeStyle.push(++getCount);
},
get era() {
era.push(++getCount);
},
get timeZoneName() {
timeZoneName.push(++getCount);
},
get formatMatcher() {
formatMatcher.push(++getCount);
}
});
assertEquals(2, weekday.length);
assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]);
assertEquals(2, hour.length);
assertEquals(5, hour[0]);
assertEquals(2, minute.length);
assertEquals(6, minute[0]);
assertEquals(2, second.length);
assertEquals(7, second[0]);
assertEquals(1, localeMatcher.length);
assertEquals(8, localeMatcher[0]);
assertEquals(1, hour12.length);
assertEquals(9, hour12[0]);
assertEquals(1, hourCycle.length);
assertEquals(10, hourCycle[0]);
assertEquals(1, timeZone.length);
assertEquals(11, timeZone[0]);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]);
assertEquals(1, timeStyle.length);
assertEquals(13, timeStyle[0]);
assertEquals(14, weekday[1]);
assertEquals(1, era.length);
assertEquals(15, era[0]);
assertEquals(16, hour[1]);
assertEquals(17, minute[1]);
assertEquals(18, second[1]);
assertEquals(1, timeZoneName.length);
assertEquals(19, timeZoneName[0]);
assertEquals(1, formatMatcher.length);
assertEquals(20, formatMatcher[0]);

View File

@ -0,0 +1,108 @@
// 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.
// Flags: --harmony-intl-datetime-style
// Throws only once during construction.
// Check for all getters to prevent regression.
// Preserve the order of getter initialization.
let getCount = 0;
let weekday = new Array();
let year = new Array();
let month = new Array();
let day = new Array();
let hour = new Array();
let minute = new Array();
let second = new Array();
let localeMatcher = new Array();
let hour12 = new Array();
let hourCycle = new Array();
let dateStyle = new Array();
let timeStyle = new Array();
let timeZone = new Array();
let era = new Array();
let timeZoneName = new Array();
let formatMatcher = new Array();
new Intl.DateTimeFormat(['en-US'], {
get weekday() {
weekday.push(++getCount);
},
get year() {
year.push(++getCount);
},
get month() {
month.push(++getCount);
},
get day() {
day.push(++getCount);
},
get hour() {
hour.push(++getCount);
},
get minute() {
minute.push(++getCount);
},
get second() {
second.push(++getCount);
},
get localeMatcher() {
localeMatcher.push(++getCount);
},
get hour12() {
hour12.push(++getCount);
},
get hourCycle() {
hourCycle.push(++getCount);
},
get timeZone() {
timeZone.push(++getCount);
},
get dateStyle() {
dateStyle.push(++getCount);
},
get timeStyle() {
timeStyle.push(++getCount);
return "full";
},
get era() {
era.push(++getCount);
},
get timeZoneName() {
timeZoneName.push(++getCount);
},
get formatMatcher() {
formatMatcher.push(++getCount);
}
});
assertEquals(1, weekday.length);
assertEquals(1, weekday[0]);
assertEquals(1, year.length);
assertEquals(2, year[0]);
assertEquals(1, month.length);
assertEquals(3, month[0]);
assertEquals(1, day.length);
assertEquals(4, day[0]);
assertEquals(1, hour.length);
assertEquals(5, hour[0]);
assertEquals(1, minute.length);
assertEquals(6, minute[0]);
assertEquals(1, second.length);
assertEquals(7, second[0]);
assertEquals(1, localeMatcher.length);
assertEquals(8, localeMatcher[0]);
assertEquals(1, hour12.length);
assertEquals(9, hour12[0]);
assertEquals(1, hourCycle.length);
assertEquals(10, hourCycle[0]);
assertEquals(1, timeZone.length);
assertEquals(11, timeZone[0]);
assertEquals(1, dateStyle.length);
assertEquals(12, dateStyle[0]);
assertEquals(1, timeStyle.length);
assertEquals(13, timeStyle[0]);
assertEquals(0, era.length);
assertEquals(0, timeZoneName.length);
assertEquals(0, formatMatcher.length);

View File

@ -0,0 +1,54 @@
// 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.
// Flags: --harmony-intl-datetime-style
// 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',
'hourCycle',
'hour12',
'weekday',
'year',
'month',
'day',
'dateStyle',
];
assertEquals(expectedProperties.length, properties.length);
properties.forEach(function(prop) {
assertFalse(expectedProperties.indexOf(prop) === -1);
});
taintProperties(properties);
var locale = Intl.DateTimeFormat().resolvedOptions().locale;

View File

@ -0,0 +1,59 @@
// 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.
// Flags: --harmony-intl-datetime-style
// 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', timeStyle: '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',
'hourCycle',
'hour12',
'weekday',
'year',
'month',
'day',
'hour',
'minute',
'second',
'timeZoneName',
'dateStyle',
'timeStyle',
];
assertEquals(expectedProperties.length, properties.length);
properties.forEach(function(prop) {
assertFalse(expectedProperties.indexOf(prop) === -1);
});
taintProperties(properties);
var locale = Intl.DateTimeFormat().resolvedOptions().locale;

View File

@ -0,0 +1,54 @@
// 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.
// Flags: --harmony-intl-datetime-style
// 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', {timeStyle: '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',
'hourCycle',
'hour12',
'hour',
'minute',
'second',
'timeZoneName',
'timeStyle',
];
assertEquals(expectedProperties.length, properties.length);
properties.forEach(function(prop) {
assertFalse(expectedProperties.indexOf(prop) === -1);
});
taintProperties(properties);
var locale = Intl.DateTimeFormat().resolvedOptions().locale;

View File

@ -46,6 +46,9 @@
# Unable to change locale on Windows:
'default_locale': [SKIP],
# Unable to change locale and TZ on Windows:
'regress-7770': [SKIP],
}], # system == windows'
['system == android', {
@ -56,5 +59,7 @@
'relative-time-format/default-locale-fr-CA': [SKIP],
'relative-time-format/default-locale-pt-BR': [SKIP],
'default_locale': [SKIP],
# Unable to change locale and TZ on Android:
'regress-7770': [SKIP],
}], # 'system == android'
]

View File

@ -8,13 +8,13 @@
let getCount = 0;
new Intl.ListFormat(['en-US'], {
get type() {
get localeMatcher() {
assertEquals(0, getCount++);
},
get style() {
get type() {
assertEquals(1, getCount++);
},
get localeMatcher() {
get style() {
assertEquals(2, getCount++);
},
});

View File

@ -0,0 +1,8 @@
// 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.
// Environment Variables: TZ=Indian/Kerguelen LANG=uk
assertEquals(
"Fri Feb 01 2019 00:00:00 GMT+0500 (за часом на Французьких Південних і Антарктичних територіях)",
new Date(2019, 1,1).toString());

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
var locales = ["tlh", "id", "en"];
var referenceRelativeTimeFormat = new Intl.RelativeTimeFormat(locales);
var referenceFormatted = referenceRelativeTimeFormat.format(3, "day");

View File

@ -0,0 +1,10 @@
// 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.
assertTrue(new Intl.DateTimeFormat(
"en", { timeZone: 'UTC', hour: 'numeric'}).resolvedOptions().hour12);
assertFalse(new Intl.DateTimeFormat(
"fr", { timeZone: 'UTC', hour: 'numeric'}).resolvedOptions().hour12);
assertFalse(new Intl.DateTimeFormat(
"de", { timeZone: 'UTC', hour: 'numeric'}).resolvedOptions().hour12);

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
// RelativeTimeFormat constructor can't be called as function.
assertThrows(() => Intl.RelativeTimeFormat('sr'), TypeError);

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format --harmony-locale
// Environment Variables: LC_ALL=fr_CA
assertEquals(
'fr-CA',

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format --harmony-locale
// Environment Variables: LC_ALL=pt_BR
assertEquals(
'pt-BR',

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
// The following test are not part of the comformance. Just some output in
// English to verify the format does return something reasonable for English.
// It may be changed when we update the CLDR data.

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
// The following test are not part of the comformance. Just some output in
// English to verify the format does return something reasonable for English.
// It may be changed when we update the CLDR data.

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
// Check plural w/ formatToParts
// http://tc39.github.io/proposal-intl-relative-time/

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
// Make sure that RelativeTimeFormat exposes all required properties. Those not specified
// should have undefined value.
// http://tc39.github.io/proposal-intl-relative-time/

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
// Make sure that RelativeTimeFormat exposes all required properties. Those not specified
// should have undefined value.
// http://tc39.github.io/proposal-intl-relative-time/

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
let rtf = new Intl.RelativeTimeFormat();
// Test 1.4.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ()
// The default style is 'long'

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-intl-relative-time-format
assertEquals(typeof Intl.RelativeTimeFormat.supportedLocalesOf, "function",
"Intl.RelativeTimeFormat.supportedLocalesOf should be a function");

View File

@ -11,9 +11,6 @@ let invalid_lb = [
"keepall",
"none",
"standard",
];
let valid_lb= [
"strict",
"normal",
"loose",
@ -30,12 +27,3 @@ invalid_lb.forEach(function(lb) {
assertEquals("en", df.resolvedOptions().locale);
}
);
valid_lb.forEach(function(lb) {
locales.forEach(function(base) {
let l = base + "-u-lb-" + lb;
let df = new Intl.Segmenter([l + "-fo-obar"]);
assertEquals(l, df.resolvedOptions().locale);
});
}
);

View File

@ -13,11 +13,8 @@ new Intl.Segmenter(['en-US'], {
get localeMatcher() {
assertEquals(0, getCount++);
},
get lineBreakStyle() {
get granularity() {
assertEquals(1, getCount++);
},
get granularity() {
assertEquals(2, getCount++);
},
});
assertEquals(3, getCount);
assertEquals(2, getCount);

View File

@ -0,0 +1,190 @@
// Copyright 2018 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.
// Flags: --harmony-intl-segmenter
// Segmenter constructor can't be called as function.
assertThrows(() => Intl.Segmenter(["sr"]), TypeError);
// Invalid locale string.
assertThrows(() => new Intl.Segmenter(["abcdefghi"]), RangeError);
assertDoesNotThrow(() => new Intl.Segmenter(["sr"], {}), TypeError);
assertDoesNotThrow(() => new Intl.Segmenter([], {}));
assertDoesNotThrow(() => new Intl.Segmenter(["fr", "ar"], {}));
assertDoesNotThrow(() => new Intl.Segmenter({ 0: "ja", 1: "fr" }, {}));
assertDoesNotThrow(() => new Intl.Segmenter({ 1: "ja", 2: "fr" }, {}));
assertDoesNotThrow(() => new Intl.Segmenter(["sr"]));
assertDoesNotThrow(() => new Intl.Segmenter());
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
lineBreakStyle: "strict",
granularity: "grapheme"
})
);
assertDoesNotThrow(
() => new Intl.Segmenter(["sr"], { granularity: "sentence" })
);
assertDoesNotThrow(() => new Intl.Segmenter(["sr"], { granularity: "word" }));
assertDoesNotThrow(
() => new Intl.Segmenter(["sr"], { granularity: "grapheme" })
);
assertThrows(() => new Intl.Segmenter(["sr"], { granularity: "line" }), RangeError);
assertThrows(
() => new Intl.Segmenter(["sr"], { granularity: "standard" }),
RangeError
);
assertDoesNotThrow(
() => new Intl.Segmenter(["sr"], { lineBreakStyle: "normal" })
);
assertDoesNotThrow(
() => new Intl.Segmenter(["sr"], { lineBreakStyle: "strict" })
);
assertDoesNotThrow(
() => new Intl.Segmenter(["sr"], { lineBreakStyle: "loose" })
);
assertDoesNotThrow(
() => new Intl.Segmenter(["sr"], { lineBreakStyle: "giant" })
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "sentence",
lineBreakStyle: "normal"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "sentence",
lineBreakStyle: "strict"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "sentence",
lineBreakStyle: "loose"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "word",
lineBreakStyle: "normal"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "word",
lineBreakStyle: "strict"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "word",
lineBreakStyle: "loose"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "grapheme",
lineBreakStyle: "normal"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "grapheme",
lineBreakStyle: "strict"
})
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(["sr"], {
granularity: "grapheme",
lineBreakStyle: "loose"
})
);
assertThrows(
() =>
new Intl.Segmenter(["sr"], {
granularity: "line",
lineBreakStyle: "loose"
}), RangeError
);
assertThrows(
() =>
new Intl.Segmenter(["sr"], {
granularity: "line",
lineBreakStyle: "normal"
}), RangeError
);
assertThrows(
() =>
new Intl.Segmenter(["sr"], {
granularity: "line",
lineBreakStyle: "strict"
}), RangeError
);
// propagate exception from getter
assertThrows(
() =>
new Intl.Segmenter(undefined, {
get localeMatcher() {
throw new TypeError("");
}
}),
TypeError
);
assertDoesNotThrow(
() =>
new Intl.Segmenter(undefined, {
get lineBreakStyle() {
throw new TypeError("");
}
})
);
assertThrows(
() =>
new Intl.Segmenter(undefined, {
get granularity() {
throw new TypeError("");
}
}),
TypeError
);

View File

@ -5,7 +5,7 @@
// Flags: --harmony-intl-segmenter
const text = "Hello World, Test 123! Foo Bar. How are you?";
for (const granularity of ["grapheme", "word", "sentence", "line"]) {
for (const granularity of ["grapheme", "word", "sentence"]) {
const segmenter = new Intl.Segmenter("en", { granularity });
const iter = segmenter.segment(text);

View File

@ -1,38 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-intl-segmenter
const seg = new Intl.Segmenter([], {granularity: "line"})
for (const text of [
"Hello world!", // English
" Hello world! ", // English with space before/after
" Hello world? Foo bar!", // English
"Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech
"Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese
"Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek
"Решение Индии о покупке российских С-400 расценили как вызов США", // Russian
"הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew,
"ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic
"भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi
"ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil
"'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu
"台北》抹黑柯P失敗朱學恒酸姚文智氣pupu嗆大老闆", // Chinese
"วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai
"九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese
"법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean
]) {
const iter = seg.segment(text);
let prev = 0;
let segments = [];
while (!iter.following()) {
assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType);
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index > prev);
segments.push(text.substring(prev, iter.index));
prev = iter.index;
}
assertEquals(text, segments.join(""));
}

View File

@ -1,45 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-intl-segmenter
const seg = new Intl.Segmenter([], {granularity: "line"})
for (const text of [
"Hello world!", // English
" Hello world! ", // English with space before/after
" Hello world? Foo bar!", // English
"Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech
"Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese
"Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek
"Решение Индии о покупке российских С-400 расценили как вызов США", // Russian
"הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew,
"ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic
"भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi
"ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil
"'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu
"台北》抹黑柯P失敗朱學恒酸姚文智氣pupu嗆大老闆", // Chinese
"วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai
"九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese
"법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean
]) {
let segments = [];
// Create another %SegmentIterator% to compare with result from the one that
// created in the for of loop.
let iter = seg.segment(text);
let prev = 0;
for (const v of seg.segment(text)) {
assertTrue(["soft", "hard"].includes(v.breakType), v.breakType);
assertEquals("string", typeof v.segment);
assertTrue(v.segment.length > 0);
segments.push(v.segment);
// manually advance the iter.
assertFalse(iter.following());
assertEquals(iter.breakType, v.breakType);
assertEquals(text.substring(prev, iter.index), v.segment);
prev = iter.index;
}
assertTrue(iter.following());
assertEquals(text, segments.join(''));
}

View File

@ -1,40 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-intl-segmenter
const seg = new Intl.Segmenter([], {granularity: "line"})
for (const text of [
"Hello world!", // English
" Hello world! ", // English with space before/after
" Hello world? Foo bar!", // English
"Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech
"Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese
"Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek
"Решение Индии о покупке российских С-400 расценили как вызов США", // Russian
"הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew,
"ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic
"भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi
"ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil
"'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu
"台北》抹黑柯P失敗朱學恒酸姚文智氣pupu嗆大老闆", // Chinese
"วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai
"九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese
"법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean
]) {
const iter = seg.segment(text);
let segments = [];
let oldPos = -1;
for (let result = iter.next(); !result.done; result = iter.next()) {
const v = result.value;
assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType);
assertEquals("string", typeof v.segment);
assertTrue(v.segment.length > 0);
segments.push(v.segment);
assertEquals("number", typeof v.index);
assertTrue(oldPos < v.index);
oldPos = v.index;
}
assertEquals(text, segments.join(''));
}

View File

@ -1,44 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-intl-segmenter
const seg = new Intl.Segmenter([], {granularity: "line"})
for (const text of [
"Hello world!", // English
" Hello world! ", // English with space before/after
" Hello world? Foo bar!", // English
"Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech
"Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese
"Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek
"Решение Индии о покупке российских С-400 расценили как вызов США", // Russian
"הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew,
"ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic
"भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi
"ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil
"'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu
"台北》抹黑柯P失敗朱學恒酸姚文智氣pupu嗆大老闆", // Chinese
"วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai
"九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese
"법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean
]) {
const iter = seg.segment(text);
let prev = text.length;
let segments = [];
iter.preceding(prev)
assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType);
assertTrue(iter.index >= 0);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
while (!iter.preceding()) {
assertTrue(["soft", "hard"].includes(iter.breakType), iter.breakType);
assertTrue(iter.index >= 0);
assertTrue(iter.index <= text.length);
assertTrue(iter.index < prev);
segments.push(text.substring(iter.index, prev));
prev = iter.index;
}
assertEquals(text, segments.reverse().join(""));
}

View File

@ -1,29 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-intl-segmenter
const seg = new Intl.Segmenter([], {granularity: "line"})
for (const text of [
"Hello world!", // English
" Hello world! ", // English with space before/after
" Hello world? Foo bar!", // English
"Jedovatou mambu objevila žena v zahrádkářské kolonii.", // Czech
"Việt Nam: Nhất thể hóa sẽ khác Trung Quốc?", // Vietnamese
"Σοβαρές ενστάσεις Κομισιόν για τον προϋπολογισμό της Ιταλίας", // Greek
"Решение Индии о покупке российских С-400 расценили как вызов США", // Russian
"הרופא שהציל נשים והנערה ששועבדה ע", // Hebrew,
"ترامب للملك سلمان: أنا جاد للغاية.. عليك دفع المزيد", // Arabic
"भारत की एस 400 मिसाइल के मुकाबले पाक की थाड, जानें कौन कितना ताकतवर", // Hindi
"ரெட் அலர்ட் எச்சரிக்கை; புதுச்சேரியில் நாளை அரசு விடுமுறை!", // Tamil
"'ఉత్తర్వులు అందే వరకు ఓటర్ల తుది జాబితాను వెబ్‌సైట్లో పెట్టవద్దు'", // Telugu
"台北》抹黑柯P失敗朱學恒酸姚文智氣pupu嗆大老闆", // Chinese
"วัดไทรตีระฆังเบาลงช่วงเข้าพรรษา เจ้าอาวาสเผยคนร้องเรียนรับผลกรรมแล้ว", // Thai
"九州北部の一部が暴風域に入りました(日直予報士 2018年10月06日) - 日本気象協会 tenki.jp", // Japanese
"법원 “다스 지분 처분권·수익권 모두 MB가 보유”", // Korean
]) {
const iter = seg.segment(text);
assertEquals(undefined, iter.breakType);
assertEquals(0, iter.index);
}

View File

@ -567,6 +567,27 @@ function TestPrototypeHoles() {
}
TestPrototypeHoles();
// The following test ensures that elements on the prototype are also copied
// for JSArrays and not only JSObjects.
function TestArrayPrototypeHasElements() {
let array = [1, 2, 3, 4, 5];
for (let i = 0; i < array.length; i++) {
delete array[i];
Object.prototype[i] = 42;
}
let comparator_called = false;
array.sort(function (a, b) {
if (a === 42 || b === 42) {
comparator_called = true;
}
return a - b;
});
assertTrue(comparator_called);
}
TestArrayPrototypeHasElements();
// The following Tests make sure that there is no crash when the element kind
// or the array length changes. Since comparison functions like this are not
// consistent, we do not have to make sure that the array is actually sorted

View File

@ -0,0 +1,28 @@
// 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.
// Flags: --allow-natives-syntax
function g(code) {
try {
if (typeof code === 'function') {
+Symbol();
} else {
eval();
}
} catch (e) {
return;
}
dummy();
}
function f() {
g(g);
}
try { g(); } catch(e) {; }
f();
%OptimizeFunctionOnNextCall(f);
f();

View File

@ -5,25 +5,25 @@
function checkIsRedeclarationError(code) {
try {
eval(`
checkIsRedeclarationError : {
break checkIsRedeclarationError;
${code}
}
`);
checkIsRedeclarationError: {
break checkIsRedeclarationError;
${code}
}
`);
assertUnreachable();
} catch(e) {
assertInstanceof(e, SyntaxError );
assertTrue( e.toString().indexOf("has already been declared") >= 0 );
} catch (e) {
assertInstanceof(e, SyntaxError);
assertTrue(e.toString().includes("has already been declared"));
}
}
function checkIsNotRedeclarationError(code) {
assertDoesNotThrow(()=>eval(`
checkIsNotRedeclarationError_label : {
break checkIsNotRedeclarationError_label;
${code}
}
`));
assertDoesNotThrow(() => eval(`
checkIsNotRedeclarationError_label: {
break checkIsNotRedeclarationError_label;
${code}
}
`));
}
@ -52,143 +52,145 @@ let not_var_e = [
'const {f:e}'
];
// Check that `for (var ... of ...)` cannot redeclare a simple catch variable
// but `for (var ... in ...)` can.
// Check that both `for (var ... of ...)` and `for (var ... in ...)`
// can redeclare a simple catch variable.
for (let binding of var_e) {
checkIsRedeclarationError(`
try {
throw 0;
} catch(e) {
for (${binding} of []);
}
`);
checkIsNotRedeclarationError(`
try {
throw 0;
} catch(e) {
for (${binding} in []);
}
`);
}
// Check that the above error occurs even for nested catches.
for (let binding of var_e) {
checkIsRedeclarationError(`
try {
throw 0;
} catch(e) {
try {
throw 1;
} catch(f) {
try {
throw 2;
} catch({}) {
throw 0;
} catch (e) {
for (${binding} of []);
}
}
}
`);
`);
checkIsNotRedeclarationError(`
try {
throw 0;
} catch(e) {
try {
throw 1;
} catch(f) {
try {
throw 2;
} catch({}) {
throw 0;
} catch (e) {
for (${binding} in []);
}
}
}
`);
`);
}
// Check that the above error does not occur if a declaration scope is between
// the catch and the loop.
// Check that the above applies even for nested catches.
for (let binding of var_e) {
checkIsNotRedeclarationError(`
try {
throw 0;
} catch(e) {
(()=>{for (${binding} of []);})();
}
`);
try {
throw 0;
} catch (e) {
try {
throw 1;
} catch (f) {
try {
throw 2;
} catch ({}) {
for (${binding} of []);
}
}
}
`);
checkIsNotRedeclarationError(`
try {
throw 0;
} catch(e) {
(function(){for (${binding} of []);})();
try {
throw 0;
} catch (e) {
try {
throw 1;
} catch (f) {
try {
throw 2;
} catch ({}) {
for (${binding} in []);
}
}
}
`);
}
`);
// Check that the above applies if a declaration scope is between the
// catch and the loop.
for (let binding of var_e) {
checkIsNotRedeclarationError(`
try {
throw 0;
} catch (e) {
(()=>{for (${binding} of []);})();
}
`);
checkIsNotRedeclarationError(`
try {
throw 0;
} catch (e) {
(function() {
for (${binding} of []);
})();
}
`);
}
// Check that there is no error when not declaring a var named e.
for (let binding of not_var_e) {
checkIsNotRedeclarationError(`
try {
throw 0;
} catch(e) {
for (${binding} of []);
}
`);
try {
throw 0;
} catch (e) {
for (${binding} of []);
}
`);
}
// Check that there is an error for both for-in and for-of when redeclaring
// a non-simple catch parameter
// a non-simple catch parameter.
for (let binding of var_e) {
checkIsRedeclarationError(`
try {
throw 0;
} catch({e}) {
for (${binding} of []);
}
`);
try {
throw 0;
} catch ({e}) {
for (${binding} of []);
}
`);
checkIsRedeclarationError(`
try {
throw 0;
} catch({e}) {
for (${binding} in []);
}
`);
try {
throw 0;
} catch ({e}) {
for (${binding} in []);
}
`);
}
// Check that the above error occurs even for nested catches.
for (let binding of var_e) {
checkIsRedeclarationError(`
try {
throw 0;
} catch({e}) {
try {
throw 1;
} catch(f) {
try {
throw 2;
} catch({}) {
for (${binding} of []);
throw 0;
} catch ({e}) {
try {
throw 1;
} catch (f) {
try {
throw 2;
} catch ({}) {
for (${binding} of []);
}
}
}
}
}
`);
`);
checkIsRedeclarationError(`
try {
throw 0;
} catch({e}) {
try {
throw 1;
} catch(f) {
try {
throw 2;
} catch({}) {
for (${binding} in []);
throw 0;
} catch ({e}) {
try {
throw 1;
} catch (f) {
try {
throw 2;
} catch ({}) {
for (${binding} in []);
}
}
}
}
}
`);
`);
}

View File

@ -54,9 +54,9 @@ assertEquals(["a", "b", "c"], Reflect.ownKeys(proxy));
keys.length = Math.pow(2, 33);
assertThrows("Reflect.ownKeys(proxy)", RangeError);
// Check that we allow duplicated keys.
// Check that we don't allow duplicated keys.
keys = ['a', 'a', 'a']
assertEquals(keys, Reflect.ownKeys(proxy));
assertThrows("Reflect.ownKeys(proxy)", TypeError);
// Non-Name results throw.
keys = [1];
@ -75,9 +75,9 @@ assertThrows("Reflect.ownKeys(proxy)", TypeError);
keys = ["nonconf"];
assertEquals(keys, Reflect.ownKeys(proxy));
// Check that we allow duplicated keys.
// Check that we don't allow duplicated keys.
keys = ['nonconf', 'nonconf', 'nonconf']
assertEquals(keys, Reflect.ownKeys(proxy));
assertThrows("Reflect.ownKeys(proxy)", TypeError);
// Step 19a: The trap result must all keys of a non-extensible target.
Object.preventExtensions(target);
@ -89,6 +89,6 @@ assertEquals(keys, Reflect.ownKeys(proxy));
keys = ["nonconf", "target_one", "fantasy"];
assertThrows("Reflect.ownKeys(proxy)", TypeError);
// Check that we allow duplicated keys.
// Check that we don't allow duplicated keys.
keys = ['nonconf', 'target_one', 'nonconf', 'nonconf', 'target_one',]
assertEquals(keys, Reflect.ownKeys(proxy));
assertThrows("Reflect.ownKeys(proxy)", TypeError);

View File

@ -69,6 +69,31 @@ for (var constructor of typedArrayConstructors) {
assertThrows(() => array.sort(), TypeError);
}
// Check that TypedArray.p.sort is stable.
for (let constructor of typedArrayConstructors) {
// Sort an array [0..kSize-1] modulo 4. If the sort is stable, the array
// will be partitioned into 4 parts, where each part has only increasing
// elements.
const kSize = 128;
const kModulo = 4;
const kRunSize = kSize / kModulo;
const template = Array.from({ length: kSize }, (_, i) => i);
const array = new constructor(template);
const compare = (a, b) => (b % kModulo) - (a % kModulo);
array.sort(compare);
function assertIncreasing(from) {
for (let i = from + 1; i < from + kRunSize; ++i) {
assertTrue(array[i - 1] < array[i]);
assertEquals(array[i - 1] % kModulo, array[i] % kModulo);
}
}
for (let i = 0; i < kModulo; ++i) assertIncreasing(i * kRunSize);
}
// The following creates a test for each typed element kind, where the array
// to sort consists of some max/min/zero elements.
//

View File

@ -144,29 +144,11 @@ function TestOrderWithDuplicates(withWarmup) {
});
if (withWarmup) {
for (const key in P) {}
for (const key in O) {};
try { for (const key in P) {} } catch {};
}
log = [];
assertEquals([
["a", 1],
["a", 1],
["456", 123],
["456", 123]
], Object.entries(P));
assertEquals([
"[[OwnPropertyKeys]]",
"[[GetOwnProperty]](\"a\")",
"[[Get]](\"a\")",
"[[GetOwnProperty]](\"a\")",
"[[Get]](\"a\")",
"[[GetOwnProperty]](\"456\")",
"[[Get]](\"456\")",
"[[GetOwnProperty]](\"HIDDEN\")",
"[[GetOwnProperty]](\"HIDDEN\")",
"[[GetOwnProperty]](\"456\")",
"[[Get]](\"456\")"
], log);
assertThrows(() => Object.entries(P), TypeError);
}
TestOrderWithDuplicates();
TestOrderWithDuplicates(true);

View File

@ -193,21 +193,7 @@ function TestDuplicateKeys() {
defineProperty(target, name, desc) { assertUnreachable(); }
});
var result = Object.getOwnPropertyDescriptors(P);
assertEquals({
"A": {
"value": "VALUE",
"writable": false,
"enumerable": false,
"configurable": true
}
}, result);
assertTrue(result.hasOwnProperty("A"));
assertEquals([
"ownKeys()",
"getOwnPropertyDescriptor(A)",
"getOwnPropertyDescriptor(A)"
], log);
assertThrows(() => Object.getOwnPropertyDescriptors(P), TypeError);
}
TestDuplicateKeys();

View File

@ -121,20 +121,7 @@ function TestOrderWithDuplicates() {
}
});
assertEquals([1, 1, 123, 123], Object.values(P));
assertEquals([
"[[OwnPropertyKeys]]",
"[[GetOwnProperty]](\"a\")",
"[[Get]](\"a\")",
"[[GetOwnProperty]](\"a\")",
"[[Get]](\"a\")",
"[[GetOwnProperty]](\"456\")",
"[[Get]](\"456\")",
"[[GetOwnProperty]](\"HIDDEN\")",
"[[GetOwnProperty]](\"HIDDEN\")",
"[[GetOwnProperty]](\"456\")",
"[[Get]](\"456\")",
], log);
assertThrows(() => Object.values(P), TypeError);
}
TestOrderWithDuplicates();

View File

@ -0,0 +1,5 @@
// 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.
assertDoesNotThrow("try { } catch (e) { var e; for (var e of []) {} }")

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-array-flat
{
class MyArray extends Array {
static get [Symbol.species]() {

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-array-flat
assertEquals(Array.prototype.flat.length, 0);
assertEquals(Array.prototype.flat.name, 'flat');

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-array-flat
{
class MyArray extends Array {
static get [Symbol.species]() {

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-array-flat --allow-natives-syntax
// Flags: --allow-natives-syntax
assertEquals(Array.prototype.flatMap.length, 1);
assertEquals(Array.prototype.flatMap.name, 'flatMap');

View File

@ -4,151 +4,88 @@
// Flags: --harmony-weak-refs
(function TestConstructWeakFactory() {
let wf = new WeakFactory(() => {});
assertEquals(wf.toString(), "[object WeakFactory]");
assertNotSame(wf.__proto__, Object.prototype);
assertSame(wf.__proto__.__proto__, Object.prototype);
(function TestConstructFinalizationGroup() {
let fg = new FinalizationGroup(() => {});
assertEquals(fg.toString(), "[object FinalizationGroup]");
assertNotSame(fg.__proto__, Object.prototype);
assertSame(fg.__proto__.__proto__, Object.prototype);
})();
(function TestWeakFactoryConstructorCallAsFunction() {
(function TestFinalizationGroupConstructorCallAsFunction() {
let caught = false;
let message = "";
try {
let f = WeakFactory(() => {});
let f = FinalizationGroup(() => {});
} catch (e) {
message = e.message;
caught = true;
} finally {
assertTrue(caught);
assertEquals(message, "Constructor WeakFactory requires 'new'");
assertEquals(message, "Constructor FinalizationGroup requires 'new'");
}
})();
(function TestConstructWeakFactoryCleanupNotCallable() {
let message = "WeakFactory: cleanup must be callable";
assertThrows(() => { let wf = new WeakFactory(); }, TypeError, message);
assertThrows(() => { let wf = new WeakFactory(1); }, TypeError, message);
assertThrows(() => { let wf = new WeakFactory(null); }, TypeError, message);
(function TestConstructFinalizationGroupCleanupNotCallable() {
let message = "FinalizationGroup: cleanup must be callable";
assertThrows(() => { let fg = new FinalizationGroup(); }, TypeError, message);
assertThrows(() => { let fg = new FinalizationGroup(1); }, TypeError, message);
assertThrows(() => { let fg = new FinalizationGroup(null); }, TypeError, message);
})();
(function TestConstructWeakFactoryWithCallableProxyAsCleanup() {
(function TestConstructFinalizationGroupWithCallableProxyAsCleanup() {
let handler = {};
let obj = () => {};
let proxy = new Proxy(obj, handler);
let wf = new WeakFactory(proxy);
let fg = new FinalizationGroup(proxy);
})();
(function TestConstructWeakFactoryWithNonCallableProxyAsCleanup() {
let message = "WeakFactory: cleanup must be callable";
(function TestConstructFinalizationGroupWithNonCallableProxyAsCleanup() {
let message = "FinalizationGroup: cleanup must be callable";
let handler = {};
let obj = {};
let proxy = new Proxy(obj, handler);
assertThrows(() => { let wf = new WeakFactory(proxy); }, TypeError, message);
assertThrows(() => { let fg = new FinalizationGroup(proxy); }, TypeError, message);
})();
(function TestMakeCell() {
let wf = new WeakFactory(() => {});
let wc = wf.makeCell({});
assertEquals(wc.toString(), "[object WeakCell]");
assertNotSame(wc.__proto__, Object.prototype);
assertSame(wc.__proto__.__proto__, Object.prototype);
assertEquals(wc.holdings, undefined);
let holdings_desc = Object.getOwnPropertyDescriptor(wc.__proto__, "holdings");
assertEquals(true, holdings_desc.configurable);
assertEquals(false, holdings_desc.enumerable);
assertEquals("function", typeof holdings_desc.get);
assertEquals(undefined, holdings_desc.set);
let clear_desc = Object.getOwnPropertyDescriptor(wc.__proto__, "clear");
assertEquals(true, clear_desc.configurable);
assertEquals(false, clear_desc.enumerable);
assertEquals("function", typeof clear_desc.value);
(function TestRegisterWithNonObjectTarget() {
let fg = new FinalizationGroup(() => {});
let message = "FinalizationGroup.prototype.register: target must be an object";
assertThrows(() => fg.register(1, "holdings"), TypeError, message);
assertThrows(() => fg.register(false, "holdings"), TypeError, message);
assertThrows(() => fg.register("foo", "holdings"), TypeError, message);
assertThrows(() => fg.register(Symbol(), "holdings"), TypeError, message);
assertThrows(() => fg.register(null, "holdings"), TypeError, message);
assertThrows(() => fg.register(undefined, "holdings"), TypeError, message);
})();
(function TestMakeCellWithHoldings() {
let wf = new WeakFactory(() => {});
let obj = {a: 1};
let holdings = {b: 2};
let wc = wf.makeCell(obj, holdings);
assertSame(wc.holdings, holdings);
})();
(function TestMakeCellWithHoldingsSetHoldings() {
let wf = new WeakFactory(() => {});
let obj = {a: 1};
let holdings = {b: 2};
let wc = wf.makeCell(obj, holdings);
assertSame(wc.holdings, holdings);
wc.holdings = 5;
assertSame(wc.holdings, holdings);
})();
(function TestMakeCellWithHoldingsSetHoldingsStrict() {
"use strict";
let wf = new WeakFactory(() => {});
let obj = {a: 1};
let holdings = {b: 2};
let wc = wf.makeCell(obj, holdings);
assertSame(wc.holdings, holdings);
assertThrows(() => { wc.holdings = 5; }, TypeError);
assertSame(wc.holdings, holdings);
})();
(function TestMakeCellWithNonObject() {
let wf = new WeakFactory(() => {});
let message = "WeakFactory.prototype.makeCell: target must be an object";
assertThrows(() => wf.makeCell(), TypeError, message);
assertThrows(() => wf.makeCell(1), TypeError, message);
assertThrows(() => wf.makeCell(false), TypeError, message);
assertThrows(() => wf.makeCell("foo"), TypeError, message);
assertThrows(() => wf.makeCell(Symbol()), TypeError, message);
assertThrows(() => wf.makeCell(null), TypeError, message);
assertThrows(() => wf.makeCell(undefined), TypeError, message);
})();
(function TestMakeCellWithProxy() {
(function TestRegisterWithProxy() {
let handler = {};
let obj = {};
let proxy = new Proxy(obj, handler);
let wf = new WeakFactory(() => {});
let wc = wf.makeCell(proxy);
let fg = new FinalizationGroup(() => {});
fg.register(proxy);
})();
(function TestMakeCellTargetAndHoldingsSameValue() {
let wf = new WeakFactory(() => {});
(function TestRegisterTargetAndHoldingsSameValue() {
let fg = new FinalizationGroup(() => {});
let obj = {a: 1};
// SameValue(target, holdings) not ok
assertThrows(() => wf.makeCell(obj, obj), TypeError,
"WeakFactory.prototype.makeCell: target and holdings must not be same");
assertThrows(() => fg.register(obj, obj), TypeError,
"FinalizationGroup.prototype.register: target and holdings must not be same");
let holdings = {a: 1};
let wc = wf.makeCell(obj, holdings);
fg.register(obj, holdings);
})();
(function TestMakeCellWithoutWeakFactory() {
assertThrows(() => WeakFactory.prototype.makeCell.call({}, {}), TypeError);
(function TestRegisterWithoutFinalizationGroup() {
assertThrows(() => FinalizationGroup.prototype.register.call({}, {}, "holdings"), TypeError);
// Does not throw:
let wf = new WeakFactory(() => {});
WeakFactory.prototype.makeCell.call(wf, {});
let fg = new FinalizationGroup(() => {});
FinalizationGroup.prototype.register.call(fg, {}, "holdings");
})();
(function TestHoldingsWithoutWeakCell() {
let wf = new WeakFactory(() => {});
let wc = wf.makeCell({});
let holdings_getter = Object.getOwnPropertyDescriptor(wc.__proto__, "holdings").get;
assertThrows(() => holdings_getter.call({}), TypeError);
// Does not throw:
holdings_getter.call(wc);
})();
(function TestClearWithoutWeakCell() {
let wf = new WeakFactory(() => {});
let wc = wf.makeCell({});
let clear = Object.getOwnPropertyDescriptor(wc.__proto__, "clear").value;
assertThrows(() => clear.call({}), TypeError);
// Does not throw:
clear.call(wc);
(function TestUnregisterWithNonExistentKey() {
let fg = new FinalizationGroup(() => {});
fg.unregister({"k": "whatever"});
})();
(function TestWeakRefConstructor() {
@ -194,21 +131,10 @@
let wr = new WeakRef(proxy);
})();
(function TestCleanupSomeWithoutWeakFactory() {
assertThrows(() => WeakFactory.prototype.cleanupSome.call({}), TypeError);
(function TestCleanupSomeWithoutFinalizationGroup() {
assertThrows(() => FinalizationGroup.prototype.cleanupSome.call({}), TypeError);
// Does not throw:
let wf = new WeakFactory(() => {});
let rv = WeakFactory.prototype.cleanupSome.call(wf);
let fg = new FinalizationGroup(() => {});
let rv = FinalizationGroup.prototype.cleanupSome.call(fg);
assertEquals(undefined, rv);
})();
(function TestDerefWithoutWeakRef() {
let wf = new WeakFactory(() => {});
let wc = wf.makeCell({});
let wr = new WeakRef({});
let deref = Object.getOwnPropertyDescriptor(wr.__proto__, "deref").value;
assertThrows(() => deref.call({}), TypeError);
assertThrows(() => deref.call(wc), TypeError);
// Does not throw:
deref.call(wr);
})();

View File

@ -7,48 +7,47 @@
let cleanup_call_count = 0;
let cleanup = function(iter) {
if (cleanup_call_count == 0) {
// First call: iterate 2 of the 3 cells
let cells = [];
for (wc of iter) {
cells.push(wc);
// Don't iterate the rest of the cells
if (cells.length == 2) {
// First call: iterate 2 of the 3 holdings
let holdings_list = [];
for (holdings of iter) {
holdings_list.push(holdings);
// Don't iterate the rest of the holdings
if (holdings_list.length == 2) {
break;
}
}
assertEquals(cells.length, 2);
assertTrue(cells[0].holdings < 3);
assertTrue(cells[1].holdings < 3);
assertEquals(holdings_list.length, 2);
assertTrue(holdings_list[0] < 3);
assertTrue(holdings_list[1] < 3);
// Update call count only after the asserts; this ensures that the test
// fails even if the exceptions inside the cleanup function are swallowed.
cleanup_call_count++;
} else {
// Second call: iterate one leftover cell and one new cell.
// Second call: iterate one leftover holdings and one holdings.
assertEquals(1, cleanup_call_count);
let cells = [];
for (wc of iter) {
cells.push(wc);
let holdings_list = [];
for (holdings of iter) {
holdings_list.push(holdings);
}
assertEquals(cells.length, 2);
assertTrue((cells[0].holdings < 3 && cells[1].holdings == 100) ||
(cells[1].holdings < 3 && cells[0].holdings == 100));
assertEquals(holdings_list.length, 2);
assertTrue((holdings_list[0] < 3 && holdings_list[1] == 100) ||
(holdings_list[1] < 3 && holdings_list[0] == 100));
// Update call count only after the asserts; this ensures that the test
// fails even if the exceptions inside the cleanup function are swallowed.
cleanup_call_count++;
}
}
let wf = new WeakFactory(cleanup);
// Create 3 objects and WeakCells pointing to them. The objects need to be
// inside a closure so that we can reliably kill them!
let weak_cells = [];
let fg = new FinalizationGroup(cleanup);
// Create 3 objects and register them in the FinalizationGroup. The objects need
// to be inside a closure so that we can reliably kill them!
(function() {
let objects = [];
for (let i = 0; i < 3; ++i) {
objects[i] = {a: i};
weak_cells[i] = wf.makeCell(objects[i], i);
fg.register(objects[i], i);
}
gc();
@ -58,14 +57,14 @@ let weak_cells = [];
objects = [];
})();
// This GC will discover dirty WeakCells.
// This GC will reclaim the targets.
gc();
assertEquals(0, cleanup_call_count);
let timeout_func_1 = function() {
assertEquals(1, cleanup_call_count);
// Assert that the cleanup function won't be called unless new WeakCells appear.
// Assert that the cleanup function won't be called unless new targets appear.
setTimeout(timeout_func_2, 0);
}
@ -74,9 +73,9 @@ setTimeout(timeout_func_1, 0);
let timeout_func_2 = function() {
assertEquals(1, cleanup_call_count);
// Create a new WeakCells to be cleaned up.
// Create a new object and register it.
let obj = {};
let wc = wf.makeCell(obj, 100);
let wc = fg.register(obj, 100);
obj = null;
gc();

View File

@ -9,15 +9,15 @@ let r = Realm.create();
let cleanup = Realm.eval(r, "var stored_global; function cleanup() { stored_global = globalThis; } cleanup");
let realm_global_this = Realm.eval(r, "globalThis");
let wf = new WeakFactory(cleanup);
let fg = new FinalizationGroup(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
// a closure so that we can reliably kill them!
// Create an object and a register it in the FinalizationGroup. The object needs
// to be inside a closure so that we can reliably kill them!
let weak_cell;
(function() {
let object = {};
weak_cell = wf.makeCell(object);
fg.register(object, {});
// object goes out of scope.
})();

View File

@ -19,17 +19,17 @@ let log = [];
let cleanup = (iter) => {
log.push("cleanup");
for (wc of iter) { }
for (holdings of iter) { }
}
let wf = new WeakFactory(cleanup);
let fg = new FinalizationGroup(cleanup);
let o = null;
(function() {
// Use a closure here to avoid other references to o which might keep it alive
// (e.g., stack frames pointing to it).
o = {};
wf.makeCell(o);
fg.register(o, {});
})();
let microtask_after_cleanup = () => {

View File

@ -9,15 +9,15 @@ let r = Realm.create();
let cleanup = Realm.eval(r, "var stored_global; let cleanup = new Proxy(function() { stored_global = globalThis;}, {}); cleanup");
let realm_global_this = Realm.eval(r, "globalThis");
let wf = new WeakFactory(cleanup);
let fg = new FinalizationGroup(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
// a closure so that we can reliably kill them!
// Create an object and register it in the FinalizationGroup. The object needs
// to be inside a closure so that we can reliably kill them!
let weak_cell;
(function() {
let object = {};
weak_cell = wf.makeCell(object);
fg.register(object, "holdings");
// object goes out of scope.
})();

View File

@ -5,31 +5,31 @@
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_count = 0;
let cleanup_cells = [];
let cleanup_holdings = [];
let cleanup = function(iter) {
for (wc of iter) {
cleanup_cells.push(wc);
for (holdings of iter) {
cleanup_holdings.push(holdings);
}
++cleanup_count;
}
let wf = new WeakFactory(cleanup);
let weak_cell;
let fg = new FinalizationGroup(cleanup);
let key = {"k": "this is the key"};
(function() {
let o = {};
weak_cell = wf.makeCell(o);
weak_cell = fg.register(o, "holdings", key);
// cleanupSome won't do anything since there are no dirty WeakCells.
wf.cleanupSome();
// cleanupSome won't do anything since there are no reclaimed targets.
fg.cleanupSome();
assertEquals(0, cleanup_count);
})();
// GC will detect the WeakCell as dirty.
gc();
// Clear the WeakCell just before we would've called cleanupSome.
weak_cell.clear();
// Unregister the tracked object just before calling cleanupSome.
fg.unregister(key);
wf.cleanupSome();
fg.cleanupSome();
assertEquals(0, cleanup_count);

View File

@ -5,29 +5,28 @@
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_count = 0;
let cleanup_cells = [];
let cleanup_holdings = [];
let cleanup = function(iter) {
for (wc of iter) {
cleanup_cells.push(wc);
for (holdings of iter) {
cleanup_holdings.push(holdings);
}
++cleanup_count;
}
let wf = new WeakFactory(cleanup);
let weak_cell;
let fg = new FinalizationGroup(cleanup);
(function() {
let o = {};
weak_cell = wf.makeCell(o);
fg.register(o, "holdings");
// cleanupSome won't do anything since there are no dirty WeakCells.
wf.cleanupSome();
// cleanupSome won't do anything since there are no reclaimed targets.
fg.cleanupSome();
assertEquals(0, cleanup_count);
})();
// GC will detect the WeakCell as dirty.
// GC will detect o as dead.
gc();
wf.cleanupSome();
fg.cleanupSome();
assertEquals(1, cleanup_count);
assertEquals(1, cleanup_cells.length);
assertEquals(weak_cell, cleanup_cells[0]);
assertEquals(1, cleanup_holdings.length);
assertEquals("holdings", cleanup_holdings[0]);

View File

@ -1,39 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup = function(iter) {
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell;
(function() {
let object = {};
weak_cell = wf.makeCell(object);
// Clear the WeakCell before the GC has a chance to discover it.
weak_cell.clear();
// Call clear again (just to assert we handle this gracefully).
weak_cell.clear();
// object goes out of scope.
})();
// This GC will discover dirty WeakCells.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function won't be called, since the WeakCell was cleared.
let timeout_func = function() {
assertEquals(0, cleanup_call_count);
}
setTimeout(timeout_func, 0);

View File

@ -1,49 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
// Test that WeakCell.prototype.clear() also clears the WeakFactory pointer of
// WeakCell. The only way to observe this is to assert that the WeakCell no
// longer keeps its WeakFactory alive after clear() has been called.
let weak_cell;
let weak_cell_pointing_to_factory;
let cleanup1_call_count = 0;
let cleanup2_call_count = 0;
let cleanup1 = function() {
++cleanup1_call_count;
}
let cleanup2 = function() {
++cleanup2_call_count;
}
let wf1 = new WeakFactory(cleanup1);
(function(){
let wf2 = new WeakFactory(cleanup2);
(function() {
let object = {};
weak_cell = wf2.makeCell(object);
// object goes out of scope.
})();
weak_cell_pointing_to_factory = wf1.makeCell(wf2);
// wf goes out of scope
})();
weak_cell.clear();
gc();
// Assert that weak_cell_pointing_to_factory now got cleared.
let timeout_func = function() {
assertEquals(1, cleanup1_call_count);
assertEquals(0, cleanup2_call_count);
}
setTimeout(timeout_func, 0);

View File

@ -1,48 +0,0 @@
// Copyright 2018 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.
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_weak_cell_count = 0;
let cleanup = function(iter) {
for (wc of iter) {
// See which WeakCell we're iterating over and clear the other one.
if (wc == weak_cell1) {
weak_cell2.clear();
} else {
assertSame(wc, weak_cell2);
weak_cell1.clear();
}
++cleanup_weak_cell_count;
}
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell1;
let weak_cell2;
(function() {
let object1 = {};
weak_cell1 = wf.makeCell(object1);
let object2 = {};
weak_cell2 = wf.makeCell(object2);
// object1 and object2 go out of scope.
})();
// This GC will discover dirty WeakCells and schedule cleanup.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called and iterated one WeakCell (but not the other one).
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(1, cleanup_weak_cell_count);
}
setTimeout(timeout_func, 0);

View File

@ -7,18 +7,19 @@
let cleanup_called = false;
let cleanup = function(iter) {
assertFalse(cleanup_called);
let cells = [];
for (wc of iter) {
cells.push(wc);
let holdings_list = [];
for (holdings of iter) {
holdings_list.push(holdings);
}
assertEquals(cells.length, 1);
assertEquals(cells[0].holdings, "this is my cell");
assertEquals(holdings_list.length, 1);
assertEquals(holdings_list[0].a, "this is the holdings object");
cleanup_called = true;
}
let wf = new WeakFactory(cleanup);
let fg = new FinalizationGroup(cleanup);
let o1 = {};
let wc1 = wf.makeCell(o1, "this is my cell");
let holdings = {'a': 'this is the holdings object'};
fg.register(o1, holdings);
gc();
assertFalse(cleanup_called);
@ -26,9 +27,9 @@ assertFalse(cleanup_called);
// Drop the last references to o1.
o1 = null;
// Drop the last reference to the WeakCell. The WeakFactory keeps it alive, so
// the cleanup function will be called as normal.
wc1 = null;
// Drop the last reference to the holdings. The FinalizationGroup keeps it
// alive, so the cleanup function will be called as normal.
holdings = null;
gc();
assertFalse(cleanup_called);

View File

@ -7,27 +7,26 @@
let cleanup_called = false;
let cleanup = function(iter) {
assertFalse(cleanup_called);
let cells = [];
for (wc of iter) {
cells.push(wc);
let holdings_list = [];
for (holdings of iter) {
holdings_list.push(holdings);
}
assertEquals(1, cells.length);
assertEquals(weak_cell, cells[0]);
assertEquals(1, holdings_list.length);
assertEquals("holdings", holdings_list[0]);
cleanup_called = true;
}
let wf = new WeakFactory(cleanup);
let fg = new FinalizationGroup(cleanup);
let weak_ref;
let weak_cell;
(function() {
let o = {};
weak_ref = new WeakRef(o);
weak_cell = wf.makeCell(o);
fg.register(o, "holdings");
})();
// Since the WeakRef was created during this turn, it is not cleared by GC. The
// WeakCell is not cleared either, since the WeakRef keeps the target object
// alive.
// pointer inside the FinalizationGroup is not cleared either, since the WeakRef
// keeps the target object alive.
gc();
(function() {
assertNotEquals(undefined, weak_ref.deref());

View File

@ -6,66 +6,66 @@
// Flags: --no-stress-flush-bytecode
let cleanup0_call_count = 0;
let cleanup0_weak_cell_count = 0;
let cleanup0_holdings_count = 0;
let cleanup1_call_count = 0;
let cleanup1_weak_cell_count = 0;
let cleanup1_holdings_count = 0;
let cleanup0 = function(iter) {
for (wc of iter) {
++cleanup0_weak_cell_count;
for (holdings of iter) {
++cleanup0_holdings_count;
}
++cleanup0_call_count;
}
let cleanup1 = function(iter) {
for (wc of iter) {
++cleanup1_weak_cell_count;
for (holdings of iter) {
++cleanup1_holdings_count;
}
++cleanup1_call_count;
}
let wf0 = new WeakFactory(cleanup0);
let wf1 = new WeakFactory(cleanup1);
let fg0 = new FinalizationGroup(cleanup0);
let fg1 = new FinalizationGroup(cleanup1);
// Create 1 WeakCell for each WeakFactory and kill the objects they point to.
// Register 1 weak reference for each FinalizationGroup and kill the objects they point to.
(function() {
// The objects need to be inside a closure so that we can reliably kill them.
let objects = [];
objects[0] = {};
objects[1] = {};
wf0.makeCell(objects[0]);
wf1.makeCell(objects[1]);
fg0.register(objects[0], "holdings0-0");
fg1.register(objects[1], "holdings1-0");
// Drop the references to the objects.
objects = [];
// Will schedule both wf0 and wf1 for cleanup.
// Will schedule both fg0 and fg1 for cleanup.
gc();
})();
// Before the cleanup task has a chance to run, do the same thing again, so both
// factories are (again) scheduled for cleanup. This has to be a IIFE function
// FinalizationGroups are (again) scheduled for cleanup. This has to be a IIFE function
// (so that we can reliably kill the objects) so we cannot use the same function
// as before.
(function() {
let objects = [];
objects[0] = {};
objects[1] = {};
wf0.makeCell(objects[0]);
wf1.makeCell(objects[1]);
fg0.register(objects[0], "holdings0-1");
fg1.register(objects[1], "holdings1-1");
objects = [];
gc();
})();
let timeout_func = function() {
assertEquals(1, cleanup0_call_count);
assertEquals(2, cleanup0_weak_cell_count);
assertEquals(2, cleanup0_holdings_count);
assertEquals(1, cleanup1_call_count);
assertEquals(2, cleanup1_weak_cell_count);
assertEquals(2, cleanup1_holdings_count);
}
// Give the cleanup task a chance to run. All WeakCells to cleanup will be
// available during the same invocation of the cleanup function.
// Give the cleanup task a chance to run. All holdings will be iterated during
// the same invocation of the cleanup function.
setTimeout(timeout_func, 0);

View File

@ -7,29 +7,25 @@
let cleanup_called = false;
let cleanup = function(iter) {
assertFalse(cleanup_called);
let cells = [];
for (wc of iter) {
cells.push(wc);
let holdings_list = [];
for (holdings of iter) {
holdings_list.push(holdings);
}
assertEquals(cells.length, 2);
if (cells[0] == wc1) {
assertEquals(cells[0].holdings, 1);
assertEquals(cells[1], wc2);
assertEquals(cells[1].holdings, 2);
assertEquals(holdings_list.length, 2);
if (holdings_list[0] == 1) {
assertEquals(holdings_list[1], 2);
} else {
assertEquals(cells[0], wc2);
assertEquals(cells[0].holdings, 2);
assertEquals(cells[1], wc1);
assertEquals(cells[1].holdings, 1);
assertEquals(holdings_list[0], 2);
assertEquals(holdings_list[1], 1);
}
cleanup_called = true;
}
let wf = new WeakFactory(cleanup);
let fg = new FinalizationGroup(cleanup);
let o1 = {};
let o2 = {};
let wc1 = wf.makeCell(o1, 1);
let wc2 = wf.makeCell(o2, 2);
fg.register(o1, 1);
fg.register(o2, 2);
gc();
assertFalse(cleanup_called);
@ -37,8 +33,8 @@ assertFalse(cleanup_called);
// Drop the last references to o1 and o2.
o1 = null;
o2 = null;
// GC will clear the WeakCells; the cleanup function will be called the next time
// we enter the event loop.
// GC will reclaim the target objects; the cleanup function will be called the
// next time we enter the event loop.
gc();
assertFalse(cleanup_called);

View File

@ -5,28 +5,26 @@
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_weak_cell_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
for (wc of iter) {
++cleanup_weak_cell_count;
for (holdings of iter) {
++cleanup_holdings_count;
}
++cleanup_call_count;
}
let wf1 = new WeakFactory(cleanup);
let wf2 = new WeakFactory(cleanup);
let fg1 = new FinalizationGroup(cleanup);
let fg2 = new FinalizationGroup(cleanup);
// Create two objects and WeakCells pointing to them. The objects need to be inside
// a closure so that we can reliably kill them!
let weak_cell1;
let weak_cell2;
// Create two objects and register them in FinalizationGroups. The objects need
// to be inside a closure so that we can reliably kill them!
(function() {
let object1 = {};
weak_cell1 = wf1.makeCell(object1);
fg1.register(object1, "holdings1");
let object2 = {};
weak_cell2 = wf2.makeCell(object2);
fg2.register(object2, "holdings2");
// object1 and object2 go out of scope.
})();
@ -35,10 +33,10 @@ let weak_cell2;
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called and iterated the WeakCells.
// Assert that the cleanup function was called and iterated the holdings.
let timeout_func = function() {
assertEquals(2, cleanup_call_count);
assertEquals(2, cleanup_weak_cell_count);
assertEquals(2, cleanup_holdings_count);
}
setTimeout(timeout_func, 0);

View File

@ -0,0 +1,39 @@
// 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.
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
for (holdings of iter) {
assertEquals(holdings, undefined);
++cleanup_holdings_count;
}
++cleanup_call_count;
}
let fg = new FinalizationGroup(cleanup);
// Create an object and register it in the FinalizationGroup. The object needs to be inside
// a closure so that we can reliably kill them!
(function() {
let object = {};
fg.register(object);
// object goes out of scope.
})();
// This GC will reclaim the target object and schedule cleanup.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called and iterated the holdings.
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(1, cleanup_holdings_count);
}
setTimeout(timeout_func, 0);

View File

@ -5,42 +5,42 @@
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_weak_cell_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
for (wc of iter) {
assertSame(wc, weak_cell);
++cleanup_weak_cell_count;
for (holdings of iter) {
assertEquals("holdings", holdings);
++cleanup_holdings_count;
}
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell;
let fg = new FinalizationGroup(cleanup);
let key = {"k": "this is the key"};
// Create an object and register it in the FinalizationGroup. The object needs
// to be inside a closure so that we can reliably kill them!
(function() {
let object = {};
weak_cell = wf.makeCell(object);
fg.register(object, "holdings", key);
// object goes out of scope.
})();
// This GC will discover dirty WeakCells and schedule cleanup.
// This GC will reclaim the target object and schedule cleanup.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called and iterated the WeakCell.
// Assert that the cleanup function was called and iterated the holdings.
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(1, cleanup_weak_cell_count);
assertEquals(1, cleanup_holdings_count);
// Clear an already iterated over WeakCell.
weak_cell.clear();
// Unregister an already iterated over weak reference.
fg.unregister(key);
// Assert that it didn't do anything.
setTimeout(() => { assertEquals(1, cleanup_call_count); }, 0);
setTimeout(() => { assertEquals(1, cleanup_weak_cell_count); }, 0);
setTimeout(() => { assertEquals(1, cleanup_holdings_count); }, 0);
}
setTimeout(timeout_func, 0);

View File

@ -9,30 +9,27 @@ let cleanup = function(iter) {
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell;
let fg = new FinalizationGroup(cleanup);
let key = {"k": "this is the key"};
// Create an object and register it in the FinalizationGroup. The object needs
// to be inside a closure so that we can reliably kill them!
(function() {
let object = {};
weak_cell = wf.makeCell(object, "my holdings");
fg.register(object, "my holdings", key);
// Clear the WeakCell before the GC has a chance to discover it.
let return_value = weak_cell.clear();
let return_value = fg.unregister(key);
assertEquals(undefined, return_value);
// Assert holdings got cleared too.
assertEquals(undefined, weak_cell.holdings);
// object goes out of scope.
})();
// This GC will discover dirty WeakCells.
// This GC will reclaim the target object.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function won't be called, since the WeakCell was cleared.
// Assert that the cleanup function won't be called, since we called unregister.
let timeout_func = function() {
assertEquals(0, cleanup_call_count);
}

View File

@ -0,0 +1,40 @@
// Copyright 2018 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.
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup = function(iter) {
++cleanup_call_count;
}
let fg = new FinalizationGroup(cleanup);
let key = {"k": "this is the key"};
// Create an object and register it in the FinalizationGroup. The object needs
// to be inside a closure so that we can reliably kill them!
(function() {
let object = {};
fg.register(object, "holdings", key);
// Unregister before the GC has a chance to discover the object.
fg.unregister(key);
// Call unregister again (just to assert we handle this gracefully).
fg.unregister(key);
// object goes out of scope.
})();
// This GC will reclaim the target object.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function won't be called, since the weak reference
// was unregistered.
let timeout_func = function() {
assertEquals(0, cleanup_call_count);
}
setTimeout(timeout_func, 0);

View File

@ -5,37 +5,37 @@
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_weak_cell_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
// Clear the WeakCell before we've iterated through it.
weak_cell.clear();
// Unregister before we've iterated through the holdings.
fg.unregister(key);
for (wc of iter) {
++cleanup_weak_cell_count;
++cleanup_holdings_count;
}
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell;
let fg = new FinalizationGroup(cleanup);
let key = {"k": "the key"};
// Create an object and register it in the FinalizationGroup. The object needs
// to be inside a closure so that we can reliably kill them!
(function() {
let object = {};
weak_cell = wf.makeCell(object);
fg.register(object, "holdings", key);
// object goes out of scope.
})();
// This GC will discover dirty WeakCells and schedule cleanup.
// This GC will discover unretained targets and schedule cleanup.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called, but didn't iterate any weak cells.
// Assert that the cleanup function was called, but didn't iterate any holdings.
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(0, cleanup_weak_cell_count);
assertEquals(0, cleanup_holdings_count);
}
setTimeout(timeout_func, 0);

View File

@ -5,24 +5,24 @@
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_weak_cell_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
for (wc of iter) {
assertSame(wc, weak_cell);
wc.clear();
++cleanup_weak_cell_count;
for (holdings of iter) {
assertEquals(holdings, "holdings");
fg.unregister(key);
++cleanup_holdings_count;
}
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
let fg = new FinalizationGroup(cleanup);
// Create an object and register it in the FinalizationGroup. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell;
let key = {"k": "this is the key"};
(function() {
let object = {};
weak_cell = wf.makeCell(object);
fg.register(object, "holdings", key);
// object goes out of scope.
})();
@ -34,7 +34,7 @@ assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called and iterated the WeakCell.
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(1, cleanup_weak_cell_count);
assertEquals(1, cleanup_holdings_count);
}
setTimeout(timeout_func, 0);

View File

@ -5,37 +5,38 @@
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_weak_cell_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
for (wc of iter) {
assertSame(wc, weak_cell);
++cleanup_weak_cell_count;
for (holdings of iter) {
assertEquals(holdings, "holdings");
++cleanup_holdings_count;
}
// Clear an already iterated over WeakCell.
weak_cell.clear();
// Unregister an already iterated over weak reference.
fg.unregister(key);
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
let fg = new FinalizationGroup(cleanup);
let key = {"k": "this is the key"};
// Create an object and register it in the FinalizationGroup. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell;
(function() {
let object = {};
weak_cell = wf.makeCell(object);
fg.register(object, "holdings", key);
// object goes out of scope.
})();
// This GC will discover dirty WeakCells and schedule cleanup.
// This GC will reclaim the target object and schedule cleanup.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called and iterated the WeakCell.
// Assert that the cleanup function was called and iterated the holdings.
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(1, cleanup_weak_cell_count);
assertEquals(1, cleanup_holdings_count);
}
setTimeout(timeout_func, 0);

View File

@ -0,0 +1,48 @@
// Copyright 2018 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.
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
for (holdings of iter) {
// See which target we're iterating over and unregister the other one.
if (holdings == 1) {
fg.unregister(key2);
} else {
assertSame(holdings, 2);
fg.unregister(key1);
}
++cleanup_holdings_count;
}
++cleanup_call_count;
}
let fg = new FinalizationGroup(cleanup);
let key1 = {"k": "first key"};
let key2 = {"k": "second key"};
// Create two objects and register them in the FinalizationGroup. The objects
// need to be inside a closure so that we can reliably kill them!
(function() {
let object1 = {};
fg.register(object1, 1, key1);
let object2 = {};
fg.register(object2, 2, key2);
// object1 and object2 go out of scope.
})();
// This GC will reclaim target objects and schedule cleanup.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function was called and iterated one holdings (but not the other one).
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(1, cleanup_holdings_count);
}
setTimeout(timeout_func, 0);

View File

@ -0,0 +1,50 @@
// 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.
// Flags: --harmony-weak-refs --expose-gc --noincremental-marking
let cleanup_call_count = 0;
let cleanup_holdings_count = 0;
let cleanup = function(iter) {
for (holdings of iter) {
assertEquals("holdings2", holdings);
++cleanup_holdings_count;
}
++cleanup_call_count;
}
let fg = new FinalizationGroup(cleanup);
let key1 = {"k": "key1"};
let key2 = {"k": "key2"};
// Create three objects and register them in the FinalizationGroup. The objects
// need to be inside a closure so that we can reliably kill them!
(function() {
let object1a = {};
fg.register(object1a, "holdings1a", key1);
let object1b = {};
fg.register(object1b, "holdings1b", key1);
let object2 = {};
fg.register(object2, "holdings2", key2);
// Unregister before the GC has a chance to discover the objects.
fg.unregister(key1);
// objects go out of scope.
})();
// This GC will reclaim the target objects.
gc();
assertEquals(0, cleanup_call_count);
// Assert that the cleanup function will be called only for the reference which
// was not unregistered.
let timeout_func = function() {
assertEquals(1, cleanup_call_count);
assertEquals(1, cleanup_holdings_count);
}
setTimeout(timeout_func, 0);

View File

@ -9,14 +9,14 @@ let cleanup = function(iter) {
++cleanup_call_count;
}
let wf = new WeakFactory(cleanup);
// Create an object and a WeakCell pointing to it. The object needs to be inside
let key = {"k": "this is my key"};
let fg = new FinalizationGroup(cleanup);
// Create an object and register it in the FinalizationGroup. The object needs to be inside
// a closure so that we can reliably kill them!
let weak_cell;
(function() {
let object = {};
weak_cell = wf.makeCell(object);
fg.register(object, {}, key);
// object goes out of scope.
})();
@ -25,10 +25,10 @@ let weak_cell;
gc();
assertEquals(0, cleanup_call_count);
// Clear the WeakCell before cleanup has ran.
weak_cell.clear();
// Unregister the object from the FinalizationGroup before cleanup has ran.
fg.unregister(key);
// Assert that the cleanup function won't be called, since the WeakCell was cleared.
// Assert that the cleanup function won't be called.
let timeout_func = function() {
assertEquals(0, cleanup_call_count);
}

View File

@ -8,16 +8,17 @@ let cleanup_called = false;
let cleanup = function(iter) {
assertFalse(cleanup_called);
let result = iter.next();
assertEquals(result.value, wc);
assertEquals(result.value, holdings);
assertFalse(result.done);
result = iter.next();
assertTrue(result.done);
cleanup_called = true;
}
let wf = new WeakFactory(cleanup);
let fg = new FinalizationGroup(cleanup);
let o = {};
let wc = wf.makeCell(o);
let holdings = {'h': 55};
fg.register(o, holdings);
gc();
assertFalse(cleanup_called);

View File

@ -0,0 +1,166 @@
// 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.
// Flags: --allow-natives-syntax
(function SealAndReconfigure() {
function C() { this.x = 1; this.y = 1; Object.seal(this); }
let c1 = new C();
c1.x = 0.1;
let c2 = new C();
let c3 = new C();
let c4 = new C();
// The objects c2, c3 and c4 should follow the same transition
// path that we reconfigured c1 to.
assertTrue(%HaveSameMap(c1, c2));
assertTrue(%HaveSameMap(c1, c3));
assertTrue(%HaveSameMap(c1, c4));
c2.x = 0.1;
c3.x = 0.1;
c4.x = 0.1;
assertTrue(%HaveSameMap(c1, c2));
assertTrue(%HaveSameMap(c1, c3));
assertTrue(%HaveSameMap(c1, c4));
})();
(function SealAndReconfigureWithIC() {
function C() { this.x = 1; this.y = 1; Object.seal(this); }
let c1 = new C();
function g(o) {
o.x = 0.1;
}
g(c1);
let c2 = new C();
let c3 = new C();
let c4 = new C();
// The objects c2, c3 and c4 should follow the same transition
// path that we reconfigured c1 to.
assertTrue(%HaveSameMap(c1, c2));
assertTrue(%HaveSameMap(c1, c3));
assertTrue(%HaveSameMap(c1, c4));
g(c2);
g(c3);
g(c4);
assertTrue(%HaveSameMap(c1, c2));
assertTrue(%HaveSameMap(c1, c3));
assertTrue(%HaveSameMap(c1, c4));
})();
(function SealReconfigureAndMigrateWithIC() {
function C() { this.x = 1; this.y = 1; Object.seal(this); }
let c1 = new C();
let c2 = new C();
let c3 = new C();
let c4 = new C();
function g(o) {
o.x = 0.1;
}
g(c1);
// Now c2, c3 and c4 have deprecated maps.
assertFalse(%HaveSameMap(c1, c2));
assertFalse(%HaveSameMap(c1, c3));
assertFalse(%HaveSameMap(c1, c4));
g(c2);
g(c3);
g(c4);
assertTrue(%HaveSameMap(c1, c2));
assertTrue(%HaveSameMap(c1, c3));
assertTrue(%HaveSameMap(c1, c4));
})();
(function SealReconfigureAndMigrateWithOptCode() {
function C() { this.x = 1; this.y = 1; Object.seal(this); }
let c1 = new C();
let c2 = new C();
let c3 = new C();
let c4 = new C();
function g(o) {
o.x = 0.1;
}
g(c1);
g(c2);
g(c3);
%OptimizeFunctionOnNextCall(g);
g(c4);
assertTrue(%HaveSameMap(c1, c2));
assertTrue(%HaveSameMap(c1, c3));
assertTrue(%HaveSameMap(c1, c4));
})();
(function PreventExtensionsAndReconfigure() {
function C() { this.x = 1; this.y = 1; Object.preventExtensions(this); }
let c1 = new C();
function g(o) {
o.x = 0.1;
}
g(c1);
let c2 = new C();
let c3 = new C();
let c4 = new C();
c2.x = 0.1;
c3.x = 0.1;
c4.x = 0.1;
assertTrue(%HaveSameMap(c1, c2));
assertTrue(%HaveSameMap(c1, c3));
assertTrue(%HaveSameMap(c1, c4));
})();
(function PreventExtensionsSealAndReconfigure() {
function C() {
this.x = 1;
this.y = 1;
Object.preventExtensions(this);
Object.seal(this);
}
let c1 = new C();
function g(o) {
o.x = 0.1;
}
g(c1);
let c2 = new C();
let c3 = new C();
let c4 = new C();
c2.x = 0.1;
c3.x = 0.1;
c4.x = 0.1;
// Ideally, all the objects would have the same map, but at the moment
// we shortcut the unnecessary integrity level transitions.
assertTrue(%HaveSameMap(c2, c3));
assertTrue(%HaveSameMap(c2, c4));
})();

View File

@ -126,13 +126,6 @@ test(function() {
[].join(o);
}, "Cannot convert object to primitive value", TypeError);
// kCircularStructure
test(function() {
var o = {};
o.o = o;
JSON.stringify(o);
}, "Converting circular structure to JSON", TypeError);
// kConstructorNotFunction
test(function() {
Map();

View File

@ -213,7 +213,7 @@ var prettyPrinted;
// TODO(neis): Remove try-catch once BigInts are enabled by default.
try {
BigIntPrototypeValueOf = BigInt.prototype.valueOf;
} catch(e) {}
} catch (e) {}
function classOf(object) {
// Argument must not be null or undefined.
@ -480,14 +480,17 @@ var prettyPrinted;
}
};
function executeCode(code) {
if (typeof code === 'function') return code();
if (typeof code === 'string') return eval(code);
failWithMessage(
'Given code is neither function nor string, but ' + (typeof code) +
': <' + prettyPrinted(code) + '>');
}
assertThrows = function assertThrows(code, type_opt, cause_opt) {
try {
if (typeof code === 'function') {
code();
} else {
eval(code);
}
executeCode(code);
} catch (e) {
if (typeof type_opt === 'function') {
assertInstanceof(e, type_opt);
@ -508,11 +511,10 @@ var prettyPrinted;
failWithMessage("Did not throw exception");
};
assertThrowsEquals = function assertThrowsEquals(fun, val) {
try {
fun();
} catch(e) {
} catch (e) {
assertSame(val, e);
return;
}
@ -533,15 +535,11 @@ var prettyPrinted;
}
};
assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) {
assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) {
try {
if (typeof code === 'function') {
return code();
} else {
return eval(code);
}
executeCode(code);
} catch (e) {
if (e instanceof MjsUnitAssertionError) throw e;
failWithMessage("threw an exception: " + (e.message || e));
}
};
@ -584,13 +582,15 @@ var prettyPrinted;
}
assertPromiseResult = function(promise, success, fail) {
if (success !== undefined) assertEquals('function', typeof success);
if (fail !== undefined) assertEquals('function', typeof fail);
const stack = (new Error()).stack;
var test_promise = promise.then(
result => {
try {
if (--promiseTestCount == 0) testRunner.notifyDone();
if (success) success(result);
if (success !== undefined) success(result);
} catch (e) {
// Use setTimeout to throw the error again to get out of the promise
// chain.
@ -602,7 +602,7 @@ var prettyPrinted;
result => {
try {
if (--promiseTestCount == 0) testRunner.notifyDone();
if (!fail) throw result;
if (fail === undefined) throw result;
fail(result);
} catch (e) {
// Use setTimeout to throw the error again to get out of the promise
@ -667,7 +667,9 @@ var prettyPrinted;
// option is provided. Such tests must add --opt to flags comment.
assertFalse((opt_status & V8OptimizationStatus.kNeverOptimize) !== 0,
"test does not make sense with --no-opt");
assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, name_opt);
assertTrue(
(opt_status & V8OptimizationStatus.kIsFunction) !== 0,
'should be a function: ' + name_opt);
if (skip_if_maybe_deopted &&
(opt_status & V8OptimizationStatus.kMaybeDeopted) !== 0) {
// When --deopt-every-n-times flag is specified it's no longer guaranteed
@ -675,7 +677,9 @@ var prettyPrinted;
// to stress test the deoptimizer.
return;
}
assertTrue((opt_status & V8OptimizationStatus.kOptimized) !== 0, name_opt);
assertTrue(
(opt_status & V8OptimizationStatus.kOptimized) !== 0,
'should be optimized: ' + name_opt);
}
isNeverOptimizeLiteMode = function isNeverOptimizeLiteMode() {
@ -772,7 +776,7 @@ var prettyPrinted;
return frame;
});
return "" + error.message + "\n" + ArrayPrototypeJoin.call(stack, "\n");
} catch(e) {};
} catch (e) {};
return error.stack;
}
})();

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@ var p = "floor";
function test() {
var bignumber = 31363200000;
assertDoesNotThrow(assertEquals(m[p](Math.round(bignumber/864E5)/7)+1, 52));
assertEquals(m[p](Math.round(bignumber/864E5)/7)+1, 52);
}
test();

View File

@ -16,4 +16,4 @@ f(str, 0);
f(str, 0);
// This is just to trigger elements validation, object already broken.
%SetKeyedProperty(str, 1, 'y', 0);
%SetKeyedProperty(str, 1, 'y');

View File

@ -28,11 +28,10 @@
// Flags: --max-old-space-size=1600
assertThrows((function() {
s = "Hello World!\n";
while (true) {
x = new Array();
x[0] = s;
x[1000] = s;
x[10000] = s;
s = x.join("::");
}}), RangeError);
let str = "a".repeat(1e7);
let arr = new Array(2000);
for (let i = 0; i < 200; ++i) {
arr[i*10] = str;
}
let res = arr.join(':');
}), RangeError);

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
(function() {

View File

@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
(function() {

View File

@ -0,0 +1,21 @@
// 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.
// ensure `delete this` throws before `super` is called.
assertThrows(()=>{
new class extends Object {
constructor() {
delete this;
super();
}
}
}, ReferenceError);
// ensure `delete this` doesn't throw after `super` is called.
new class extends Object {
constructor() {
super();
delete this;
}
}

View File

@ -29,9 +29,8 @@
// update a accessor property to a data property using Object.defineProperty.
var obj = { get value() {}, set value (v) { throw "Error";} };
assertDoesNotThrow(
Object.defineProperty(obj, "value",
{ value: 5, writable:true, configurable: true }));
Object.defineProperty(obj, "value",
{ value: 5, writable:true, configurable: true });
var desc = Object.getOwnPropertyDescriptor(obj, "value");
assertEquals(obj.value, 5);
assertTrue(desc.configurable);
@ -49,7 +48,7 @@ var proto = {
var create = Object.create(proto);
assertEquals(create.value, undefined);
assertDoesNotThrow(create.value = 4);
create.value = 4;
assertEquals(create.value, 4);
// These tests where provided in bug 959, but are all related to the this issue.

View File

@ -4,7 +4,6 @@
// Flags: --invoke-weak-callbacks --omit-quit --expose-wasm --allow-natives-syntax
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
const builder = new WasmModuleBuilder();

View File

@ -4,7 +4,6 @@
// Flags: --no-liftoff --no-wasm-tier-up --no-future --debug-code
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();

View File

@ -0,0 +1,10 @@
// 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.
// Flags: --stack-size=100
let array = new Array(1);
array.splice(1, 0, array);
assertThrows(() => array.flat(Infinity), RangeError);

View File

@ -0,0 +1,14 @@
// 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.
// Flags: --stack-size=50
function __f_3() {
try {
__f_3();
} catch(e) {
eval("let fun = ({a} = {a: 30}) => {");
}
}
assertThrows(__f_3);

View File

@ -0,0 +1,5 @@
// 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.
assertThrows("async() => { for await (var a ;;) {} }", SyntaxError);

View File

@ -20,6 +20,6 @@ for (var i = 0; i < test_set.length; ++i) {
src = src.replace(/MODULE/g, "Module" + i);
src = src.replace(/LIMIT/g, test_set[i]);
var module = eval("(" + src + ")");
assertDoesNotThrow(module(this).f());
module(this).f();
assertFalse(%IsAsmWasmCode(module));
}

View File

@ -4,7 +4,6 @@
// Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder();
@ -14,4 +13,4 @@ let table = new WebAssembly.Table({element: "anyfunc",
initial: 1, maximum:1000000});
let instance = new WebAssembly.Instance(module, {x: {table:table}});
assertThrows(() => table.grow(Infinity), RangeError);
assertThrows(() => table.grow(Infinity), TypeError);

View File

@ -0,0 +1,27 @@
// 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.
// Flags: --verify-heap --expose-gc
let paramName = '';
for (let i=0; i < 2**10; i++) {
paramName += 'a';
}
let params = '';
for (let i = 0; i < 2**10; i++) {
params += paramName + i + ',';
}
let fn = eval(`(
class A {
constructor (${params}) {
function lazy() {
return function lazier() { return ${paramName+1} }
};
return lazy;
}
})`);
gc()

View File

@ -0,0 +1,9 @@
// 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.
let a = {0: 5, 1: 4, 2: 3, length: 2};
Object.freeze(a);
assertThrows(() => Array.prototype.sort.call(a));
assertPropertiesEqual({0: 5, 1: 4, 2: 3, length: 2}, a);

View File

@ -0,0 +1,15 @@
// 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.
// Flags: --verify-heap
function __f_5() {
function __f_1() {
function __f_0() {
({y = eval()}) => assertEquals()();
}
}
}
__f_5();

View File

@ -0,0 +1,5 @@
// Copyright 2015 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.
assertThrows("a(function(){{let f;function f}})", SyntaxError);

View File

@ -0,0 +1,18 @@
// 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.
// Need a fast array with enough elements to surpass
// kMaxRegularHeapObjectSize.
var size = 63392;
var a = [];
function build() {
for (let i = 0; i < size; i++) {
a.push(i);
}
}
build();
function c(v) { return v + 0.5; }
a.map(c);

View File

@ -4,7 +4,6 @@
// Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
(function() {

View File

@ -264,7 +264,6 @@ var __v_11 = this;
var __v_12 = {};
var __v_13 = {};
try {
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-__v_1.js");
__v_2 = 0x10000;
} catch (e) {

View File

@ -4,7 +4,6 @@
// Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
(function() {

Some files were not shown because too many files have changed in this diff Show More