mirror of https://github.com/tc39/test262.git
Class Fields: private fields variants
This commit is contained in:
parent
192c8fd4f6
commit
ba97c2a5ce
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class C {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(/*{ earlyerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class C {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(/*{ executionerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var C = class {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(/*{ earlyerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var C = class {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(/*{ executionerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class C {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
var c = new C();
|
||||
|
||||
assert.sameValue(executed, true);
|
||||
assert.sameValue(c.x, undefined);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class C {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var C = class {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
var c = new C();
|
||||
|
||||
assert.sameValue(executed, true);
|
||||
assert.sameValue(c.x, undefined);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var C = class {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-derived-cls-direct-
|
||||
name: direct eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class A {}
|
||||
class C extends A {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-derived-cls-indirect-
|
||||
name: indirect eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class A {}
|
||||
class C extends A {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-derived-cls-direct-
|
||||
name: direct eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var A = class {}
|
||||
var C = class extends A {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-derived-cls-indirect-
|
||||
name: indirect eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var A = class {}
|
||||
var C = class extends A {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-derived-cls-direct-
|
||||
name: direct eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class A {}
|
||||
class C extends A {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
new C();
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-derived-cls-indirect-
|
||||
name: indirect eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class A {}
|
||||
class C extends A {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-derived-cls-direct-
|
||||
name: direct eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var A = class {}
|
||||
var C = class extends A {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
};
|
||||
|
||||
new C();
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-derived-cls-indirect-
|
||||
name: indirect eval
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var A = class {}
|
||||
var C = class extends A {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
};
|
||||
|
||||
assert.throws(SyntaxError, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-derived-cls-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class A = {}
|
||||
class C extends A {
|
||||
#x = eval('executed = true; /*{ initializer }*/;';
|
||||
}
|
||||
|
||||
assert.throws(/*{ earlyerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-derived-cls-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
class A = {}
|
||||
|
||||
var executed = false;
|
||||
class C extends A {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;';
|
||||
}
|
||||
|
||||
assert.throws(/*{ executionerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-derived-cls-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var A = class {}
|
||||
var C = class extends A {
|
||||
#x = eval('executed = true; /*{ initializer }*/;';
|
||||
};
|
||||
|
||||
assert.throws(/*{ earlyerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-derived-cls-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var A = class {}
|
||||
var C = class extends A {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;';
|
||||
};
|
||||
|
||||
assert.throws(/*{ executionerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class C {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(/*{ earlyerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/statements/class/fields-private-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
class C {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(/*{ executionerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-direct-
|
||||
name: direct eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var C = class {
|
||||
#x = eval('executed = true; /*{ initializer }*/;');
|
||||
}
|
||||
|
||||
assert.throws(/*{ earlyerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-performeval-rules-in-initializer
|
||||
path: language/expressions/class/fields-private-indirect-
|
||||
name: indirect eval
|
||||
features: [class, class-fields-private]
|
||||
---*/
|
||||
|
||||
var executed = false;
|
||||
var C = class {
|
||||
#x = (0, eval)('executed = true; /*{ initializer }*/;');
|
||||
};
|
||||
|
||||
assert.throws(/*{ executionerror }*/, function() {
|
||||
new C();
|
||||
});
|
||||
|
||||
assert.sameValue(executed, true);
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: literal private names
|
||||
info: |
|
||||
ClassElement:
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition:
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassElementName:
|
||||
PrivateName
|
||||
|
||||
PrivateName:
|
||||
# IdentifierName
|
||||
|
||||
template: default
|
||||
features: [class-static-methods-private]
|
||||
---*/
|
||||
|
||||
//- fields
|
||||
static #xVal; static #yVal
|
||||
//- privateinspectionfunctions
|
||||
static #x(value) {
|
||||
this.#xVal = value;
|
||||
return this.#xVal;
|
||||
}
|
||||
static #y(value) {
|
||||
this.#y = value;
|
||||
return this.#yVal;
|
||||
}
|
||||
static x() {
|
||||
return this.#x(42);
|
||||
}
|
||||
static y() {
|
||||
return this.#y(43);
|
||||
}
|
||||
|
||||
//- assertions
|
||||
|
||||
// Test the private methods do not appear as properties before set to value
|
||||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#xVal"), false, "test 1");
|
||||
assert.sameValue(Object.hasOwnProperty.call(C, "#xVal"), false, "test 2");
|
||||
assert.sameValue(Object.hasOwnProperty.call(c, "#xVal"), false, "test 3");
|
||||
|
||||
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "#yVal"), false, "test 4");
|
||||
assert.sameValue(Object.hasOwnProperty.call(C, "#yVal"), false, "test 5");
|
||||
assert.sameValue(Object.hasOwnProperty.call(c, "#yVal"), false, "test 6");
|
||||
|
||||
// Test if private fields can be sucessfully accessed and set to value
|
||||
assert.sameValue(C.x(), 42, "test 7");
|
||||
assert.sameValue(C.y(), 43, "test 8");
|
||||
|
||||
// Test the private fields do not appear as properties before after set to value
|
||||
assert.sameValue(Object.hasOwnProperty.call(C, "#xVal"), false, "test 9");
|
||||
assert.sameValue(Object.hasOwnProperty.call(C, "#yVal"), false, "test 10");
|
Loading…
Reference in New Issue