mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
Extend coverage for Promise.prototype.catch
This commit is contained in:
parent
12902b29c0
commit
23659d6128
31
test/built-ins/Promise/prototype/catch/this-value-non-object.js
vendored
Normal file
31
test/built-ins/Promise/prototype/catch/this-value-non-object.js
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.prototype.catch
|
||||||
|
es6id: 25.4.5.1
|
||||||
|
description: >
|
||||||
|
Promise.prototype.catch called with a non-object-coercible `this` value
|
||||||
|
info: |
|
||||||
|
1. Let promise be the this value.
|
||||||
|
2. Return ? Invoke(promise, "then", «undefined, onRejected»).
|
||||||
|
|
||||||
|
7.3.18 Invoke
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||||
|
3. Let func be ? GetV(V, P).
|
||||||
|
4. Return ? Call(func, V, argumentsList).
|
||||||
|
|
||||||
|
7.3.2 GetV
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. Let O be ? ToObject(V).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call(undefined);
|
||||||
|
}, 'undefined');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call(null);
|
||||||
|
}, 'null');
|
44
test/built-ins/Promise/prototype/catch/this-value-obj-coercible.js
vendored
Normal file
44
test/built-ins/Promise/prototype/catch/this-value-obj-coercible.js
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.prototype.catch
|
||||||
|
es6id: 25.4.5.1
|
||||||
|
description: >
|
||||||
|
Promise.prototype.catch called with an object-coercible `this` value
|
||||||
|
info: |
|
||||||
|
1. Let promise be the this value.
|
||||||
|
2. Return ? Invoke(promise, "then", «undefined, onRejected»).
|
||||||
|
|
||||||
|
7.3.18 Invoke
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||||
|
3. Let func be ? GetV(V, P).
|
||||||
|
4. Return ? Call(func, V, argumentsList).
|
||||||
|
|
||||||
|
7.3.2 GetV
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. Let O be ? ToObject(V).
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var booleanCount = 0;
|
||||||
|
Boolean.prototype.then = function() { booleanCount += 1; };
|
||||||
|
Promise.prototype.catch.call(true);
|
||||||
|
assert.sameValue(booleanCount, 1, 'boolean');
|
||||||
|
|
||||||
|
var numberCount = 0;
|
||||||
|
Number.prototype.then = function() { numberCount += 1; };
|
||||||
|
Promise.prototype.catch.call(34);
|
||||||
|
assert.sameValue(numberCount, 1, 'number');
|
||||||
|
|
||||||
|
var stringCount = 0;
|
||||||
|
String.prototype.then = function() { stringCount += 1; };
|
||||||
|
Promise.prototype.catch.call('');
|
||||||
|
assert.sameValue(stringCount, 1, 'string');
|
||||||
|
|
||||||
|
var symbolCount = 0;
|
||||||
|
Symbol.prototype.then = function() { symbolCount += 1; };
|
||||||
|
Promise.prototype.catch.call(Symbol());
|
||||||
|
assert.sameValue(symbolCount, 1, 'symbol');
|
62
test/built-ins/Promise/prototype/catch/this-value-then-not-callable.js
vendored
Normal file
62
test/built-ins/Promise/prototype/catch/this-value-then-not-callable.js
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.prototype.catch
|
||||||
|
es6id: 25.4.5.1
|
||||||
|
description: >
|
||||||
|
Promise.prototype.catch called with a `this` value that does not define a
|
||||||
|
callable `this` property
|
||||||
|
info: |
|
||||||
|
1. Let promise be the this value.
|
||||||
|
2. Return ? Invoke(promise, "then", «undefined, onRejected»).
|
||||||
|
|
||||||
|
7.3.18 Invoke
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||||
|
3. Let func be ? GetV(V, P).
|
||||||
|
4. Return ? Call(func, V, argumentsList).
|
||||||
|
|
||||||
|
7.3.2 GetV
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. Let O be ? ToObject(V).
|
||||||
|
3. Return ? O.[[Get]](P, V).
|
||||||
|
|
||||||
|
7.3.12 Call (F, V [ , argumentsList ])
|
||||||
|
|
||||||
|
1. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||||
|
2. If IsCallable(F) is false, throw a TypeError exception.
|
||||||
|
3. Return ? F.[[Call]](V, argumentsList).
|
||||||
|
features: [Symbol]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var symbol = Symbol();
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call({});
|
||||||
|
}, 'undefined');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call({ then: null });
|
||||||
|
}, 'null');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call({ then: 1 });
|
||||||
|
}, 'number');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call({ then: '' });
|
||||||
|
}, 'string');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call({ then: true });
|
||||||
|
}, 'boolean');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call({ then: symbol });
|
||||||
|
}, 'symbol');
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Promise.prototype.catch.call({ then: {} });
|
||||||
|
}, 'ordinary object');
|
34
test/built-ins/Promise/prototype/catch/this-value-then-poisoned.js
vendored
Normal file
34
test/built-ins/Promise/prototype/catch/this-value-then-poisoned.js
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.prototype.catch
|
||||||
|
es6id: 25.4.5.1
|
||||||
|
description: >
|
||||||
|
Promise.prototype.catch called with a `this` value whose `then` property is
|
||||||
|
an accessor property that returns an abrupt completion
|
||||||
|
info: |
|
||||||
|
1. Let promise be the this value.
|
||||||
|
2. Return ? Invoke(promise, "then", «undefined, onRejected»).
|
||||||
|
|
||||||
|
7.3.18 Invoke
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||||
|
3. Let func be ? GetV(V, P).
|
||||||
|
|
||||||
|
7.3.2 GetV
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. Let O be ? ToObject(V).
|
||||||
|
3. Return ? O.[[Get]](P, V).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var poisonedThen = Object.defineProperty({}, 'then', {
|
||||||
|
get: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
Promise.prototype.catch.call(poisonedThen);
|
||||||
|
});
|
41
test/built-ins/Promise/prototype/catch/this-value-then-throws.js
vendored
Normal file
41
test/built-ins/Promise/prototype/catch/this-value-then-throws.js
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-promise.prototype.catch
|
||||||
|
es6id: 25.4.5.1
|
||||||
|
description: >
|
||||||
|
Promise.prototype.catch called with a `this` value that defines a `then`
|
||||||
|
method which returns an abrupt completion.
|
||||||
|
info: |
|
||||||
|
1. Let promise be the this value.
|
||||||
|
2. Return ? Invoke(promise, "then", «undefined, onRejected»).
|
||||||
|
|
||||||
|
7.3.18 Invoke
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||||
|
3. Let func be ? GetV(V, P).
|
||||||
|
4. Return ? Call(func, V, argumentsList).
|
||||||
|
|
||||||
|
7.3.2 GetV
|
||||||
|
|
||||||
|
1. Assert: IsPropertyKey(P) is true.
|
||||||
|
2. Let O be ? ToObject(V).
|
||||||
|
3. Return ? O.[[Get]](P, V).
|
||||||
|
|
||||||
|
7.3.12 Call (F, V [ , argumentsList ])
|
||||||
|
|
||||||
|
1. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||||
|
2. If IsCallable(F) is false, throw a TypeError exception.
|
||||||
|
3. Return ? F.[[Call]](V, argumentsList).
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var thrower = {
|
||||||
|
then: function() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
Promise.prototype.catch.call(thrower);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user