tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

context-non-object-with-promise.js (1289B)


      1 // Copyright (C) 2015 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 es6id: 25.4.4.5
      6 description: >
      7  Throws a TypeError if `this` is not an Object.
      8 info: |
      9  Promise.resolve ( x )
     10 
     11  1. Let C be the this value.
     12  2. If Type(C) is not Object, throw a TypeError exception.
     13  ...
     14 features: [Symbol]
     15 ---*/
     16 
     17 var promise = new Promise(function() {});
     18 
     19 promise.constructor = undefined;
     20 assert.throws(TypeError, function() {
     21  Promise.resolve.call(undefined, promise);
     22 }, "`this` value is undefined");
     23 
     24 promise.constructor = null;
     25 assert.throws(TypeError, function() {
     26  Promise.resolve.call(null, promise);
     27 }, "`this` value is null");
     28 
     29 promise.constructor = true;
     30 assert.throws(TypeError, function() {
     31  Promise.resolve.call(true, promise);
     32 }, "`this` value is a Boolean");
     33 
     34 promise.constructor = 1;
     35 assert.throws(TypeError, function() {
     36  Promise.resolve.call(1, promise);
     37 }, "`this` value is a Number");
     38 
     39 promise.constructor = "";
     40 assert.throws(TypeError, function() {
     41  Promise.resolve.call("", promise);
     42 }, "`this` value is a String");
     43 
     44 var symbol = Symbol();
     45 promise.constructor = symbol;
     46 assert.throws(TypeError, function() {
     47  Promise.resolve.call(symbol, promise);
     48 }, "`this` value is a Symbol");
     49 
     50 reportCompare(0, 0);