tests.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  1. 'use strict';
  2. var test = require('tape');
  3. var forEach = require('foreach');
  4. var is = require('object-is');
  5. var debug = require('util').format;
  6. var assign = require('object.assign');
  7. var v = require('./helpers/values');
  8. var diffOps = require('./diffOps');
  9. var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
  10. var getArraySubclassWithSpeciesConstructor = function getArraySubclass(speciesConstructor) {
  11. var Bar = function Bar() {
  12. var inst = [];
  13. Object.setPrototypeOf(inst, Bar.prototype);
  14. Object.defineProperty(inst, 'constructor', { value: Bar });
  15. return inst;
  16. };
  17. Bar.prototype = Object.create(Array.prototype);
  18. Object.setPrototypeOf(Bar, Array);
  19. Object.defineProperty(Bar, Symbol.species, { value: speciesConstructor });
  20. return Bar;
  21. };
  22. var hasSpecies = v.hasSymbols && Symbol.species;
  23. var es2015 = function ES2015(ES, ops, expectedMissing) {
  24. test('has expected operations', function (t) {
  25. var diff = diffOps(ES, ops);
  26. t.deepEqual(diff.extra, [], 'no extra ops');
  27. t.deepEqual(diff.missing, expectedMissing, 'no unexpected missing ops');
  28. t.end();
  29. });
  30. test('ToPrimitive', function (t) {
  31. t.test('primitives', function (st) {
  32. var testPrimitive = function (primitive) {
  33. st.ok(is(ES.ToPrimitive(primitive), primitive), debug(primitive) + ' is returned correctly');
  34. };
  35. forEach(v.primitives, testPrimitive);
  36. st.end();
  37. });
  38. t.test('objects', function (st) {
  39. st.equal(ES.ToPrimitive(v.coercibleObject), 3, 'coercibleObject with no hint coerces to valueOf');
  40. st.ok(is(ES.ToPrimitive({}), '[object Object]'), '{} with no hint coerces to Object#toString');
  41. st.equal(ES.ToPrimitive(v.coercibleObject, Number), 3, 'coercibleObject with hint Number coerces to valueOf');
  42. st.ok(is(ES.ToPrimitive({}, Number), '[object Object]'), '{} with hint Number coerces to NaN');
  43. st.equal(ES.ToPrimitive(v.coercibleObject, String), 42, 'coercibleObject with hint String coerces to nonstringified toString');
  44. st.equal(ES.ToPrimitive({}, String), '[object Object]', '{} with hint String coerces to Object#toString');
  45. st.equal(ES.ToPrimitive(v.toStringOnlyObject), 7, 'toStringOnlyObject returns non-stringified toString');
  46. st.equal(ES.ToPrimitive(v.valueOfOnlyObject), 4, 'valueOfOnlyObject returns valueOf');
  47. st['throws'](function () { return ES.ToPrimitive(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws a TypeError');
  48. st.end();
  49. });
  50. t.test('dates', function (st) {
  51. var invalid = new Date(NaN);
  52. st.equal(ES.ToPrimitive(invalid), Date.prototype.toString.call(invalid), 'invalid Date coerces to Date#toString');
  53. var now = new Date();
  54. st.equal(ES.ToPrimitive(now), Date.prototype.toString.call(now), 'Date coerces to Date#toString');
  55. st.end();
  56. });
  57. t.end();
  58. });
  59. test('ToBoolean', function (t) {
  60. t.equal(false, ES.ToBoolean(undefined), 'undefined coerces to false');
  61. t.equal(false, ES.ToBoolean(null), 'null coerces to false');
  62. t.equal(false, ES.ToBoolean(false), 'false returns false');
  63. t.equal(true, ES.ToBoolean(true), 'true returns true');
  64. t.test('numbers', function (st) {
  65. forEach([0, -0, NaN], function (falsyNumber) {
  66. st.equal(false, ES.ToBoolean(falsyNumber), 'falsy number ' + falsyNumber + ' coerces to false');
  67. });
  68. forEach([Infinity, 42, 1, -Infinity], function (truthyNumber) {
  69. st.equal(true, ES.ToBoolean(truthyNumber), 'truthy number ' + truthyNumber + ' coerces to true');
  70. });
  71. st.end();
  72. });
  73. t.equal(false, ES.ToBoolean(''), 'empty string coerces to false');
  74. t.equal(true, ES.ToBoolean('foo'), 'nonempty string coerces to true');
  75. t.test('objects', function (st) {
  76. forEach(v.objects, function (obj) {
  77. st.equal(true, ES.ToBoolean(obj), 'object coerces to true');
  78. });
  79. st.equal(true, ES.ToBoolean(v.uncoercibleObject), 'uncoercibleObject coerces to true');
  80. st.end();
  81. });
  82. t.end();
  83. });
  84. test('ToNumber', function (t) {
  85. t.ok(is(NaN, ES.ToNumber(undefined)), 'undefined coerces to NaN');
  86. t.ok(is(ES.ToNumber(null), 0), 'null coerces to +0');
  87. t.ok(is(ES.ToNumber(false), 0), 'false coerces to +0');
  88. t.equal(1, ES.ToNumber(true), 'true coerces to 1');
  89. t.test('numbers', function (st) {
  90. st.ok(is(NaN, ES.ToNumber(NaN)), 'NaN returns itself');
  91. forEach([0, -0, 42, Infinity, -Infinity], function (num) {
  92. st.equal(num, ES.ToNumber(num), num + ' returns itself');
  93. });
  94. forEach(['foo', '0', '4a', '2.0', 'Infinity', '-Infinity'], function (numString) {
  95. st.ok(is(+numString, ES.ToNumber(numString)), '"' + numString + '" coerces to ' + Number(numString));
  96. });
  97. st.end();
  98. });
  99. t.test('objects', function (st) {
  100. forEach(v.objects, function (object) {
  101. st.ok(is(ES.ToNumber(object), ES.ToNumber(ES.ToPrimitive(object))), 'object ' + object + ' coerces to same as ToPrimitive of object does');
  102. });
  103. st['throws'](function () { return ES.ToNumber(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  104. st.end();
  105. });
  106. t.test('binary literals', function (st) {
  107. st.equal(ES.ToNumber('0b10'), 2, '0b10 is 2');
  108. st.equal(ES.ToNumber({ toString: function () { return '0b11'; } }), 3, 'Object that toStrings to 0b11 is 3');
  109. st.equal(true, is(ES.ToNumber('0b12'), NaN), '0b12 is NaN');
  110. st.equal(true, is(ES.ToNumber({ toString: function () { return '0b112'; } }), NaN), 'Object that toStrings to 0b112 is NaN');
  111. st.end();
  112. });
  113. t.test('octal literals', function (st) {
  114. st.equal(ES.ToNumber('0o10'), 8, '0o10 is 8');
  115. st.equal(ES.ToNumber({ toString: function () { return '0o11'; } }), 9, 'Object that toStrings to 0o11 is 9');
  116. st.equal(true, is(ES.ToNumber('0o18'), NaN), '0o18 is NaN');
  117. st.equal(true, is(ES.ToNumber({ toString: function () { return '0o118'; } }), NaN), 'Object that toStrings to 0o118 is NaN');
  118. st.end();
  119. });
  120. t.test('signed hex numbers', function (st) {
  121. st.equal(true, is(ES.ToNumber('-0xF'), NaN), '-0xF is NaN');
  122. st.equal(true, is(ES.ToNumber(' -0xF '), NaN), 'space-padded -0xF is NaN');
  123. st.equal(true, is(ES.ToNumber('+0xF'), NaN), '+0xF is NaN');
  124. st.equal(true, is(ES.ToNumber(' +0xF '), NaN), 'space-padded +0xF is NaN');
  125. st.end();
  126. });
  127. t.test('trimming of whitespace and non-whitespace characters', function (st) {
  128. var whitespace = ' \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000';
  129. st.equal(0, ES.ToNumber(whitespace + 0 + whitespace), 'whitespace is trimmed');
  130. // Zero-width space (zws), next line character (nel), and non-character (bom) are not whitespace.
  131. var nonWhitespaces = {
  132. '\\u0085': '\u0085',
  133. '\\u200b': '\u200b',
  134. '\\ufffe': '\ufffe'
  135. };
  136. forEach(nonWhitespaces, function (desc, nonWS) {
  137. st.equal(true, is(ES.ToNumber(nonWS + 0 + nonWS), NaN), 'non-whitespace ' + desc + ' not trimmed');
  138. });
  139. st.end();
  140. });
  141. forEach(v.symbols, function (symbol) {
  142. t['throws'](
  143. function () { ES.ToNumber(symbol); },
  144. TypeError,
  145. 'Symbols can’t be converted to a Number: ' + debug(symbol)
  146. );
  147. });
  148. t.test('dates', function (st) {
  149. var invalid = new Date(NaN);
  150. st.ok(is(ES.ToNumber(invalid), NaN), 'invalid Date coerces to NaN');
  151. var now = Date.now();
  152. st.equal(ES.ToNumber(new Date(now)), now, 'Date coerces to timestamp');
  153. st.end();
  154. });
  155. t.end();
  156. });
  157. test('ToInteger', function (t) {
  158. t.ok(is(0, ES.ToInteger(NaN)), 'NaN coerces to +0');
  159. forEach([0, Infinity, 42], function (num) {
  160. t.ok(is(num, ES.ToInteger(num)), num + ' returns itself');
  161. t.ok(is(-num, ES.ToInteger(-num)), '-' + num + ' returns itself');
  162. });
  163. t.equal(3, ES.ToInteger(Math.PI), 'pi returns 3');
  164. t['throws'](function () { return ES.ToInteger(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  165. t.end();
  166. });
  167. test('ToInt32', function (t) {
  168. t.ok(is(0, ES.ToInt32(NaN)), 'NaN coerces to +0');
  169. forEach([0, Infinity], function (num) {
  170. t.ok(is(0, ES.ToInt32(num)), num + ' returns +0');
  171. t.ok(is(0, ES.ToInt32(-num)), '-' + num + ' returns +0');
  172. });
  173. t['throws'](function () { return ES.ToInt32(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  174. t.ok(is(ES.ToInt32(0x100000000), 0), '2^32 returns +0');
  175. t.ok(is(ES.ToInt32(0x100000000 - 1), -1), '2^32 - 1 returns -1');
  176. t.ok(is(ES.ToInt32(0x80000000), -0x80000000), '2^31 returns -2^31');
  177. t.ok(is(ES.ToInt32(0x80000000 - 1), 0x80000000 - 1), '2^31 - 1 returns 2^31 - 1');
  178. forEach([0, Infinity, NaN, 0x100000000, 0x80000000, 0x10000, 0x42], function (num) {
  179. t.ok(is(ES.ToInt32(num), ES.ToInt32(ES.ToUint32(num))), 'ToInt32(x) === ToInt32(ToUint32(x)) for 0x' + num.toString(16));
  180. t.ok(is(ES.ToInt32(-num), ES.ToInt32(ES.ToUint32(-num))), 'ToInt32(x) === ToInt32(ToUint32(x)) for -0x' + num.toString(16));
  181. });
  182. t.end();
  183. });
  184. test('ToUint32', function (t) {
  185. t.ok(is(0, ES.ToUint32(NaN)), 'NaN coerces to +0');
  186. forEach([0, Infinity], function (num) {
  187. t.ok(is(0, ES.ToUint32(num)), num + ' returns +0');
  188. t.ok(is(0, ES.ToUint32(-num)), '-' + num + ' returns +0');
  189. });
  190. t['throws'](function () { return ES.ToUint32(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  191. t.ok(is(ES.ToUint32(0x100000000), 0), '2^32 returns +0');
  192. t.ok(is(ES.ToUint32(0x100000000 - 1), 0x100000000 - 1), '2^32 - 1 returns 2^32 - 1');
  193. t.ok(is(ES.ToUint32(0x80000000), 0x80000000), '2^31 returns 2^31');
  194. t.ok(is(ES.ToUint32(0x80000000 - 1), 0x80000000 - 1), '2^31 - 1 returns 2^31 - 1');
  195. forEach([0, Infinity, NaN, 0x100000000, 0x80000000, 0x10000, 0x42], function (num) {
  196. t.ok(is(ES.ToUint32(num), ES.ToUint32(ES.ToInt32(num))), 'ToUint32(x) === ToUint32(ToInt32(x)) for 0x' + num.toString(16));
  197. t.ok(is(ES.ToUint32(-num), ES.ToUint32(ES.ToInt32(-num))), 'ToUint32(x) === ToUint32(ToInt32(x)) for -0x' + num.toString(16));
  198. });
  199. t.end();
  200. });
  201. test('ToInt16', function (t) {
  202. t.ok(is(0, ES.ToInt16(NaN)), 'NaN coerces to +0');
  203. forEach([0, Infinity], function (num) {
  204. t.ok(is(0, ES.ToInt16(num)), num + ' returns +0');
  205. t.ok(is(0, ES.ToInt16(-num)), '-' + num + ' returns +0');
  206. });
  207. t['throws'](function () { return ES.ToInt16(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  208. t.ok(is(ES.ToInt16(0x100000000), 0), '2^32 returns +0');
  209. t.ok(is(ES.ToInt16(0x100000000 - 1), -1), '2^32 - 1 returns -1');
  210. t.ok(is(ES.ToInt16(0x80000000), 0), '2^31 returns +0');
  211. t.ok(is(ES.ToInt16(0x80000000 - 1), -1), '2^31 - 1 returns -1');
  212. t.ok(is(ES.ToInt16(0x10000), 0), '2^16 returns +0');
  213. t.ok(is(ES.ToInt16(0x10000 - 1), -1), '2^16 - 1 returns -1');
  214. t.end();
  215. });
  216. test('ToUint16', function (t) {
  217. t.ok(is(0, ES.ToUint16(NaN)), 'NaN coerces to +0');
  218. forEach([0, Infinity], function (num) {
  219. t.ok(is(0, ES.ToUint16(num)), num + ' returns +0');
  220. t.ok(is(0, ES.ToUint16(-num)), '-' + num + ' returns +0');
  221. });
  222. t['throws'](function () { return ES.ToUint16(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  223. t.ok(is(ES.ToUint16(0x100000000), 0), '2^32 returns +0');
  224. t.ok(is(ES.ToUint16(0x100000000 - 1), 0x10000 - 1), '2^32 - 1 returns 2^16 - 1');
  225. t.ok(is(ES.ToUint16(0x80000000), 0), '2^31 returns +0');
  226. t.ok(is(ES.ToUint16(0x80000000 - 1), 0x10000 - 1), '2^31 - 1 returns 2^16 - 1');
  227. t.ok(is(ES.ToUint16(0x10000), 0), '2^16 returns +0');
  228. t.ok(is(ES.ToUint16(0x10000 - 1), 0x10000 - 1), '2^16 - 1 returns 2^16 - 1');
  229. t.end();
  230. });
  231. test('ToInt8', function (t) {
  232. t.ok(is(0, ES.ToInt8(NaN)), 'NaN coerces to +0');
  233. forEach([0, Infinity], function (num) {
  234. t.ok(is(0, ES.ToInt8(num)), num + ' returns +0');
  235. t.ok(is(0, ES.ToInt8(-num)), '-' + num + ' returns +0');
  236. });
  237. t['throws'](function () { return ES.ToInt8(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  238. t.ok(is(ES.ToInt8(0x100000000), 0), '2^32 returns +0');
  239. t.ok(is(ES.ToInt8(0x100000000 - 1), -1), '2^32 - 1 returns -1');
  240. t.ok(is(ES.ToInt8(0x80000000), 0), '2^31 returns +0');
  241. t.ok(is(ES.ToInt8(0x80000000 - 1), -1), '2^31 - 1 returns -1');
  242. t.ok(is(ES.ToInt8(0x10000), 0), '2^16 returns +0');
  243. t.ok(is(ES.ToInt8(0x10000 - 1), -1), '2^16 - 1 returns -1');
  244. t.ok(is(ES.ToInt8(0x100), 0), '2^8 returns +0');
  245. t.ok(is(ES.ToInt8(0x100 - 1), -1), '2^8 - 1 returns -1');
  246. t.ok(is(ES.ToInt8(0x10), 0x10), '2^4 returns 2^4');
  247. t.end();
  248. });
  249. test('ToUint8', function (t) {
  250. t.ok(is(0, ES.ToUint8(NaN)), 'NaN coerces to +0');
  251. forEach([0, Infinity], function (num) {
  252. t.ok(is(0, ES.ToUint8(num)), num + ' returns +0');
  253. t.ok(is(0, ES.ToUint8(-num)), '-' + num + ' returns +0');
  254. });
  255. t['throws'](function () { return ES.ToUint8(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  256. t.ok(is(ES.ToUint8(0x100000000), 0), '2^32 returns +0');
  257. t.ok(is(ES.ToUint8(0x100000000 - 1), 0x100 - 1), '2^32 - 1 returns 2^8 - 1');
  258. t.ok(is(ES.ToUint8(0x80000000), 0), '2^31 returns +0');
  259. t.ok(is(ES.ToUint8(0x80000000 - 1), 0x100 - 1), '2^31 - 1 returns 2^8 - 1');
  260. t.ok(is(ES.ToUint8(0x10000), 0), '2^16 returns +0');
  261. t.ok(is(ES.ToUint8(0x10000 - 1), 0x100 - 1), '2^16 - 1 returns 2^8 - 1');
  262. t.ok(is(ES.ToUint8(0x100), 0), '2^8 returns +0');
  263. t.ok(is(ES.ToUint8(0x100 - 1), 0x100 - 1), '2^8 - 1 returns 2^16 - 1');
  264. t.ok(is(ES.ToUint8(0x10), 0x10), '2^4 returns 2^4');
  265. t.ok(is(ES.ToUint8(0x10 - 1), 0x10 - 1), '2^4 - 1 returns 2^4 - 1');
  266. t.end();
  267. });
  268. test('ToUint8Clamp', function (t) {
  269. t.ok(is(0, ES.ToUint8Clamp(NaN)), 'NaN coerces to +0');
  270. t.ok(is(0, ES.ToUint8Clamp(0)), '+0 returns +0');
  271. t.ok(is(0, ES.ToUint8Clamp(-0)), '-0 returns +0');
  272. t.ok(is(0, ES.ToUint8Clamp(-Infinity)), '-Infinity returns +0');
  273. t['throws'](function () { return ES.ToUint8Clamp(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  274. forEach([255, 256, 0x100000, Infinity], function (number) {
  275. t.ok(is(255, ES.ToUint8Clamp(number)), number + ' coerces to 255');
  276. });
  277. t.equal(1, ES.ToUint8Clamp(1.49), '1.49 coerces to 1');
  278. t.equal(2, ES.ToUint8Clamp(1.5), '1.5 coerces to 2, because 2 is even');
  279. t.equal(2, ES.ToUint8Clamp(1.51), '1.51 coerces to 2');
  280. t.equal(2, ES.ToUint8Clamp(2.49), '2.49 coerces to 2');
  281. t.equal(2, ES.ToUint8Clamp(2.5), '2.5 coerces to 2, because 2 is even');
  282. t.equal(3, ES.ToUint8Clamp(2.51), '2.51 coerces to 3');
  283. t.end();
  284. });
  285. test('ToString', function (t) {
  286. forEach(v.objects.concat(v.nonSymbolPrimitives), function (item) {
  287. t.equal(ES.ToString(item), String(item), 'ES.ToString(' + debug(item) + ') ToStrings to String(' + debug(item) + ')');
  288. });
  289. t['throws'](function () { return ES.ToString(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws');
  290. forEach(v.symbols, function (symbol) {
  291. t['throws'](function () { return ES.ToString(symbol); }, TypeError, debug(symbol) + ' throws');
  292. });
  293. t.end();
  294. });
  295. test('ToObject', function (t) {
  296. t['throws'](function () { return ES.ToObject(undefined); }, TypeError, 'undefined throws');
  297. t['throws'](function () { return ES.ToObject(null); }, TypeError, 'null throws');
  298. forEach(v.numbers, function (number) {
  299. var obj = ES.ToObject(number);
  300. t.equal(typeof obj, 'object', 'number ' + number + ' coerces to object');
  301. t.equal(true, obj instanceof Number, 'object of ' + number + ' is Number object');
  302. t.ok(is(obj.valueOf(), number), 'object of ' + number + ' coerces to ' + number);
  303. });
  304. t.end();
  305. });
  306. test('RequireObjectCoercible', function (t) {
  307. t.equal(false, 'CheckObjectCoercible' in ES, 'CheckObjectCoercible -> RequireObjectCoercible in ES6');
  308. t['throws'](function () { return ES.RequireObjectCoercible(undefined); }, TypeError, 'undefined throws');
  309. t['throws'](function () { return ES.RequireObjectCoercible(null); }, TypeError, 'null throws');
  310. var isCoercible = function (value) {
  311. t.doesNotThrow(function () { return ES.RequireObjectCoercible(value); }, debug(value) + ' does not throw');
  312. };
  313. forEach(v.objects.concat(v.nonNullPrimitives), isCoercible);
  314. t.end();
  315. });
  316. test('IsCallable', function (t) {
  317. t.equal(true, ES.IsCallable(function () {}), 'function is callable');
  318. var nonCallables = [/a/g, {}, Object.prototype, NaN].concat(v.primitives);
  319. forEach(nonCallables, function (nonCallable) {
  320. t.equal(false, ES.IsCallable(nonCallable), debug(nonCallable) + ' is not callable');
  321. });
  322. t.end();
  323. });
  324. test('SameValue', function (t) {
  325. t.equal(true, ES.SameValue(NaN, NaN), 'NaN is SameValue as NaN');
  326. t.equal(false, ES.SameValue(0, -0), '+0 is not SameValue as -0');
  327. forEach(v.objects.concat(v.primitives), function (val) {
  328. t.equal(val === val, ES.SameValue(val, val), debug(val) + ' is SameValue to itself');
  329. });
  330. t.end();
  331. });
  332. test('SameValueZero', function (t) {
  333. t.equal(true, ES.SameValueZero(NaN, NaN), 'NaN is SameValueZero as NaN');
  334. t.equal(true, ES.SameValueZero(0, -0), '+0 is SameValueZero as -0');
  335. forEach(v.objects.concat(v.primitives), function (val) {
  336. t.equal(val === val, ES.SameValueZero(val, val), debug(val) + ' is SameValueZero to itself');
  337. });
  338. t.end();
  339. });
  340. test('ToPropertyKey', function (t) {
  341. forEach(v.objects.concat(v.nonSymbolPrimitives), function (value) {
  342. t.equal(ES.ToPropertyKey(value), String(value), 'ToPropertyKey(value) === String(value) for non-Symbols');
  343. });
  344. forEach(v.symbols, function (symbol) {
  345. t.equal(
  346. ES.ToPropertyKey(symbol),
  347. symbol,
  348. 'ToPropertyKey(' + debug(symbol) + ') === ' + debug(symbol)
  349. );
  350. t.equal(
  351. ES.ToPropertyKey(Object(symbol)),
  352. symbol,
  353. 'ToPropertyKey(' + debug(Object(symbol)) + ') === ' + debug(symbol)
  354. );
  355. });
  356. t.end();
  357. });
  358. test('ToLength', function (t) {
  359. t['throws'](function () { return ES.ToLength(v.uncoercibleObject); }, TypeError, 'uncoercibleObject throws a TypeError');
  360. t.equal(3, ES.ToLength(v.coercibleObject), 'coercibleObject coerces to 3');
  361. t.equal(42, ES.ToLength('42.5'), '"42.5" coerces to 42');
  362. t.equal(7, ES.ToLength(7.3), '7.3 coerces to 7');
  363. forEach([-0, -1, -42, -Infinity], function (negative) {
  364. t.ok(is(0, ES.ToLength(negative)), negative + ' coerces to +0');
  365. });
  366. t.equal(MAX_SAFE_INTEGER, ES.ToLength(MAX_SAFE_INTEGER + 1), '2^53 coerces to 2^53 - 1');
  367. t.equal(MAX_SAFE_INTEGER, ES.ToLength(MAX_SAFE_INTEGER + 3), '2^53 + 2 coerces to 2^53 - 1');
  368. t.end();
  369. });
  370. test('IsArray', function (t) {
  371. t.equal(true, ES.IsArray([]), '[] is array');
  372. t.equal(false, ES.IsArray({}), '{} is not array');
  373. t.equal(false, ES.IsArray({ length: 1, 0: true }), 'arraylike object is not array');
  374. forEach(v.objects.concat(v.primitives), function (value) {
  375. t.equal(false, ES.IsArray(value), debug(value) + ' is not array');
  376. });
  377. t.end();
  378. });
  379. test('IsRegExp', function (t) {
  380. forEach([/a/g, new RegExp('a', 'g')], function (regex) {
  381. t.equal(true, ES.IsRegExp(regex), regex + ' is regex');
  382. });
  383. forEach(v.objects.concat(v.primitives), function (nonRegex) {
  384. t.equal(false, ES.IsRegExp(nonRegex), debug(nonRegex) + ' is not regex');
  385. });
  386. t.test('Symbol.match', { skip: !v.hasSymbols || !Symbol.match }, function (st) {
  387. var obj = {};
  388. obj[Symbol.match] = true;
  389. st.equal(true, ES.IsRegExp(obj), 'object with truthy Symbol.match is regex');
  390. var regex = /a/;
  391. regex[Symbol.match] = false;
  392. st.equal(false, ES.IsRegExp(regex), 'regex with falsy Symbol.match is not regex');
  393. st.end();
  394. });
  395. t.end();
  396. });
  397. test('IsPropertyKey', function (t) {
  398. forEach(v.numbers.concat(v.objects), function (notKey) {
  399. t.equal(false, ES.IsPropertyKey(notKey), debug(notKey) + ' is not property key');
  400. });
  401. t.equal(true, ES.IsPropertyKey('foo'), 'string is property key');
  402. forEach(v.symbols, function (symbol) {
  403. t.equal(true, ES.IsPropertyKey(symbol), debug(symbol) + ' is property key');
  404. });
  405. t.end();
  406. });
  407. test('IsInteger', function (t) {
  408. for (var i = -100; i < 100; i += 10) {
  409. t.equal(true, ES.IsInteger(i), i + ' is integer');
  410. t.equal(false, ES.IsInteger(i + 0.2), (i + 0.2) + ' is not integer');
  411. }
  412. t.equal(true, ES.IsInteger(-0), '-0 is integer');
  413. var notInts = v.nonNumbers.concat(v.nonIntegerNumbers, [Infinity, -Infinity, NaN, [], new Date()]);
  414. forEach(notInts, function (notInt) {
  415. t.equal(false, ES.IsInteger(notInt), debug(notInt) + ' is not integer');
  416. });
  417. t.equal(false, ES.IsInteger(v.uncoercibleObject), 'uncoercibleObject is not integer');
  418. t.end();
  419. });
  420. test('IsExtensible', function (t) {
  421. forEach(v.objects, function (object) {
  422. t.equal(true, ES.IsExtensible(object), debug(object) + ' object is extensible');
  423. });
  424. forEach(v.primitives, function (primitive) {
  425. t.equal(false, ES.IsExtensible(primitive), debug(primitive) + ' is not extensible');
  426. });
  427. if (Object.preventExtensions) {
  428. t.equal(false, ES.IsExtensible(Object.preventExtensions({})), 'object with extensions prevented is not extensible');
  429. }
  430. t.end();
  431. });
  432. test('CanonicalNumericIndexString', function (t) {
  433. var throwsOnNonString = function (notString) {
  434. t['throws'](
  435. function () { return ES.CanonicalNumericIndexString(notString); },
  436. TypeError,
  437. debug(notString) + ' is not a string'
  438. );
  439. };
  440. forEach(v.objects.concat(v.numbers), throwsOnNonString);
  441. t.ok(is(-0, ES.CanonicalNumericIndexString('-0')), '"-0" returns -0');
  442. for (var i = -50; i < 50; i += 10) {
  443. t.equal(i, ES.CanonicalNumericIndexString(String(i)), '"' + i + '" returns ' + i);
  444. t.equal(undefined, ES.CanonicalNumericIndexString(String(i) + 'a'), '"' + i + 'a" returns undefined');
  445. }
  446. t.end();
  447. });
  448. test('IsConstructor', function (t) {
  449. t.equal(true, ES.IsConstructor(function () {}), 'function is constructor');
  450. t.equal(false, ES.IsConstructor(/a/g), 'regex is not constructor');
  451. forEach(v.objects, function (object) {
  452. t.equal(false, ES.IsConstructor(object), object + ' object is not constructor');
  453. });
  454. try {
  455. var foo = Function('return class Foo {}')(); // eslint-disable-line no-new-func
  456. t.equal(ES.IsConstructor(foo), true, 'class is constructor');
  457. } catch (e) {
  458. t.comment('SKIP: class syntax not supported.');
  459. }
  460. t.end();
  461. });
  462. test('Call', function (t) {
  463. var receiver = {};
  464. var notFuncs = v.objects.concat(v.primitives).concat([/a/g, new RegExp('a', 'g')]);
  465. t.plan(notFuncs.length + 4);
  466. var throwsIfNotCallable = function (notFunc) {
  467. t['throws'](
  468. function () { return ES.Call(notFunc, receiver); },
  469. TypeError,
  470. debug(notFunc) + ' (' + typeof notFunc + ') is not callable'
  471. );
  472. };
  473. forEach(notFuncs, throwsIfNotCallable);
  474. ES.Call(function (a, b) {
  475. t.equal(this, receiver, 'context matches expected');
  476. t.deepEqual([a, b], [1, 2], 'named args are correct');
  477. t.equal(arguments.length, 3, 'extra argument was passed');
  478. t.equal(arguments[2], 3, 'extra argument was correct');
  479. }, receiver, [1, 2, 3]);
  480. t.end();
  481. });
  482. test('GetV', function (t) {
  483. t['throws'](function () { return ES.GetV({ 7: 7 }, 7); }, TypeError, 'Throws a TypeError if `P` is not a property key');
  484. var obj = { a: function () {} };
  485. t.equal(ES.GetV(obj, 'a'), obj.a, 'returns property if it exists');
  486. t.equal(ES.GetV(obj, 'b'), undefined, 'returns undefiend if property does not exist');
  487. t.end();
  488. });
  489. test('GetMethod', function (t) {
  490. t['throws'](function () { return ES.GetMethod({ 7: 7 }, 7); }, TypeError, 'Throws a TypeError if `P` is not a property key');
  491. t.equal(ES.GetMethod({}, 'a'), undefined, 'returns undefined in property is undefined');
  492. t.equal(ES.GetMethod({ a: null }, 'a'), undefined, 'returns undefined if property is null');
  493. t.equal(ES.GetMethod({ a: undefined }, 'a'), undefined, 'returns undefined if property is undefined');
  494. var obj = { a: function () {} };
  495. t['throws'](function () { ES.GetMethod({ a: 'b' }, 'a'); }, TypeError, 'throws TypeError if property exists and is not callable');
  496. t.equal(ES.GetMethod(obj, 'a'), obj.a, 'returns property if it is callable');
  497. t.end();
  498. });
  499. test('Get', function (t) {
  500. t['throws'](function () { return ES.Get('a', 'a'); }, TypeError, 'Throws a TypeError if `O` is not an Object');
  501. t['throws'](function () { return ES.Get({ 7: 7 }, 7); }, TypeError, 'Throws a TypeError if `P` is not a property key');
  502. var value = {};
  503. t.test('Symbols', { skip: !v.hasSymbols }, function (st) {
  504. var sym = Symbol('sym');
  505. var obj = {};
  506. obj[sym] = value;
  507. st.equal(ES.Get(obj, sym), value, 'returns property `P` if it exists on object `O`');
  508. st.end();
  509. });
  510. t.equal(ES.Get({ a: value }, 'a'), value, 'returns property `P` if it exists on object `O`');
  511. t.end();
  512. });
  513. test('Type', { skip: !v.hasSymbols }, function (t) {
  514. t.equal(ES.Type(Symbol.iterator), 'Symbol', 'Type(Symbol.iterator) is Symbol');
  515. t.end();
  516. });
  517. test('SpeciesConstructor', function (t) {
  518. t['throws'](function () { ES.SpeciesConstructor(null); }, TypeError);
  519. t['throws'](function () { ES.SpeciesConstructor(undefined); }, TypeError);
  520. var defaultConstructor = function Foo() {};
  521. t.equal(
  522. ES.SpeciesConstructor({ constructor: undefined }, defaultConstructor),
  523. defaultConstructor,
  524. 'undefined constructor returns defaultConstructor'
  525. );
  526. t['throws'](
  527. function () { return ES.SpeciesConstructor({ constructor: null }, defaultConstructor); },
  528. TypeError,
  529. 'non-undefined non-object constructor throws'
  530. );
  531. t.test('with Symbol.species', { skip: !hasSpecies }, function (st) {
  532. var Bar = function Bar() {};
  533. Bar[Symbol.species] = null;
  534. st.equal(
  535. ES.SpeciesConstructor(new Bar(), defaultConstructor),
  536. defaultConstructor,
  537. 'undefined/null Symbol.species returns default constructor'
  538. );
  539. var Baz = function Baz() {};
  540. Baz[Symbol.species] = Bar;
  541. st.equal(
  542. ES.SpeciesConstructor(new Baz(), defaultConstructor),
  543. Bar,
  544. 'returns Symbol.species constructor value'
  545. );
  546. Baz[Symbol.species] = {};
  547. st['throws'](
  548. function () { ES.SpeciesConstructor(new Baz(), defaultConstructor); },
  549. TypeError,
  550. 'throws when non-constructor non-null non-undefined species value found'
  551. );
  552. st.end();
  553. });
  554. t.end();
  555. });
  556. var bothDescriptor = function () {
  557. return { '[[Get]]': function () {}, '[[Value]]': true };
  558. };
  559. var accessorDescriptor = function () {
  560. return {
  561. '[[Get]]': function () {},
  562. '[[Enumerable]]': true,
  563. '[[Configurable]]': true
  564. };
  565. };
  566. var mutatorDescriptor = function () {
  567. return {
  568. '[[Set]]': function () {},
  569. '[[Enumerable]]': true,
  570. '[[Configurable]]': true
  571. };
  572. };
  573. var dataDescriptor = function () {
  574. return {
  575. '[[Value]]': 42,
  576. '[[Writable]]': false
  577. };
  578. };
  579. var genericDescriptor = function () {
  580. return {
  581. '[[Configurable]]': true,
  582. '[[Enumerable]]': false
  583. };
  584. };
  585. test('IsPropertyDescriptor', function (t) {
  586. forEach(v.nonUndefinedPrimitives, function (primitive) {
  587. t.equal(
  588. ES.IsPropertyDescriptor(primitive),
  589. false,
  590. debug(primitive) + ' is not a Property Descriptor'
  591. );
  592. });
  593. t.equal(ES.IsPropertyDescriptor({ invalid: true }), false, 'invalid keys not allowed on a Property Descriptor');
  594. t.equal(ES.IsPropertyDescriptor({}), true, 'empty object is an incomplete Property Descriptor');
  595. t.equal(ES.IsPropertyDescriptor(accessorDescriptor()), true, 'accessor descriptor is a Property Descriptor');
  596. t.equal(ES.IsPropertyDescriptor(mutatorDescriptor()), true, 'mutator descriptor is a Property Descriptor');
  597. t.equal(ES.IsPropertyDescriptor(dataDescriptor()), true, 'data descriptor is a Property Descriptor');
  598. t.equal(ES.IsPropertyDescriptor(genericDescriptor()), true, 'generic descriptor is a Property Descriptor');
  599. t['throws'](function () {
  600. ES.IsPropertyDescriptor(bothDescriptor());
  601. }, TypeError, 'a Property Descriptor can not be both a Data and an Accessor Descriptor');
  602. t.end();
  603. });
  604. test('IsAccessorDescriptor', function (t) {
  605. forEach(v.nonUndefinedPrimitives, function (primitive) {
  606. t['throws'](
  607. function () { ES.IsAccessorDescriptor(primitive); },
  608. TypeError,
  609. debug(primitive) + ' is not a Property Descriptor'
  610. );
  611. });
  612. t.equal(ES.IsAccessorDescriptor(), false, 'no value is not an Accessor Descriptor');
  613. t.equal(ES.IsAccessorDescriptor(undefined), false, 'undefined value is not an Accessor Descriptor');
  614. t.equal(ES.IsAccessorDescriptor(accessorDescriptor()), true, 'accessor descriptor is an Accessor Descriptor');
  615. t.equal(ES.IsAccessorDescriptor(mutatorDescriptor()), true, 'mutator descriptor is an Accessor Descriptor');
  616. t.equal(ES.IsAccessorDescriptor(dataDescriptor()), false, 'data descriptor is not an Accessor Descriptor');
  617. t.equal(ES.IsAccessorDescriptor(genericDescriptor()), false, 'generic descriptor is not an Accessor Descriptor');
  618. t.end();
  619. });
  620. test('IsDataDescriptor', function (t) {
  621. forEach(v.nonUndefinedPrimitives, function (primitive) {
  622. t['throws'](
  623. function () { ES.IsDataDescriptor(primitive); },
  624. TypeError,
  625. debug(primitive) + ' is not a Property Descriptor'
  626. );
  627. });
  628. t.equal(ES.IsDataDescriptor(), false, 'no value is not a Data Descriptor');
  629. t.equal(ES.IsDataDescriptor(undefined), false, 'undefined value is not a Data Descriptor');
  630. t.equal(ES.IsDataDescriptor(accessorDescriptor()), false, 'accessor descriptor is not a Data Descriptor');
  631. t.equal(ES.IsDataDescriptor(mutatorDescriptor()), false, 'mutator descriptor is not a Data Descriptor');
  632. t.equal(ES.IsDataDescriptor(dataDescriptor()), true, 'data descriptor is a Data Descriptor');
  633. t.equal(ES.IsDataDescriptor(genericDescriptor()), false, 'generic descriptor is not a Data Descriptor');
  634. t.end();
  635. });
  636. test('IsGenericDescriptor', function (t) {
  637. forEach(v.nonUndefinedPrimitives, function (primitive) {
  638. t['throws'](
  639. function () { ES.IsGenericDescriptor(primitive); },
  640. TypeError,
  641. debug(primitive) + ' is not a Property Descriptor'
  642. );
  643. });
  644. t.equal(ES.IsGenericDescriptor(), false, 'no value is not a Data Descriptor');
  645. t.equal(ES.IsGenericDescriptor(undefined), false, 'undefined value is not a Data Descriptor');
  646. t.equal(ES.IsGenericDescriptor(accessorDescriptor()), false, 'accessor descriptor is not a generic Descriptor');
  647. t.equal(ES.IsGenericDescriptor(mutatorDescriptor()), false, 'mutator descriptor is not a generic Descriptor');
  648. t.equal(ES.IsGenericDescriptor(dataDescriptor()), false, 'data descriptor is not a generic Descriptor');
  649. t.equal(ES.IsGenericDescriptor(genericDescriptor()), true, 'generic descriptor is a generic Descriptor');
  650. t.end();
  651. });
  652. test('FromPropertyDescriptor', function (t) {
  653. t.equal(ES.FromPropertyDescriptor(), undefined, 'no value begets undefined');
  654. t.equal(ES.FromPropertyDescriptor(undefined), undefined, 'undefined value begets undefined');
  655. forEach(v.nonUndefinedPrimitives, function (primitive) {
  656. t['throws'](
  657. function () { ES.FromPropertyDescriptor(primitive); },
  658. TypeError,
  659. debug(primitive) + ' is not a Property Descriptor'
  660. );
  661. });
  662. var accessor = accessorDescriptor();
  663. t.deepEqual(ES.FromPropertyDescriptor(accessor), {
  664. get: accessor['[[Get]]'],
  665. set: accessor['[[Set]]'],
  666. enumerable: !!accessor['[[Enumerable]]'],
  667. configurable: !!accessor['[[Configurable]]']
  668. });
  669. var mutator = mutatorDescriptor();
  670. t.deepEqual(ES.FromPropertyDescriptor(mutator), {
  671. get: mutator['[[Get]]'],
  672. set: mutator['[[Set]]'],
  673. enumerable: !!mutator['[[Enumerable]]'],
  674. configurable: !!mutator['[[Configurable]]']
  675. });
  676. var data = dataDescriptor();
  677. t.deepEqual(ES.FromPropertyDescriptor(data), {
  678. value: data['[[Value]]'],
  679. writable: data['[[Writable]]'],
  680. enumerable: !!data['[[Enumerable]]'],
  681. configurable: !!data['[[Configurable]]']
  682. });
  683. t['throws'](
  684. function () { ES.FromPropertyDescriptor(genericDescriptor()); },
  685. TypeError,
  686. 'a complete Property Descriptor is required'
  687. );
  688. t.end();
  689. });
  690. test('ToPropertyDescriptor', function (t) {
  691. forEach(v.nonUndefinedPrimitives, function (primitive) {
  692. t['throws'](
  693. function () { ES.ToPropertyDescriptor(primitive); },
  694. TypeError,
  695. debug(primitive) + ' is not an Object'
  696. );
  697. });
  698. var accessor = accessorDescriptor();
  699. t.deepEqual(ES.ToPropertyDescriptor({
  700. get: accessor['[[Get]]'],
  701. enumerable: !!accessor['[[Enumerable]]'],
  702. configurable: !!accessor['[[Configurable]]']
  703. }), accessor);
  704. var mutator = mutatorDescriptor();
  705. t.deepEqual(ES.ToPropertyDescriptor({
  706. set: mutator['[[Set]]'],
  707. enumerable: !!mutator['[[Enumerable]]'],
  708. configurable: !!mutator['[[Configurable]]']
  709. }), mutator);
  710. var data = dataDescriptor();
  711. t.deepEqual(ES.ToPropertyDescriptor({
  712. value: data['[[Value]]'],
  713. writable: data['[[Writable]]'],
  714. configurable: !!data['[[Configurable]]']
  715. }), assign(data, { '[[Configurable]]': false }));
  716. var both = bothDescriptor();
  717. t['throws'](
  718. function () {
  719. ES.FromPropertyDescriptor({ get: both['[[Get]]'], value: both['[[Value]]'] });
  720. },
  721. TypeError,
  722. 'data and accessor descriptors are mutually exclusive'
  723. );
  724. t.end();
  725. });
  726. test('CompletePropertyDescriptor', function (t) {
  727. forEach(v.nonUndefinedPrimitives, function (primitive) {
  728. t['throws'](
  729. function () { ES.CompletePropertyDescriptor(primitive); },
  730. TypeError,
  731. debug(primitive) + ' is not a Property Descriptor'
  732. );
  733. });
  734. var generic = genericDescriptor();
  735. t.deepEqual(ES.CompletePropertyDescriptor(generic), {
  736. '[[Configurable]]': !!generic['[[Configurable]]'],
  737. '[[Enumerable]]': !!generic['[[Enumerable]]'],
  738. '[[Value]]': undefined,
  739. '[[Writable]]': false
  740. }, 'completes a Generic Descriptor');
  741. var data = dataDescriptor();
  742. t.deepEqual(ES.CompletePropertyDescriptor(data), {
  743. '[[Configurable]]': !!data['[[Configurable]]'],
  744. '[[Enumerable]]': false,
  745. '[[Value]]': data['[[Value]]'],
  746. '[[Writable]]': !!data['[[Writable]]']
  747. }, 'completes a Data Descriptor');
  748. var accessor = accessorDescriptor();
  749. t.deepEqual(ES.CompletePropertyDescriptor(accessor), {
  750. '[[Get]]': accessor['[[Get]]'],
  751. '[[Enumerable]]': !!accessor['[[Enumerable]]'],
  752. '[[Configurable]]': !!accessor['[[Configurable]]'],
  753. '[[Set]]': undefined
  754. }, 'completes an Accessor Descriptor');
  755. var mutator = mutatorDescriptor();
  756. t.deepEqual(ES.CompletePropertyDescriptor(mutator), {
  757. '[[Set]]': mutator['[[Set]]'],
  758. '[[Enumerable]]': !!mutator['[[Enumerable]]'],
  759. '[[Configurable]]': !!mutator['[[Configurable]]'],
  760. '[[Get]]': undefined
  761. }, 'completes a mutator Descriptor');
  762. t['throws'](
  763. function () { ES.CompletePropertyDescriptor(bothDescriptor()); },
  764. TypeError,
  765. 'data and accessor descriptors are mutually exclusive'
  766. );
  767. t.end();
  768. });
  769. test('Set', function (t) {
  770. forEach(v.primitives, function (primitive) {
  771. t['throws'](
  772. function () { ES.Set(primitive, '', null, false); },
  773. TypeError,
  774. debug(primitive) + ' is not an Object'
  775. );
  776. });
  777. forEach(v.nonPropertyKeys, function (nonKey) {
  778. t['throws'](
  779. function () { ES.Set({}, nonKey, null, false); },
  780. TypeError,
  781. debug(nonKey) + ' is not a Property Key'
  782. );
  783. });
  784. forEach(v.nonBooleans, function (nonBoolean) {
  785. t['throws'](
  786. function () { ES.Set({}, '', null, nonBoolean); },
  787. TypeError,
  788. debug(nonBoolean) + ' is not a Boolean'
  789. );
  790. });
  791. var o = {};
  792. var value = {};
  793. ES.Set(o, 'key', value, true);
  794. t.deepEqual(o, { key: value }, 'key is set');
  795. t.test('nonwritable', { skip: !Object.defineProperty }, function (st) {
  796. var obj = { a: value };
  797. Object.defineProperty(obj, 'a', { writable: false });
  798. st['throws'](
  799. function () { ES.Set(obj, 'a', value, true); },
  800. TypeError,
  801. 'can not Set nonwritable property'
  802. );
  803. st.doesNotThrow(
  804. function () { ES.Set(obj, 'a', value, false); },
  805. 'setting Throw to false prevents an exception'
  806. );
  807. st.end();
  808. });
  809. t.test('nonconfigurable', { skip: !Object.defineProperty }, function (st) {
  810. var obj = { a: value };
  811. Object.defineProperty(obj, 'a', { configurable: false });
  812. ES.Set(obj, 'a', value, true);
  813. st.deepEqual(obj, { a: value }, 'key is set');
  814. st.end();
  815. });
  816. t.end();
  817. });
  818. test('HasOwnProperty', function (t) {
  819. forEach(v.primitives, function (primitive) {
  820. t['throws'](
  821. function () { ES.HasOwnProperty(primitive, 'key'); },
  822. TypeError,
  823. debug(primitive) + ' is not an Object'
  824. );
  825. });
  826. forEach(v.nonPropertyKeys, function (nonKey) {
  827. t['throws'](
  828. function () { ES.HasOwnProperty({}, nonKey); },
  829. TypeError,
  830. debug(nonKey) + ' is not a Property Key'
  831. );
  832. });
  833. t.equal(ES.HasOwnProperty({}, 'toString'), false, 'inherited properties are not own');
  834. t.equal(
  835. ES.HasOwnProperty({ toString: 1 }, 'toString'),
  836. true,
  837. 'shadowed inherited own properties are own'
  838. );
  839. t.equal(ES.HasOwnProperty({ a: 1 }, 'a'), true, 'own properties are own');
  840. t.end();
  841. });
  842. test('HasProperty', function (t) {
  843. forEach(v.primitives, function (primitive) {
  844. t['throws'](
  845. function () { ES.HasProperty(primitive, 'key'); },
  846. TypeError,
  847. debug(primitive) + ' is not an Object'
  848. );
  849. });
  850. forEach(v.nonPropertyKeys, function (nonKey) {
  851. t['throws'](
  852. function () { ES.HasProperty({}, nonKey); },
  853. TypeError,
  854. debug(nonKey) + ' is not a Property Key'
  855. );
  856. });
  857. t.equal(ES.HasProperty({}, 'nope'), false, 'object does not have nonexistent properties');
  858. t.equal(ES.HasProperty({}, 'toString'), true, 'object has inherited properties');
  859. t.equal(
  860. ES.HasProperty({ toString: 1 }, 'toString'),
  861. true,
  862. 'object has shadowed inherited own properties'
  863. );
  864. t.equal(ES.HasProperty({ a: 1 }, 'a'), true, 'object has own properties');
  865. t.end();
  866. });
  867. test('IsConcatSpreadable', function (t) {
  868. forEach(v.primitives, function (primitive) {
  869. t.equal(ES.IsConcatSpreadable(primitive), false, debug(primitive) + ' is not an Object');
  870. });
  871. var hasSymbolConcatSpreadable = v.hasSymbols && Symbol.isConcatSpreadable;
  872. t.test('Symbol.isConcatSpreadable', { skip: !hasSymbolConcatSpreadable }, function (st) {
  873. forEach(v.falsies, function (falsy) {
  874. var obj = {};
  875. obj[Symbol.isConcatSpreadable] = falsy;
  876. st.equal(
  877. ES.IsConcatSpreadable(obj),
  878. false,
  879. 'an object with ' + debug(falsy) + ' as Symbol.isConcatSpreadable is not concat spreadable'
  880. );
  881. });
  882. forEach(v.truthies, function (truthy) {
  883. var obj = {};
  884. obj[Symbol.isConcatSpreadable] = truthy;
  885. st.equal(
  886. ES.IsConcatSpreadable(obj),
  887. true,
  888. 'an object with ' + debug(truthy) + ' as Symbol.isConcatSpreadable is concat spreadable'
  889. );
  890. });
  891. st.end();
  892. });
  893. forEach(v.objects, function (object) {
  894. t.equal(
  895. ES.IsConcatSpreadable(object),
  896. false,
  897. 'non-array without Symbol.isConcatSpreadable is not concat spreadable'
  898. );
  899. });
  900. t.equal(ES.IsConcatSpreadable([]), true, 'arrays are concat spreadable');
  901. t.end();
  902. });
  903. test('Invoke', function (t) {
  904. forEach(v.nonPropertyKeys, function (nonKey) {
  905. t['throws'](
  906. function () { ES.Invoke({}, nonKey); },
  907. TypeError,
  908. debug(nonKey) + ' is not a Property Key'
  909. );
  910. });
  911. t['throws'](function () { ES.Invoke({ o: false }, 'o'); }, TypeError, 'fails on a non-function');
  912. t.test('invoked callback', function (st) {
  913. var aValue = {};
  914. var bValue = {};
  915. var obj = {
  916. f: function (a) {
  917. st.equal(arguments.length, 2, '2 args passed');
  918. st.equal(a, aValue, 'first arg is correct');
  919. st.equal(arguments[1], bValue, 'second arg is correct');
  920. }
  921. };
  922. st.plan(3);
  923. ES.Invoke(obj, 'f', aValue, bValue);
  924. });
  925. t.end();
  926. });
  927. test('GetIterator', { skip: true });
  928. test('IteratorNext', { skip: true });
  929. test('IteratorComplete', { skip: true });
  930. test('IteratorValue', { skip: true });
  931. test('IteratorStep', { skip: true });
  932. test('IteratorClose', { skip: true });
  933. test('CreateIterResultObject', function (t) {
  934. forEach(v.nonBooleans, function (nonBoolean) {
  935. t['throws'](
  936. function () { ES.CreateIterResultObject({}, nonBoolean); },
  937. TypeError,
  938. '"done" argument must be a boolean; ' + debug(nonBoolean) + ' is not'
  939. );
  940. });
  941. var value = {};
  942. t.deepEqual(ES.CreateIterResultObject(value, true), {
  943. value: value,
  944. done: true
  945. }, 'creates a "done" iteration result');
  946. t.deepEqual(ES.CreateIterResultObject(value, false), {
  947. value: value,
  948. done: false
  949. }, 'creates a "not done" iteration result');
  950. t.end();
  951. });
  952. test('RegExpExec', function (t) {
  953. forEach(v.primitives, function (primitive) {
  954. t['throws'](
  955. function () { ES.RegExpExec(primitive); },
  956. TypeError,
  957. '"R" argument must be an object; ' + debug(primitive) + ' is not'
  958. );
  959. });
  960. forEach(v.nonStrings, function (nonString) {
  961. t['throws'](
  962. function () { ES.RegExpExec({}, nonString); },
  963. TypeError,
  964. '"S" argument must be a String; ' + debug(nonString) + ' is not'
  965. );
  966. });
  967. t.test('gets and calls a callable "exec"', function (st) {
  968. var str = '123';
  969. var o = {
  970. exec: function (S) {
  971. st.equal(this, o, '"exec" receiver is R');
  972. st.equal(S, str, '"exec" argument is S');
  973. return null;
  974. }
  975. };
  976. st.plan(2);
  977. ES.RegExpExec(o, str);
  978. st.end();
  979. });
  980. t.test('throws if a callable "exec" returns a non-null non-object', function (st) {
  981. var str = '123';
  982. st.plan(v.nonNullPrimitives.length);
  983. forEach(v.nonNullPrimitives, function (nonNullPrimitive) {
  984. st['throws'](
  985. function () { ES.RegExpExec({ exec: function () { return nonNullPrimitive; } }, str); },
  986. TypeError,
  987. '"exec" method must return `null` or an Object; ' + debug(nonNullPrimitive) + ' is not'
  988. );
  989. });
  990. st.end();
  991. });
  992. t.test('actual regex that should match against a string', function (st) {
  993. var S = 'aabc';
  994. var R = /a/g;
  995. var match1 = ES.RegExpExec(R, S);
  996. var match2 = ES.RegExpExec(R, S);
  997. var match3 = ES.RegExpExec(R, S);
  998. st.deepEqual(match1, assign(['a'], { index: 0, input: S }), 'match object 1 is as expected');
  999. st.deepEqual(match2, assign(['a'], { index: 1, input: S }), 'match object 2 is as expected');
  1000. st.equal(match3, null, 'match 3 is null as expected');
  1001. st.end();
  1002. });
  1003. t.test('actual regex that should match against a string, with shadowed "exec"', function (st) {
  1004. var S = 'aabc';
  1005. var R = /a/g;
  1006. R.exec = undefined;
  1007. var match1 = ES.RegExpExec(R, S);
  1008. var match2 = ES.RegExpExec(R, S);
  1009. var match3 = ES.RegExpExec(R, S);
  1010. st.deepEqual(match1, assign(['a'], { index: 0, input: S }), 'match object 1 is as expected');
  1011. st.deepEqual(match2, assign(['a'], { index: 1, input: S }), 'match object 2 is as expected');
  1012. st.equal(match3, null, 'match 3 is null as expected');
  1013. st.end();
  1014. });
  1015. t.end();
  1016. });
  1017. test('ArraySpeciesCreate', function (t) {
  1018. t.test('errors', function (st) {
  1019. var testNonNumber = function (nonNumber) {
  1020. st['throws'](
  1021. function () { ES.ArraySpeciesCreate([], nonNumber); },
  1022. TypeError,
  1023. debug(nonNumber) + ' is not a number'
  1024. );
  1025. };
  1026. forEach(v.nonNumbers, testNonNumber);
  1027. st['throws'](
  1028. function () { ES.ArraySpeciesCreate([], -1); },
  1029. TypeError,
  1030. '-1 is not >= 0'
  1031. );
  1032. st['throws'](
  1033. function () { ES.ArraySpeciesCreate([], -Infinity); },
  1034. TypeError,
  1035. '-Infinity is not >= 0'
  1036. );
  1037. var testNonIntegers = function (nonInteger) {
  1038. st['throws'](
  1039. function () { ES.ArraySpeciesCreate([], nonInteger); },
  1040. TypeError,
  1041. debug(nonInteger) + ' is not an integer'
  1042. );
  1043. };
  1044. forEach(v.nonIntegerNumbers, testNonIntegers);
  1045. st.end();
  1046. });
  1047. t.test('works with a non-array', function (st) {
  1048. forEach(v.objects.concat(v.primitives), function (nonArray) {
  1049. var arr = ES.ArraySpeciesCreate(nonArray, 0);
  1050. st.ok(ES.IsArray(arr), 'is an array');
  1051. st.equal(arr.length, 0, 'length is correct');
  1052. st.equal(arr.constructor, Array, 'constructor is correct');
  1053. });
  1054. st.end();
  1055. });
  1056. t.test('works with a normal array', function (st) {
  1057. var len = 2;
  1058. var orig = [1, 2, 3];
  1059. var arr = ES.ArraySpeciesCreate(orig, len);
  1060. st.ok(ES.IsArray(arr), 'is an array');
  1061. st.equal(arr.length, len, 'length is correct');
  1062. st.equal(arr.constructor, orig.constructor, 'constructor is correct');
  1063. st.end();
  1064. });
  1065. t.test('-0 length produces +0 length', function (st) {
  1066. var len = -0;
  1067. st.ok(is(len, -0), '-0 is negative zero');
  1068. st.notOk(is(len, 0), '-0 is not positive zero');
  1069. var orig = [1, 2, 3];
  1070. var arr = ES.ArraySpeciesCreate(orig, len);
  1071. st.equal(ES.IsArray(arr), true);
  1072. st.ok(is(arr.length, 0));
  1073. st.equal(arr.constructor, orig.constructor);
  1074. st.end();
  1075. });
  1076. t.test('works with species construtor', { skip: !hasSpecies }, function (st) {
  1077. var sentinel = {};
  1078. var Foo = function Foo(len) {
  1079. this.length = len;
  1080. this.sentinel = sentinel;
  1081. };
  1082. var Bar = getArraySubclassWithSpeciesConstructor(Foo);
  1083. var bar = new Bar();
  1084. t.equal(ES.IsArray(bar), true, 'Bar instance is an array');
  1085. var arr = ES.ArraySpeciesCreate(bar, 3);
  1086. st.equal(arr.constructor, Foo, 'result used species constructor');
  1087. st.equal(arr.length, 3, 'length property is correct');
  1088. st.equal(arr.sentinel, sentinel, 'Foo constructor was exercised');
  1089. st.end();
  1090. });
  1091. t.test('works with null species constructor', { skip: !hasSpecies }, function (st) {
  1092. var Bar = getArraySubclassWithSpeciesConstructor(null);
  1093. var bar = new Bar();
  1094. t.equal(ES.IsArray(bar), true, 'Bar instance is an array');
  1095. var arr = ES.ArraySpeciesCreate(bar, 3);
  1096. st.equal(arr.constructor, Array, 'result used default constructor');
  1097. st.equal(arr.length, 3, 'length property is correct');
  1098. st.end();
  1099. });
  1100. t.test('works with undefined species constructor', { skip: !hasSpecies }, function (st) {
  1101. var Bar = getArraySubclassWithSpeciesConstructor();
  1102. var bar = new Bar();
  1103. t.equal(ES.IsArray(bar), true, 'Bar instance is an array');
  1104. var arr = ES.ArraySpeciesCreate(bar, 3);
  1105. st.equal(arr.constructor, Array, 'result used default constructor');
  1106. st.equal(arr.length, 3, 'length property is correct');
  1107. st.end();
  1108. });
  1109. t.test('throws with object non-construtor species constructor', { skip: !hasSpecies }, function (st) {
  1110. forEach(v.objects, function (obj) {
  1111. var Bar = getArraySubclassWithSpeciesConstructor(obj);
  1112. var bar = new Bar();
  1113. st.equal(ES.IsArray(bar), true, 'Bar instance is an array');
  1114. st['throws'](
  1115. function () { ES.ArraySpeciesCreate(bar, 3); },
  1116. TypeError,
  1117. debug(obj) + ' is not a constructor'
  1118. );
  1119. });
  1120. st.end();
  1121. });
  1122. t.end();
  1123. });
  1124. test('CreateDataProperty', function (t) {
  1125. forEach(v.primitives, function (primitive) {
  1126. t['throws'](
  1127. function () { ES.CreateDataProperty(primitive); },
  1128. TypeError,
  1129. debug(primitive) + ' is not an object'
  1130. );
  1131. });
  1132. forEach(v.nonPropertyKeys, function (nonPropertyKey) {
  1133. t['throws'](
  1134. function () { ES.CreateDataProperty({}, nonPropertyKey); },
  1135. TypeError,
  1136. debug(nonPropertyKey) + ' is not a property key'
  1137. );
  1138. });
  1139. var sentinel = {};
  1140. forEach(v.propertyKeys, function (propertyKey) {
  1141. var obj = {};
  1142. var status = ES.CreateDataProperty(obj, propertyKey, sentinel);
  1143. t.equal(status, true, 'status is true');
  1144. t.equal(
  1145. obj[propertyKey],
  1146. sentinel,
  1147. debug(sentinel) + ' is installed on "' + debug(propertyKey) + '" on the object'
  1148. );
  1149. if (typeof Object.defineProperty === 'function') {
  1150. var nonWritable = Object.defineProperty({}, propertyKey, { configurable: true, writable: false });
  1151. var nonWritableStatus = ES.CreateDataProperty(nonWritable, propertyKey, sentinel);
  1152. t.equal(nonWritableStatus, false, 'create data property failed');
  1153. t.notEqual(
  1154. nonWritable[propertyKey],
  1155. sentinel,
  1156. debug(sentinel) + ' is not installed on "' + debug(propertyKey) + '" on the object when key is nonwritable'
  1157. );
  1158. var nonConfigurable = Object.defineProperty({}, propertyKey, { configurable: false, writable: true });
  1159. var nonConfigurableStatus = ES.CreateDataProperty(nonConfigurable, propertyKey, sentinel);
  1160. t.equal(nonConfigurableStatus, false, 'create data property failed');
  1161. t.notEqual(
  1162. nonConfigurable[propertyKey],
  1163. sentinel,
  1164. debug(sentinel) + ' is not installed on "' + debug(propertyKey) + '" on the object when key is nonconfigurable'
  1165. );
  1166. }
  1167. });
  1168. t.end();
  1169. });
  1170. test('CreateDataPropertyOrThrow', function (t) {
  1171. forEach(v.primitives, function (primitive) {
  1172. t['throws'](
  1173. function () { ES.CreateDataPropertyOrThrow(primitive); },
  1174. TypeError,
  1175. debug(primitive) + ' is not an object'
  1176. );
  1177. });
  1178. forEach(v.nonPropertyKeys, function (nonPropertyKey) {
  1179. t['throws'](
  1180. function () { ES.CreateDataPropertyOrThrow({}, nonPropertyKey); },
  1181. TypeError,
  1182. debug(nonPropertyKey) + ' is not a property key'
  1183. );
  1184. });
  1185. var sentinel = {};
  1186. forEach(v.propertyKeys, function (propertyKey) {
  1187. var obj = {};
  1188. var status = ES.CreateDataPropertyOrThrow(obj, propertyKey, sentinel);
  1189. t.equal(status, true, 'status is true');
  1190. t.equal(
  1191. obj[propertyKey],
  1192. sentinel,
  1193. debug(sentinel) + ' is installed on "' + debug(propertyKey) + '" on the object'
  1194. );
  1195. if (typeof Object.preventExtensions === 'function') {
  1196. var notExtensible = {};
  1197. Object.preventExtensions(notExtensible);
  1198. t['throws'](
  1199. function () { ES.CreateDataPropertyOrThrow(notExtensible, propertyKey, sentinel); },
  1200. TypeError,
  1201. 'can not install ' + debug(propertyKey) + ' on non-extensible object'
  1202. );
  1203. t.notEqual(
  1204. notExtensible[propertyKey],
  1205. sentinel,
  1206. debug(sentinel) + ' is not installed on "' + debug(propertyKey) + '" on the object'
  1207. );
  1208. }
  1209. });
  1210. t.end();
  1211. });
  1212. test('AdvanceStringIndex', function (t) {
  1213. forEach(v.nonStrings, function (nonString) {
  1214. t['throws'](
  1215. function () { ES.AdvanceStringIndex(nonString); },
  1216. TypeError,
  1217. '"S" argument must be a String; ' + debug(nonString) + ' is not'
  1218. );
  1219. });
  1220. forEach(v.nonIntegerNumbers, function (nonInteger) {
  1221. t['throws'](
  1222. function () { ES.AdvanceStringIndex('', nonInteger, false); },
  1223. TypeError,
  1224. '"index" argument must be an integer; ' + debug(nonInteger) + ' is not'
  1225. );
  1226. });
  1227. forEach([-1, -42], function (negative) {
  1228. t['throws'](
  1229. function () { ES.AdvanceStringIndex('', negative, false); },
  1230. RangeError,
  1231. '"index" argument must be a non-negative integer; ' + debug(negative) + ' is not'
  1232. );
  1233. });
  1234. t['throws'](
  1235. function () { ES.AdvanceStringIndex('', MAX_SAFE_INTEGER + 1, false); },
  1236. RangeError,
  1237. 'too large integers throw'
  1238. );
  1239. forEach(v.nonBooleans, function (nonBoolean) {
  1240. t['throws'](
  1241. function () { ES.AdvanceStringIndex('', 0, nonBoolean); },
  1242. TypeError,
  1243. '"unicode" argument must be a Boolean; ' + debug(nonBoolean) + ' is not'
  1244. );
  1245. });
  1246. t.test('when unicode is false', function (st) {
  1247. st.equal(ES.AdvanceStringIndex('', 0, false), 1, 'index is incremented by 1');
  1248. st.equal(ES.AdvanceStringIndex('abc', 0, false), 1, 'index is incremented by 1');
  1249. st.equal(ES.AdvanceStringIndex('', 3, false), 4, 'index is incremented by 1');
  1250. st.equal(ES.AdvanceStringIndex('abc', 3, false), 4, 'index is incremented by 1');
  1251. st.test('when the index is within the string', function (s2t) {
  1252. s2t.equal(ES.AdvanceStringIndex('abc', 0, false), 1, '0 -> 1');
  1253. s2t.equal(ES.AdvanceStringIndex('abc', 1, false), 2, '1 -> 2');
  1254. s2t.equal(ES.AdvanceStringIndex('abc', 2, false), 3, '2 -> 3');
  1255. s2t.end();
  1256. });
  1257. st.end();
  1258. });
  1259. t.test('when unicode is true', function (st) {
  1260. st.test('when index + 1 >= length', function (s2t) {
  1261. t.equal(ES.AdvanceStringIndex('', 0, true), 1, 'index is incremented by 1');
  1262. t.equal(ES.AdvanceStringIndex('a', 0, true), 1, 'index is incremented by 1');
  1263. t.equal(ES.AdvanceStringIndex('a', 5, true), 6, 'index is incremented by 1');
  1264. s2t.end();
  1265. });
  1266. st.test('when the index is within the string', function (s2t) {
  1267. s2t.equal(ES.AdvanceStringIndex('abc', 0, true), 1, '0 -> 1');
  1268. s2t.equal(ES.AdvanceStringIndex('abc', 1, true), 2, '1 -> 2');
  1269. s2t.equal(ES.AdvanceStringIndex('abc', 2, true), 3, '2 -> 3');
  1270. s2t.end();
  1271. });
  1272. st.test('surrogate pairs', function (s2t) {
  1273. var lowestPair = String.fromCharCode('0xD800') + String.fromCharCode('0xDC00');
  1274. var highestPair = String.fromCharCode('0xDBFF') + String.fromCharCode('0xDFFF');
  1275. var poop = String.fromCharCode('0xD83D') + String.fromCharCode('0xDCA9');
  1276. s2t.equal(ES.AdvanceStringIndex(lowestPair, 0, true), 2, 'lowest surrogate pair, 0 -> 2');
  1277. s2t.equal(ES.AdvanceStringIndex(highestPair, 0, true), 2, 'highest surrogate pair, 0 -> 2');
  1278. s2t.equal(ES.AdvanceStringIndex(poop, 0, true), 2, 'poop, 0 -> 2');
  1279. s2t.end();
  1280. });
  1281. st.end();
  1282. });
  1283. t.end();
  1284. });
  1285. };
  1286. var es2016 = function ES2016(ES, ops, expectedMissing) {
  1287. es2015(ES, ops, expectedMissing);
  1288. test('SameValueNonNumber', function (t) {
  1289. var willThrow = [
  1290. [3, 4],
  1291. [NaN, 4],
  1292. [4, ''],
  1293. ['abc', true],
  1294. [{}, false]
  1295. ];
  1296. forEach(willThrow, function (nums) {
  1297. t['throws'](function () { return ES.SameValueNonNumber.apply(ES, nums); }, TypeError, 'value must be same type and non-number');
  1298. });
  1299. forEach(v.objects.concat(v.nonNumberPrimitives), function (val) {
  1300. t.equal(val === val, ES.SameValueNonNumber(val, val), debug(val) + ' is SameValueNonNumber to itself');
  1301. });
  1302. t.end();
  1303. });
  1304. };
  1305. var es2017 = function E2017(ES, ops, expectedMissing) {
  1306. es2016(ES, ops, expectedMissing);
  1307. test('ToIndex', function (t) {
  1308. t.ok(is(ES.ToIndex(), 0), 'no value gives 0');
  1309. t.ok(is(ES.ToIndex(undefined), 0), 'undefined value gives 0');
  1310. t['throws'](function () { ES.ToIndex(-1); }, RangeError, 'negative numbers throw');
  1311. t['throws'](function () { ES.ToIndex(MAX_SAFE_INTEGER + 1); }, RangeError, 'too large numbers throw');
  1312. t.equal(ES.ToIndex(3), 3, 'numbers work');
  1313. t.equal(ES.ToIndex(v.valueOfOnlyObject), 4, 'coercible objects are coerced');
  1314. t.end();
  1315. });
  1316. };
  1317. module.exports = {
  1318. es2015: es2015,
  1319. es2016: es2016,
  1320. es2017: es2017
  1321. };