Skip to content

Commit

Permalink
Fixup some review comments.
Browse files Browse the repository at this point in the history
Fix some typos, improve the handling of non-element and attribute nodes, and
add some support for shadow roots
  • Loading branch information
jgraham committed Oct 26, 2020
1 parent ebc1afa commit 61517fb
Showing 1 changed file with 55 additions and 32 deletions.
87 changes: 55 additions & 32 deletions index.bs
Expand Up @@ -59,7 +59,7 @@ spec: WEBDRIVER; urlPrefix: https://w3c.github.io/webdriver/
text: WebDriver new session algorithm; url: dfn-webdriver-new-session-algorithm
text: web element reference; url: dfn-web-element-reference
text: window handle; url: dfn-window-handle
spec: ECMASCRIPT urlPrefix: https://tc39.es/ecma262/
spec: ECMASCRIPT; urlPrefix: https://tc39.es/ecma262/
type: dfn
text: Array; url: sec-array-objects
text: CreateArrayFromList; url: sec-createarrayfromlist
Expand All @@ -83,7 +83,7 @@ spec: ECMASCRIPT urlPrefix: https://tc39.es/ecma262/
text: ToString; url: sec-tostring
text: Type; url: sec-ecmascript-data-types-and-values
text: realm; url: sec-code-realms
spec: HTML urlPrefix: https://html.spec.whatwg.org/
spec: HTML; urlPrefix: https://html.spec.whatwg.org/
type: dfn
text: WindowProxy; url: windowproxy
</pre>
Expand Down Expand Up @@ -735,15 +735,18 @@ object, specified as <code>RemoteValue</code>. The value's type is specified in
the <code>type</code> property. In the case of JSON-representable primitive
values, this contains the value in the <code>value</code> property; in the case
of non-JSON-representable primitives, the <code>value</code> property contains a
string representation of the object. For non-primitive objects, the
string representation of the value. For non-primitive objects, the
<code>objectId</code> property contains a string id that provides a unique
handle to the object, valid for its lifetime inside the engine. In this case the
<code>value</code> property can contain a complex object (either a list or a
struct) itself containing further remote object values. This allows objects like
arrays to have a single representation.
handle to the object, valid for its lifetime inside the engine. For some
non-primitive types, the <code>value</code> property contains a representation
of the data in the ECMAScript object; for container types this can contain
further <code>RemoteValue</code> instances. The <code>value</code> property can
be null if there is a duplicate object i.e. the object has already been
serialized in the current <code>RemoteValue</code>, perhaps as part of a
cycle, or otherwise when the maximum serialization depth is reached.

[=Nodes=] are also represented by <code>RemoteObject</code> instances. These
have a partial serialization of the node in the value property.
[=Nodes=] are also represented by <code>RemoteValue</code> instances. These have
a partial serialization of the node in the value property.

Note: mirror objects do not keep the original object alive in the runtime. If an
object is discarded in the runtime subsequent attempts to access it via the
Expand Down Expand Up @@ -897,12 +900,12 @@ SetValue = {
}

WeakMapValue = {
type: "map",
type: "weakmap",
objectId: ObjectId,
}

WeakSetValue = {
type: "set",
type: "weakset",
objectId: ObjectId,
}

Expand Down Expand Up @@ -934,12 +937,13 @@ NodeValue = {

NodeProperties = {
nodeType: uint,
nodeName: text,
localName: text,
nodeValue: text,
localName?: text,
namespaceURI?: text,
childNodeCount: uint,
children?: [*NodeValue],
attributes?: {*text => text},
shadowRoot?: NodeValue / null,
}

WindowProxyValue = {
Expand All @@ -950,8 +954,6 @@ WindowProxyValue = {

Issue: Add WASM types?

Issue: NodeValue needs more attributes

Issue: Should WindowProxy get attributes in a similar style to Node?

Issue: handle String / Number / etc. wrapper objects specially?
Expand Down Expand Up @@ -1041,7 +1043,7 @@ To <dfn>serialize as a remote value</dfn> given an |value|, a |max depth|,

1. Let |serialized| be the string-concatenation of "/", |pattern|, "/", and |flags|.

1. Let |remote| be an [=object=] matching the <code>RegExpValue</code>
1. Let |remote value| be an [=object=] matching the <code>RegExpValue</code>
production in the [=local end definition=], with the <code>objectId</code>
property set to the [=object id for an object=] |object| and the value
set to |serialized|
Expand All @@ -1063,7 +1065,7 @@ To <dfn>serialize as a remote value</dfn> given an |value|, a |max depth|,
is not null and greater than 0, run the following steps:
1. Append |value| to the |set of known objects|

1. Let |serialized| be the result of [=serialize as a list=] given
1. Let |serialized| be the result of [=serialize as a mapping=] given
[=CreateMapIterator=](|value|, key+value), |max depth|, |node details| and
|set of known objects|.

Expand Down Expand Up @@ -1131,19 +1133,23 @@ To <dfn>serialize as a remote value</dfn> given an |value|, a |max depth|,

1. [=Set=](|serialized|, "nodeType", [=Get=](|value|, "nodeType"), false)

1. [=Set=](|serialized|, "nodeName", [=Get=](|value|, "nodeName"), false)
1. [=Set=](|serialized|, "nodeValue", [=Get=](|value|, "nodeValue"), false)

1. [=Set=](|serialized|, "localName", [=Get=](|value|, "localName"), false)
1. If |value| is an [=/Element=] or an <a spec=dom>Attribute</a>:


1. [=Set=](|serialized|, "localName", [=Get=](|value|, "localName"), false)

1. [=Set=](|serialized|, "namespaceURI", [=Get=](|value|, "namespaceURI"), false)

1. [=Set=](|serialized|, "nodeValue", [=Get=](|value|, "nodeValue"), false)

1. Let |child node count| be the size of |serialized|'s [=children=].

1. [=Set=](|serialized|, "childNodeCount", |child node count|, false)

1. If |max depth| is null and or equal to 0 let |children| be null.
1. If |max depth| is equal to 0 let |children| be null.
Otherwise, let |children| be an empty list and, for each node
|child| in |value|'s [=children=]:
|child| in the [=children=] of |value|:

1. Let |serialized| be the result of [=serialize as a remote value=]
with |child|, |max depth| - 1, |node details| and
Expand All @@ -1153,17 +1159,32 @@ To <dfn>serialize as a remote value</dfn> given an |value|, a |max depth|,

1. [=Set=](|serialized|, "children", |serialized|, false)

1. Let |attributes| be a new [=Object=].
1. If |value| is an [=/Element=]:

1. Let |attributes| be a new [=Object=].

1. For each |attribute| in |value|'s [=Element/attribute list=]:

1. For each |attribute| in |value|'s <a spec=dom>attributes</a>:
1. Let |name| be |attribute|'s [=Attr/qualified name=]

1. Let |name| be |attribute|'s [=Attr/qualified name=]
1. Let |serialized| be |attribute|'s [=Attr/value=].

1. Let |serialized| be |attribute|'s [=Attr/value=].
1. [=Set=](|attributes|, |name|, |serialized|, false)

1. [=Set=](|attributes|, |name|, |serialized|, false)
1. [=Set=](|serialized|, "attributes", |attributes|, false)

1. [=Set=](|serialized|, "attributes", |attributes|, false)
1. Let |shadow root| be |value|'s [=Element/shadow root=]

1. If |shadow root| is null, let |serialized shadow| be null.
Otherwise let |serialized shadow| be the result of
[=serialize as a remote value=] with |shadow root|, |max depth| - 1,
false and |set of known objects|.

Note: this means the <code>objectId</code> for the shadow root
will be serialized irrespective of whether the shadow is open or closed,
but no properties of the node will be returned.

1. [=Set=](|serialized|, "shadowRoot", |serialized shadow|, false)

1. Let |remote value| be an [=object=] matching the <code>NodeValue</code>
production in the [=local end definition=], with the <code>objectId</code>
Expand All @@ -1187,10 +1208,12 @@ To <dfn>serialize as a remote value</dfn> given an |value|, a |max depth|,

<dt>Otherwise:
<dd>
1. Let |serialized| be null.
1. [=Assert=]: [=type=](|value|) is Object

1. let |serialized| be null.

1. If |value| is not in the |set of known objects|, and |max depth|
is not null and greater than 0, run the following steps:
is greater than 0, run the following steps:
1. Append |value| to the |set of known objects|

1. Let |serialized| be the result of [=serialize as a mapping=] given
Expand All @@ -1213,8 +1236,6 @@ in general?
</div>

<div algorithm>
Issue: this assumes for-in works on iterators

To <dfn>serialize as a list</dfn> given |iterable|, |max depth|,
|node details| and |set of known objects|:

Expand All @@ -1231,6 +1252,8 @@ To <dfn>serialize as a list</dfn> given |iterable|, |max depth|,
1. Return [=CreateArrayFromList=](|serialized|)
</div>

Issue: this assumes for-in works on iterators

<div algorithm>
To <dfn>serialize as a mapping</dfn> given |iterable|, |max depth|,
|node details| and |set of known objects|:
Expand Down

0 comments on commit 61517fb

Please sign in to comment.