Skip to content

Commit

Permalink
Remove unused AO and add SharedArray constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
syg committed Sep 17, 2024
1 parent e03192a commit 4457afc
Showing 1 changed file with 90 additions and 28 deletions.
118 changes: 90 additions & 28 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ <h1>
1. If _constructor_.[[ConstructorKind]] is ~derived~, then
1. Let _parent_ be ! _constructor_.[[GetPrototypeOf]]().
1. Perform InitializeStructInstanceFieldsAndBrand(_receiver_, _parent_).
1. Prepend _constructor_.[[StructBrand]] to _receiver_.[[StructBrands]].
1. If _constructor_ has a [[StructBrand]] internal slot, then
1. Prepend _constructor_.[[StructBrand]] to _receiver_.[[StructBrands]].
1. NOTE: Shared Struct constructors do not have a [[StructBrand]] internal slot because per-Realm prototypes is currently an open design question and are not included in this draft. Without per-Realm prototypes, Shared Structs cannot have methods, and there are no users of Shared Struct brands.
1. Let _methods_ be the value of _constructor_.[[PrivateMethods]].
1. For each PrivateElement _method_ of _methods_, do
1. Perform ! PrivateMethodOrAccessorAdd(_receiver_, _method_).
Expand Down Expand Up @@ -174,7 +176,7 @@ <h1>
1. If _superclass_ is *null*, then
1. Let _protoParent_ be *null*.
1. Let _constructorParent_ be %Function.prototype%.
1. Else if _superclass_ does not have a [[IsStructConstructor]] internal field, then
1. Else if _superclass_ does not have a [[IsStructConstructor]] internal slot, then
1. Throw a *TypeError* exception.
1. Else,
1. Let _protoParent_ be ? Get(_superclass_, *"prototype"*).
Expand Down Expand Up @@ -369,9 +371,9 @@ <h1>
1. Let _target_ be _F_.[[BoundTargetMethod]].
1. Let _homeObject_ be _target_.[[HomeObject]].
1. Assert: _homeObject_ is not *undefined*.
1. Assert: _homeObject_ has a [[StructBrand]] internal field.
1. Assert: _homeObject_ has a [[StructBrand]] internal slot.
1. If _thisArgument_ is not an Object, throw a *TypeError* exception.
1. If _thisArgument_ does not have a [[StructBrands]] internal field, throw a *TypeError* exception.
1. If _thisArgument_ does not have a [[StructBrands]] internal slot, throw a *TypeError* exception.
1. If _thisArgument_.[[StructBrands]] does not contain _homeObject_.[[StructBrand]], throw a *TypeError* exception.
1. Return ? Call(_target_, _thisArgument_, argumentsList_).
</emu-alg>
Expand Down Expand Up @@ -411,7 +413,7 @@ <h1>Runtime Semantics: Evaluation</h1>
1. Let _func_ be GetSuperConstructor().
1. Let _argList_ be ? ArgumentListEvaluation of |Arguments|.
1. If IsConstructor(_func_) is *false*, throw a *TypeError* exception.
1. <ins>If _func_ has a [[StructInitializer]] internal field, then</ins>
1. <ins>If _func_ has a [[StructInitializer]] internal slot, then</ins>
1. <ins>If _func_.[[StructInitializer]] is not ~empty~, then</ins>
1. <ins>Let _envRec_ be GetThisEnvironment().</ins>
1. <ins>Let _thisValue_ be _envRec_.GetThisBinding().</ins>
Expand Down Expand Up @@ -869,28 +871,6 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-initializesharedstructinstancefieldsandbrands" type="abstract operation">
<h1>
InitializeSharedStructInstanceFieldsAndBrand (
_receiver_: an Object,
_constructor_: an ECMAScript function object,
): ~unused~
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Assert: The surrounding agent is in the critical section for Shared Struct creation.
1. If _constructor_.[[ConstructorKind]] is ~derived~, then
1. Let _parent_ be ! _constructor_.[[GetPrototypeOf]]().
1. Perform InitializeSharedStructInstanceFieldsAndBrand(_receiver_, _parent_).
1. Prepend _constructor_.[[StructBrand]] to _receiver_.[[StructBrands]].
1. Let _fields_ be the value of _constructor_.[[Fields]].
1. For each element _fieldRecord_ of _fields_, do
1. Perform DefineSharedStructField(_receiver_, _fieldRecord_).
1. Return ~unused~.
</emu-alg>
</emu-clause>

<emu-clause id="sec-runtime-semantics-sharedstructdefinitionevaluation" type="sdo">
<h1>
Runtime Semantics: SharedStructDefinitionEvaluation (
Expand Down Expand Up @@ -924,7 +904,7 @@ <h1>
1. Let _superclass_ be ? GetValue(? _superclassRef_).
1. If _superclass_ is *null*, then
1. Let _constructorParent_ be %Function.prototype%.
1. Else if _superclass_ does not have a [[IsSharedStructConstructor]] internal field, then
1. Else if _superclass_ does not have a [[IsSharedStructConstructor]] internal slot, then
1. Throw a *TypeError* exception.
1. Else,
1. Let _constructorParent_ be _superclass_.
Expand Down Expand Up @@ -1431,3 +1411,85 @@ <h1>Memory Model Fundamentals</h1>
</emu-clause>
<p>For brevity, the refactoring of the memory model relations to use SharedStructStorage and the modified definition of event ranges is omitted.</p>
</emu-clause>
<emu-clause id="sec-shared-arrays">
<h1>Shared Array Object</h1>
<p><dfn variant="Shared Array">Shared Arrays</dfn> are a special case of Shared Structs with array indexed properties and an immutable *"length"* own property. Since they are Shared Structs, their layout, i.e. their length, is fixed at creation time.</p>
<ins class="block">
<emu-clause id="sec-shared-array-constructor">
<h1>The SharedArray Constructor</h1>
<p>The SharedArray constructor:</p>
<ul>
<li>is <dfn>%SharedArray%</dfn>.</li>
<li>is the initial value of the *"SharedArray"* property of the global object.</li>
<li>creates and initializes a new Shared Array when called as a constructor.</li>
<li>is not intended to be called as a function and will throw an exception when called in that manner.</li>
<li>is a function whose behaviour differs based upon the number and types of its arguments.</li>
</ul>
<emu-clause id="sec-sharedarraycreate" type="abstract operation">
<h1>
SharedArrayCreate (
_length_: an non-negative integer,
): a Shared Array
</h1>
<dl class="header">
<dt>description</dt>
<dd>It is used to specify the creation of new Shared Arrays.</dd>
</dl>
<emu-alg>
1. Assert: _length_ &le; 2<sup>32</sup> - 1.
1. Perform EnterSharedStructCreationCriticalSection().
1. Let _A_ be OrdinaryObjectCreate(*null*, « »).
1. Set _A_.[[GetOwnProperty]] as specified in <emu-xref href="#sec-shared-struct-getownproperty"></emu-xref>.
1. Set _A_.[[DefineOwnProperty]] as specified in <emu-xref href="#sec-shared-struct-defineownproperty"></emu-xref>.
1. Set _A_.[[HasProperty]] as specified in <emu-xref href="#sec-shared-struct-hasproperty"></emu-xref>.
1. Set _A_.[[Get]] as specified in <emu-xref href="#sec-shared-struct-get"></emu-xref>.
1. Set _A_.[[Set]] as specified in <emu-xref href="#sec-shared-struct-set"></emu-xref>.
1. Set _A_.[[Delete]] as specified in <emu-xref href="#sec-shared-struct-delete"></emu-xref>.
1. Let _k_ be 0.
1. Repeat, while _k_ &lt; _length_,
1. Let _Pk_ be ! ToString(𝔽(_k_)).
1. Create an own data property named _Pk_ of object _A_ whose [[Value]] is *undefined*, [[Writable]] is *true*, [[Enumerable]] is *true*, and [[Configurable]] is *false*.
1. Perform WriteSharedStructField(_A_, _Pk_, *undefined*, ~init~).
1. Create an own data property named *"length"* of object _A_ whose [[Value]] is 𝔽(_length_), [[Writable]] is *false*, [[Enumerable]] is *false*, and [[Configurable]] is *false*.
1. Perform WriteSharedStructField(_A_, *"length"*, 𝔽(_length_), ~init~).
1. Perform ! _A_.[[PreventExtensions]]().
1. Perform LeaveSharedStructCreationCriticalSection().
1. Assert: ! TestIntegrityLevel(_A_, ~sealed~) is *true*.
1. Return _A_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-sharedarray">
<h1>SharedArray ( ..._values_ )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. EDITOR'S NOTE: Per-Realm prototypes, which is currently an open design question and not included in this draft, will give Shared Arrays a per-Realm prototype with built-in methods.
1. Let _numberOfArgs_ be the number of elements in _values_.
1. If _numberOfArgs_ = 0, then
1. Return SharedArrayCreate(0).
1. Else if _numberOfArgs_ = 1, then
1. Let _len_ be _values_[0].
1. If _len_ is not an integral Number, throw a *TypeError* exception.
1. If _len_ &lt; 0, throw a *RangeError* exception.
1. Let _lenReal_ be ℝ(_len_).
1. If _lenReal_ > 2<sup>32</sup> - 1, throw a *RangeError* exception.
1. Return SharedArrayCreate(_lenReal_).
1. Else,
1. Assert: _numberOfArgs_ ≥ 2.
1. Let _array_ be SharedArrayCreate(_numberOfArgs_).
1. Let _k_ be 0.
1. Repeat, while _k_ &lt; _numberOfArgs_,
1. Let _Pk_ be ! ToString(𝔽(_k_)).
1. Let _itemK_ be _values_[_k_].
1. Perform ! Set(_array_, _Pk_, _itemK_, *true*).
1. Set _k_ to _k_ + 1.
1. Return _array_.
</emu-alg>
</emu-clause>
</emu-clause>
</ins>
</emu-clause>

0 comments on commit 4457afc

Please sign in to comment.