Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

es2015.js 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. 'use strict';
  2. var has = require('has');
  3. var toPrimitive = require('es-to-primitive/es6');
  4. var keys = require('object-keys');
  5. var inspect = require('object-inspect');
  6. var GetIntrinsic = require('./GetIntrinsic');
  7. var $TypeError = GetIntrinsic('%TypeError%');
  8. var $RangeError = GetIntrinsic('%RangeError%');
  9. var $SyntaxError = GetIntrinsic('%SyntaxError%');
  10. var $Array = GetIntrinsic('%Array%');
  11. var $ArrayPrototype = $Array.prototype;
  12. var $String = GetIntrinsic('%String%');
  13. var $Object = GetIntrinsic('%Object%');
  14. var $Number = GetIntrinsic('%Number%');
  15. var $Symbol = GetIntrinsic('%Symbol%', true);
  16. var $RegExp = GetIntrinsic('%RegExp%');
  17. var $Date = GetIntrinsic('%Date%');
  18. var $Function = GetIntrinsic('%Function%');
  19. var $preventExtensions = $Object.preventExtensions;
  20. var hasSymbols = require('has-symbols')();
  21. var assertRecord = require('./helpers/assertRecord');
  22. var $isNaN = require('./helpers/isNaN');
  23. var $isFinite = require('./helpers/isFinite');
  24. var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1;
  25. var MAX_SAFE_INTEGER = require('./helpers/maxSafeInteger');
  26. var assign = require('./helpers/assign');
  27. var sign = require('./helpers/sign');
  28. var mod = require('./helpers/mod');
  29. var isPrimitive = require('./helpers/isPrimitive');
  30. var forEach = require('./helpers/forEach');
  31. var every = require('./helpers/every');
  32. var isSamePropertyDescriptor = require('./helpers/isSamePropertyDescriptor');
  33. var isPropertyDescriptor = require('./helpers/isPropertyDescriptor');
  34. var parseInteger = parseInt;
  35. var callBound = require('./helpers/callBound');
  36. var regexTester = require('./helpers/regexTester');
  37. var getIteratorMethod = require('./helpers/getIteratorMethod');
  38. var getSymbolDescription = require('./helpers/getSymbolDescription');
  39. var $PromiseThen = callBound('Promise.prototype.then', true);
  40. var arraySlice = callBound('Array.prototype.slice');
  41. var strSlice = callBound('String.prototype.slice');
  42. var $indexOf = callBound('Array.prototype.indexOf');
  43. var $push = callBound('Array.prototype.push');
  44. var isBinary = regexTester(/^0b[01]+$/i);
  45. var isOctal = regexTester(/^0o[0-7]+$/i);
  46. var isDigit = regexTester(/^[0-9]$/);
  47. var regexExec = callBound('RegExp.prototype.exec');
  48. var nonWS = ['\u0085', '\u200b', '\ufffe'].join('');
  49. var nonWSregex = new $RegExp('[' + nonWS + ']', 'g');
  50. var hasNonWS = regexTester(nonWSregex);
  51. var isInvalidHexLiteral = regexTester(/^[-+]0x[0-9a-f]+$/i);
  52. var $charCodeAt = callBound('String.prototype.charCodeAt');
  53. var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
  54. var toStr = callBound('Object.prototype.toString');
  55. var $NumberValueOf = callBound('Number.prototype.valueOf');
  56. var $BooleanValueOf = callBound('Boolean.prototype.valueOf');
  57. var $StringValueOf = callBound('String.prototype.valueOf');
  58. var $DateValueOf = callBound('Date.prototype.valueOf');
  59. var $SymbolToString = callBound('Symbol.prototype.toString', true);
  60. var $floor = Math.floor;
  61. var $abs = Math.abs;
  62. var $ObjectCreate = $Object.create;
  63. var $gOPD = $Object.getOwnPropertyDescriptor;
  64. var $gOPN = $Object.getOwnPropertyNames;
  65. var $gOPS = $Object.getOwnPropertySymbols;
  66. var $isExtensible = $Object.isExtensible;
  67. var $defineProperty = $Object.defineProperty;
  68. var $setProto = require('./helpers/setProto');
  69. var DefineOwnProperty = function DefineOwnProperty(ES, O, P, desc) {
  70. if (!$defineProperty) {
  71. if (!ES.IsDataDescriptor(desc)) {
  72. // ES3 does not support getters/setters
  73. return false;
  74. }
  75. if (!desc['[[Configurable]]'] || !desc['[[Writable]]']) {
  76. return false;
  77. }
  78. // fallback for ES3
  79. if (P in O && $isEnumerable(O, P) !== !!desc['[[Enumerable]]']) {
  80. // a non-enumerable existing property
  81. return false;
  82. }
  83. // property does not exist at all, or exists but is enumerable
  84. var V = desc['[[Value]]'];
  85. O[P] = V; // will use [[Define]]
  86. return ES.SameValue(O[P], V);
  87. }
  88. $defineProperty(O, P, ES.FromPropertyDescriptor(desc));
  89. return true;
  90. };
  91. // whitespace from: https://es5.github.io/#x15.5.4.20
  92. // implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324
  93. var ws = [
  94. '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003',
  95. '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028',
  96. '\u2029\uFEFF'
  97. ].join('');
  98. var trimRegex = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');
  99. var $replace = callBound('String.prototype.replace');
  100. var trim = function (value) {
  101. return $replace(value, trimRegex, '');
  102. };
  103. var ES5 = require('./es5');
  104. var hasRegExpMatcher = require('is-regex');
  105. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-abstract-operations
  106. var ES6 = assign(assign({}, ES5), {
  107. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-call-f-v-args
  108. Call: function Call(F, V) {
  109. var args = arguments.length > 2 ? arguments[2] : [];
  110. if (!this.IsCallable(F)) {
  111. throw new $TypeError(inspect(F) + ' is not a function');
  112. }
  113. return F.apply(V, args);
  114. },
  115. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toprimitive
  116. ToPrimitive: toPrimitive,
  117. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toboolean
  118. // ToBoolean: ES5.ToBoolean,
  119. // https://ecma-international.org/ecma-262/6.0/#sec-tonumber
  120. ToNumber: function ToNumber(argument) {
  121. var value = isPrimitive(argument) ? argument : toPrimitive(argument, $Number);
  122. if (typeof value === 'symbol') {
  123. throw new $TypeError('Cannot convert a Symbol value to a number');
  124. }
  125. if (typeof value === 'string') {
  126. if (isBinary(value)) {
  127. return this.ToNumber(parseInteger(strSlice(value, 2), 2));
  128. } else if (isOctal(value)) {
  129. return this.ToNumber(parseInteger(strSlice(value, 2), 8));
  130. } else if (hasNonWS(value) || isInvalidHexLiteral(value)) {
  131. return NaN;
  132. } else {
  133. var trimmed = trim(value);
  134. if (trimmed !== value) {
  135. return this.ToNumber(trimmed);
  136. }
  137. }
  138. }
  139. return $Number(value);
  140. },
  141. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tointeger
  142. // ToInteger: ES5.ToNumber,
  143. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint32
  144. // ToInt32: ES5.ToInt32,
  145. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint32
  146. // ToUint32: ES5.ToUint32,
  147. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint16
  148. ToInt16: function ToInt16(argument) {
  149. var int16bit = this.ToUint16(argument);
  150. return int16bit >= 0x8000 ? int16bit - 0x10000 : int16bit;
  151. },
  152. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint16
  153. // ToUint16: ES5.ToUint16,
  154. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toint8
  155. ToInt8: function ToInt8(argument) {
  156. var int8bit = this.ToUint8(argument);
  157. return int8bit >= 0x80 ? int8bit - 0x100 : int8bit;
  158. },
  159. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint8
  160. ToUint8: function ToUint8(argument) {
  161. var number = this.ToNumber(argument);
  162. if ($isNaN(number) || number === 0 || !$isFinite(number)) { return 0; }
  163. var posInt = sign(number) * $floor($abs(number));
  164. return mod(posInt, 0x100);
  165. },
  166. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-touint8clamp
  167. ToUint8Clamp: function ToUint8Clamp(argument) {
  168. var number = this.ToNumber(argument);
  169. if ($isNaN(number) || number <= 0) { return 0; }
  170. if (number >= 0xFF) { return 0xFF; }
  171. var f = $floor(argument);
  172. if (f + 0.5 < number) { return f + 1; }
  173. if (number < f + 0.5) { return f; }
  174. if (f % 2 !== 0) { return f + 1; }
  175. return f;
  176. },
  177. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tostring
  178. ToString: function ToString(argument) {
  179. if (typeof argument === 'symbol') {
  180. throw new $TypeError('Cannot convert a Symbol value to a string');
  181. }
  182. return $String(argument);
  183. },
  184. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-toobject
  185. ToObject: function ToObject(value) {
  186. this.RequireObjectCoercible(value);
  187. return $Object(value);
  188. },
  189. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-topropertykey
  190. ToPropertyKey: function ToPropertyKey(argument) {
  191. var key = this.ToPrimitive(argument, $String);
  192. return typeof key === 'symbol' ? key : this.ToString(key);
  193. },
  194. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
  195. ToLength: function ToLength(argument) {
  196. var len = this.ToInteger(argument);
  197. if (len <= 0) { return 0; } // includes converting -0 to +0
  198. if (len > MAX_SAFE_INTEGER) { return MAX_SAFE_INTEGER; }
  199. return len;
  200. },
  201. // https://ecma-international.org/ecma-262/6.0/#sec-canonicalnumericindexstring
  202. CanonicalNumericIndexString: function CanonicalNumericIndexString(argument) {
  203. if (toStr(argument) !== '[object String]') {
  204. throw new $TypeError('must be a string');
  205. }
  206. if (argument === '-0') { return -0; }
  207. var n = this.ToNumber(argument);
  208. if (this.SameValue(this.ToString(n), argument)) { return n; }
  209. return void 0;
  210. },
  211. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-requireobjectcoercible
  212. RequireObjectCoercible: ES5.CheckObjectCoercible,
  213. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isarray
  214. IsArray: $Array.isArray || function IsArray(argument) {
  215. return toStr(argument) === '[object Array]';
  216. },
  217. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-iscallable
  218. // IsCallable: ES5.IsCallable,
  219. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isconstructor
  220. IsConstructor: function IsConstructor(argument) {
  221. return typeof argument === 'function' && !!argument.prototype; // unfortunately there's no way to truly check this without try/catch `new argument` or Proxy
  222. },
  223. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isextensible-o
  224. IsExtensible: $preventExtensions
  225. ? function IsExtensible(obj) {
  226. if (isPrimitive(obj)) {
  227. return false;
  228. }
  229. return $isExtensible(obj);
  230. }
  231. : function isExtensible(obj) { return true; }, // eslint-disable-line no-unused-vars
  232. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-isinteger
  233. IsInteger: function IsInteger(argument) {
  234. if (typeof argument !== 'number' || $isNaN(argument) || !$isFinite(argument)) {
  235. return false;
  236. }
  237. var abs = $abs(argument);
  238. return $floor(abs) === abs;
  239. },
  240. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-ispropertykey
  241. IsPropertyKey: function IsPropertyKey(argument) {
  242. return typeof argument === 'string' || typeof argument === 'symbol';
  243. },
  244. // https://ecma-international.org/ecma-262/6.0/#sec-isregexp
  245. IsRegExp: function IsRegExp(argument) {
  246. if (!argument || typeof argument !== 'object') {
  247. return false;
  248. }
  249. if (hasSymbols) {
  250. var isRegExp = argument[$Symbol.match];
  251. if (typeof isRegExp !== 'undefined') {
  252. return ES5.ToBoolean(isRegExp);
  253. }
  254. }
  255. return hasRegExpMatcher(argument);
  256. },
  257. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevalue
  258. // SameValue: ES5.SameValue,
  259. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero
  260. SameValueZero: function SameValueZero(x, y) {
  261. return (x === y) || ($isNaN(x) && $isNaN(y));
  262. },
  263. /**
  264. * 7.3.2 GetV (V, P)
  265. * 1. Assert: IsPropertyKey(P) is true.
  266. * 2. Let O be ToObject(V).
  267. * 3. ReturnIfAbrupt(O).
  268. * 4. Return O.[[Get]](P, V).
  269. */
  270. GetV: function GetV(V, P) {
  271. // 7.3.2.1
  272. if (!this.IsPropertyKey(P)) {
  273. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  274. }
  275. // 7.3.2.2-3
  276. var O = this.ToObject(V);
  277. // 7.3.2.4
  278. return O[P];
  279. },
  280. /**
  281. * 7.3.9 - https://ecma-international.org/ecma-262/6.0/#sec-getmethod
  282. * 1. Assert: IsPropertyKey(P) is true.
  283. * 2. Let func be GetV(O, P).
  284. * 3. ReturnIfAbrupt(func).
  285. * 4. If func is either undefined or null, return undefined.
  286. * 5. If IsCallable(func) is false, throw a TypeError exception.
  287. * 6. Return func.
  288. */
  289. GetMethod: function GetMethod(O, P) {
  290. // 7.3.9.1
  291. if (!this.IsPropertyKey(P)) {
  292. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  293. }
  294. // 7.3.9.2
  295. var func = this.GetV(O, P);
  296. // 7.3.9.4
  297. if (func == null) {
  298. return void 0;
  299. }
  300. // 7.3.9.5
  301. if (!this.IsCallable(func)) {
  302. throw new $TypeError(P + 'is not a function');
  303. }
  304. // 7.3.9.6
  305. return func;
  306. },
  307. /**
  308. * 7.3.1 Get (O, P) - https://ecma-international.org/ecma-262/6.0/#sec-get-o-p
  309. * 1. Assert: Type(O) is Object.
  310. * 2. Assert: IsPropertyKey(P) is true.
  311. * 3. Return O.[[Get]](P, O).
  312. */
  313. Get: function Get(O, P) {
  314. // 7.3.1.1
  315. if (this.Type(O) !== 'Object') {
  316. throw new $TypeError('Assertion failed: Type(O) is not Object');
  317. }
  318. // 7.3.1.2
  319. if (!this.IsPropertyKey(P)) {
  320. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true, got ' + inspect(P));
  321. }
  322. // 7.3.1.3
  323. return O[P];
  324. },
  325. Type: function Type(x) {
  326. if (typeof x === 'symbol') {
  327. return 'Symbol';
  328. }
  329. return ES5.Type(x);
  330. },
  331. // https://ecma-international.org/ecma-262/6.0/#sec-speciesconstructor
  332. SpeciesConstructor: function SpeciesConstructor(O, defaultConstructor) {
  333. if (this.Type(O) !== 'Object') {
  334. throw new $TypeError('Assertion failed: Type(O) is not Object');
  335. }
  336. var C = O.constructor;
  337. if (typeof C === 'undefined') {
  338. return defaultConstructor;
  339. }
  340. if (this.Type(C) !== 'Object') {
  341. throw new $TypeError('O.constructor is not an Object');
  342. }
  343. var S = hasSymbols && $Symbol.species ? C[$Symbol.species] : void 0;
  344. if (S == null) {
  345. return defaultConstructor;
  346. }
  347. if (this.IsConstructor(S)) {
  348. return S;
  349. }
  350. throw new $TypeError('no constructor found');
  351. },
  352. // https://www.ecma-international.org/ecma-262/6.0/#sec-frompropertydescriptor
  353. FromPropertyDescriptor: function FromPropertyDescriptor(Desc) {
  354. if (typeof Desc === 'undefined') {
  355. return Desc;
  356. }
  357. assertRecord(this, 'Property Descriptor', 'Desc', Desc);
  358. var obj = {};
  359. if ('[[Value]]' in Desc) {
  360. obj.value = Desc['[[Value]]'];
  361. }
  362. if ('[[Writable]]' in Desc) {
  363. obj.writable = Desc['[[Writable]]'];
  364. }
  365. if ('[[Get]]' in Desc) {
  366. obj.get = Desc['[[Get]]'];
  367. }
  368. if ('[[Set]]' in Desc) {
  369. obj.set = Desc['[[Set]]'];
  370. }
  371. if ('[[Enumerable]]' in Desc) {
  372. obj.enumerable = Desc['[[Enumerable]]'];
  373. }
  374. if ('[[Configurable]]' in Desc) {
  375. obj.configurable = Desc['[[Configurable]]'];
  376. }
  377. return obj;
  378. },
  379. // https://ecma-international.org/ecma-262/6.0/#sec-completepropertydescriptor
  380. CompletePropertyDescriptor: function CompletePropertyDescriptor(Desc) {
  381. assertRecord(this, 'Property Descriptor', 'Desc', Desc);
  382. if (this.IsGenericDescriptor(Desc) || this.IsDataDescriptor(Desc)) {
  383. if (!has(Desc, '[[Value]]')) {
  384. Desc['[[Value]]'] = void 0;
  385. }
  386. if (!has(Desc, '[[Writable]]')) {
  387. Desc['[[Writable]]'] = false;
  388. }
  389. } else {
  390. if (!has(Desc, '[[Get]]')) {
  391. Desc['[[Get]]'] = void 0;
  392. }
  393. if (!has(Desc, '[[Set]]')) {
  394. Desc['[[Set]]'] = void 0;
  395. }
  396. }
  397. if (!has(Desc, '[[Enumerable]]')) {
  398. Desc['[[Enumerable]]'] = false;
  399. }
  400. if (!has(Desc, '[[Configurable]]')) {
  401. Desc['[[Configurable]]'] = false;
  402. }
  403. return Desc;
  404. },
  405. // https://ecma-international.org/ecma-262/6.0/#sec-set-o-p-v-throw
  406. Set: function Set(O, P, V, Throw) {
  407. if (this.Type(O) !== 'Object') {
  408. throw new $TypeError('O must be an Object');
  409. }
  410. if (!this.IsPropertyKey(P)) {
  411. throw new $TypeError('P must be a Property Key');
  412. }
  413. if (this.Type(Throw) !== 'Boolean') {
  414. throw new $TypeError('Throw must be a Boolean');
  415. }
  416. if (Throw) {
  417. O[P] = V;
  418. return true;
  419. } else {
  420. try {
  421. O[P] = V;
  422. } catch (e) {
  423. return false;
  424. }
  425. }
  426. },
  427. // https://ecma-international.org/ecma-262/6.0/#sec-hasownproperty
  428. HasOwnProperty: function HasOwnProperty(O, P) {
  429. if (this.Type(O) !== 'Object') {
  430. throw new $TypeError('O must be an Object');
  431. }
  432. if (!this.IsPropertyKey(P)) {
  433. throw new $TypeError('P must be a Property Key');
  434. }
  435. return has(O, P);
  436. },
  437. // https://ecma-international.org/ecma-262/6.0/#sec-hasproperty
  438. HasProperty: function HasProperty(O, P) {
  439. if (this.Type(O) !== 'Object') {
  440. throw new $TypeError('O must be an Object');
  441. }
  442. if (!this.IsPropertyKey(P)) {
  443. throw new $TypeError('P must be a Property Key');
  444. }
  445. return P in O;
  446. },
  447. // https://ecma-international.org/ecma-262/6.0/#sec-isconcatspreadable
  448. IsConcatSpreadable: function IsConcatSpreadable(O) {
  449. if (this.Type(O) !== 'Object') {
  450. return false;
  451. }
  452. if (hasSymbols && typeof $Symbol.isConcatSpreadable === 'symbol') {
  453. var spreadable = this.Get(O, Symbol.isConcatSpreadable);
  454. if (typeof spreadable !== 'undefined') {
  455. return this.ToBoolean(spreadable);
  456. }
  457. }
  458. return this.IsArray(O);
  459. },
  460. // https://ecma-international.org/ecma-262/6.0/#sec-invoke
  461. Invoke: function Invoke(O, P) {
  462. if (!this.IsPropertyKey(P)) {
  463. throw new $TypeError('P must be a Property Key');
  464. }
  465. var argumentsList = arraySlice(arguments, 2);
  466. var func = this.GetV(O, P);
  467. return this.Call(func, O, argumentsList);
  468. },
  469. // https://ecma-international.org/ecma-262/6.0/#sec-getiterator
  470. GetIterator: function GetIterator(obj, method) {
  471. var actualMethod = method;
  472. if (arguments.length < 2) {
  473. actualMethod = getIteratorMethod(this, obj);
  474. }
  475. var iterator = this.Call(actualMethod, obj);
  476. if (this.Type(iterator) !== 'Object') {
  477. throw new $TypeError('iterator must return an object');
  478. }
  479. return iterator;
  480. },
  481. // https://ecma-international.org/ecma-262/6.0/#sec-iteratornext
  482. IteratorNext: function IteratorNext(iterator, value) {
  483. var result = this.Invoke(iterator, 'next', arguments.length < 2 ? [] : [value]);
  484. if (this.Type(result) !== 'Object') {
  485. throw new $TypeError('iterator next must return an object');
  486. }
  487. return result;
  488. },
  489. // https://ecma-international.org/ecma-262/6.0/#sec-iteratorcomplete
  490. IteratorComplete: function IteratorComplete(iterResult) {
  491. if (this.Type(iterResult) !== 'Object') {
  492. throw new $TypeError('Assertion failed: Type(iterResult) is not Object');
  493. }
  494. return this.ToBoolean(this.Get(iterResult, 'done'));
  495. },
  496. // https://ecma-international.org/ecma-262/6.0/#sec-iteratorvalue
  497. IteratorValue: function IteratorValue(iterResult) {
  498. if (this.Type(iterResult) !== 'Object') {
  499. throw new $TypeError('Assertion failed: Type(iterResult) is not Object');
  500. }
  501. return this.Get(iterResult, 'value');
  502. },
  503. // https://ecma-international.org/ecma-262/6.0/#sec-iteratorstep
  504. IteratorStep: function IteratorStep(iterator) {
  505. var result = this.IteratorNext(iterator);
  506. var done = this.IteratorComplete(result);
  507. return done === true ? false : result;
  508. },
  509. // https://ecma-international.org/ecma-262/6.0/#sec-iteratorclose
  510. IteratorClose: function IteratorClose(iterator, completion) {
  511. if (this.Type(iterator) !== 'Object') {
  512. throw new $TypeError('Assertion failed: Type(iterator) is not Object');
  513. }
  514. if (!this.IsCallable(completion)) {
  515. throw new $TypeError('Assertion failed: completion is not a thunk for a Completion Record');
  516. }
  517. var completionThunk = completion;
  518. var iteratorReturn = this.GetMethod(iterator, 'return');
  519. if (typeof iteratorReturn === 'undefined') {
  520. return completionThunk();
  521. }
  522. var completionRecord;
  523. try {
  524. var innerResult = this.Call(iteratorReturn, iterator, []);
  525. } catch (e) {
  526. // if we hit here, then "e" is the innerResult completion that needs re-throwing
  527. // if the completion is of type "throw", this will throw.
  528. completionRecord = completionThunk();
  529. completionThunk = null; // ensure it's not called twice.
  530. // if not, then return the innerResult completion
  531. throw e;
  532. }
  533. completionRecord = completionThunk(); // if innerResult worked, then throw if the completion does
  534. completionThunk = null; // ensure it's not called twice.
  535. if (this.Type(innerResult) !== 'Object') {
  536. throw new $TypeError('iterator .return must return an object');
  537. }
  538. return completionRecord;
  539. },
  540. // https://ecma-international.org/ecma-262/6.0/#sec-createiterresultobject
  541. CreateIterResultObject: function CreateIterResultObject(value, done) {
  542. if (this.Type(done) !== 'Boolean') {
  543. throw new $TypeError('Assertion failed: Type(done) is not Boolean');
  544. }
  545. return {
  546. value: value,
  547. done: done
  548. };
  549. },
  550. // https://ecma-international.org/ecma-262/6.0/#sec-regexpexec
  551. RegExpExec: function RegExpExec(R, S) {
  552. if (this.Type(R) !== 'Object') {
  553. throw new $TypeError('R must be an Object');
  554. }
  555. if (this.Type(S) !== 'String') {
  556. throw new $TypeError('S must be a String');
  557. }
  558. var exec = this.Get(R, 'exec');
  559. if (this.IsCallable(exec)) {
  560. var result = this.Call(exec, R, [S]);
  561. if (result === null || this.Type(result) === 'Object') {
  562. return result;
  563. }
  564. throw new $TypeError('"exec" method must return `null` or an Object');
  565. }
  566. return regexExec(R, S);
  567. },
  568. // https://ecma-international.org/ecma-262/6.0/#sec-arrayspeciescreate
  569. ArraySpeciesCreate: function ArraySpeciesCreate(originalArray, length) {
  570. if (!this.IsInteger(length) || length < 0) {
  571. throw new $TypeError('Assertion failed: length must be an integer >= 0');
  572. }
  573. var len = length === 0 ? 0 : length;
  574. var C;
  575. var isArray = this.IsArray(originalArray);
  576. if (isArray) {
  577. C = this.Get(originalArray, 'constructor');
  578. // TODO: figure out how to make a cross-realm normal Array, a same-realm Array
  579. // if (this.IsConstructor(C)) {
  580. // if C is another realm's Array, C = undefined
  581. // Object.getPrototypeOf(Object.getPrototypeOf(Object.getPrototypeOf(Array))) === null ?
  582. // }
  583. if (this.Type(C) === 'Object' && hasSymbols && $Symbol.species) {
  584. C = this.Get(C, $Symbol.species);
  585. if (C === null) {
  586. C = void 0;
  587. }
  588. }
  589. }
  590. if (typeof C === 'undefined') {
  591. return $Array(len);
  592. }
  593. if (!this.IsConstructor(C)) {
  594. throw new $TypeError('C must be a constructor');
  595. }
  596. return new C(len); // this.Construct(C, len);
  597. },
  598. CreateDataProperty: function CreateDataProperty(O, P, V) {
  599. if (this.Type(O) !== 'Object') {
  600. throw new $TypeError('Assertion failed: Type(O) is not Object');
  601. }
  602. if (!this.IsPropertyKey(P)) {
  603. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  604. }
  605. var oldDesc = $gOPD(O, P);
  606. var extensible = oldDesc || this.IsExtensible(O);
  607. var immutable = oldDesc && (!oldDesc.writable || !oldDesc.configurable);
  608. if (immutable || !extensible) {
  609. return false;
  610. }
  611. return DefineOwnProperty(this, O, P, {
  612. '[[Configurable]]': true,
  613. '[[Enumerable]]': true,
  614. '[[Value]]': V,
  615. '[[Writable]]': true
  616. });
  617. },
  618. // https://ecma-international.org/ecma-262/6.0/#sec-createdatapropertyorthrow
  619. CreateDataPropertyOrThrow: function CreateDataPropertyOrThrow(O, P, V) {
  620. if (this.Type(O) !== 'Object') {
  621. throw new $TypeError('Assertion failed: Type(O) is not Object');
  622. }
  623. if (!this.IsPropertyKey(P)) {
  624. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  625. }
  626. var success = this.CreateDataProperty(O, P, V);
  627. if (!success) {
  628. throw new $TypeError('unable to create data property');
  629. }
  630. return success;
  631. },
  632. // https://www.ecma-international.org/ecma-262/6.0/#sec-objectcreate
  633. ObjectCreate: function ObjectCreate(proto, internalSlotsList) {
  634. if (proto !== null && this.Type(proto) !== 'Object') {
  635. throw new $TypeError('Assertion failed: proto must be null or an object');
  636. }
  637. var slots = arguments.length < 2 ? [] : internalSlotsList;
  638. if (slots.length > 0) {
  639. throw new $SyntaxError('es-abstract does not yet support internal slots');
  640. }
  641. if (proto === null && !$ObjectCreate) {
  642. throw new $SyntaxError('native Object.create support is required to create null objects');
  643. }
  644. return $ObjectCreate(proto);
  645. },
  646. // https://ecma-international.org/ecma-262/6.0/#sec-advancestringindex
  647. AdvanceStringIndex: function AdvanceStringIndex(S, index, unicode) {
  648. if (this.Type(S) !== 'String') {
  649. throw new $TypeError('S must be a String');
  650. }
  651. if (!this.IsInteger(index) || index < 0 || index > MAX_SAFE_INTEGER) {
  652. throw new $TypeError('Assertion failed: length must be an integer >= 0 and <= 2**53');
  653. }
  654. if (this.Type(unicode) !== 'Boolean') {
  655. throw new $TypeError('Assertion failed: unicode must be a Boolean');
  656. }
  657. if (!unicode) {
  658. return index + 1;
  659. }
  660. var length = S.length;
  661. if ((index + 1) >= length) {
  662. return index + 1;
  663. }
  664. var first = $charCodeAt(S, index);
  665. if (first < 0xD800 || first > 0xDBFF) {
  666. return index + 1;
  667. }
  668. var second = $charCodeAt(S, index + 1);
  669. if (second < 0xDC00 || second > 0xDFFF) {
  670. return index + 1;
  671. }
  672. return index + 2;
  673. },
  674. // https://www.ecma-international.org/ecma-262/6.0/#sec-createmethodproperty
  675. CreateMethodProperty: function CreateMethodProperty(O, P, V) {
  676. if (this.Type(O) !== 'Object') {
  677. throw new $TypeError('Assertion failed: Type(O) is not Object');
  678. }
  679. if (!this.IsPropertyKey(P)) {
  680. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  681. }
  682. var newDesc = {
  683. '[[Configurable]]': true,
  684. '[[Enumerable]]': false,
  685. '[[Value]]': V,
  686. '[[Writable]]': true
  687. };
  688. return DefineOwnProperty(this, O, P, newDesc);
  689. },
  690. // https://www.ecma-international.org/ecma-262/6.0/#sec-definepropertyorthrow
  691. DefinePropertyOrThrow: function DefinePropertyOrThrow(O, P, desc) {
  692. if (this.Type(O) !== 'Object') {
  693. throw new $TypeError('Assertion failed: Type(O) is not Object');
  694. }
  695. if (!this.IsPropertyKey(P)) {
  696. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  697. }
  698. var Desc = isPropertyDescriptor(this, desc) ? desc : this.ToPropertyDescriptor(desc);
  699. if (!isPropertyDescriptor(this, Desc)) {
  700. throw new $TypeError('Assertion failed: Desc is not a valid Property Descriptor');
  701. }
  702. return DefineOwnProperty(this, O, P, Desc);
  703. },
  704. // https://www.ecma-international.org/ecma-262/6.0/#sec-deletepropertyorthrow
  705. DeletePropertyOrThrow: function DeletePropertyOrThrow(O, P) {
  706. if (this.Type(O) !== 'Object') {
  707. throw new $TypeError('Assertion failed: Type(O) is not Object');
  708. }
  709. if (!this.IsPropertyKey(P)) {
  710. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  711. }
  712. var success = delete O[P];
  713. if (!success) {
  714. throw new TypeError('Attempt to delete property failed.');
  715. }
  716. return success;
  717. },
  718. // https://www.ecma-international.org/ecma-262/6.0/#sec-enumerableownnames
  719. EnumerableOwnNames: function EnumerableOwnNames(O) {
  720. if (this.Type(O) !== 'Object') {
  721. throw new $TypeError('Assertion failed: Type(O) is not Object');
  722. }
  723. return keys(O);
  724. },
  725. // https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-number-prototype-object
  726. thisNumberValue: function thisNumberValue(value) {
  727. if (this.Type(value) === 'Number') {
  728. return value;
  729. }
  730. return $NumberValueOf(value);
  731. },
  732. // https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-boolean-prototype-object
  733. thisBooleanValue: function thisBooleanValue(value) {
  734. if (this.Type(value) === 'Boolean') {
  735. return value;
  736. }
  737. return $BooleanValueOf(value);
  738. },
  739. // https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-string-prototype-object
  740. thisStringValue: function thisStringValue(value) {
  741. if (this.Type(value) === 'String') {
  742. return value;
  743. }
  744. return $StringValueOf(value);
  745. },
  746. // https://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-date-prototype-object
  747. thisTimeValue: function thisTimeValue(value) {
  748. return $DateValueOf(value);
  749. },
  750. // https://www.ecma-international.org/ecma-262/6.0/#sec-setintegritylevel
  751. SetIntegrityLevel: function SetIntegrityLevel(O, level) {
  752. if (this.Type(O) !== 'Object') {
  753. throw new $TypeError('Assertion failed: Type(O) is not Object');
  754. }
  755. if (level !== 'sealed' && level !== 'frozen') {
  756. throw new $TypeError('Assertion failed: `level` must be `"sealed"` or `"frozen"`');
  757. }
  758. if (!$preventExtensions) {
  759. throw new $SyntaxError('SetIntegrityLevel requires native `Object.preventExtensions` support');
  760. }
  761. var status = $preventExtensions(O);
  762. if (!status) {
  763. return false;
  764. }
  765. if (!$gOPN) {
  766. throw new $SyntaxError('SetIntegrityLevel requires native `Object.getOwnPropertyNames` support');
  767. }
  768. var theKeys = $gOPN(O);
  769. var ES = this;
  770. if (level === 'sealed') {
  771. forEach(theKeys, function (k) {
  772. ES.DefinePropertyOrThrow(O, k, { configurable: false });
  773. });
  774. } else if (level === 'frozen') {
  775. forEach(theKeys, function (k) {
  776. var currentDesc = $gOPD(O, k);
  777. if (typeof currentDesc !== 'undefined') {
  778. var desc;
  779. if (ES.IsAccessorDescriptor(ES.ToPropertyDescriptor(currentDesc))) {
  780. desc = { configurable: false };
  781. } else {
  782. desc = { configurable: false, writable: false };
  783. }
  784. ES.DefinePropertyOrThrow(O, k, desc);
  785. }
  786. });
  787. }
  788. return true;
  789. },
  790. // https://www.ecma-international.org/ecma-262/6.0/#sec-testintegritylevel
  791. TestIntegrityLevel: function TestIntegrityLevel(O, level) {
  792. if (this.Type(O) !== 'Object') {
  793. throw new $TypeError('Assertion failed: Type(O) is not Object');
  794. }
  795. if (level !== 'sealed' && level !== 'frozen') {
  796. throw new $TypeError('Assertion failed: `level` must be `"sealed"` or `"frozen"`');
  797. }
  798. var status = this.IsExtensible(O);
  799. if (status) {
  800. return false;
  801. }
  802. var theKeys = $gOPN(O);
  803. var ES = this;
  804. return theKeys.length === 0 || every(theKeys, function (k) {
  805. var currentDesc = $gOPD(O, k);
  806. if (typeof currentDesc !== 'undefined') {
  807. if (currentDesc.configurable) {
  808. return false;
  809. }
  810. if (level === 'frozen' && ES.IsDataDescriptor(ES.ToPropertyDescriptor(currentDesc)) && currentDesc.writable) {
  811. return false;
  812. }
  813. }
  814. return true;
  815. });
  816. },
  817. // https://www.ecma-international.org/ecma-262/6.0/#sec-ordinaryhasinstance
  818. OrdinaryHasInstance: function OrdinaryHasInstance(C, O) {
  819. if (this.IsCallable(C) === false) {
  820. return false;
  821. }
  822. if (this.Type(O) !== 'Object') {
  823. return false;
  824. }
  825. var P = this.Get(C, 'prototype');
  826. if (this.Type(P) !== 'Object') {
  827. throw new $TypeError('OrdinaryHasInstance called on an object with an invalid prototype property.');
  828. }
  829. return O instanceof C;
  830. },
  831. // https://www.ecma-international.org/ecma-262/6.0/#sec-ordinaryhasproperty
  832. OrdinaryHasProperty: function OrdinaryHasProperty(O, P) {
  833. if (this.Type(O) !== 'Object') {
  834. throw new $TypeError('Assertion failed: Type(O) is not Object');
  835. }
  836. if (!this.IsPropertyKey(P)) {
  837. throw new $TypeError('Assertion failed: P must be a Property Key');
  838. }
  839. return P in O;
  840. },
  841. // https://www.ecma-international.org/ecma-262/6.0/#sec-instanceofoperator
  842. InstanceofOperator: function InstanceofOperator(O, C) {
  843. if (this.Type(O) !== 'Object') {
  844. throw new $TypeError('Assertion failed: Type(O) is not Object');
  845. }
  846. var instOfHandler = hasSymbols && $Symbol.hasInstance ? this.GetMethod(C, $Symbol.hasInstance) : void 0;
  847. if (typeof instOfHandler !== 'undefined') {
  848. return this.ToBoolean(this.Call(instOfHandler, C, [O]));
  849. }
  850. if (!this.IsCallable(C)) {
  851. throw new $TypeError('`C` is not Callable');
  852. }
  853. return this.OrdinaryHasInstance(C, O);
  854. },
  855. // https://www.ecma-international.org/ecma-262/6.0/#sec-ispromise
  856. IsPromise: function IsPromise(x) {
  857. if (this.Type(x) !== 'Object') {
  858. return false;
  859. }
  860. if (!$PromiseThen) { // Promises are not supported
  861. return false;
  862. }
  863. try {
  864. $PromiseThen(x); // throws if not a promise
  865. } catch (e) {
  866. return false;
  867. }
  868. return true;
  869. },
  870. // https://www.ecma-international.org/ecma-262/6.0/#sec-abstract-equality-comparison
  871. 'Abstract Equality Comparison': function AbstractEqualityComparison(x, y) {
  872. var xType = this.Type(x);
  873. var yType = this.Type(y);
  874. if (xType === yType) {
  875. return x === y; // ES6+ specified this shortcut anyways.
  876. }
  877. if (x == null && y == null) {
  878. return true;
  879. }
  880. if (xType === 'Number' && yType === 'String') {
  881. return this['Abstract Equality Comparison'](x, this.ToNumber(y));
  882. }
  883. if (xType === 'String' && yType === 'Number') {
  884. return this['Abstract Equality Comparison'](this.ToNumber(x), y);
  885. }
  886. if (xType === 'Boolean') {
  887. return this['Abstract Equality Comparison'](this.ToNumber(x), y);
  888. }
  889. if (yType === 'Boolean') {
  890. return this['Abstract Equality Comparison'](x, this.ToNumber(y));
  891. }
  892. if ((xType === 'String' || xType === 'Number' || xType === 'Symbol') && yType === 'Object') {
  893. return this['Abstract Equality Comparison'](x, this.ToPrimitive(y));
  894. }
  895. if (xType === 'Object' && (yType === 'String' || yType === 'Number' || yType === 'Symbol')) {
  896. return this['Abstract Equality Comparison'](this.ToPrimitive(x), y);
  897. }
  898. return false;
  899. },
  900. // eslint-disable-next-line max-lines-per-function, max-statements, id-length, max-params
  901. ValidateAndApplyPropertyDescriptor: function ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current) {
  902. // this uses the ES2017+ logic, since it fixes a number of bugs in the ES2015 logic.
  903. var oType = this.Type(O);
  904. if (oType !== 'Undefined' && oType !== 'Object') {
  905. throw new $TypeError('Assertion failed: O must be undefined or an Object');
  906. }
  907. if (this.Type(extensible) !== 'Boolean') {
  908. throw new $TypeError('Assertion failed: extensible must be a Boolean');
  909. }
  910. if (!isPropertyDescriptor(this, Desc)) {
  911. throw new $TypeError('Assertion failed: Desc must be a Property Descriptor');
  912. }
  913. if (this.Type(current) !== 'Undefined' && !isPropertyDescriptor(this, current)) {
  914. throw new $TypeError('Assertion failed: current must be a Property Descriptor, or undefined');
  915. }
  916. if (oType !== 'Undefined' && !this.IsPropertyKey(P)) {
  917. throw new $TypeError('Assertion failed: if O is not undefined, P must be a Property Key');
  918. }
  919. if (this.Type(current) === 'Undefined') {
  920. if (!extensible) {
  921. return false;
  922. }
  923. if (this.IsGenericDescriptor(Desc) || this.IsDataDescriptor(Desc)) {
  924. if (oType !== 'Undefined') {
  925. DefineOwnProperty(this, O, P, {
  926. '[[Configurable]]': Desc['[[Configurable]]'],
  927. '[[Enumerable]]': Desc['[[Enumerable]]'],
  928. '[[Value]]': Desc['[[Value]]'],
  929. '[[Writable]]': Desc['[[Writable]]']
  930. });
  931. }
  932. } else {
  933. if (!this.IsAccessorDescriptor(Desc)) {
  934. throw new $TypeError('Assertion failed: Desc is not an accessor descriptor');
  935. }
  936. if (oType !== 'Undefined') {
  937. return DefineOwnProperty(this, O, P, Desc);
  938. }
  939. }
  940. return true;
  941. }
  942. if (this.IsGenericDescriptor(Desc) && !('[[Configurable]]' in Desc) && !('[[Enumerable]]' in Desc)) {
  943. return true;
  944. }
  945. if (isSamePropertyDescriptor(this, Desc, current)) {
  946. return true; // removed by ES2017, but should still be correct
  947. }
  948. // "if every field in Desc is absent, return true" can't really match the assertion that it's a Property Descriptor
  949. if (!current['[[Configurable]]']) {
  950. if (Desc['[[Configurable]]']) {
  951. return false;
  952. }
  953. if ('[[Enumerable]]' in Desc && !Desc['[[Enumerable]]'] === !!current['[[Enumerable]]']) {
  954. return false;
  955. }
  956. }
  957. if (this.IsGenericDescriptor(Desc)) {
  958. // no further validation is required.
  959. } else if (this.IsDataDescriptor(current) !== this.IsDataDescriptor(Desc)) {
  960. if (!current['[[Configurable]]']) {
  961. return false;
  962. }
  963. if (this.IsDataDescriptor(current)) {
  964. if (oType !== 'Undefined') {
  965. DefineOwnProperty(this, O, P, {
  966. '[[Configurable]]': current['[[Configurable]]'],
  967. '[[Enumerable]]': current['[[Enumerable]]'],
  968. '[[Get]]': undefined
  969. });
  970. }
  971. } else if (oType !== 'Undefined') {
  972. DefineOwnProperty(this, O, P, {
  973. '[[Configurable]]': current['[[Configurable]]'],
  974. '[[Enumerable]]': current['[[Enumerable]]'],
  975. '[[Value]]': undefined
  976. });
  977. }
  978. } else if (this.IsDataDescriptor(current) && this.IsDataDescriptor(Desc)) {
  979. if (!current['[[Configurable]]'] && !current['[[Writable]]']) {
  980. if ('[[Writable]]' in Desc && Desc['[[Writable]]']) {
  981. return false;
  982. }
  983. if ('[[Value]]' in Desc && !this.SameValue(Desc['[[Value]]'], current['[[Value]]'])) {
  984. return false;
  985. }
  986. return true;
  987. }
  988. } else if (this.IsAccessorDescriptor(current) && this.IsAccessorDescriptor(Desc)) {
  989. if (!current['[[Configurable]]']) {
  990. if ('[[Set]]' in Desc && !this.SameValue(Desc['[[Set]]'], current['[[Set]]'])) {
  991. return false;
  992. }
  993. if ('[[Get]]' in Desc && !this.SameValue(Desc['[[Get]]'], current['[[Get]]'])) {
  994. return false;
  995. }
  996. return true;
  997. }
  998. } else {
  999. throw new $TypeError('Assertion failed: current and Desc are not both data, both accessors, or one accessor and one data.');
  1000. }
  1001. if (oType !== 'Undefined') {
  1002. return DefineOwnProperty(this, O, P, Desc);
  1003. }
  1004. return true;
  1005. },
  1006. // https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarydefineownproperty
  1007. OrdinaryDefineOwnProperty: function OrdinaryDefineOwnProperty(O, P, Desc) {
  1008. if (this.Type(O) !== 'Object') {
  1009. throw new $TypeError('Assertion failed: O must be an Object');
  1010. }
  1011. if (!this.IsPropertyKey(P)) {
  1012. throw new $TypeError('Assertion failed: P must be a Property Key');
  1013. }
  1014. if (!isPropertyDescriptor(this, Desc)) {
  1015. throw new $TypeError('Assertion failed: Desc must be a Property Descriptor');
  1016. }
  1017. var desc = $gOPD(O, P);
  1018. var current = desc && this.ToPropertyDescriptor(desc);
  1019. var extensible = this.IsExtensible(O);
  1020. return this.ValidateAndApplyPropertyDescriptor(O, P, extensible, Desc, current);
  1021. },
  1022. // https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarygetownproperty
  1023. OrdinaryGetOwnProperty: function OrdinaryGetOwnProperty(O, P) {
  1024. if (this.Type(O) !== 'Object') {
  1025. throw new $TypeError('Assertion failed: O must be an Object');
  1026. }
  1027. if (!this.IsPropertyKey(P)) {
  1028. throw new $TypeError('Assertion failed: P must be a Property Key');
  1029. }
  1030. if (!has(O, P)) {
  1031. return void 0;
  1032. }
  1033. if (!$gOPD) {
  1034. // ES3 fallback
  1035. var arrayLength = this.IsArray(O) && P === 'length';
  1036. var regexLastIndex = this.IsRegExp(O) && P === 'lastIndex';
  1037. return {
  1038. '[[Configurable]]': !(arrayLength || regexLastIndex),
  1039. '[[Enumerable]]': $isEnumerable(O, P),
  1040. '[[Value]]': O[P],
  1041. '[[Writable]]': true
  1042. };
  1043. }
  1044. return this.ToPropertyDescriptor($gOPD(O, P));
  1045. },
  1046. // https://www.ecma-international.org/ecma-262/6.0/#sec-arraycreate
  1047. ArrayCreate: function ArrayCreate(length) {
  1048. if (!this.IsInteger(length) || length < 0) {
  1049. throw new $TypeError('Assertion failed: `length` must be an integer Number >= 0');
  1050. }
  1051. if (length > MAX_ARRAY_LENGTH) {
  1052. throw new $RangeError('length is greater than (2**32 - 1)');
  1053. }
  1054. var proto = arguments.length > 1 ? arguments[1] : $ArrayPrototype;
  1055. var A = []; // steps 5 - 7, and 9
  1056. if (proto !== $ArrayPrototype) { // step 8
  1057. if (!$setProto) {
  1058. throw new $SyntaxError('ArrayCreate: a `proto` argument that is not `Array.prototype` is not supported in an environment that does not support setting the [[Prototype]]');
  1059. }
  1060. $setProto(A, proto);
  1061. }
  1062. if (length !== 0) { // bypasses the need for step 2
  1063. A.length = length;
  1064. }
  1065. /* step 10, the above as a shortcut for the below
  1066. this.OrdinaryDefineOwnProperty(A, 'length', {
  1067. '[[Configurable]]': false,
  1068. '[[Enumerable]]': false,
  1069. '[[Value]]': length,
  1070. '[[Writable]]': true
  1071. });
  1072. */
  1073. return A;
  1074. },
  1075. // eslint-disable-next-line max-statements, max-lines-per-function
  1076. ArraySetLength: function ArraySetLength(A, Desc) {
  1077. if (!this.IsArray(A)) {
  1078. throw new $TypeError('Assertion failed: A must be an Array');
  1079. }
  1080. if (!isPropertyDescriptor(this, Desc)) {
  1081. throw new $TypeError('Assertion failed: Desc must be a Property Descriptor');
  1082. }
  1083. if (!('[[Value]]' in Desc)) {
  1084. return this.OrdinaryDefineOwnProperty(A, 'length', Desc);
  1085. }
  1086. var newLenDesc = assign({}, Desc);
  1087. var newLen = this.ToUint32(Desc['[[Value]]']);
  1088. var numberLen = this.ToNumber(Desc['[[Value]]']);
  1089. if (newLen !== numberLen) {
  1090. throw new $RangeError('Invalid array length');
  1091. }
  1092. newLenDesc['[[Value]]'] = newLen;
  1093. var oldLenDesc = this.OrdinaryGetOwnProperty(A, 'length');
  1094. if (!this.IsDataDescriptor(oldLenDesc)) {
  1095. throw new $TypeError('Assertion failed: an array had a non-data descriptor on `length`');
  1096. }
  1097. var oldLen = oldLenDesc['[[Value]]'];
  1098. if (newLen >= oldLen) {
  1099. return this.OrdinaryDefineOwnProperty(A, 'length', newLenDesc);
  1100. }
  1101. if (!oldLenDesc['[[Writable]]']) {
  1102. return false;
  1103. }
  1104. var newWritable;
  1105. if (!('[[Writable]]' in newLenDesc) || newLenDesc['[[Writable]]']) {
  1106. newWritable = true;
  1107. } else {
  1108. newWritable = false;
  1109. newLenDesc['[[Writable]]'] = true;
  1110. }
  1111. var succeeded = this.OrdinaryDefineOwnProperty(A, 'length', newLenDesc);
  1112. if (!succeeded) {
  1113. return false;
  1114. }
  1115. while (newLen < oldLen) {
  1116. oldLen -= 1;
  1117. var deleteSucceeded = delete A[this.ToString(oldLen)];
  1118. if (!deleteSucceeded) {
  1119. newLenDesc['[[Value]]'] = oldLen + 1;
  1120. if (!newWritable) {
  1121. newLenDesc['[[Writable]]'] = false;
  1122. this.OrdinaryDefineOwnProperty(A, 'length', newLenDesc);
  1123. return false;
  1124. }
  1125. }
  1126. }
  1127. if (!newWritable) {
  1128. return this.OrdinaryDefineOwnProperty(A, 'length', { '[[Writable]]': false });
  1129. }
  1130. return true;
  1131. },
  1132. // https://www.ecma-international.org/ecma-262/6.0/#sec-createhtml
  1133. CreateHTML: function CreateHTML(string, tag, attribute, value) {
  1134. if (this.Type(tag) !== 'String' || this.Type(attribute) !== 'String') {
  1135. throw new $TypeError('Assertion failed: `tag` and `attribute` must be strings');
  1136. }
  1137. var str = this.RequireObjectCoercible(string);
  1138. var S = this.ToString(str);
  1139. var p1 = '<' + tag;
  1140. if (attribute !== '') {
  1141. var V = this.ToString(value);
  1142. var escapedV = $replace(V, /\x22/g, '&quot;');
  1143. p1 += '\x20' + attribute + '\x3D\x22' + escapedV + '\x22';
  1144. }
  1145. return p1 + '>' + S + '</' + tag + '>';
  1146. },
  1147. // https://www.ecma-international.org/ecma-262/6.0/#sec-getownpropertykeys
  1148. GetOwnPropertyKeys: function GetOwnPropertyKeys(O, Type) {
  1149. if (this.Type(O) !== 'Object') {
  1150. throw new $TypeError('Assertion failed: Type(O) is not Object');
  1151. }
  1152. if (Type === 'Symbol') {
  1153. return hasSymbols && $gOPS ? $gOPS(O) : [];
  1154. }
  1155. if (Type === 'String') {
  1156. if (!$gOPN) {
  1157. return keys(O);
  1158. }
  1159. return $gOPN(O);
  1160. }
  1161. throw new $TypeError('Assertion failed: `Type` must be `"String"` or `"Symbol"`');
  1162. },
  1163. // https://www.ecma-international.org/ecma-262/6.0/#sec-symboldescriptivestring
  1164. SymbolDescriptiveString: function SymbolDescriptiveString(sym) {
  1165. if (this.Type(sym) !== 'Symbol') {
  1166. throw new $TypeError('Assertion failed: `sym` must be a Symbol');
  1167. }
  1168. return $SymbolToString(sym);
  1169. },
  1170. // https://www.ecma-international.org/ecma-262/6.0/#sec-getsubstitution
  1171. // eslint-disable-next-line max-statements, max-params, max-lines-per-function
  1172. GetSubstitution: function GetSubstitution(matched, str, position, captures, replacement) {
  1173. if (this.Type(matched) !== 'String') {
  1174. throw new $TypeError('Assertion failed: `matched` must be a String');
  1175. }
  1176. var matchLength = matched.length;
  1177. if (this.Type(str) !== 'String') {
  1178. throw new $TypeError('Assertion failed: `str` must be a String');
  1179. }
  1180. var stringLength = str.length;
  1181. if (!this.IsInteger(position) || position < 0 || position > stringLength) {
  1182. throw new $TypeError('Assertion failed: `position` must be a nonnegative integer, and less than or equal to the length of `string`, got ' + inspect(position));
  1183. }
  1184. var ES = this;
  1185. var isStringOrHole = function (capture, index, arr) { return ES.Type(capture) === 'String' || !(index in arr); };
  1186. if (!this.IsArray(captures) || !every(captures, isStringOrHole)) {
  1187. throw new $TypeError('Assertion failed: `captures` must be a List of Strings, got ' + inspect(captures));
  1188. }
  1189. if (this.Type(replacement) !== 'String') {
  1190. throw new $TypeError('Assertion failed: `replacement` must be a String');
  1191. }
  1192. var tailPos = position + matchLength;
  1193. var m = captures.length;
  1194. var result = '';
  1195. for (var i = 0; i < replacement.length; i += 1) {
  1196. // if this is a $, and it's not the end of the replacement
  1197. var current = replacement[i];
  1198. var isLast = (i + 1) >= replacement.length;
  1199. var nextIsLast = (i + 2) >= replacement.length;
  1200. if (current === '$' && !isLast) {
  1201. var next = replacement[i + 1];
  1202. if (next === '$') {
  1203. result += '$';
  1204. i += 1;
  1205. } else if (next === '&') {
  1206. result += matched;
  1207. i += 1;
  1208. } else if (next === '`') {
  1209. result += position === 0 ? '' : strSlice(str, 0, position - 1);
  1210. i += 1;
  1211. } else if (next === "'") {
  1212. result += tailPos >= stringLength ? '' : strSlice(str, tailPos);
  1213. i += 1;
  1214. } else {
  1215. var nextNext = nextIsLast ? null : replacement[i + 2];
  1216. if (isDigit(next) && next !== '0' && (nextIsLast || !isDigit(nextNext))) {
  1217. // $1 through $9, and not followed by a digit
  1218. var n = parseInteger(next, 10);
  1219. // if (n > m, impl-defined)
  1220. result += (n <= m && this.Type(captures[n - 1]) === 'Undefined') ? '' : captures[n - 1];
  1221. i += 1;
  1222. } else if (isDigit(next) && (nextIsLast || isDigit(nextNext))) {
  1223. // $00 through $99
  1224. var nn = next + nextNext;
  1225. var nnI = parseInteger(nn, 10) - 1;
  1226. // if nn === '00' or nn > m, impl-defined
  1227. result += (nn <= m && this.Type(captures[nnI]) === 'Undefined') ? '' : captures[nnI];
  1228. i += 2;
  1229. } else {
  1230. result += '$';
  1231. }
  1232. }
  1233. } else {
  1234. // the final $, or else not a $
  1235. result += replacement[i];
  1236. }
  1237. }
  1238. return result;
  1239. },
  1240. // https://ecma-international.org/ecma-262/6.0/#sec-todatestring
  1241. ToDateString: function ToDateString(tv) {
  1242. if (this.Type(tv) !== 'Number') {
  1243. throw new $TypeError('Assertion failed: `tv` must be a Number');
  1244. }
  1245. if ($isNaN(tv)) {
  1246. return 'Invalid Date';
  1247. }
  1248. return $Date(tv);
  1249. },
  1250. // https://ecma-international.org/ecma-262/6.0/#sec-createlistfromarraylike
  1251. CreateListFromArrayLike: function CreateListFromArrayLike(obj) {
  1252. var elementTypes = arguments.length > 1
  1253. ? arguments[1]
  1254. : ['Undefined', 'Null', 'Boolean', 'String', 'Symbol', 'Number', 'Object'];
  1255. if (this.Type(obj) !== 'Object') {
  1256. throw new $TypeError('Assertion failed: `obj` must be an Object');
  1257. }
  1258. if (!this.IsArray(elementTypes)) {
  1259. throw new $TypeError('Assertion failed: `elementTypes`, if provided, must be an array');
  1260. }
  1261. var len = this.ToLength(this.Get(obj, 'length'));
  1262. var list = [];
  1263. var index = 0;
  1264. while (index < len) {
  1265. var indexName = this.ToString(index);
  1266. var next = this.Get(obj, indexName);
  1267. var nextType = this.Type(next);
  1268. if ($indexOf(elementTypes, nextType) < 0) {
  1269. throw new $TypeError('item type ' + nextType + ' is not a valid elementType');
  1270. }
  1271. $push(list, next);
  1272. index += 1;
  1273. }
  1274. return list;
  1275. },
  1276. // https://ecma-international.org/ecma-262/6.0/#sec-getprototypefromconstructor
  1277. GetPrototypeFromConstructor: function GetPrototypeFromConstructor(constructor, intrinsicDefaultProto) {
  1278. var intrinsic = GetIntrinsic(intrinsicDefaultProto); // throws if not a valid intrinsic
  1279. if (!this.IsConstructor(constructor)) {
  1280. throw new $TypeError('Assertion failed: `constructor` must be a constructor');
  1281. }
  1282. var proto = this.Get(constructor, 'prototype');
  1283. if (this.Type(proto) !== 'Object') {
  1284. if (!(constructor instanceof $Function)) {
  1285. // ignore other realms, for now
  1286. throw new $TypeError('cross-realm constructors not currently supported');
  1287. }
  1288. proto = intrinsic;
  1289. }
  1290. return proto;
  1291. },
  1292. // https://ecma-international.org/ecma-262/6.0/#sec-setfunctionname
  1293. SetFunctionName: function SetFunctionName(F, name) {
  1294. if (typeof F !== 'function') {
  1295. throw new $TypeError('Assertion failed: `F` must be a function');
  1296. }
  1297. if (!this.IsExtensible(F) || has(F, 'name')) {
  1298. throw new $TypeError('Assertion failed: `F` must be extensible, and must not have a `name` own property');
  1299. }
  1300. var nameType = this.Type(name);
  1301. if (nameType !== 'Symbol' && nameType !== 'String') {
  1302. throw new $TypeError('Assertion failed: `name` must be a Symbol or a String');
  1303. }
  1304. if (nameType === 'Symbol') {
  1305. var description = getSymbolDescription(name);
  1306. // eslint-disable-next-line no-param-reassign
  1307. name = typeof description === 'undefined' ? '' : '[' + description + ']';
  1308. }
  1309. if (arguments.length > 2) {
  1310. var prefix = arguments[2];
  1311. // eslint-disable-next-line no-param-reassign
  1312. name = prefix + ' ' + name;
  1313. }
  1314. return this.DefinePropertyOrThrow(F, 'name', {
  1315. '[[Value]]': name,
  1316. '[[Writable]]': false,
  1317. '[[Enumerable]]': false,
  1318. '[[Configurable]]': true
  1319. });
  1320. }
  1321. });
  1322. delete ES6.CheckObjectCoercible; // renamed in ES6 to RequireObjectCoercible
  1323. module.exports = ES6;