shell.js (3034B)
1 // GENERATED, DO NOT EDIT 2 // file: isConstructor.js 3 // Copyright (C) 2017 André Bargull. All rights reserved. 4 // This code is governed by the BSD license found in the LICENSE file. 5 6 /*--- 7 description: | 8 Test if a given function is a constructor function. 9 defines: [isConstructor] 10 features: [Reflect.construct] 11 ---*/ 12 13 function isConstructor(f) { 14 if (typeof f !== "function") { 15 throw new Test262Error("isConstructor invoked with a non-function value"); 16 } 17 18 try { 19 Reflect.construct(function(){}, [], f); 20 } catch (e) { 21 return false; 22 } 23 return true; 24 } 25 26 // file: promiseHelper.js 27 // Copyright (C) 2017 Ecma International. All rights reserved. 28 // This code is governed by the BSD license found in the LICENSE file. 29 /*--- 30 description: | 31 Check that an array contains a numeric sequence starting at 1 32 and incrementing by 1 for each entry in the array. Used by 33 Promise tests to assert the order of execution in deep Promise 34 resolution pipelines. 35 defines: [checkSequence, checkSettledPromises] 36 ---*/ 37 38 function checkSequence(arr, message) { 39 arr.forEach(function(e, i) { 40 if (e !== (i+1)) { 41 throw new Test262Error((message ? message : "Steps in unexpected sequence:") + 42 " '" + arr.join(',') + "'"); 43 } 44 }); 45 46 return true; 47 } 48 49 function checkSettledPromises(settleds, expected, message) { 50 const prefix = message ? `${message}: ` : ''; 51 52 assert.sameValue(Array.isArray(settleds), true, `${prefix}Settled values is an array`); 53 54 assert.sameValue( 55 settleds.length, 56 expected.length, 57 `${prefix}The settled values has a different length than expected` 58 ); 59 60 settleds.forEach((settled, i) => { 61 assert.sameValue( 62 Object.prototype.hasOwnProperty.call(settled, 'status'), 63 true, 64 `${prefix}The settled value has a property status` 65 ); 66 67 assert.sameValue(settled.status, expected[i].status, `${prefix}status for item ${i}`); 68 69 if (settled.status === 'fulfilled') { 70 assert.sameValue( 71 Object.prototype.hasOwnProperty.call(settled, 'value'), 72 true, 73 `${prefix}The fulfilled promise has a property named value` 74 ); 75 76 assert.sameValue( 77 Object.prototype.hasOwnProperty.call(settled, 'reason'), 78 false, 79 `${prefix}The fulfilled promise has no property named reason` 80 ); 81 82 assert.sameValue(settled.value, expected[i].value, `${prefix}value for item ${i}`); 83 } else { 84 assert.sameValue(settled.status, 'rejected', `${prefix}Valid statuses are only fulfilled or rejected`); 85 86 assert.sameValue( 87 Object.prototype.hasOwnProperty.call(settled, 'value'), 88 false, 89 `${prefix}The fulfilled promise has no property named value` 90 ); 91 92 assert.sameValue( 93 Object.prototype.hasOwnProperty.call(settled, 'reason'), 94 true, 95 `${prefix}The fulfilled promise has a property named reason` 96 ); 97 98 assert.sameValue(settled.reason, expected[i].reason, `${prefix}Reason value for item ${i}`); 99 } 100 }); 101 }