From 9da660803f57d23fef4fbde929fa0ce8e95d3665 Mon Sep 17 00:00:00 2001 From: Arlen22 Date: Wed, 5 Feb 2025 01:08:36 +0000 Subject: [PATCH] update spec and add author --- README.md | 1 + spec.emu | 212 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 125 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 3b12d4c..cc10abb 100644 --- a/README.md +++ b/README.md @@ -483,6 +483,7 @@ This proposal is in its early stages, and we welcome your input to help refine i ## Authors - [Arthur Fiorette](https://github.com/arthurfiorette) ([X](https://x.com/arthurfiorette)) +- [Arlen Beiler](https://github.com/Arlen22)
diff --git a/spec.emu b/spec.emu index 343c60e..ce7bf8c 100644 --- a/spec.emu +++ b/spec.emu @@ -4,98 +4,134 @@
-title: ECMAScript Safe Assignment Operator
+title: ECMAScript Try Operator
 stage: -1
-contributors: Arthur Fiorette
+contributors: Arthur Fiorette, Arlen Beiler
 
- -

Introduction

-

This proposal introduces syntax and semantics for safe assignments

-
+ +

Assignment Operators

+

Syntax

+ + AssignmentExpression[In, Yield, Await] : + TryExpression[?In, ?Yield, ?Await] + TryExpression[In, Yield, Await] : + `try` [no LineTerminator here] [lookahead != `{`] AssignmentExpression[?In, ?Yield, ?Await] + - -

ECMAScript Data Types and Values

- -

ECMAScript Language Types

- -

The Symbol Type

- -

Well-Known Symbols

- - - - - - - - - - - - - - -
- Specification Name - - [[Description]] - - Value and Purpose -
- @@result - - `"Symbol.result"` - - A method that wraps function call result into a tuple array. Called by the semantics of `?=` operator and `ResultableStack` objects. -
-
-
-
- -

The Object Type

- -

Well-Known Intrinsic Objects

- - - - - - - - - - - - - - - - - -
- Intrinsic Name - - Global Name - - ECMAScript Language Association -
- %Function% - - `Function` - - The Function constructor () -
- %Promise% - - `Promise` - - The Promise object () -
-
-
-
+ +

Runtime Semantics: Evaluation

+ TryExpression : `try` AssignmentExpression + + 1. Let _A_ be Completion(Evaluation of |Expression|). + 1. If _A_ is an abrupt completion, return ? TryExpressionResult(_A_). + 1. Let _B_ be Completion(GetValue(_A_)). + 1. Return ? TryExpressionResult(_B_). + + +

GetValue must be called even though its value is not used because it may have observable side-effects.

+
-
\ No newline at end of file + + +

+ TryExpressionResult ( + _result_: a Completion Record, + ): either a normal completion containing a TryResult or an abrupt completion +

+
+
+ + 1. If _result_ is a normal completion, return TryResult.ok(_result_.[[VALUE]]). + 1. If _result_ is a throw completion, return TryResult.error(_result_.[[VALUE]]). + 1. Return ? _result_. + +
+ +

+ TryResult.ok ( + _value_: an ECMAScript language value, + ): a TryResult +

+
+
description
+
It is the abstract equivelant of calling `TryResult.ok(value)`
+
+
+ +

+ TryResult.error ( + _value_: an ECMAScript language value, + ): a TryResult +

+
+
description
+
It is the abstract equivelant of calling `TryResult.error(value)`
+
+
+
+ + +

Well-Known Intrinsic Objects

+ + + + + + + + + + + + + + +
+ Intrinsic Name + + Global Name + + ECMAScript Language Association +
+ %TryResult% + + `TryResult` + + The `TryResult` constructor () +
+
+
+ + +

The TryResult Constructor

+

The TryResult constructor:

+
    +
  • is %TryResult%.
  • +
  • is the initial value of the *"TryResult"* property of the global object.
  • +
  • is the functional equivelant of the following code: +
    
    +        class TryResult {
    +          constructor(ok, error, value) {
    +            this.ok = ok
    +            this.error = error
    +            this.value = value
    +          }
    +          *[Symbol.iterator]() {
    +            yield this.ok
    +            yield this.error
    +            yield this.value
    +          }
    +          static ok(value) {
    +            return new TryResult(true, undefined, value)
    +          }
    +          static error(error) {
    +            return new TryResult(false, error, undefined)
    +          }
    +        }
    +      
    +
  • +
+