From 1bc193528bf6cf339d182250412b2000c4161392 Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Thu, 7 Nov 2019 11:01:21 -0500 Subject: [PATCH] Add tests for AggregateError (#2406) This covers part of the Promise.any proposal --- features.txt | 5 + .../errors-iterabletolist-failures.js | 183 ++++++++++++++++++ .../AggregateError/errors-iterabletolist.js | 69 +++++++ test/built-ins/AggregateError/length.js | 32 +++ .../message-method-prop-cast.js | 69 +++++++ .../AggregateError/message-method-prop.js | 33 ++++ .../message-tostring-abrupt-symbol.js | 39 ++++ .../AggregateError/message-tostring-abrupt.js | 59 ++++++ .../message-undefined-no-prop.js | 33 ++++ test/built-ins/AggregateError/name.js | 33 ++++ .../AggregateError/newtarget-proto-custom.js | 47 +++++ .../newtarget-proto-fallback.js | 62 ++++++ .../AggregateError/newtarget-proto.js | 35 ++++ test/built-ins/AggregateError/prop-desc.js | 26 +++ test/built-ins/AggregateError/proto.js | 16 ++ .../AggregateError/prototype/constructor.js | 25 +++ .../prototype/errors/invoked-as-accessor.js | 21 ++ .../prototype/errors/invoked-as-func.js | 25 +++ .../AggregateError/prototype/errors/length.js | 33 ++++ .../AggregateError/prototype/errors/name.js | 28 +++ .../prototype/errors/prop-desc.js | 25 +++ .../errors/return-from-iterable-errors.js | 51 +++++ .../errors/return-new-array-from-list.js | 76 ++++++++ .../this-has-no-typedarrayname-internal.js | 29 +++ .../prototype/errors/this-is-not-object.js | 46 +++++ .../AggregateError/prototype/message.js | 25 +++ .../AggregateError/prototype/name.js | 24 +++ .../AggregateError/prototype/prop-desc.js | 24 +++ .../AggregateError/prototype/proto.js | 16 ++ .../prototype/toString/get-message-abrupt.js | 39 ++++ .../toString/get-message-empty-string.js | 54 ++++++ .../toString/get-message-toString-object.js | 83 ++++++++ .../toString/get-message-toString-symbol.js | 35 ++++ .../get-message-toString-undefined.js | 38 ++++ .../toString/get-message-toString.js | 36 ++++ .../toString/get-message-undefined.js | 64 ++++++ .../prototype/toString/get-message.js | 33 ++++ .../prototype/toString/get-name-abrupt.js | 33 ++++ .../toString/get-name-empty-string.js | 70 +++++++ .../toString/get-name-toString-object.js | 83 ++++++++ .../toString/get-name-toString-symbol.js | 34 ++++ .../toString/get-name-toString-undefined.js | 38 ++++ .../prototype/toString/get-name-toString.js | 36 ++++ .../prototype/toString/get-name-undefined.js | 68 +++++++ .../prototype/toString/get-name.js | 30 +++ .../prototype/toString/length.js | 31 +++ .../AggregateError/prototype/toString/name.js | 24 +++ .../prototype/toString/prop-desc.js | 23 +++ .../prototype/toString/returns-string.js | 38 ++++ .../toString/this-not-object-throws.js | 45 +++++ 50 files changed, 2124 insertions(+) create mode 100644 test/built-ins/AggregateError/errors-iterabletolist-failures.js create mode 100644 test/built-ins/AggregateError/errors-iterabletolist.js create mode 100644 test/built-ins/AggregateError/length.js create mode 100644 test/built-ins/AggregateError/message-method-prop-cast.js create mode 100644 test/built-ins/AggregateError/message-method-prop.js create mode 100644 test/built-ins/AggregateError/message-tostring-abrupt-symbol.js create mode 100644 test/built-ins/AggregateError/message-tostring-abrupt.js create mode 100644 test/built-ins/AggregateError/message-undefined-no-prop.js create mode 100644 test/built-ins/AggregateError/name.js create mode 100644 test/built-ins/AggregateError/newtarget-proto-custom.js create mode 100644 test/built-ins/AggregateError/newtarget-proto-fallback.js create mode 100644 test/built-ins/AggregateError/newtarget-proto.js create mode 100644 test/built-ins/AggregateError/prop-desc.js create mode 100644 test/built-ins/AggregateError/proto.js create mode 100644 test/built-ins/AggregateError/prototype/constructor.js create mode 100644 test/built-ins/AggregateError/prototype/errors/invoked-as-accessor.js create mode 100644 test/built-ins/AggregateError/prototype/errors/invoked-as-func.js create mode 100644 test/built-ins/AggregateError/prototype/errors/length.js create mode 100644 test/built-ins/AggregateError/prototype/errors/name.js create mode 100644 test/built-ins/AggregateError/prototype/errors/prop-desc.js create mode 100644 test/built-ins/AggregateError/prototype/errors/return-from-iterable-errors.js create mode 100644 test/built-ins/AggregateError/prototype/errors/return-new-array-from-list.js create mode 100644 test/built-ins/AggregateError/prototype/errors/this-has-no-typedarrayname-internal.js create mode 100644 test/built-ins/AggregateError/prototype/errors/this-is-not-object.js create mode 100644 test/built-ins/AggregateError/prototype/message.js create mode 100644 test/built-ins/AggregateError/prototype/name.js create mode 100644 test/built-ins/AggregateError/prototype/prop-desc.js create mode 100644 test/built-ins/AggregateError/prototype/proto.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message-abrupt.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message-empty-string.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message-toString-object.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message-toString-symbol.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message-toString-undefined.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message-toString.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message-undefined.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-message.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name-abrupt.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name-empty-string.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name-toString-object.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name-toString-symbol.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name-toString-undefined.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name-toString.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name-undefined.js create mode 100644 test/built-ins/AggregateError/prototype/toString/get-name.js create mode 100644 test/built-ins/AggregateError/prototype/toString/length.js create mode 100644 test/built-ins/AggregateError/prototype/toString/name.js create mode 100644 test/built-ins/AggregateError/prototype/toString/prop-desc.js create mode 100644 test/built-ins/AggregateError/prototype/toString/returns-string.js create mode 100644 test/built-ins/AggregateError/prototype/toString/this-not-object-throws.js diff --git a/features.txt b/features.txt index 3dc886705c..26a540509b 100644 --- a/features.txt +++ b/features.txt @@ -153,6 +153,11 @@ coalesce-expression # https://github.com/tc39-transfer/proposal-intl-displaynames Intl.DisplayNames +# Promise.any +# https://github.com/tc39/proposal-promise-any +Promise.any +AggregateError + ## Standard language features # # Language features that have been included in a published version of the diff --git a/test/built-ins/AggregateError/errors-iterabletolist-failures.js b/test/built-ins/AggregateError/errors-iterabletolist-failures.js new file mode 100644 index 0000000000..e1b44b45e0 --- /dev/null +++ b/test/built-ins/AggregateError/errors-iterabletolist-failures.js @@ -0,0 +1,183 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Return abrupt completion from IterableToList(errors) +info: | + AggregateError ( errors, message ) + + ... + 3. Let errorsList be ? IterableToList(errors). + 4. Set O.[[AggregateErrors]] to errorsList. + ... + 6. Return O. + + Runtime Semantics: IterableToList ( items [ , method ] ) + + 1. If method is present, then + ... + 2. Else, + b. Let iteratorRecord be ? GetIterator(items, sync). + 3. Let values be a new empty List. + 4. Let next be true. + 5. Repeat, while next is not false + a. Set next to ? IteratorStep(iteratorRecord). + b. If next is not false, then + i. Let nextValue be ? IteratorValue(next). + ii. Append nextValue to the end of the List values. + 6. Return values. + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + 6. Let nextMethod be ? GetV(iterator, "next"). + ... + 8. Return iteratorRecord. +features: [AggregateError, Symbol.iterator] +---*/ + +var case1 = { + get [Symbol.iterator]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + var obj = new AggregateError(case1); +}, 'get Symbol.iterator'); + +var case2 = { + get [Symbol.iterator]() { + return {}; + } +}; + +assert.throws(TypeError, () => { + var obj = new AggregateError(case2); +}, 'GetMethod(obj, @@iterator) abrupts from non callable'); + +var case3 = { + [Symbol.iterator]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + var obj = new AggregateError(case3); +}, 'Abrupt from @@iterator call'); + +var case4 = { + [Symbol.iterator]() { + return 'a string'; + } +}; + +assert.throws(TypeError, () => { + var obj = new AggregateError(case4); +}, '@@iterator call returns a string'); + +var case5 = { + [Symbol.iterator]() { + return undefined; + } +}; + +assert.throws(TypeError, () => { + var obj = new AggregateError(case5); +}, '@@iterator call returns undefined'); + +var case6 = { + [Symbol.iterator]() { + return { + get next() { + throw new Test262Error(); + } + } + } +}; + +assert.throws(Test262Error, () => { + var obj = new AggregateError(case6); +}, 'GetV(iterator, next) returns abrupt'); + +var case7 = { + [Symbol.iterator]() { + return { + get next() { + return {}; + } + } + } +}; + +assert.throws(TypeError, () => { + var obj = new AggregateError(case7); +}, 'GetV(iterator, next) returns a non callable'); + +var case8 = { + [Symbol.iterator]() { + return { + next() { + throw new Test262Error(); + } + } + } +}; + +assert.throws(Test262Error, () => { + var obj = new AggregateError(case8); +}, 'abrupt from iterator.next()'); + +var case9 = { + [Symbol.iterator]() { + return { + next() { + return undefined; + } + } + } +}; + +assert.throws(TypeError, () => { + var obj = new AggregateError(case9); +}, 'iterator.next() returns undefined'); + +var case10 = { + [Symbol.iterator]() { + return { + next() { + return 'a string'; + } + } + } +}; + +assert.throws(TypeError, () => { + var obj = new AggregateError(case10); +}, 'iterator.next() returns a string'); + +var case11 = { + [Symbol.iterator]() { + return { + next() { + return { + get done() { + throw new Test262Error(); + } + }; + } + } + } +}; + +assert.throws(Test262Error, () => { + var obj = new AggregateError(case11); +}, 'IteratorCompete abrupts getting the done property'); diff --git a/test/built-ins/AggregateError/errors-iterabletolist.js b/test/built-ins/AggregateError/errors-iterabletolist.js new file mode 100644 index 0000000000..8cd4543a9e --- /dev/null +++ b/test/built-ins/AggregateError/errors-iterabletolist.js @@ -0,0 +1,69 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Iteration of errors +info: | + AggregateError ( errors, message ) + + ... + 3. Let errorsList be ? IterableToList(errors). + 4. Set O.[[AggregateErrors]] to errorsList. + ... + 6. Return O. + + Runtime Semantics: IterableToList ( items [ , method ] ) + + 1. If method is present, then + ... + 2. Else, + b. Let iteratorRecord be ? GetIterator(items, sync). + 3. Let values be a new empty List. + 4. Let next be true. + 5. Repeat, while next is not false + a. Set next to ? IteratorStep(iteratorRecord). + b. If next is not false, then + i. Let nextValue be ? IteratorValue(next). + ii. Append nextValue to the end of the List values. + 6. Return values. + + GetIterator ( obj [ , hint [ , method ] ] ) + + ... + 3. If method is not present, then + a. If hint is async, then + ... + b. Otherwise, set method to ? GetMethod(obj, @@iterator). + 4. Let iterator be ? Call(method, obj). + 5. If Type(iterator) is not Object, throw a TypeError exception. + 6. Let nextMethod be ? GetV(iterator, "next"). + ... + 8. Return iteratorRecord. +features: [AggregateError, Symbol.iterator] +includes: [compareArray.js] +---*/ + +var count = 0; +var values = []; +var case1 = { + [Symbol.iterator]() { + return { + next() { + count += 1; + return { + done: count === 3, + get value() { + values.push(count) + } + }; + } + }; + } +}; + +new AggregateError(case1); + +assert.sameValue(count, 3); +assert.compareArray(values, [1, 2]); diff --git a/test/built-ins/AggregateError/length.js b/test/built-ins/AggregateError/length.js new file mode 100644 index 0000000000..d17d7151af --- /dev/null +++ b/test/built-ins/AggregateError/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: AggregateError.length property descriptor +info: | + AggregateError ( errors, message ) + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in + function object has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +verifyProperty(AggregateError, 'length', { + value: 2, + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/AggregateError/message-method-prop-cast.js b/test/built-ins/AggregateError/message-method-prop-cast.js new file mode 100644 index 0000000000..2561839ac6 --- /dev/null +++ b/test/built-ins/AggregateError/message-method-prop-cast.js @@ -0,0 +1,69 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Cast ToString values of message in the created method property +info: | + AggregateError ( errors, message ) + + ... + 5. If message is not undefined, then + a. Let msg be ? ToString(message). + b. Perform ! CreateMethodProperty(O, "message", msg). + 6. Return O. + + CreateMethodProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }. + 4. Return ? O.[[DefineOwnProperty]](P, newDesc). +features: [AggregateError] +includes: [propertyHelper.js] +---*/ + +var case1 = new AggregateError([], 42); + +verifyProperty(case1, 'message', { + value: '42', + writable: true, + enumerable: false, + configurable: true, +}); + +var case2 = new AggregateError([], false); + +verifyProperty(case2, 'message', { + value: 'false', + writable: true, + enumerable: false, + configurable: true, +}); + +var case3 = new AggregateError([], true); + +verifyProperty(case3, 'message', { + value: 'true', + writable: true, + enumerable: false, + configurable: true, +}); + +var case4 = new AggregateError([], { toString() { return 'string'; }}); + +verifyProperty(case4, 'message', { + value: 'string', + writable: true, + enumerable: false, + configurable: true, +}); + +var case5 = new AggregateError([], null); + +verifyProperty(case5, 'message', { + value: 'null', + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/AggregateError/message-method-prop.js b/test/built-ins/AggregateError/message-method-prop.js new file mode 100644 index 0000000000..14759abba7 --- /dev/null +++ b/test/built-ins/AggregateError/message-method-prop.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Creates a method property for message +info: | + AggregateError ( errors, message ) + + ... + 5. If message is not undefined, then + a. Let msg be ? ToString(message). + b. Perform ! CreateMethodProperty(O, "message", msg). + 6. Return O. + + CreateMethodProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }. + 4. Return ? O.[[DefineOwnProperty]](P, newDesc). +features: [AggregateError] +includes: [propertyHelper.js] +---*/ + +var obj = new AggregateError([], '42'); + +verifyProperty(obj, 'message', { + value: '42', + writable: true, + enumerable: false, + configurable: true, +}); diff --git a/test/built-ins/AggregateError/message-tostring-abrupt-symbol.js b/test/built-ins/AggregateError/message-tostring-abrupt-symbol.js new file mode 100644 index 0000000000..e2c1323646 --- /dev/null +++ b/test/built-ins/AggregateError/message-tostring-abrupt-symbol.js @@ -0,0 +1,39 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Abrupt completions of ToString(Symbol message) +info: | + AggregateError ( errors, message ) + + ... + 5. If message is not undefined, then + a. Let msg be ? ToString(message). + b. Perform ! CreateMethodProperty(O, "message", msg). + 6. Return O. +features: [AggregateError, Symbol, Symbol.toPrimitive] +---*/ + +var case1 = Symbol(); + +assert.throws(TypeError, () => { + new AggregateError([], case1); +}, 'toPrimitive'); + +var case2 = { + [Symbol.toPrimitive]() { + return Symbol(); + }, + toString() { + throw new Test262Error(); + }, + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(TypeError, () => { + new AggregateError([], case2); +}, 'from ToPrimitive'); diff --git a/test/built-ins/AggregateError/message-tostring-abrupt.js b/test/built-ins/AggregateError/message-tostring-abrupt.js new file mode 100644 index 0000000000..d018d28dd3 --- /dev/null +++ b/test/built-ins/AggregateError/message-tostring-abrupt.js @@ -0,0 +1,59 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Abrupt completions of ToString(message) +info: | + AggregateError ( errors, message ) + + ... + 5. If message is not undefined, then + a. Let msg be ? ToString(message). + b. Perform ! CreateMethodProperty(O, "message", msg). + 6. Return O. +features: [AggregateError, Symbol.toPrimitive] +---*/ + +var case1 = { + [Symbol.toPrimitive]() { + throw new Test262Error(); + }, + toString() { + throw 'toString called'; + }, + valueOf() { + throw 'valueOf called'; + } +}; + +assert.throws(Test262Error, () => { + new AggregateError([], case1); +}, 'toPrimitive'); + +var case2 = { + [Symbol.toPrimitive]: undefined, + toString() { + throw new Test262Error(); + }, + valueOf() { + throw 'valueOf called'; + } +}; + +assert.throws(Test262Error, () => { + new AggregateError([], case2); +}, 'toString'); + +var case3 = { + [Symbol.toPrimitive]: undefined, + toString: undefined, + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new AggregateError([], case3); +}, 'valueOf'); diff --git a/test/built-ins/AggregateError/message-undefined-no-prop.js b/test/built-ins/AggregateError/message-undefined-no-prop.js new file mode 100644 index 0000000000..6d56ac65f1 --- /dev/null +++ b/test/built-ins/AggregateError/message-undefined-no-prop.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + If message is undefined, no property will be set to the new instance +info: | + AggregateError ( errors, message ) + + ... + 5. If message is not undefined, then + a. Let msg be ? ToString(message). + b. Perform ! CreateMethodProperty(O, "message", msg). + 6. Return O. +features: [AggregateError] +---*/ + +var case1 = new AggregateError([], undefined); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(case1, 'message'), + false, + 'explicit' +); + +var case2 = new AggregateError([]); + +assert.sameValue( + Object.prototype.hasOwnProperty.call(case2, 'message'), + false, + 'implicit' +); diff --git a/test/built-ins/AggregateError/name.js b/test/built-ins/AggregateError/name.js new file mode 100644 index 0000000000..9ee3af054e --- /dev/null +++ b/test/built-ins/AggregateError/name.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: AggregateError.name property descriptor +info: | + Properties of the AggregateError Constructor + + - has a name property whose value is the String value "AggregateError". + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. Unless otherwise specified, this value is the name that + is given to the function in this specification. For functions that + are specified as properties of objects, the name value is the + property name string used to access the function. [...] + + Unless otherwise specified, the name property of a built-in function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +verifyProperty(AggregateError, 'name', { + value: 'AggregateError', + writable: false, + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/AggregateError/newtarget-proto-custom.js b/test/built-ins/AggregateError/newtarget-proto-custom.js new file mode 100644 index 0000000000..da946dbdd4 --- /dev/null +++ b/test/built-ins/AggregateError/newtarget-proto-custom.js @@ -0,0 +1,47 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Use a custom NewTarget prototype +info: | + AggregateError ( errors, message ) + + 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. + 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]], [[AggregateErrors]] »). + ... + 6. Return O. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + Return proto. +features: [AggregateError] +---*/ + +var custom = { x: 42 }; +var newt = new Proxy(function() {}, { + get(t, p) { + if (p === 'prototype') { + return custom; + } + + return t[p]; + } +}); + +var obj = Reflect.construct(AggregateError, [], newt); + +assert.sameValue(Object.getPrototypeOf(obj), custom); +assert.sameValue(obj.x, 42); diff --git a/test/built-ins/AggregateError/newtarget-proto-fallback.js b/test/built-ins/AggregateError/newtarget-proto-fallback.js new file mode 100644 index 0000000000..63c4d35867 --- /dev/null +++ b/test/built-ins/AggregateError/newtarget-proto-fallback.js @@ -0,0 +1,62 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Fallback to the NewTarget's [[Prototype]] if the prototype property is not an object +info: | + AggregateError ( errors, message ) + + 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. + 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]], [[AggregateErrors]] »). + ... + 6. Return O. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + Return proto. +features: [AggregateError, Symbol] +---*/ + +var custom = { x: 42 }; +var ctor = function() {}; +Object.setPrototypeOf(ctor, custom); + +var values = [ + undefined, + null, + 42, + false, + true, + Symbol(), + 'string' +]; + +for (const value of values) { + const newt = new Proxy(ctor, { + get(t, p) { + if (p === 'prototype') { + return value; + } + + return t[p]; + } + }); + + const obj = Reflect.construct(AggregateError, [], newt); + + assert.sameValue(Object.getPrototypeOf(obj), custom); + assert.sameValue(obj.x, 42); +} diff --git a/test/built-ins/AggregateError/newtarget-proto.js b/test/built-ins/AggregateError/newtarget-proto.js new file mode 100644 index 0000000000..1e24e93757 --- /dev/null +++ b/test/built-ins/AggregateError/newtarget-proto.js @@ -0,0 +1,35 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Default prototype is the %AggregateError.prototype%" +info: | + AggregateError ( errors, message ) + + 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. + 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]], [[AggregateErrors]] »). + ... + 6. Return O. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + Return proto. +features: [AggregateError] +---*/ + +var obj = new AggregateError([]); + +assert.sameValue(Object.getPrototypeOf(obj), AggregateError.prototype); diff --git a/test/built-ins/AggregateError/prop-desc.js b/test/built-ins/AggregateError/prop-desc.js new file mode 100644 index 0000000000..6637e637b0 --- /dev/null +++ b/test/built-ins/AggregateError/prop-desc.js @@ -0,0 +1,26 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error +description: > + Property descriptor of AggregateError +info: | + The AggregateError Object + + ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +assert.sameValue(typeof AggregateError, 'function'); + +verifyProperty(this, 'AggregateError', { + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/built-ins/AggregateError/proto.js b/test/built-ins/AggregateError/proto.js new file mode 100644 index 0000000000..81bb99ae2b --- /dev/null +++ b/test/built-ins/AggregateError/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: The prototype of AggregateError constructor is Error +esid: sec-aggregate-error +info: | + Properties of the AggregateError Constructor + + - has a [[Prototype]] internal slot whose value is the intrinsic object %Error%. +features: [AggregateError] +---*/ + +var proto = Object.getPrototypeOf(AggregateError); + +assert.sameValue(proto, Error); diff --git a/test/built-ins/AggregateError/prototype/constructor.js b/test/built-ins/AggregateError/prototype/constructor.js new file mode 100644 index 0000000000..69aa8ab607 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/constructor.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.constructor +description: > + The `AggregateError.prototype.constructor` property descriptor. +info: | + The initial value of AggregateError.prototype.constructor is the intrinsic + object %AggregateError%. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described (...) has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +verifyProperty(AggregateError.prototype, 'constructor', { + value: AggregateError, + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/errors/invoked-as-accessor.js b/test/built-ins/AggregateError/prototype/errors/invoked-as-accessor.js new file mode 100644 index 0000000000..6c2cd1f7cf --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/invoked-as-accessor.js @@ -0,0 +1,21 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + Requires this value to have a [[AggregateErrorData]] internal slot +info: | + get AggregateError.prototype.errors + + 1. Let E be the this value. + 2. If Type(E) is not Object, throw a TypeError exception. + 3. If E does not have an [[ErrorData]] internal slot, throw a TypeError exception. + 4. If E does not have an [[AggregateErrors]] internal slot, throw a TypeError exception. + 5. Return ! CreateArrayFromList(E.[[AggregateErrors]]). +features: [AggregateError] +---*/ + +assert.throws(TypeError, function() { + AggregateError.prototype.errors; +}); diff --git a/test/built-ins/AggregateError/prototype/errors/invoked-as-func.js b/test/built-ins/AggregateError/prototype/errors/invoked-as-func.js new file mode 100644 index 0000000000..625b7e4279 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/invoked-as-func.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + Throws a TypeError exception when invoked as a function +info: | + get AggregateError.prototype.errors + + 1. Let E be the this value. + 2. If Type(E) is not Object, throw a TypeError exception. + 3. If E does not have an [[ErrorData]] internal slot, throw a TypeError exception. + 4. If E does not have an [[AggregateErrors]] internal slot, throw a TypeError exception. + 5. Return ! CreateArrayFromList(E.[[AggregateErrors]]). +features: [AggregateError] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + AggregateError.prototype, 'errors' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/AggregateError/prototype/errors/length.js b/test/built-ins/AggregateError/prototype/errors/length.js new file mode 100644 index 0000000000..9d603b4322 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + Property descriptor of (get AggregateError.prototype.errors).length +info: | + get AggregateError.prototype.errors + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +var desc = Object.getOwnPropertyDescriptor(AggregateError.prototype, 'errors'); + +verifyProperty(desc.get, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/errors/name.js b/test/built-ins/AggregateError/prototype/errors/name.js new file mode 100644 index 0000000000..8a2ee17ec2 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + Property descriptor of (get AggregateError.prototype.errors).name +info: | + get AggregateError.prototype.errors + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +var desc = Object.getOwnPropertyDescriptor( + AggregateError.prototype, 'errors' +); + +verifyProperty(desc.get, 'name', { + value: 'get errors', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/errors/prop-desc.js b/test/built-ins/AggregateError/prototype/errors/prop-desc.js new file mode 100644 index 0000000000..d4334b9db7 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/prop-desc.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + "errors" property of AggregateError.prototype +info: | + AggregateError.prototype.errors is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +var desc = Object.getOwnPropertyDescriptor(AggregateError.prototype, 'errors'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +verifyProperty(AggregateError.prototype, 'errors', { + enumerable: false, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/errors/return-from-iterable-errors.js b/test/built-ins/AggregateError/prototype/errors/return-from-iterable-errors.js new file mode 100644 index 0000000000..56c4af10c1 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/return-from-iterable-errors.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + Return a new array from the [[AggregateErrors]] list, after an iterable errors arg. +info: | + get AggregateError.prototype.errors + + 1. Let E be the this value. + ... + 5. Return ! CreateArrayFromList(E.[[AggregateErrors]]). +includes: [compareArray.js] +features: [AggregateError, Symbol.iterator] +---*/ + +var count = 0; +var errors = { + [Symbol.iterator]() { + return { + next() { + count += 1; + return { + done: count === 3, + get value() { + return count * 3; + } + }; + } + }; + } +}; + +var case1 = new AggregateError(errors); + +assert.sameValue(count, 3); + +var get1 = case1.errors; +var get2 = case1.errors; + +assert.sameValue(Array.isArray(get1), true); +assert.sameValue(Array.isArray(get2), true); + +assert.notSameValue(get1, errors, 'creates a new array #1'); +assert.notSameValue(get2, errors, 'creates a new array #2'); +assert.notSameValue(get1, get2, 'creates a new array everytime it gets the values'); + +assert.compareArray(get1, [3, 6], 'get accessor does not trigger a new iteration #1'); +assert.compareArray(get2, [3, 6], 'get accessor does not trigger a new iteration #2'); + +assert.sameValue(count, 3, 'count is preserved'); diff --git a/test/built-ins/AggregateError/prototype/errors/return-new-array-from-list.js b/test/built-ins/AggregateError/prototype/errors/return-new-array-from-list.js new file mode 100644 index 0000000000..e44115ec8e --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/return-new-array-from-list.js @@ -0,0 +1,76 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + Return a new array from the [[AggregateErrors]] list. +info: | + get AggregateError.prototype.errors + + 1. Let E be the this value. + ... + 5. Return ! CreateArrayFromList(E.[[AggregateErrors]]). +includes: [compareArray.js] +features: [AggregateError, Symbol] +---*/ + +var errors = []; +var case1 = new AggregateError(errors); +var case1get1 = case1.errors; +var case1get2 = case1.errors; + +assert.sameValue(Array.isArray(case1get1), true); +assert.sameValue(Array.isArray(case1get2), true); + +assert.notSameValue(case1get1, errors, 'case1 - creates a new array #1'); +assert.notSameValue(case1get2, errors, 'case1 - creates a new array #2'); +assert.notSameValue(case1get1, case1get2, 'creates a new array everytime it gets the values'); + +assert.compareArray(case1get1, errors); +assert.compareArray(case1get2, errors); + +///// + +errors = [undefined, null, 1, 0, '', {}, Symbol()]; +var case2 = new AggregateError(errors); +var case2get1 = case2.errors; +var case2get2 = case2.errors; + +assert.sameValue(Array.isArray(case2get1), true); +assert.sameValue(Array.isArray(case2get2), true); + +assert.notSameValue(case2get1, errors, 'case2 - creates a new array #1'); +assert.notSameValue(case2get2, errors, 'case2 - creates a new array #2'); +assert.notSameValue(case2get1, case2get2, 'creates a new array everytime it gets the values'); + +assert.compareArray(case2get1, errors); +assert.compareArray(case2get2, errors); + +///// + +errors = [undefined,,,,undefined]; +var case3 = new AggregateError(errors); +var case3get1 = case3.errors; +var case3get2 = case3.errors; + +assert.sameValue(Array.isArray(case3get1), true); +assert.sameValue(Array.isArray(case3get2), true); + +assert.notSameValue(case3get1, errors, 'case3 - creates a new array #1'); +assert.notSameValue(case3get2, errors, 'case3 - creates a new array #2'); +assert.notSameValue(case3get1, case3get2, 'creates a new array everytime it gets the values'); + +assert.compareArray(case3get1, errors); +assert.compareArray(case3get2, errors); + +assert(Object.prototype.hasOwnProperty.call(case3get1, 0), 'filled array from a sparse origin - case3get1, 0'); +assert(Object.prototype.hasOwnProperty.call(case3get1, 1), 'filled array from a sparse origin - case3get1, 1'); +assert(Object.prototype.hasOwnProperty.call(case3get1, 2), 'filled array from a sparse origin - case3get1, 2'); +assert(Object.prototype.hasOwnProperty.call(case3get1, 3), 'filled array from a sparse origin - case3get1, 3'); +assert(Object.prototype.hasOwnProperty.call(case3get1, 4), 'filled array from a sparse origin - case3get1, 4'); + +assert(Object.prototype.hasOwnProperty.call(case3get2, 0), 'filled array from a sparse origin - case3get2, 0'); +assert(Object.prototype.hasOwnProperty.call(case3get2, 1), 'filled array from a sparse origin - case3get2, 1'); +assert(Object.prototype.hasOwnProperty.call(case3get2, 2), 'filled array from a sparse origin - case3get2, 2'); +assert(Object.prototype.hasOwnProperty.call(case3get2, 3), 'filled array from a sparse origin - case3get2, 3'); +assert(Object.prototype.hasOwnProperty.call(case3get2, 4), 'filled array from a sparse origin - case3get2, 4'); diff --git a/test/built-ins/AggregateError/prototype/errors/this-has-no-typedarrayname-internal.js b/test/built-ins/AggregateError/prototype/errors/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000..c9b6ebcdc1 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/this-has-no-typedarrayname-internal.js @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: > + Throws a TypeError exception when `this` does not have a [[AggregateErrorData]] + internal slot +info: | + get AggregateError.prototype.errors + + 1. Let E be the this value. + 2. If Type(E) is not Object, throw a TypeError exception. + 3. If E does not have an [[ErrorData]] internal slot, throw a TypeError exception. + 4. If E does not have an [[AggregateErrors]] internal slot, throw a TypeError exception. + 5. Return ! CreateArrayFromList(E.[[AggregateErrors]]). +features: [AggregateError] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + AggregateError.prototype, 'errors' +).get; + +assert.throws(TypeError, function() { + getter.call(new Error()); +}, 'this is an instance of Error, no [[AggregateErrors]]'); + +assert.throws(TypeError, function() { + getter.call(AggregateError); +}, 'AggregateError does not have an [[AggregateErrors]] internal'); diff --git a/test/built-ins/AggregateError/prototype/errors/this-is-not-object.js b/test/built-ins/AggregateError/prototype/errors/this-is-not-object.js new file mode 100644 index 0000000000..7813021817 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/errors/this-is-not-object.js @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-aggregate-error.prototype.errors +description: Throws a TypeError exception when `this` is not Object +info: | + get AggregateError.prototype.errors + + 1. Let E be the this value. + 2. If Type(E) is not Object, throw a TypeError exception. + ... +features: [AggregateError, Symbol] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + AggregateError.prototype, 'errors' +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, 'this is undefined'); + +assert.throws(TypeError, function() { + getter.call(null); +}, 'this is null'); + +assert.throws(TypeError, function() { + getter.call(42); +}, 'this is 42'); + +assert.throws(TypeError, function() { + getter.call('1'); +}, 'this is a string'); + +assert.throws(TypeError, function() { + getter.call(true); +}, 'this is true'); + +assert.throws(TypeError, function() { + getter.call(false); +}, 'this is false'); + +var s = Symbol('s'); +assert.throws(TypeError, function() { + getter.call(s); +}, 'this is a Symbol'); diff --git a/test/built-ins/AggregateError/prototype/message.js b/test/built-ins/AggregateError/prototype/message.js new file mode 100644 index 0000000000..c37a83830d --- /dev/null +++ b/test/built-ins/AggregateError/prototype/message.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.message +description: > + The `AggregateError.prototype.message` property descriptor. +info: | + The initial value of the message property of the prototype for a given AggregateError + constructor is the empty String. + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described (...) has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +verifyProperty(AggregateError.prototype, 'message', { + value: '', + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/name.js b/test/built-ins/AggregateError/prototype/name.js new file mode 100644 index 0000000000..b15a19e757 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.name +description: > + The `AggregateError.prototype.name` property descriptor. +info: | + The initial value of AggregateError.prototype.name is "AggregateError". + + 17 ECMAScript Standard Built-in Objects: + + Every other data property described (...) has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +verifyProperty(AggregateError.prototype, 'name', { + value: 'AggregateError', + enumerable: false, + writable: true, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/prop-desc.js b/test/built-ins/AggregateError/prototype/prop-desc.js new file mode 100644 index 0000000000..29ceda94b7 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype +description: > + Property descriptor of AggregateError.prototype +info: | + AggregateError.prototype + + The initial value of AggregateError.prototype is the intrinsic object %AggregateErrorPrototype%. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +assert.sameValue(typeof AggregateError.prototype, 'object'); + +verifyProperty(AggregateError, 'prototype', { + enumerable: false, + writable: false, + configurable: false +}); diff --git a/test/built-ins/AggregateError/prototype/proto.js b/test/built-ins/AggregateError/prototype/proto.js new file mode 100644 index 0000000000..2283c6ccb9 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-aggregate-error-prototype-objects +description: The prototype of AggregateError.prototype constructor is Error.prototype +info: | + Properties of the AggregateError Prototype Object + + - has a [[Prototype]] internal slot whose value is the intrinsic object %Error.prototype%. +features: [AggregateError] +---*/ + +var proto = Object.getPrototypeOf(AggregateError.prototype); + +assert.sameValue(proto, Error.prototype); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message-abrupt.js b/test/built-ins/AggregateError/prototype/toString/get-message-abrupt.js new file mode 100644 index 0000000000..b70c907e44 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message-abrupt.js @@ -0,0 +1,39 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Gets the Object message, returning abrupt completion +info: | + AggregateError.prototype.toString ( ) + + ... + 5. Let msg be ? Get(O, "message"). + 6. If msg is undefined, set msg to the empty String; otherwise set msg to ? ToString(msg). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var called = 0; +var nameCalled = 0; +var obj = { + get name() { + nameCalled += 1; + }, + get message() { + called += 1; + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + method.call(obj); +}); + +assert.sameValue(called, 1); +assert.sameValue(nameCalled, 1); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message-empty-string.js b/test/built-ins/AggregateError/prototype/toString/get-message-empty-string.js new file mode 100644 index 0000000000..3aebaeb05c --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message-empty-string.js @@ -0,0 +1,54 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + If message value is the empty string, return name +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var result = method.call({ + name: 'the name', + message: '', +}); + +assert.sameValue(result, 'the name', 'explicit from own property'); + +result = false; +result = method.call(Object.create({ + name: 'the name', + message: '', +})); + +assert.sameValue(result, 'the name', 'explicit from prototype'); + +result = false; +result = method.call({ + name: 'the name', + message: undefined, +}); + +assert.sameValue(result, 'the name', 'message is undefined'); + +result = false; +result = method.call({ + name: 'the name!', + message: { toString() { return ''; } }, +}); + +assert.sameValue(result, 'the name!', 'return name'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message-toString-object.js b/test/built-ins/AggregateError/prototype/toString/get-message-toString-object.js new file mode 100644 index 0000000000..c6de5b6ecb --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message-toString-object.js @@ -0,0 +1,83 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString on the message object value +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError, Symbol.toPrimitive] +---*/ + +var method = AggregateError.prototype.toString; + +var called = 0; +var obj = { + message: { + [Symbol.toPrimitive]() { + called += 1; + return 'from @@toPrimitive'; + }, + toString() { + throw new Test262Error(); + }, + valueOf() { + throw new Test262Error(); + }, + }, + name: '', +}; + +var result = method.call(obj); + +assert.sameValue(called, 1); +assert.sameValue(result, 'from @@toPrimitive'); + +called = 0; +obj = { + message: { + [Symbol.toPrimitive]: undefined, + toString() { + called += 1; + return 'from the toString method'; + }, + valueOf() { + throw new Test262Error(); + }, + }, + name: '', +}; +result = false; + +result = method.call(obj); +assert.sameValue(called, 1); +assert.sameValue(result, 'from the toString method'); + +called = 0; +obj = { + message: { + [Symbol.toPrimitive]: undefined, + toString: undefined, + valueOf() { + called += 1; + return 'from the valueOf method'; + }, + }, + name: '', +}; +result = false; + +result = method.call(obj); +assert.sameValue(called, 1); +assert.sameValue(result, 'from the valueOf method'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message-toString-symbol.js b/test/built-ins/AggregateError/prototype/toString/get-message-toString-symbol.js new file mode 100644 index 0000000000..2e8302a929 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message-toString-symbol.js @@ -0,0 +1,35 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString(Symbol msg) +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError, Symbol] +---*/ + +var method = AggregateError.prototype.toString; + +var obj = { name: '', message: Symbol() }; + +assert.throws(TypeError, function() { + method.call(obj); +}, 'own property'); + +obj = Object.create({ name: '', message: Symbol() }); + +assert.throws(TypeError, function() { + method.call(obj); +}, 'from prototype'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message-toString-undefined.js b/test/built-ins/AggregateError/prototype/toString/get-message-toString-undefined.js new file mode 100644 index 0000000000..0dfb914fad --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message-toString-undefined.js @@ -0,0 +1,38 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString(msg) where it can return "undefined" +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var obj = { + message: { + toString() { + return undefined; + } + }, + name: 'hi', +}; + +assert.sameValue(method.call(obj), 'hi\u003A\u0020undefined', 'with name'); + +obj.name = ''; + +assert.sameValue(method.call(obj), 'undefined', 'without name'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message-toString.js b/test/built-ins/AggregateError/prototype/toString/get-message-toString.js new file mode 100644 index 0000000000..c65c8a34bb --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message-toString.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString(message) +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var obj = { name: '' }; + +obj.message = 0; +assert.sameValue(method.call(obj), '0', 'Number 0'); +obj.message = null; +assert.sameValue(method.call(obj), 'null', 'null'); +obj.message = false; +assert.sameValue(method.call(obj), 'false', 'false'); +obj.message = true; +assert.sameValue(method.call(obj), 'true', 'true'); +obj.message = 1; +assert.sameValue(method.call(obj), '1', 'Number 1'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message-undefined.js b/test/built-ins/AggregateError/prototype/toString/get-message-undefined.js new file mode 100644 index 0000000000..c708cc9706 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message-undefined.js @@ -0,0 +1,64 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + An undefined message property value is cast to 'AggregateError' +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var result = method.call({ + message: undefined, +}); + +assert.sameValue(result, 'AggregateError', 'explicit from own property'); + +result = false; +result = method.call({}); + +assert.sameValue(result, 'AggregateError', 'implicit'); + +result = false; +result = method.call(Object.create({ + message: undefined, +})); + +assert.sameValue(result, 'AggregateError', 'explicit from prototype'); + +result = false; +result = method.call({ + message: undefined, + name: 'a name', +}); + +assert.sameValue(result, 'a name', 'explicit from own property, name is set'); + +result = false; +result = method.call({ + name: 'a name', +}); + +assert.sameValue(result, 'a name', 'implicit, name is set'); + +result = false; +result = method.call(Object.create({ + message: undefined, + name: 'a name', +})); + +assert.sameValue(result, 'a name', 'explicit from prototype, name is set'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-message.js b/test/built-ins/AggregateError/prototype/toString/get-message.js new file mode 100644 index 0000000000..07cb270c1f --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-message.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Gets the Object message +info: | + AggregateError.prototype.toString ( ) + + ... + 5. Let msg be ? Get(O, "message"). + ... +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var called = 0; +var nameCalled = 0; +var obj = { + get name() { + nameCalled += 1; + }, + get message() { + called += 1; + } +}; + +method.call(obj); + +assert.sameValue(nameCalled, 1); +assert.sameValue(called, 1); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name-abrupt.js b/test/built-ins/AggregateError/prototype/toString/get-name-abrupt.js new file mode 100644 index 0000000000..de8a27551c --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name-abrupt.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Gets the Object name, returning abrupt completion +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; otherwise set name to ? ToString(name). + ... +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var called = 0; +var obj = { + get name() { + called += 1; + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + method.call(obj); +}); + +assert.sameValue(called, 1); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name-empty-string.js b/test/built-ins/AggregateError/prototype/toString/get-name-empty-string.js new file mode 100644 index 0000000000..22a9391bfa --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name-empty-string.js @@ -0,0 +1,70 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + If name value is the empty string, return msg +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var result = method.call({ + name: '', + message: 'the message', +}); + +assert.sameValue(result, 'the message', 'explicit from own property'); + +result = false; +result = method.call(Object.create({ + name: '', + message: 'the message', +})); + +assert.sameValue(result, 'the message', 'explicit from prototype'); + +result = false; +result = method.call({ + name: '', + message: '', +}); + +assert.sameValue(result, '', 'both name and msg are the empty string'); + +result = false; +result = method.call({ + name: '', + message: undefined, +}); + +assert.sameValue(result, 'message', 'return msg'); + +result = false; +result = method.call({ + name: { toString() { return ''; } }, + message: 'the message!', +}); + +assert.sameValue(result, 'the message!', 'own name property is cast to an empty string'); + +result = false; +result = method.call(Object.create({ + name: { toString() { return ''; } }, + message: 'the message!', +})); + +assert.sameValue(result, 'the message!', 'chained name property is cast to an empty string'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name-toString-object.js b/test/built-ins/AggregateError/prototype/toString/get-name-toString-object.js new file mode 100644 index 0000000000..39bf62d674 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name-toString-object.js @@ -0,0 +1,83 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString on the name object value +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError, Symbol.toPrimitive] +---*/ + +var method = AggregateError.prototype.toString; + +var called = 0; +var obj = { + name: { + [Symbol.toPrimitive]() { + called += 1; + return 'from @@toPrimitive'; + }, + toString() { + throw new Test262Error(); + }, + valueOf() { + throw new Test262Error(); + }, + }, + message: '', +}; + +var result = method.call(obj); + +assert.sameValue(called, 1); +assert.sameValue(result, 'from @@toPrimitive'); + +called = 0; +obj = { + name: { + [Symbol.toPrimitive]: undefined, + toString() { + called += 1; + return 'from the toString method'; + }, + valueOf() { + throw new Test262Error(); + }, + }, + message: '', +}; +result = false; + +result = method.call(obj); +assert.sameValue(called, 1); +assert.sameValue(result, 'from the toString method'); + +called = 0; +obj = { + name: { + [Symbol.toPrimitive]: undefined, + toString: undefined, + valueOf() { + called += 1; + return 'from the valueOf method'; + }, + }, + message: '', +}; +result = false; + +result = method.call(obj); +assert.sameValue(called, 1); +assert.sameValue(result, 'from the valueOf method'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name-toString-symbol.js b/test/built-ins/AggregateError/prototype/toString/get-name-toString-symbol.js new file mode 100644 index 0000000000..6b17b58281 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name-toString-symbol.js @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString(name) +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError, Symbol] +---*/ + +var method = AggregateError.prototype.toString; + +var obj = { name: Symbol(), message: '' }; + +assert.throws(TypeError, function() { + method.call(obj); +}, 'own property'); + +obj = Object.create({ name: Symbol(), message: '' }); +assert.throws(TypeError, function() { + method.call(obj); +}, 'from prototype'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name-toString-undefined.js b/test/built-ins/AggregateError/prototype/toString/get-name-toString-undefined.js new file mode 100644 index 0000000000..1ed8337b7b --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name-toString-undefined.js @@ -0,0 +1,38 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString(name) where it can return "undefined" +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var obj = { + name: { + toString() { + return undefined; + } + }, + message: '', +}; + +assert.sameValue(method.call(obj), 'undefined', 'without message'); + +obj.message = 'lol'; + +assert.sameValue(method.call(obj), 'undefined\u003A\u0020lol', 'with message'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name-toString.js b/test/built-ins/AggregateError/prototype/toString/get-name-toString.js new file mode 100644 index 0000000000..2aaf95d475 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name-toString.js @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + ToString(name) +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var obj = { message: '' }; + +obj.name = 0; +assert.sameValue(method.call(obj), '0', 'Number 0'); +obj.name = null; +assert.sameValue(method.call(obj), 'null', 'null'); +obj.name = false; +assert.sameValue(method.call(obj), 'false', 'false'); +obj.name = true; +assert.sameValue(method.call(obj), 'true', 'true'); +obj.name = 1; +assert.sameValue(method.call(obj), '1', 'Number 1'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name-undefined.js b/test/built-ins/AggregateError/prototype/toString/get-name-undefined.js new file mode 100644 index 0000000000..01d5d2745b --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name-undefined.js @@ -0,0 +1,68 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + An undefined name property value is cast to 'AggregateError' +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var result = method.call({ + name: undefined, + message: '', +}); + +assert.sameValue(result, 'AggregateError', 'explicit from own property'); + +result = false; +result = method.call({ + message: '', +}); + +assert.sameValue(result, 'AggregateError', 'implicit'); + +result = false; +result = method.call(Object.create({ + name: undefined, + message: '', +})); + +assert.sameValue(result, 'AggregateError', 'explicit from prototype'); + +result = false; +result = method.call({ + name: undefined, + message: 'a message', +}); + +assert.sameValue(result, 'AggregateError\u003A\u0020a message', 'explicit from own property, message is set'); + +result = false; +result = method.call({ + message: 'a message', +}); + +assert.sameValue(result, 'AggregateError\u003A\u0020a message', 'implicit, message is set'); + +result = false; +result = method.call(Object.create({ + name: undefined, + message: 'a message', +})); + +assert.sameValue(result, 'AggregateError\u003A\u0020a message', 'explicit from prototype, message is set'); diff --git a/test/built-ins/AggregateError/prototype/toString/get-name.js b/test/built-ins/AggregateError/prototype/toString/get-name.js new file mode 100644 index 0000000000..8926bc8c3d --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/get-name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Gets the Object name +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; otherwise set name to ? ToString(name). + ... +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var called = 0; +var obj = { + get name() { + called += 1; + } +}; + +method.call(obj); + +assert.sameValue(called, 1); diff --git a/test/built-ins/AggregateError/prototype/toString/length.js b/test/built-ins/AggregateError/prototype/toString/length.js new file mode 100644 index 0000000000..949e053a26 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Property descriptor of AggregateError.prototype.toString.length +info: | + AggregateError.prototype.toString + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +verifyProperty(AggregateError.prototype.toString, 'length', { + value: 0, + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/toString/name.js b/test/built-ins/AggregateError/prototype/toString/name.js new file mode 100644 index 0000000000..f44abe5e3d --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/name.js @@ -0,0 +1,24 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Property descriptor of AggregateError.prototype.toString.name +info: | + AggregateError.prototype.toString + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +verifyProperty(AggregateError.prototype.toString, 'name', { + value: 'toString', + enumerable: false, + writable: false, + configurable: true +}); diff --git a/test/built-ins/AggregateError/prototype/toString/prop-desc.js b/test/built-ins/AggregateError/prototype/toString/prop-desc.js new file mode 100644 index 0000000000..a5cc8c6a4a --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/prop-desc.js @@ -0,0 +1,23 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Property descriptor of AggregateError.prototype.toString +info: | + ES Section 17 + + Every other data property (...) has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [AggregateError] +---*/ + +assert.sameValue(typeof AggregateError.prototype.toString, 'function'); + +verifyProperty(AggregateError.prototype, 'toString', { + configurable: true, + writable: true, + enumerable: false, +}); diff --git a/test/built-ins/AggregateError/prototype/toString/returns-string.js b/test/built-ins/AggregateError/prototype/toString/returns-string.js new file mode 100644 index 0000000000..b528719974 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/returns-string.js @@ -0,0 +1,38 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Returns a string concatenating name and msg when both are defined +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. Let name be ? Get(O, "name"). + 4. If name is undefined, set name to "AggregateError"; 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). + 7. If name is the empty String, return msg. + 8. If msg is the empty String, return name. + 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE) and msg. +features: [AggregateError] +---*/ + +var method = AggregateError.prototype.toString; + +var obj = { + name: 'foo', + message: 'bar', +}; + +assert.sameValue(method.call(obj), 'foo\u003A\u0020bar'); + +obj = new AggregateError(['a', 'b', 'c'], 'Hello World!'); + +assert.sameValue(method.call(obj), 'AggregateError\u003A\u0020Hello World!'); + +obj = new AggregateError(['a', 'b', 'c']); + +assert.sameValue(method.call(obj), 'AggregateError'); diff --git a/test/built-ins/AggregateError/prototype/toString/this-not-object-throws.js b/test/built-ins/AggregateError/prototype/toString/this-not-object-throws.js new file mode 100644 index 0000000000..22b958f581 --- /dev/null +++ b/test/built-ins/AggregateError/prototype/toString/this-not-object-throws.js @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-aggregate-error.prototype.toString +description: > + Property descriptor of AggregateError.prototype.toString +info: | + AggregateError.prototype.toString ( ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. +features: [AggregateError, Symbol] +---*/ + +var method = AggregateError.prototype.toString; + +assert.throws(TypeError, () => { + method.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, () => { + method.call(null); +}, 'null'); + +assert.throws(TypeError, () => { + method.call(false); +}, 'false'); + +assert.throws(TypeError, () => { + method.call(true); +}, 'true'); + +assert.throws(TypeError, () => { + method.call(42); +}, 'number'); + +assert.throws(TypeError, () => { + method.call('string'); +}, 'string'); + +var s = Symbol(); +assert.throws(TypeError, () => { + method.call(s); +}, 'symbol');