mirror of https://github.com/tc39/test262.git
Add context tests
This commit is contained in:
parent
715964b16b
commit
aca10842a2
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Promise.any invoked on a constructor value that throws an error
|
||||
esid: sec-promise.any
|
||||
info: |
|
||||
2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
|
||||
NewPromiseCapability
|
||||
|
||||
...
|
||||
7. Let promise be ? Construct(C, « executor »).
|
||||
features: [Promise.any]
|
||||
---*/
|
||||
|
||||
var CustomPromise = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Promise.any.call(CustomPromise);
|
||||
});
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Promise.any invoked on a constructor value
|
||||
esid: sec-promise.any
|
||||
info: |
|
||||
2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
...
|
||||
5. Let result be PerformPromiseany(iteratorRecord, C, promiseCapability).
|
||||
...
|
||||
7. Return Completion(result).
|
||||
features: [Promise.any, class]
|
||||
---*/
|
||||
|
||||
var executor = null;
|
||||
var callCount = 0;
|
||||
|
||||
class SubPromise extends Promise {
|
||||
constructor(a) {
|
||||
super(a);
|
||||
executor = a;
|
||||
callCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
var instance = Promise.any.call(SubPromise, []);
|
||||
|
||||
assert.sameValue(instance.constructor, SubPromise);
|
||||
assert.sameValue(instance instanceof SubPromise, true);
|
||||
|
||||
assert.sameValue(callCount, 1);
|
||||
assert.sameValue(typeof executor, 'function');
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Promise.any invoked on a non-constructor value
|
||||
esid: sec-promise.any
|
||||
info: |
|
||||
...
|
||||
2. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
|
||||
NewPromiseCapability ( C )
|
||||
|
||||
1. If IsConstructor(C) is false, throw a TypeError exception.
|
||||
features: [Promise.any]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.any.call(eval);
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Promise.any invoked on a non-object value
|
||||
esid: sec-promise.any
|
||||
info: |
|
||||
1. Let C be the this value.
|
||||
2. If Type(C) is not Object, throw a TypeError exception.
|
||||
features: [Promise.any, Symbol]
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.any.call(undefined, []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.any.call(null, []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.any.call(86, []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.any.call('string', []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.any.call(true, []);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Promise.any.call(Symbol(), []);
|
||||
});
|
Loading…
Reference in New Issue