mirror of https://github.com/tc39/test262.git
Updating test with 'o?.#field' to be valid program
This commit is contained in:
parent
df59ad6134
commit
539c001941
|
@ -1,20 +1,37 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// Copyright (C) 2020 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName after '?.' is not valid syntax
|
||||
desc: PrivateName after '?.' is valid syntax
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
MemberExpression[Yield]:
|
||||
MemberExpression[?Yield].PrivateName
|
||||
template: syntax/invalid
|
||||
OptionalChain[Yield, Await]:
|
||||
`?.` `[` Expression[+In, ?Yield, ?Await] `]`
|
||||
`?.` IdentifierName
|
||||
`?.` Arguments[?Yield, ?Await]
|
||||
`?.` TemplateLiteral[?Yield, ?Await, +Tagged]
|
||||
`?.` PrivateIdentifier
|
||||
template: default
|
||||
features: [class-fields-private, optional-chaining]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
#m = 'test262';
|
||||
|
||||
access(obj) {
|
||||
static access(obj) {
|
||||
return obj?.#m;
|
||||
}
|
||||
//- assertions
|
||||
|
||||
let c = new C();
|
||||
|
||||
assert.sameValue(C.access(c), 'test262');
|
||||
|
||||
assert.sameValue(C.access(null), undefined);
|
||||
assert.sameValue(C.access(undefined), undefined);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.access({});
|
||||
}, 'accessed private field from an ordinary object');
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/grammar-private-field-optional-chaining.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName after '?.' is valid syntax (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-fields-private, optional-chaining, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
OptionalChain[Yield, Await]:
|
||||
`?.` `[` Expression[+In, ?Yield, ?Await] `]`
|
||||
`?.` IdentifierName
|
||||
`?.` Arguments[?Yield, ?Await]
|
||||
`?.` TemplateLiteral[?Yield, ?Await, +Tagged]
|
||||
`?.` PrivateIdentifier
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
#m = 'test262';
|
||||
|
||||
static access(obj) {
|
||||
return obj?.#m;
|
||||
}
|
||||
}
|
||||
|
||||
let c = new C();
|
||||
|
||||
assert.sameValue(C.access(c), 'test262');
|
||||
|
||||
assert.sameValue(C.access(null), undefined);
|
||||
assert.sameValue(C.access(undefined), undefined);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.access({});
|
||||
}, 'accessed private field from an ordinary object');
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/grammar-private-field-optional-chaining.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName after '?.' is valid syntax (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-fields-private, optional-chaining, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
OptionalChain[Yield, Await]:
|
||||
`?.` `[` Expression[+In, ?Yield, ?Await] `]`
|
||||
`?.` IdentifierName
|
||||
`?.` Arguments[?Yield, ?Await]
|
||||
`?.` TemplateLiteral[?Yield, ?Await, +Tagged]
|
||||
`?.` PrivateIdentifier
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
#m = 'test262';
|
||||
|
||||
static access(obj) {
|
||||
return obj?.#m;
|
||||
}
|
||||
}
|
||||
|
||||
let c = new C();
|
||||
|
||||
assert.sameValue(C.access(c), 'test262');
|
||||
|
||||
assert.sameValue(C.access(null), undefined);
|
||||
assert.sameValue(C.access(undefined), undefined);
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.access({});
|
||||
}, 'accessed private field from an ordinary object');
|
||||
|
Loading…
Reference in New Issue