summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/resolve/context-non-object-with-promise.js
blob: be4934f14e25d2961855f4ed1875f3e38eda5238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (C) 2015 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
es6id: 25.4.4.5
description: >
  Throws a TypeError if `this` is not an Object.
info: |
  Promise.resolve ( x )

  1. Let C be the this value.
  2. If Type(C) is not Object, throw a TypeError exception.
  ...
features: [Symbol]
---*/

var promise = new Promise(function() {});

promise.constructor = undefined;
assert.throws(TypeError, function() {
  Promise.resolve.call(undefined, promise);
}, "`this` value is undefined");

promise.constructor = null;
assert.throws(TypeError, function() {
  Promise.resolve.call(null, promise);
}, "`this` value is null");

promise.constructor = true;
assert.throws(TypeError, function() {
  Promise.resolve.call(true, promise);
}, "`this` value is a Boolean");

promise.constructor = 1;
assert.throws(TypeError, function() {
  Promise.resolve.call(1, promise);
}, "`this` value is a Number");

promise.constructor = "";
assert.throws(TypeError, function() {
  Promise.resolve.call("", promise);
}, "`this` value is a String");

var symbol = Symbol();
promise.constructor = symbol;
assert.throws(TypeError, function() {
  Promise.resolve.call(symbol, promise);
}, "`this` value is a Symbol");

reportCompare(0, 0);