Comments (6)
The first solution that comes to mind is for Infra to define a macro-like shorthand named "throw if abrupt". It could look something like this:
Algorithms steps that say or are otherwise equivalent to:
- Throw if abrupt given argument.
mean the same thing as:
- Assert: argument is a Completion Record.
- If argument is an abrupt completion, throw argument.[[Value]].
- Else, set argument to argument.[[Value]].
And here's how it could be used to correct "serialize a JavaScript value to a JSON string":
-1. Let result be ? Call(%JSON.stringify%, undefined, « value »).
+1. Let result be Call(%JSON.stringify%, undefined, « value »).
+1. Throw if abrupt given result.
1. If result is undefined, then throw a TypeError.
1. Assert: result is a string.
1. Return result.
from infra.
The "?" operator appears about 60 times in HTML (the simple search query includes some false positives):
$ grep '\s?' html/source | wc -l
60
In addition to the semantics problem detailed in this issue's description, neither Infra nor HTML explain what "?" means.
WebIDL is more explicit in its application of "?", annotating each use with a reference to the definition in ECMA262.
$ grep '\[=?=]' webidl/index.bs | wc -l
74
WebIDL also indirectly explains the operator by explicitly adopting the algorithm conventions of ECMA262. Unfortunately, it does this by making some inaccurate statements about the relevant semantics:
Algorithms in this section use the conventions described in [=ECMA-262 Algorithm conventions=], such as the use of steps and substeps, the use of mathematical operations, and so on. This section may also reference abstract operations and notations defined in other parts of ECMA-262.
When an algorithm says to throw a
|Something|Error
then this means to construct a new ECMAScript|Something|Error
object in the [=current realm=] and to throw it, just as the algorithms in ECMA-262 do.Note that algorithm steps can call in to other algorithms and abstract operations and not explicitly handle exceptions that are thrown from them. When an exception is thrown by an algorithm or abstract operation and it is not explicitly handled by the caller, then it is taken to end the algorithm and propagate out to its caller, and so on.
With all this in mind, here's a variation on the solution I suggested above:
- Define the "?" operator in Infra using the above description of "throw if abrupt" and a note highlighting the distinction with ECMA262's definition
- Annotate Infra's uses of the operator with a reference to Infra's new definition
- Annotate HTML's uses of the operator with a reference to Infra's new definition
- Update WebIDL's uses of the operator to instead reference Infra's new definition
- Clarify the description of "throw" semantics in WebIDL
Generally, I'd prefer to use a distinct algorithm name in order to avoid confusion, especially for an esoteric shorthand like "?". One issue with that is the amount of churn it would involve (using "throw if abrupt" or similar would involve splitting algorithm steps apart).
I think overriding the operator might work in this case, though. The proliferation of this problem suggests that folks are tacitly performing the translation on their own. In that respect, overriding the operator for web specs just closes a loophole for folks who are new to this work and for those who are scrutinizing the boundaries with ECMA262.
from infra.
I like the idea of linking ?
and explaining its slightly adjusted meaning. I wonder if that covers all potentially confusing cases or if you can still stumble upon some resulting from this mixing of styles.
from infra.
I agree with the problem statement, and the 5-step approach sounds good.
However, the problem of completion records is a bit bigger:.
- Infra probably needs to say something about break/continue/return completions.
- There's the question of what to do in cases where it's known that a particular invocation of an AO can only return a normal completion. Possibilities:
- Infra could define its version of
!
too. - Infra-based specs could inline the semantics of
!
if/where appropriate. - Infra-based specs could use
?
in those situations and not care that it looks like it might throw when you know it can't.
- Infra could define its version of
from infra.
Thanks, @jmdyck! As a fourth possibility about asserting normal completions, could we consider just referencing ECMA262's definition of "!" directly? As I understand the semantics, they already seem coherent from the perspective of WHATWG conventions.
from infra.
Yup, that too.
from infra.
Related Issues (20)
- Clarify USV handling in "serialize a JavaScript value to JSON bytes" HOT 1
- Consider defining "failure" HOT 2
- Expand on list indexing syntax
- Conditional abort edge case HOT 2
- Forgiving base64 HOT 8
- "do while" loops HOT 5
- Iteration and append methods for byte sequence used in standards are undefined HOT 1
- Skipping an item while iterating is undefined HOT 1
- Define monkeypatching HOT 3
- Consider defining "unique internal value"
- Explicit unions HOT 1
- definitions of "Continue" and "Break" should be clear that they apply to the innermost loop
- Define ordering for sets and maps? HOT 4
- Define remainder (and/or modulo) HOT 2
- Peek operation for stacks
- "Parse JSON to Infra" algorithms shouldn't require a current JS realm HOT 5
- Define set difference
- Give some examples of how to use structs
- Add a clone method for struct
- tracking/icon for features that might expose use of accessibility tools HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from infra.