-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
ArrayBuffer.prototype.transfer
and friends Stage 3 proposal
- Loading branch information
Showing
36 changed files
with
364 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/internals/array-buffer-byte-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/internals/array-buffer-is-detached.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/internals/array-buffer-transfer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/esnext.array-buffer.detached.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/esnext.array-buffer.transfer-to-fixed-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/esnext.array-buffer.transfer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
var parent = require('../../stable/array-buffer/constructor'); | ||
require('../../modules/esnext.array-buffer.detached'); | ||
require('../../modules/esnext.array-buffer.transfer'); | ||
require('../../modules/esnext.array-buffer.transfer-to-fixed-length'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('../../stable/array-buffer'); | ||
require('../../modules/esnext.array-buffer.detached'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
var parent = require('../../stable/array-buffer'); | ||
require('../../modules/esnext.array-buffer.detached'); | ||
require('../../modules/esnext.array-buffer.transfer'); | ||
require('../../modules/esnext.array-buffer.transfer-to-fixed-length'); | ||
|
||
module.exports = parent; |
2 changes: 2 additions & 0 deletions
2
packages/core-js/actual/array-buffer/transfer-to-fixed-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('../../stable/array-buffer'); | ||
require('../../modules/esnext.array-buffer.transfer-to-fixed-length'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('../../stable/array-buffer'); | ||
require('../../modules/esnext.array-buffer.transfer'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var parent = require('../../actual/array-buffer/detached'); | ||
|
||
module.exports = parent; |
3 changes: 3 additions & 0 deletions
3
packages/core-js/full/array-buffer/transfer-to-fixed-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var parent = require('../../actual/array-buffer/transfer-to-fixed-length'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var parent = require('../../actual/array-buffer/transfer'); | ||
|
||
module.exports = parent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var uncurryThisAccessor = require('../internals/function-uncurry-this-accessor'); | ||
var classof = require('../internals/classof-raw'); | ||
|
||
var $TypeError = TypeError; | ||
|
||
// Includes | ||
// - Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). | ||
// - If IsSharedArrayBuffer(O) is true, throw a TypeError exception. | ||
module.exports = uncurryThisAccessor(ArrayBuffer.prototype, 'byteLength', 'get') || function (O) { | ||
if (classof(O) != 'ArrayBuffer') throw $TypeError('ArrayBuffer expected'); | ||
return O.byteLength; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
var arrayBufferByteLength = require('../internals/array-buffer-byte-length'); | ||
|
||
var slice = uncurryThis(ArrayBuffer.prototype.slice); | ||
|
||
module.exports = function (O) { | ||
if (arrayBufferByteLength(O) !== 0) return false; | ||
try { | ||
slice(O, 0, 0); | ||
return false; | ||
} catch (error) { | ||
return true; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var global = require('../internals/global'); | ||
var uncurryThis = require('../internals/function-uncurry-this'); | ||
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 PROPER_TRANSFER = require('../internals/structured-clone-proper-transfer'); | ||
|
||
var TypeError = global.TypeError; | ||
var structuredClone = global.structuredClone; | ||
var ArrayBuffer = global.ArrayBuffer; | ||
var DataView = global.DataView; | ||
var ArrayBufferPrototype = ArrayBuffer.prototype; | ||
var DataViewPrototype = DataView.prototype; | ||
var slice = uncurryThis(ArrayBufferPrototype.slice); | ||
var isResizable = uncurryThisAccessor(ArrayBufferPrototype, 'resizable', 'get'); | ||
var maxByteLength = uncurryThisAccessor(ArrayBufferPrototype, 'maxByteLength', 'get'); | ||
var getInt8 = uncurryThis(DataViewPrototype.getInt8); | ||
var setInt8 = uncurryThis(DataViewPrototype.setInt8); | ||
|
||
module.exports = PROPER_TRANSFER && function (arrayBuffer, newLength, preserveResizability) { | ||
var byteLength = arrayBufferByteLength(arrayBuffer); | ||
var newByteLength = newLength === undefined ? byteLength : toIndex(newLength); | ||
if (isDetached(arrayBuffer)) throw TypeError('ArrayBuffer is detached'); | ||
var newBuffer = structuredClone(arrayBuffer, { transfer: [arrayBuffer] }); | ||
if (byteLength <= newByteLength) return newBuffer; | ||
if (!preserveResizability || !isResizable || !isResizable(newBuffer)) return slice(newBuffer, 0, newByteLength); | ||
var newNewBuffer = new ArrayBuffer(newByteLength, maxByteLength && { maxByteLength: maxByteLength(newBuffer) }); | ||
var a = new DataView(newBuffer); | ||
var b = new DataView(newNewBuffer); | ||
for (var i = 0; i < newByteLength; i++) setInt8(b, i, getInt8(a, i)); | ||
return newNewBuffer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/core-js/internals/structured-clone-proper-transfer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var global = require('../internals/global'); | ||
var fails = require('../internals/fails'); | ||
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 structuredClone = global.structuredClone; | ||
|
||
module.exports = !!structuredClone && !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 = structuredClone(buffer, { transfer: [buffer] }); | ||
return buffer.byteLength != 0 || clone.byteLength != 8; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
var DESCRIPTORS = require('../internals/descriptors'); | ||
var defineBuiltInAccessor = require('../internals/define-built-in-accessor'); | ||
var isDetached = require('../internals/array-buffer-is-detached'); | ||
|
||
var ArrayBufferPrototype = ArrayBuffer.prototype; | ||
|
||
if (DESCRIPTORS && !('detached' in ArrayBufferPrototype)) { | ||
defineBuiltInAccessor(ArrayBufferPrototype, 'detached', { | ||
configurable: true, | ||
get: function detached() { | ||
return isDetached(this); | ||
} | ||
}); | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/core-js/modules/esnext.array-buffer.transfer-to-fixed-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var $transfer = require('../internals/array-buffer-transfer'); | ||
|
||
// `ArrayBuffer.prototype.transferToFixedLength` method | ||
// https://tc39.es/proposal-arraybuffer-transfer/#sec-arraybuffer.prototype.transfertofixedlength | ||
if ($transfer) $({ target: 'ArrayBuffer', proto: true }, { | ||
transferToFixedLength: function transferToFixedLength() { | ||
return $transfer(this, arguments.length ? arguments[0] : undefined, false); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var $transfer = require('../internals/array-buffer-transfer'); | ||
|
||
// `ArrayBuffer.prototype.transfer` method | ||
// https://tc39.es/proposal-arraybuffer-transfer/#sec-arraybuffer.prototype.transfer | ||
if ($transfer) $({ target: 'ArrayBuffer', proto: true }, { | ||
transfer: function transfer() { | ||
return $transfer(this, arguments.length ? arguments[0] : undefined, true); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require('../modules/esnext.array-buffer.detached'); | ||
require('../modules/esnext.array-buffer.transfer'); | ||
require('../modules/esnext.array-buffer.transfer-to-fixed-length'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.