1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
// Copyright 2025 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.
// *********************************** ES2016
(() => {
// Exponentiation operator
let v = 2 ** 2;
v **= 3;
})();
// *********************************** ES2018
(() => {
// Async generators
async function* foo1() {
await 42;
yield 0;
}
async function foo2() {
for await (let a of b) {
bar1(x);
}
}
})();
(() => {
// Dotall regexp
/./s;
/./su;
})();
(() => {
// Named capturing groups regex
let v = /(?<month>\d{2})-(?<day>\d{2})/;
v.exec("11-11").groups.month;
})();
(() => {
// Rest
let { a, ...b } = { x: 1, y: 2, z: 3 };
// Spread
let v = { a, ...b };
})();
// *********************************** ES2019
(() => {
// Optional catch binding
try {
throw 0;
} catch {
foo();
} finally {
bar();
}
})();
(() => {
// Json strings - here: "a\u2028b"
"a
b";
})();
// *********************************** ES2020
(() => {
// BigInts
let v1 = 6n;
let v2 = BigInt(1234546) + v1;
let v3 = 0b1000011n;
})();
(() => {
// Nullish coalescing operator
object.foo ?? "42";
})();
(() => {
// Optional chaining
const obj = {
foo: {
bar: 42,
},
};
obj?.foo?.bar;
obj?.meh?.bar;
obj?.meh?.bar();
})();
// *********************************** ES2021
(() => {
// Numeric separator
let v1 = 1_000_000_000_000;
let v2 = 0b1010_0001;
})();
(() => {
// Logical assignment operators
let v = false;
v ||= true;
})();
// *********************************** ES2022
(() => {
// Private methods and properties
// Private property in object
class Foo {
#xValue = 0;
get #x() {
return this.#xValue;
}
set #x(value) {
this.#xValue = value;
}
#inc() {
this.#x++;
}
baz(obj) {
return #xValue in obj;
}
}
})();
(() => {
// Class properties
class Foo {
prop = "42";
fun = () => {
return this.prop;
};
static staticProp = "42";
static staticFun = function() {
return Foo2.staticProp;
};
}
})();
(() => {
// Class static block
class Foo {
static #a = 42;
static b;
static {
this.b = bar(this.#a);
}
}
})();
// *********************************** ES2024
(() => {
// Unicode sets regex
/[\p{Decimal_Number}&&\p{ASCII}]/v;
})();
// *********************************** ES2025
(() => {
// Duplicate named capturing groups regex
let v = /(?<month>\d{2})-(?<year>\d{4})|(?<year>\d{4})-(?<month>\d{2})/;
v.exec("11-1111").groups.year;
})();
(() => {
// Regexp modifiers
/(?i:a)a/;
/(?m:^a)a/;
/(?s:.)./;
/(?im:^a)a/;
})();
// *********************************** Proposals
(() => {
// Do expressions
let v = do {
if (v) {
("1");
} else {
("2");
}
};
})();
(() => {
// Explicit resource management
async function foo() {
using sync = openSync();
await using async = await openAsync();
}
})();
|