序列成员的字符串化
Stringification of sequence members
A key path is a DOMString or sequence that defines how to
extract a key from a value. A valid key path is one of:
- An empty DOMString.
- An identifier, which is a DOMString matching the
IdentifierName production from the ECMAScript Language Specification
[ECMA-262].
- A DOMString consisting of two or more identifiers
separated by periods (ASCII character code 46, U+002E FULL STOP).
- A
non-empty sequence containing only strings conforming to
the above requirements.
根据"evaluate a key path on a value"、
的步骤
- If keyPath is a sequence, run these substeps:
- Let result be a new Array ECMAScript object.
- For each item in the keyPath sequence, run these substeps:
- Let key be the result of recursively running the steps to extract a key from a value using a key path using item as keyPath and
value as value.
- ReturnIfAbrupt(key)
- If key is failure, abort the overall algorithm and return failure.
- Append the result of the first sub-step to end of result.
- Return result.
This will only ever "recurse" one level since key path sequences can’t ever be nested.
根据上面(和递归extract a key from a value using a key path), it would seem to me that a non-empty sequence containing non-strings (even with toString()
methods) would not be permitted. Yet the W3C tests indicate at least stringifiable objects (not sure about boolean or number primitives) can be converted, and they indeed pass.
我是否遗漏了规范中的某些内容,这些内容表明在 validated/entered/utilized 之前应首先对这些内容进行字符串化,如果是,在什么条件下?
这发生在绑定 ECMAScript 和 API 的 Web IDL 层。例如,对于 createObjectStore()
API,输入字典定义为:
dictionary IDBObjectStoreParameters {
(DOMString or sequence<DOMString>)? keyPath = null;
boolean autoIncrement = false;
};
到时候 createObjectStore() is executed, the IDL layer guarantees that the value for keyPath
is either a DOMString, a sequence, or null, via the conversions defined in WebIDL 的逻辑。如果传递了无法转换的内容,WebIDL 定义该方法将在到达 API 逻辑之前抛出。
A key path is a DOMString or sequence that defines how to extract a key from a value. A valid key path is one of:
- An empty DOMString.
- An identifier, which is a DOMString matching the IdentifierName production from the ECMAScript Language Specification [ECMA-262].
- A DOMString consisting of two or more identifiers separated by periods (ASCII character code 46, U+002E FULL STOP).
- A non-empty sequence containing only strings conforming to the above requirements.
根据"evaluate a key path on a value"、
的步骤
- If keyPath is a sequence, run these substeps:
- Let result be a new Array ECMAScript object.
- For each item in the keyPath sequence, run these substeps:
- Let key be the result of recursively running the steps to extract a key from a value using a key path using item as keyPath and value as value.
- ReturnIfAbrupt(key)
- If key is failure, abort the overall algorithm and return failure.
- Append the result of the first sub-step to end of result.
- Return result.
This will only ever "recurse" one level since key path sequences can’t ever be nested.
根据上面(和递归extract a key from a value using a key path), it would seem to me that a non-empty sequence containing non-strings (even with toString()
methods) would not be permitted. Yet the W3C tests indicate at least stringifiable objects (not sure about boolean or number primitives) can be converted, and they indeed pass.
我是否遗漏了规范中的某些内容,这些内容表明在 validated/entered/utilized 之前应首先对这些内容进行字符串化,如果是,在什么条件下?
这发生在绑定 ECMAScript 和 API 的 Web IDL 层。例如,对于 createObjectStore()
API,输入字典定义为:
dictionary IDBObjectStoreParameters {
(DOMString or sequence<DOMString>)? keyPath = null;
boolean autoIncrement = false;
};
到时候 createObjectStore() is executed, the IDL layer guarantees that the value for keyPath
is either a DOMString, a sequence, or null, via the conversions defined in WebIDL 的逻辑。如果传递了无法转换的内容,WebIDL 定义该方法将在到达 API 逻辑之前抛出。