-
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,213 additions
and
10 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
Jint.Tests.Test262/Language/Expressions/OptionalChaining.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Xunit; | ||
|
||
namespace Jint.Tests.Test262.Language.Expressions | ||
{ | ||
public class OptionalChaining : Test262Test | ||
{ | ||
[Theory(DisplayName = "language\\expressions\\optional-chaining")] | ||
[MemberData(nameof(SourceFiles), "language\\expressions\\optional-chaining", false)] | ||
[MemberData(nameof(SourceFiles), "language\\expressions\\optional-chaining", true, Skip = "Skipped")] | ||
protected void Chaining(SourceFile sourceFile) | ||
{ | ||
RunTestInternal(sourceFile); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ests.Test262/test/language/expressions/optional-chaining/call-expression-super-no-base.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2019 Google, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
should not suppress error if super called on class with no base | ||
info: | | ||
Left-Hand-Side Expressions | ||
OptionalExpression: | ||
SuperCall OptionalChain | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
class C { | ||
constructor () { | ||
super()?.a; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
Jint.Tests.Test262/test/language/expressions/optional-chaining/call-expression.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2019 Google, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
optional chain on call expression | ||
info: | | ||
Left-Hand-Side Expressions | ||
OptionalExpression: | ||
CallExpression OptionalChain | ||
features: [optional-chaining] | ||
---*/ | ||
|
||
// CallExpression CoverCallExpressionAndAsyncArrowHead | ||
function fn () { | ||
return {a: 33}; | ||
}; | ||
const obj = { | ||
fn () { | ||
return 44; | ||
} | ||
} | ||
assert.sameValue(33, fn()?.a); | ||
assert.sameValue(undefined, fn()?.b); | ||
assert.sameValue(44, obj?.fn()); | ||
|
||
// CallExpression SuperCall | ||
class A {} | ||
class B extends A { | ||
constructor () { | ||
assert.sameValue(undefined, super()?.a); | ||
} | ||
} | ||
new B(); | ||
|
||
// CallExpression Arguments | ||
function fn2 () { | ||
return () => { | ||
return {a: 66}; | ||
}; | ||
} | ||
function fn3 () { | ||
return () => { | ||
return null; | ||
}; | ||
} | ||
assert.sameValue(66, fn2()()?.a); | ||
assert.sameValue(undefined, fn3()()?.a); | ||
|
||
// CallExpression [Expression] | ||
function fn4 () { | ||
return [{a: 77}]; | ||
} | ||
function fn5 () { | ||
return []; | ||
} | ||
assert.sameValue(77, fn4()[0]?.a); | ||
assert.sameValue(undefined, fn5()[0]?.a); | ||
|
||
// CallExpression .IdentifierName | ||
function fn6 () { | ||
return { | ||
a: { | ||
b: 88 | ||
} | ||
}; | ||
} | ||
assert.sameValue(88, fn6().a?.b); | ||
assert.sameValue(undefined, fn6().b?.c); | ||
|
||
// CallExpression TemplateLiteral | ||
function fn7 () { | ||
return () => {}; | ||
} | ||
assert.sameValue(undefined, fn7()`hello`?.a); |
25 changes: 25 additions & 0 deletions
25
...e/expressions/optional-chaining/early-errors-tail-position-null-op-template-string-esi.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2020 Salesforce.com, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
// This production exists in order to prevent automatic semicolon | ||
// insertion rules. | ||
null?. | ||
`hello` |
22 changes: 22 additions & 0 deletions
22
...guage/expressions/optional-chaining/early-errors-tail-position-null-op-template-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020 Salesforce.com, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
null?.`hello`; |
25 changes: 25 additions & 0 deletions
25
...essions/optional-chaining/early-errors-tail-position-null-optchain-template-string-esi.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2020 Salesforce.com, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
// This production exists in order to prevent automatic semicolon | ||
// insertion rules. | ||
null?.fn | ||
`hello` |
22 changes: 22 additions & 0 deletions
22
...expressions/optional-chaining/early-errors-tail-position-null-optchain-template-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020 Salesforce.com, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
null?.fn`hello`; |
27 changes: 27 additions & 0 deletions
27
...nguage/expressions/optional-chaining/early-errors-tail-position-op-template-string-esi.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2020 Salesforce.com, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
const a = function() {}; | ||
|
||
// This production exists in order to prevent automatic semicolon | ||
// insertion rules. | ||
a?. | ||
`hello` |
24 changes: 24 additions & 0 deletions
24
...t/language/expressions/optional-chaining/early-errors-tail-position-op-template-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2020 Salesforce.com, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
const a = function() {}; | ||
|
||
a?.`hello`; |
27 changes: 27 additions & 0 deletions
27
.../expressions/optional-chaining/early-errors-tail-position-optchain-template-string-esi.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2019 Google, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
const a = {fn() {}}; | ||
|
||
// This production exists in order to prevent automatic semicolon | ||
// insertion rules. | ||
a?.fn | ||
`hello` |
24 changes: 24 additions & 0 deletions
24
...uage/expressions/optional-chaining/early-errors-tail-position-optchain-template-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2019 Google, Inc. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
template string passed to tail position of optional chain | ||
info: | | ||
Static Semantics: Early Errors | ||
OptionalChain: | ||
?.TemplateLiteral | ||
OptionalChain TemplateLiteral | ||
It is a Syntax Error if any code matches this production. | ||
features: [optional-chaining] | ||
negative: | ||
type: SyntaxError | ||
phase: parse | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
const a = {fn() {}}; | ||
|
||
a?.fn`hello`; |
39 changes: 39 additions & 0 deletions
39
Jint.Tests.Test262/test/language/expressions/optional-chaining/eval-optional-call.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2020 Toru Nagashima. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-optional-chaining-chain-evaluation | ||
description: optional call invoked on eval function should be indirect eval. | ||
info: | | ||
Runtime Semantics: ChainEvaluation | ||
OptionalChain: ?. Arguments | ||
1. Let thisChain be this OptionalChain. | ||
2. Let tailCall be IsInTailPosition(thisChain). | ||
3. Return ? EvaluateCall(baseValue, baseReference, Arguments, tailCall). | ||
Runtime Semantics: EvaluateCall ( func, ref, arguments, tailPosition ) | ||
... | ||
7. Let result be Call(func, thisValue, argList). | ||
... | ||
eval ( x ) | ||
... | ||
4. Return ? PerformEval(x, callerRealm, false, false). | ||
Runtime Semantics: PerformEval ( x, callerRealm, strictCaller, direct ) | ||
features: [optional-chaining] | ||
---*/ | ||
|
||
const a = 'global'; | ||
|
||
function fn() { | ||
const a = 'local'; | ||
return eval?.('a'); | ||
} | ||
|
||
assert.sameValue(fn(), 'global', 'fn() returns "global" value from indirect eval'); | ||
|
||
const b = (a => eval?.('a'))('local'); | ||
|
||
assert.sameValue(b, 'global', 'b is "global", from indirect eval not observing parameter'); |
18 changes: 18 additions & 0 deletions
18
Jint.Tests.Test262/test/language/expressions/optional-chaining/iteration-statement-do.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2019 Google, LLC. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: prod-OptionalExpression | ||
description: > | ||
optional chain in test portion of do while statement | ||
info: | | ||
IterationStatement | ||
do Statement while (OptionalExpression) | ||
features: [optional-chaining] | ||
---*/ | ||
let count = 0; | ||
const obj = {a: true}; | ||
do { | ||
count++; | ||
break; | ||
} while (obj?.a); | ||
assert.sameValue(1, count); |
Oops, something went wrong.