thenable-counter.js (960B)
1 assertEq(getUseCounterResults().ThenableUse, 0); 2 assertEq(getUseCounterResults().ThenableUseProto, 0); 3 assertEq(getUseCounterResults().ThenableUseStandardProto, 0); 4 5 function test_thenable(obj, keys) { 6 let before = keys.map(prop => getUseCounterResults()[prop]); 7 Promise.resolve(obj); 8 let after = keys.map(prop => getUseCounterResults()[prop]); 9 for (var i = 0; i < keys.length; i++) { 10 assertEq(before[i] + 1, after[i]); 11 } 12 } 13 14 let obj = { then: () => { console.log("hello"); } }; 15 test_thenable(obj, ["ThenableUse"]); 16 17 let obj_with_proto = { __proto__: obj }; 18 test_thenable(obj_with_proto, ["ThenableUse", "ThenableUseProto"]); 19 20 Array.prototype.then = () => { console.log("hello"); }; 21 test_thenable([], ["ThenableUse", "ThenableUseProto", "ThenableUseStandardProto"]); 22 23 Object.prototype.then = () => { console.log("then"); } 24 test_thenable({}, ["ThenableUse", "ThenableUseProto", "ThenableUseStandardProto", "ThenableUseObjectProto"]);