-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.emu
124 lines (123 loc) · 6.51 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: Negated in and instanceof operators
stage: 1
contributors: Pablo Gorostiaga Belio
</pre>
<emu-clause id="sec-relational-operators">
<h1>Relational Operators</h1>
<emu-note>
<p>The result of evaluating a relational operator is always of type Boolean, reflecting whether the relationship named by the operator holds between its two operands.</p>
</emu-note>
<h2>Syntax</h2>
<emu-grammar type="definition">
RelationalExpression[In, Yield, Await] :
ShiftExpression[?Yield, ?Await]
RelationalExpression[?In, ?Yield, ?Await] `<` ShiftExpression[?Yield, ?Await]
RelationalExpression[?In, ?Yield, ?Await] `>` ShiftExpression[?Yield, ?Await]
RelationalExpression[?In, ?Yield, ?Await] `<=` ShiftExpression[?Yield, ?Await]
RelationalExpression[?In, ?Yield, ?Await] `>=` ShiftExpression[?Yield, ?Await]
RelationalExpression[?In, ?Yield, ?Await] `instanceof` ShiftExpression[?Yield, ?Await]
<ins>RelationalExpression[?In, ?Yield, ?Await] `!instanceof` ShiftExpression[?Yield, ?Await]</ins>
[+In] RelationalExpression[+In, ?Yield, ?Await] `in` ShiftExpression[?Yield, ?Await]
<ins>RelationalExpression[?In, ?Yield, ?Await] `!in` ShiftExpression[?Yield, ?Await]</ins>
[+In] PrivateIdentifier `in` ShiftExpression[?Yield, ?Await]
</emu-grammar>
<emu-note>
<p>The <sub>[In]</sub> grammar parameter is needed to avoid confusing the `in` operator in a relational expression with the `in` operator in a `for` statement.</p>
</emu-note>
<emu-clause id="sec-relational-operators-runtime-semantics-evaluation" type="sdo">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>RelationalExpression : RelationalExpression `<` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. Let _r_ be ? IsLessThan(_lval_, _rval_, *true*).
1. If _r_ is *undefined*, return *false*. Otherwise, return _r_.
</emu-alg>
<emu-grammar>RelationalExpression : RelationalExpression `>` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. Let _r_ be ? IsLessThan(_rval_, _lval_, *false*).
1. If _r_ is *undefined*, return *false*. Otherwise, return _r_.
</emu-alg>
<emu-grammar>RelationalExpression : RelationalExpression `<=` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. Let _r_ be ? IsLessThan(_rval_, _lval_, *false*).
1. If _r_ is either *true* or *undefined*, return *false*. Otherwise, return *true*.
</emu-alg>
<emu-grammar>RelationalExpression : RelationalExpression `>=` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. Let _r_ be ? IsLessThan(_lval_, _rval_, *true*).
1. If _r_ is either *true* or *undefined*, return *false*. Otherwise, return *true*.
</emu-alg>
<emu-grammar>RelationalExpression : RelationalExpression `instanceof` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. Return ? InstanceofOperator(_lval_, _rval_).
</emu-alg>
<ins class="block">
<emu-grammar>RelationalExpression : RelationalExpression `!instanceof` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. Let _r_ be ? InstanceofOperator(_lval_, _rval_).
1. If _r_ is *true*, return *false*. Otherwise, return *true*.
</emu-alg>
</ins>
<emu-grammar>RelationalExpression : RelationalExpression `in` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. If _rval_ is not an Object, throw a *TypeError* exception.
1. Return ? HasProperty(_rval_, ? ToPropertyKey(_lval_)).
</emu-alg>
<ins class="block">
<emu-grammar>RelationalExpression : RelationalExpression `!in` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _lref_ be ? Evaluation of |RelationalExpression|.
1. Let _lval_ be ? GetValue(_lref_).
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. If _rval_ is not an Object, throw a *TypeError* exception.
1. Let _r_ be ? HasProperty(_rval_, ? ToPropertyKey(_lval_)).
1. If _r_ is *true*, return *false*. Otherwise, return *true*.
</emu-alg>
</ins>
<emu-grammar>RelationalExpression : PrivateIdentifier `in` ShiftExpression</emu-grammar>
<emu-alg>
1. Let _privateIdentifier_ be the StringValue of |PrivateIdentifier|.
1. Let _rref_ be ? Evaluation of |ShiftExpression|.
1. Let _rval_ be ? GetValue(_rref_).
1. If _rval_ is not an Object, throw a *TypeError* exception.
1. Let _privateEnv_ be the running execution context's PrivateEnvironment.
1. Let _privateName_ be ResolvePrivateIdentifier(_privateEnv_, _privateIdentifier_).
1. If PrivateElementFind(_rval_, _privateName_) is not ~empty~, return *true*.
1. Return *false*.
</emu-alg>
</emu-clause>
</emu-clause>