Skip to content

Commit

Permalink
prevent V8 ArrayBufferDetaching protector cell invalidation and perfo…
Browse files Browse the repository at this point in the history
…rmance degradation

one more case of #679
  • Loading branch information
zloirock committed Jun 11, 2022
1 parent 6338c5f commit e1a0d39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@
- Added `Array.prototype.unshift` polyfill with some fixes for modern engines
- Fixed a bug in the order of getting flags in `RegExp.prototype.flags` in the actual version of V8
- Fixed property descriptors of some `Math` and `Number` constants
- Added a workaround of V8 `ArrayBufferDetaching` protector cell invalidation and performance degradation on `structuredClone` feature detection, one more case of [#679](https://github.com/zloirock/core-js/issues/679)
- Added detection of NodeJS [bug](https://github.com/nodejs/node/issues/41038) in `structuredClone` that can not clone `DOMException` (just in case for future versions that will fix other issues)
- Compat data:
- Added NodeJS 18.3 compat data mapping
Expand Down
2 changes: 2 additions & 0 deletions packages/core-js/internals/engine-is-deno.js
@@ -0,0 +1,2 @@
/* global Deno -- Deno case */
module.exports = typeof Deno == 'object' && Deno && typeof Deno.version == 'object';
7 changes: 7 additions & 0 deletions packages/core-js/modules/web.structured-clone.js
Expand Up @@ -19,6 +19,10 @@ var lengthOfArrayLike = require('../internals/length-of-array-like');
var validateArgumentsLength = require('../internals/validate-arguments-length');
var getRegExpFlags = require('../internals/regexp-get-flags');
var ERROR_STACK_INSTALLABLE = require('../internals/error-stack-installable');
var V8 = require('../internals/engine-v8-version');
var IS_BROWSER = require('../internals/engine-is-browser');
var IS_DENO = require('../internals/engine-is-deno');
var IS_NODE = require('../internals/engine-is-node');

var Object = global.Object;
var Date = global.Date;
Expand Down Expand Up @@ -402,6 +406,9 @@ var structuredCloneInternal = function (value, map) {
};

var PROPER_TRANSFER = nativeStructuredClone && !fails(function () {
// prevent V8 ArrayBufferDetaching protector cell invalidation and performance degradation
// https://github.com/zloirock/core-js/issues/679
if ((IS_DENO && V8 > 92) || (IS_NODE && V8 > 94) || (IS_BROWSER && V8 > 97)) return false;
var buffer = new ArrayBuffer(8);
var clone = nativeStructuredClone(buffer, { transfer: [buffer] });
return buffer.byteLength != 0 || clone.byteLength != 8;
Expand Down

0 comments on commit e1a0d39

Please sign in to comment.