V8 Release V9.1 04 May 2021
V8 release v9.1
Chrome V8 released v9.1 on May 4, bringing several new features
A,Top-level await
(at the topawait
)
Top-level await is enabled by default in V8 starting with v9.1 and is available without –harmony-top-level-await.
In short: we can use await in the module top-level without adding async in addition
So happy, so you can avoid some redundant code
Try… (Please update your Chrome browser to the latest version)
1. Add the following code to the pagesleep
Delay the function and open the page
<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="Width = device - width, initial - scale = 1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
const sleep = (time = 500) = > {
console.log('sleep execution')
return new Promise((resolve) = > {
setTimeout(() = > {
resolve(true)
}, time)
})
}
await sleep()
</script>
Copy the code
It was a mistake…
await is only valid in async functions and the top level bodies of modules
Await is valid only in the top-level body of asynchronous functions and modules
So, let’s change the script to module and open the page again.
<script type="module">
const sleep = (time = 500) = > {
console.log('sleep execution')
return new Promise((resolve) = > {
setTimeout(() = > {
resolve(true)
}, time)
})
}
await sleep()
</script>
Copy the code
The operation succeeds.
Tips:
Top-level await only works at the top level of modules. There is no support for classic scripts or non-async functions.
The top-level await applies only to the top level of the module. There is no support for classical scripts or non-asynchronous functions.
Second,Private brand checks a.k.a. #foo in obj
The private brands check syntax is enabled by default in v9.1 without requiring –harmony-private-brand-checks. This feature extends the in operator to also work with private fields’ #-names.
In short, it extends the in operator’s ability to check private attributes
Example 1.
class A {
static test(obj) {
console.log(#foo in obj);
}
#foo = 0;
}
A.test(new A()); // true
A.test({}); // false
class B {
#foo = 0;
}
A.test(new B()); // false; it's not the same #foo
Copy the code
Short built-in calls
reference
V8 v9.1