← 返回 💻 编程 & 软件工程

Notable V8 changes from Node.js 26 to 27 (Alpha)

Node.js Blog 11月5日 nodejs.org

The Node.js 27 Alpha release upgrades V8 to version 15.6, from the 14.6 used by Node.js 26, bringing several new JavaScript language features and improvements. In this post, let's explore the notable V8 changes introduced in this release that are interesting for Node.js developers.

Before we dive in, keep in mind that after Node.js switches to a new release schedule with an Alpha phase, Node.js may introduce breaking V8 changes, such as a bulk V8 upgrade, during the Alpha and Current phases. Breakages that affect the native addon ABI will come with a NODE_MODULE_VERSION bump, allowing toolchains that select prebuilt native addons by ABI version to continue working. Once the 27 release enters LTS, the V8 version in this release line is expected to remain stable, and no ABI or API breaking changes are expected except in exceptional circumstances, such as critical security fixes.

Compared to summing up numbers in a loop, Math.sumPrecise reduces the accumulation of floating-point errors.

The new Intl.Locale.prototype.variants getter provides access to the variants of a locale.

Several new iterator methods have been added in this release:

Some fixes have been made to these experimental language features that were already available in v26:

The new version of Node.js uses LLVM's libm for some Math methods, which leads to slightly different results for some inputs compared to the previous implementation. Code that compares floating point results to hard-coded values from an older version of Node.js may be broken by a difference in the last bit.

Math.random() now runs the xorshift128+ generator directly and no longer uses a cache, and the sequence of values returned now changes for a given --random-seed.

The value returned by Date.prototype.getTimezoneOffset() is no longer truncated to whole minutes. For historical dates when the time zone used a local mean time offset that is not a whole number of minutes (typically before the zone adopted standard time), the returned value can contain a fraction.

V8 now uses PowerSort instead of TimSort in Array.prototype.sort() for bigger arrays. The sort is still stable and the result from using a consistent comparator remains the same, but tests that record comparator calls or comparators with side effects can now behave differently.

The error.stack getter no longer looks up the captured stack trace from the prototype chain, as required by the error stack accessor proposal. Errors created with new, error subclasses and objects passed to Error.captureStackTrace are not affected.

When an ES module with top-level await is evaluated, as the specification requires, V8 no longer calls Promise.prototype.then() in a way that looks up constructor and Symbol.species on the promise.

When the callback passed to Promise.try returns a promise whose constructor is Promise in the same realm, Promise.try now returns that promise directly, see ecma262#3883.

Calling Atomics.wait() on a worker thread that is already blocked by Atomics.wait() now throws a TypeError instead of crashing the process. This usually only happens when a debugger evaluates code on a worker thread blocked by Atomics.wait().

Atomics.notify(), Atomics.wait() and Atomics.waitAsync() now read the length of the typed array before coercing the index, as the specification requires. If the coercion leads to a growth of the buffer, an index that is originally out of bounds still results in RangeError.

Passing a finite limit above 2^53-1 to take() and drop() leads to RangeError and closes the iterator, as specified in ecma262#3776. An Infinity limit is still valid.

AsyncIterator.prototype[Symbol.asyncDispose] now calls return() with no arguments, as the explicit resource management proposal specifies.

new import(...).x now correctly leads to SyntaxError, like new import(...):

A few edge cases (1, 2) that used to result in crashes during module loading now reject with appropriate errors instead.

Negative lookahead and lookbehind assertions no longer match inside surrogate pairs in /u and /v mode.

TypedArray.prototype.subarray(), when called on a length-tracking typed array subclass over a resizable ArrayBuffer without an end argument, now only passes the buffer and the byte offset to the subclass constructor, and omits the third undefined length argument, as the specification requires.

Float16Array.prototype.indexOf(), lastIndexOf() and includes() now support negative values.

TypedArray.prototype.set() with a negative offset on an immutable buffer now throws TypeError before RangeError.

await and return inside static class initialization blocks after instance members now correctly lead to SyntaxError.

using in a C-style for loop initializer is now disposed once and treated as immutable, according to the explicit resource management proposal.

Escaped get and set as class field names followed by a newline now get automatic semicolon insertion. See also test262#5134.

delete super[key] now checks the this binding before evaluating key.

new Function(...) now consults the code generation policy before converting arguments.

In Node.js 27, more fatal V8 errors are now handled by Node.js's fatal error handling before aborting, so --report-on-fatalerror can produce a diagnostic report in cases where Node.js would previously abort without one.

Some extreme use of language features such as overly long template literals, classes with too many elements, Object.defineProperties with too many properties, a regexp that is too large to compile etc. now throw RangeError instead of crashing the process. This is not guaranteed and should not be relied upon for program logic, however.

v8.serialize(), structuredClone() and postMessage now use a new serialization format. Older Node.js releases cannot deserialize data serialized by this version and will fail with an "invalid or unsupported version" error. This version can still deserialize data serialized by older releases. The new format supports typed arrays and resizable ArrayBuffers larger than 4 GB in structuredClone() and postMessage(). v8.serialize() currently still retains the 4 GB limit.

The v8.cachedDataVersionTag() now changes whenever Node.js applies its own patches on top of V8, not only when the V8 version changes. In addition, the built-in module compilation cache and cached data from vm.Script/vm.Module can be invalidated more often across Node.js releases. This improves safety, since a patched V8 can produce different compiled code, but it does introduce more cache misses across Node.js patch and minor releases.

The performance impact described here can vary depending on platform, workload and build configurations. The numbers referenced below are only relevant to the benchmarks mentioned.

Heap snapshots now include more detailed information about the JavaScript heap. Taking a snapshot can take about twice as long and the file is about twice as large.

在原文站打开 ↗

Cloudflare Workers 每 3 分钟抓一批,9 批轮完最快约 27 分钟 · 点右上 ↻ 立刻全量抓一次