source: trip-planner-front/node_modules/object.assign/polyfill.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3var implementation = require('./implementation');
4
5var lacksProperEnumerationOrder = function () {
6 if (!Object.assign) {
7 return false;
8 }
9 /*
10 * v8, specifically in node 4.x, has a bug with incorrect property enumeration order
11 * note: this does not detect the bug unless there's 20 characters
12 */
13 var str = 'abcdefghijklmnopqrst';
14 var letters = str.split('');
15 var map = {};
16 for (var i = 0; i < letters.length; ++i) {
17 map[letters[i]] = letters[i];
18 }
19 var obj = Object.assign({}, map);
20 var actual = '';
21 for (var k in obj) {
22 actual += k;
23 }
24 return str !== actual;
25};
26
27var assignHasPendingExceptions = function () {
28 if (!Object.assign || !Object.preventExtensions) {
29 return false;
30 }
31 /*
32 * Firefox 37 still has "pending exception" logic in its Object.assign implementation,
33 * which is 72% slower than our shim, and Firefox 40's native implementation.
34 */
35 var thrower = Object.preventExtensions({ 1: 2 });
36 try {
37 Object.assign(thrower, 'xy');
38 } catch (e) {
39 return thrower[1] === 'y';
40 }
41 return false;
42};
43
44module.exports = function getPolyfill() {
45 if (!Object.assign) {
46 return implementation;
47 }
48 if (lacksProperEnumerationOrder()) {
49 return implementation;
50 }
51 if (assignHasPendingExceptions()) {
52 return implementation;
53 }
54 return Object.assign;
55};
Note: See TracBrowser for help on using the repository browser.