OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-species --allow-natives-syntax |
| 6 |
| 7 // Test that Promises use @@species appropriately |
| 8 |
| 9 // Another constructor with no species will not be instantiated |
| 10 var test = new Promise(function(){}); |
| 11 var bogoCount = 0; |
| 12 function bogusConstructor() { bogoCount++; } |
| 13 test.constructor = bogusConstructor; |
| 14 assertTrue(Promise.resolve(test) instanceof Promise); |
| 15 assertFalse(Promise.resolve(test) instanceof bogusConstructor); |
| 16 // Tests that chromium:575314 is fixed thoroughly |
| 17 Promise.resolve(test).catch(e => %AbortJS("Error " + e)).then(() => { |
| 18 if (bogoCount != 0) %AbortJS("bogoCount was " + bogoCount + " should be 0"); |
| 19 }); |
| 20 |
| 21 // If there is a species, it will be instantiated |
| 22 // @@species will be read exactly once, and the constructor is called with a |
| 23 // function |
| 24 var count = 0; |
| 25 var params; |
| 26 class MyPromise extends Promise { |
| 27 constructor(...args) { |
| 28 super(...args); |
| 29 params = args; |
| 30 } |
| 31 static get [Symbol.species]() { |
| 32 count++ |
| 33 return this; |
| 34 } |
| 35 } |
| 36 |
| 37 var myPromise = MyPromise.resolve().then(); |
| 38 assertEquals(1, count); |
| 39 assertEquals(1, params.length); |
| 40 assertEquals('function', typeof(params[0])); |
| 41 assertTrue(myPromise instanceof MyPromise); |
| 42 assertTrue(myPromise instanceof Promise); |
OLD | NEW |