| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
- var tests = [
- {
- name: "Assigning an undeclared variable in a class' computed property name",
- body: function () {
- assert.throws(
- function () {
- class C {
- [f = 5]() { }
- }
- },
- ReferenceError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus a variable assignment to an undeclared variable should throw a ReferenceError in strict mode",
- "Variable undefined in strict mode"
- );
- assert.throws(
- function () {
- class C {
- static [f = 5]() { }
- }
- },
- ReferenceError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus a variable assignment to an undeclared variable should throw a ReferenceError in strict mode",
- "Variable undefined in strict mode"
- );
- assert.throws(
- function () {
- "use strict";
- class C {
- [f = 5]() { }
- }
- },
- ReferenceError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus a variable assignment to an undeclared variable should throw a ReferenceError in strict mode",
- "Variable undefined in strict mode"
- );
- }
- },
- {
- name: "Writing to a non writable object property in a class' computed property name",
- body: function () {
- assert.throws(
- function () {
- var a = {};
- Object.defineProperty(a, 'b', { value: 5, writable: false });
- class C {
- [a.b = 6]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus assigning a value to a non writable property should throw a TypeError in strict mode",
- "Assignment to read-only properties is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = {};
- Object.defineProperty(a, 'b', { value: 5, writable: false });
- class C {
- static [a.b = 6]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus assigning a value to a non writable property should throw a TypeError in strict mode",
- "Assignment to read-only properties is not allowed in strict mode"
- );
- }
- },
- {
- name: "Writing to a getter-only object property in a class' computed property name",
- body: function () {
- assert.throws(
- function () {
- var a = { get b() { return 5; } };
- class C {
- [a.b = 6]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus assigning a value to a getter-only property should throw a TypeError in strict mode",
- "Assignment to read-only properties is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = { get b() { return 5; } };
- class C {
- static [a.b = 6]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus assigning a value to a getter-only property should throw a TypeError in strict mode",
- "Assignment to read-only properties is not allowed in strict mode"
- );
- }
- },
- {
- name: "Writing to a property of a non-extensible object in a class' computed property name",
- body: function () {
- assert.throws(
- function () {
- var a = {};
- Object.preventExtensions(a);
- class C {
- [a.b = 5]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus assigning a value to a property of a non-extensible object should throw a TypeError in strict mode",
- "Cannot create property for a non-extensible object"
- );
- assert.throws(
- function () {
- var a = {};
- Object.preventExtensions(a);
- class C {
- static [a.b = 5]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus assigning a value to a property of a non-extensible object should throw a TypeError in strict mode",
- "Cannot create property for a non-extensible object"
- );
- }
- },
- {
- name: "Calling delete on an undeletable property in a class' computed property name",
- body: function () {
- assert.throws(
- function () {
- class C {
- [delete Object.prototype]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'prototype' is not allowed in strict mode"
- );
- assert.throws(
- function () {
- class C {
- static [delete Object.prototype]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode,\
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'prototype' is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = 5;
- class C {
- [a < 6 ? delete Object.prototype : 5]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode, \
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'prototype' is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = 5;
- class C {
- static [a < 6 ? delete Object.prototype : 5]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode, \
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'prototype' is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = {};
- Object.preventExtensions(a);
- class C {
- [a && delete Object.prototype]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode, \
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'prototype' is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = {};
- Object.preventExtensions(a);
- class C {
- static [a && delete Object.prototype]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode, \
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'prototype' is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = {};
- Object.defineProperty(a, "x", { value: 5, configurable: false });
- class C {
- [delete a["x"]]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode, \
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'x' is not allowed in strict mode"
- );
- assert.throws(
- function () {
- var a = {};
- Object.defineProperty(a, "x", { value: 5, configurable: false });
- class C {
- static [delete a["x"]]() { }
- }
- },
- TypeError,
- "Computed property names inside classes are specified to execute in strict mode, \
- thus calling delete on an undeletable property of object should throw a TypeError in strict mode",
- "Calling delete on 'x' is not allowed in strict mode"
- );
- }
- },
- ]
- testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
|