From bb5f0a72d4f5db6ccbdb6bdfd3b2aad824c7f366 Mon Sep 17 00:00:00 2001
From: Domenic Denicola
Date
classSharedArrayBuffer
classTypeError
classRangeError
classtypeof
operator
JavaScript defines the concept of an agent. This corresponds, in a 1-to-1 manner, + with this specification's concept of an event loop.
+ +To determine the manifestation of JavaScript's agent cluster concept in user + agents, we first define the set of directly share-to-able event loops for a given + event loop loop:
+ +Then, the transitive closure of all event loops that are + directly share-to-able event loops forms a unit of share-within-able event + loops, and a JavaScript agent cluster consists of all the corresponding agents.
+ +The agent cluster concept is crucial for defining the JavaScript
+ memory model, and in particular among which agents the backing data of
+ SharedArrayBuffer
objects can be shared.
The following pairs of global objects are each within the same unit of share-within-able
+ event loops, and thus can use SharedArrayBuffer
instances to share memory
+ with each other:
Window
and a dedicated worker that it createdWindow
and the Window
of a same origin-domain
+ iframe
Window
and the Window
that opened itThe following pairs of global objects are not within the same unit of + share-within-able event loops, and thus cannot share memory:
+ +Window
and a shared worker it createsWindow
and a service worker it createsWindow
and the Window
of a non-same origin-domain
+ iframe
If IsDetachedBuffer(input) is true, then throw a
"DataCloneError
" DOMException
.
Let outputArrayBuffer be the %ArrayBuffer% intrinsic object in - targetRealm. +
If IsSharedArrayBuffer(input) is true, then:
+ +If targetRealm's settings
+ object's responsible event loop is not in the same unit of
+ share-within-able event loops as the current Realm Record's settings object's responsible event
+ loop, then throw a "DataCloneError
"
+ DOMException
.
Let output be a new SharedArrayBuffer object in targetRealm + whose [[ArrayBufferData]] internal slot value is input.[[ArrayBufferData]] and + whose [[ArrayBufferByteLength]] internal slot value is + input.[[ArrayBufferByteLength]].
Otherwise:
+ +Let outputConstructor be the %ArrayBuffer% intrinsic object in + targetRealm.
Let output be ? CloneArrayBuffer(input, 0, - outputArrayBuffer).
Let output be ? CloneArrayBuffer(input, 0, + outputConstructor).
If IsDetachedBuffer(O) is true, then return false.
If IsSharedArrayBuffer(O) is true, then return false.
Return true.
Assert: IsTransferable(input) is true.
If input has an [[ArrayBufferData]] internal slot, then:
From d0555e2a1d4aeb4391f409363b9b86225bf5eb58 Mon Sep 17 00:00:00 2001 From: Domenic DenicolaIf IsSharedArrayBuffer(input) is true, then:
If targetRealm's settings
- object's responsible event loop is not in the same unit of
- share-within-able event loops as the current Realm Record's settings object's responsible event
- loop, then throw a "DataCloneError
"
- DOMException
.
If targetRealm's settings + object's responsible event loop is not in the same unit of + share-within-able event loops as the current Realm Record's settings object's responsible event + loop, then:
+ +Let outputConstructor be the %SharedArrayBuffer% intrinsic + object in targetRealm.
Let output be ! + AllocateSharedArrayBuffer(outputConstructor, 0).
The reason that this step creates a zero-length
+ SharedArrayBuffer
instance, instead of throwing an error, is due to the fact
+ that at the time StructuredCloneWithTransfer is performed, the
+ targetRealm is not always known, so we cannot synchronously throw an error to the
+ caller. (An example is when we use postMessage()
on a MessagePort
+ whose messages are initially paused.) This subtlety is unfortunately obfuscated by the
+ current StructuredCloneWithTransfer algorithm; see issue #935.
Let output be a new SharedArrayBuffer object in targetRealm - whose [[ArrayBufferData]] internal slot value is input.[[ArrayBufferData]] and - whose [[ArrayBufferByteLength]] internal slot value is - input.[[ArrayBufferByteLength]].
Otherwise, let output be a new SharedArrayBuffer object in + targetRealm whose [[ArrayBufferData]] internal slot value is + input.[[ArrayBufferData]] and whose [[ArrayBufferByteLength]] internal slot value + is input.[[ArrayBufferByteLength]].
The exception to this general design principle is the JavaScript SharedArrayBuffer
+ class. Using SharedArrayBuffer
s, it can in fact be observed that scripts in other
+ event loops are executing simultaneously. Furthermore, due to the
+ JavaScript memory model, there are situations which not only are un-representable via serialized
+ script execution, but also un-representable via serialized statement execution
+ among those scripts.