Skip to content

Commit

Permalink
avoid ArrayBufferDetaching protector cell invalidating in modern V8
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Sep 27, 2023
1 parent da31c40 commit cb8cea4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/core-js/internals/array-buffer-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var uncurryThisAccessor = require('../internals/function-uncurry-this-accessor')
var toIndex = require('../internals/to-index');
var isDetached = require('../internals/array-buffer-is-detached');
var arrayBufferByteLength = require('../internals/array-buffer-byte-length');
var detachViaMessageChannel = require('../internals/detach-via-message-channel');
var detachTransferable = require('../internals/detach-transferable');
var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');

var structuredClone = global.structuredClone;
Expand All @@ -21,7 +21,7 @@ var maxByteLength = uncurryThisAccessor(ArrayBufferPrototype, 'maxByteLength', '
var getInt8 = uncurryThis(DataViewPrototype.getInt8);
var setInt8 = uncurryThis(DataViewPrototype.setInt8);

module.exports = (PROPER_STRUCTURED_CLONE_TRANSFER || detachViaMessageChannel) && function (arrayBuffer, newLength, preserveResizability) {
module.exports = (PROPER_STRUCTURED_CLONE_TRANSFER || detachTransferable) && function (arrayBuffer, newLength, preserveResizability) {
var byteLength = arrayBufferByteLength(arrayBuffer);
var newByteLength = newLength === undefined ? byteLength : toIndex(newLength);
var fixedLength = !isResizable || !isResizable(arrayBuffer);
Expand All @@ -41,6 +41,6 @@ module.exports = (PROPER_STRUCTURED_CLONE_TRANSFER || detachViaMessageChannel) &
var copyLength = min(newByteLength, byteLength);
for (var i = 0; i < copyLength; i++) setInt8(b, i, getInt8(a, i));
}
if (!PROPER_STRUCTURED_CLONE_TRANSFER) detachViaMessageChannel(arrayBuffer);
if (!PROPER_STRUCTURED_CLONE_TRANSFER) detachTransferable(arrayBuffer);
return newBuffer;
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
'use strict';
var global = require('../internals/global');
var tryNodeRequire = require('../internals/try-node-require');
var PROPER_STRUCTURED_CLONE_TRANSFER = require('../internals/structured-clone-proper-transfer');

var structuredClone = global.structuredClone;
var $ArrayBuffer = global.ArrayBuffer;
var $MessageChannel = global.MessageChannel;
var detach = false;
var WorkerThreads, channel, buffer, $detach;

if ($ArrayBuffer) try {
if (PROPER_STRUCTURED_CLONE_TRANSFER) {
detach = function (transferable) {
structuredClone(transferable, { transfer: [transferable] });
};
} else if ($ArrayBuffer) try {
if (!$MessageChannel) {
WorkerThreads = tryNodeRequire('worker_threads');
if (WorkerThreads) $MessageChannel = WorkerThreads.MessageChannel;
Expand Down

0 comments on commit cb8cea4

Please sign in to comment.