From 502cc20010f26ed54c5b76484f6de6a9caa1526b Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Sat, 21 Dec 2019 15:57:41 -0600 Subject: [PATCH] fix delete test, add error tests, fix lint (#2453) --- .../prototype/toString/invalid-receiver.js | 18 ++++++++++++ .../prototype/toString/undefined-props.js | 20 +++++++++++++ .../Object/freeze/throws-when-false.js | 28 +++++++++++++++++++ .../preventExtensions/throws-when-false.js | 23 +++++++++++++++ .../Object/seal/throws-when-false.js | 28 +++++++++++++++++++ .../target-is-not-object-throws.js | 10 +++---- .../expressions/delete/super-property.js | 1 + .../new-target-optional-call.js | 1 - 8 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 test/built-ins/Error/prototype/toString/invalid-receiver.js create mode 100644 test/built-ins/Error/prototype/toString/undefined-props.js create mode 100644 test/built-ins/Object/freeze/throws-when-false.js create mode 100644 test/built-ins/Object/preventExtensions/throws-when-false.js create mode 100644 test/built-ins/Object/seal/throws-when-false.js diff --git a/test/built-ins/Error/prototype/toString/invalid-receiver.js b/test/built-ins/Error/prototype/toString/invalid-receiver.js new file mode 100644 index 0000000000..3be2ecfc94 --- /dev/null +++ b/test/built-ins/Error/prototype/toString/invalid-receiver.js @@ -0,0 +1,18 @@ +// Copyright (C) 2019 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-error.prototype.tostring +description: > + Error.prototype.toString throws if its receiver is not an object. +info: | + Error.prototype.toString ( ) + 1. Let O be this value. + 2. If Type(O) is not Object, throw a TypeError exception. +---*/ + +[undefined, null, 1, true, 'string', Symbol()].forEach((v) => { + assert.throws(TypeError, () => { + Error.prototype.toString.call(v); + }, `Error.prototype.toString.call(${String(v)})`); +}); diff --git a/test/built-ins/Error/prototype/toString/undefined-props.js b/test/built-ins/Error/prototype/toString/undefined-props.js new file mode 100644 index 0000000000..61fc981002 --- /dev/null +++ b/test/built-ins/Error/prototype/toString/undefined-props.js @@ -0,0 +1,20 @@ +// Copyright (C) 2019 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-error.prototype.tostring +description: > + Error.prototype.toString handles this.name and this.message being undefined. +info: | + Error.prototype.toString ( ) + ... + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "Error"; otherwise set name to ? ToString(name). + 5. Let msg be ? Get(O, "message"). + 6. If msg is undefined, set msg to the empty String; otherwise set msg to ? ToString(msg). +---*/ + +assert.sameValue(Error.prototype.toString.call({}), 'Error'); +assert.sameValue(Error.prototype.toString.call({ message: '42' }), 'Error: 42'); +assert.sameValue(Error.prototype.toString.call({ name: '24' }), '24'); +assert.sameValue(Error.prototype.toString.call({ name: '24', message: '42' }), '24: 42'); diff --git a/test/built-ins/Object/freeze/throws-when-false.js b/test/built-ins/Object/freeze/throws-when-false.js new file mode 100644 index 0000000000..9d07efa83b --- /dev/null +++ b/test/built-ins/Object/freeze/throws-when-false.js @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.freeze +description: > + Object.freeze throws if SetIntegrityLevel(O, frozen) returns false. +info: | + Object.freeze ( O ) + ... + 2. Let status be ? SetIntegrityLevel(O, frozen). + 3. If status is false, throw a TypeError exception. + + SetIntegrityLevel ( O, level ) + ... + 3. Let status be ? O.[[PreventExtensions]](). + 4. If status is false, return false. +---*/ + +const p = new Proxy({}, { + preventExtensions() { + return false; + }, +}); + +assert.throws(TypeError, () => { + Object.freeze(p); +}); diff --git a/test/built-ins/Object/preventExtensions/throws-when-false.js b/test/built-ins/Object/preventExtensions/throws-when-false.js new file mode 100644 index 0000000000..1cc8b6a668 --- /dev/null +++ b/test/built-ins/Object/preventExtensions/throws-when-false.js @@ -0,0 +1,23 @@ +// Copyright (C) 2019 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.preventextensions +description: > + Object.preventExtensions throws if O.[[PreventExtensions]]() returns false. +info: | + Object.preventExtensions ( O ) + ... + 2. Let status be ? O.[[PreventExtensions]](). + 3. If status is false, throw a TypeError exception. +---*/ + +const p = new Proxy({}, { + preventExtensions() { + return false; + }, +}); + +assert.throws(TypeError, () => { + Object.preventExtensions(p); +}); diff --git a/test/built-ins/Object/seal/throws-when-false.js b/test/built-ins/Object/seal/throws-when-false.js new file mode 100644 index 0000000000..495112f74f --- /dev/null +++ b/test/built-ins/Object/seal/throws-when-false.js @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-object.seal +description: > + Object.seal throws if SetIntegrityLevel(O, sealed) returns false. +info: | + Object.seal ( O ) + ... + 2. Let status be ? SetIntegrityLevel(O, sealed). + 3. If status is false, throw a TypeError exception. + + SetIntegrityLevel ( O, level ) + ... + 3. Let status be ? O.[[PreventExtensions]](). + 4. If status is false, return false. +---*/ + +const p = new Proxy({}, { + preventExtensions() { + return false; + }, +}); + +assert.throws(TypeError, () => { + Object.seal(p); +}); diff --git a/test/built-ins/Reflect/preventExtensions/target-is-not-object-throws.js b/test/built-ins/Reflect/preventExtensions/target-is-not-object-throws.js index 89f81fdd1b..41ae57f944 100644 --- a/test/built-ins/Reflect/preventExtensions/target-is-not-object-throws.js +++ b/test/built-ins/Reflect/preventExtensions/target-is-not-object-throws.js @@ -5,7 +5,7 @@ es6id: 26.1.10 description: > Throws a TypeError if target is not an Object. info: | - 26.1.10 Reflect.isExtensible (target) + 26.1.11 Reflect.preventExtensions ( target ) 1. If Type(target) is not Object, throw a TypeError exception. ... @@ -13,17 +13,17 @@ features: [Reflect] ---*/ assert.throws(TypeError, function() { - Reflect.isExtensible(1); + Reflect.preventExtensions(1); }); assert.throws(TypeError, function() { - Reflect.isExtensible(null); + Reflect.preventExtensions(null); }); assert.throws(TypeError, function() { - Reflect.isExtensible(undefined); + Reflect.preventExtensions(undefined); }); assert.throws(TypeError, function() { - Reflect.isExtensible(''); + Reflect.preventExtensions(''); }); diff --git a/test/language/expressions/delete/super-property.js b/test/language/expressions/delete/super-property.js index 319cb03130..4f4fa00144 100644 --- a/test/language/expressions/delete/super-property.js +++ b/test/language/expressions/delete/super-property.js @@ -15,6 +15,7 @@ var caught; class C extends Object { constructor() { + super(); try { delete super.x; } catch (err) { diff --git a/test/language/expressions/optional-chaining/new-target-optional-call.js b/test/language/expressions/optional-chaining/new-target-optional-call.js index 2ae2ea6619..aae31b9c0b 100644 --- a/test/language/expressions/optional-chaining/new-target-optional-call.js +++ b/test/language/expressions/optional-chaining/new-target-optional-call.js @@ -9,7 +9,6 @@ info: | MemberExpression OptionalChain NewTarget OptionalChain features: [optional-chaining] -includes: [fnGlobalObject.js] ---*/ const newTargetContext = (function() { return this; })();