Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

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