Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed May 10, 2021
1 parent 4d83ebd commit c528d79
Show file tree
Hide file tree
Showing 45 changed files with 1,213 additions and 10 deletions.
15 changes: 15 additions & 0 deletions Jint.Tests.Test262/Language/Expressions/OptionalChaining.cs
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);
}
}
}
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;
}
}
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);
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`
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`;
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`
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`;
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`
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`;
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`
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`;
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');
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);
Loading

0 comments on commit c528d79

Please sign in to comment.