CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
polyfill.js56 linesDownload Raw Back to object.assign
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 order11	 * note: this does not detect the bug unless there's 20 characters12	 */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};56 
basant307/AI_Governance_Project · CoolFace