This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspec.emu
89 lines (83 loc) · 4.08 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<meta charset="utf8">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: ArrayBuffer transfer
status: proposal
stage: 4
contributors: Shu-yu Guo, Jordan Harband, Yagiz Nizipli
location: https://github.com/tc39/proposal-arraybuffer-transfer
copyright: false
markEffects: true
</pre>
<emu-clause id="sec-new-abstract-operations-for-arraybuffer-objects" number="25.1.2">
<h1>Abstract Operations for ArrayBuffer Objects</h1>
<emu-clause id="sec-arraybuffercopyanddetach" type="abstract operation" number="14">
<h1>
<ins>
ArrayBufferCopyAndDetach (
_arrayBuffer_: an ECMAScript language value,
_newLength_: an ECMAScript language value,
_preserveResizability_: ~preserve-resizability~ or ~fixed-length~,
): either a normal completion containing an ArrayBuffer or a throw completion
</ins>
</h1>
<dl class="header">
</dl>
<ins>
<emu-alg>
1. Perform ? RequireInternalSlot(_arrayBuffer_, [[ArrayBufferData]]).
1. If IsSharedArrayBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.
1. If _newLength_ is *undefined*, then
1. Let _newByteLength_ be _arrayBuffer_.[[ArrayBufferByteLength]].
1. Else,
1. Let _newByteLength_ be ? ToIndex(_newLength_).
1. If IsDetachedBuffer(_arrayBuffer_) is *true*, throw a *TypeError* exception.
1. If _preserveResizability_ is ~preserve-resizability~ and IsResizableArrayBuffer(_arrayBuffer_) is *true*, then
1. Let _newMaxByteLength_ be _arrayBuffer_.[[ArrayBufferMaxByteLength]].
1. Else,
1. Let _newMaxByteLength_ be ~empty~.
1. If _arrayBuffer_.[[ArrayBufferDetachKey]] is not *undefined*, throw a *TypeError* exception.
1. Let _newBuffer_ be ? <emu-meta suppress-effects="user-code">AllocateArrayBuffer(%ArrayBuffer%, _newByteLength_, _newMaxByteLength_)</emu-meta>.
1. Let _copyLength_ be min(_newByteLength_, _arrayBuffer_.[[ArrayBufferByteLength]]).
1. Let _fromBlock_ be _arrayBuffer_.[[ArrayBufferData]].
1. Let _toBlock_ be _newBuffer_.[[ArrayBufferData]].
1. Perform CopyDataBlockBytes(_toBlock_, 0, _fromBlock_, 0, _copyLength_).
1. NOTE: Neither creation of the new Data Block nor copying from the old Data Block are observable. Implementations may implement this method as a zero-copy move or a `realloc`.
1. Perform ! DetachArrayBuffer(_arrayBuffer_).
1. Return _newBuffer_.
</emu-alg>
</ins>
</emu-clause>
</emu-clause>
<emu-clause id="sec-new-properties-of-the-arraybuffer-prototype-object" number="25.1.5">
<h1>Properties of the ArrayBuffer Prototype Object</h1>
<emu-clause id="sec-get-arraybuffer.prototype.detached" number="4">
<h1>get ArrayBuffer.prototype.detached</h1>
<p>`ArrayBuffer.prototype.detached` is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Perform ? RequireInternalSlot(_O_, [[ArrayBufferData]]).
1. If IsSharedArrayBuffer(_O_) is *true*, throw a *TypeError* exception.
1. Return IsDetachedBuffer(_O_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-arraybuffer.prototype.transfer" number="5">
<h1>ArrayBuffer.prototype.transfer ( [ _newLength_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Return ? ArrayBufferCopyAndDetach(_O_, _newLength_, ~preserve-resizability~).
</emu-alg>
</emu-clause>
<emu-clause id="sec-arraybuffer.prototype.transfertofixedlength" number="6">
<h1>ArrayBuffer.prototype.transferToFixedLength ( [ _newLength_ ] )</h1>
<p>This method performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Return ? ArrayBufferCopyAndDetach(_O_, _newLength_, ~fixed-length~).
</emu-alg>
</emu-clause>
</emu-clause>