massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / object-create.js
1 /* global ActiveXObject -- old IE, WSH */
2 var anObject = require('../internals/an-object');
3 var defineProperties = require('../internals/object-define-properties');
4 var enumBugKeys = require('../internals/enum-bug-keys');
5 var hiddenKeys = require('../internals/hidden-keys');
6 var html = require('../internals/html');
7 var documentCreateElement = require('../internals/document-create-element');
8 var sharedKey = require('../internals/shared-key');
9
10 var GT = '>';
11 var LT = '<';
12 var PROTOTYPE = 'prototype';
13 var SCRIPT = 'script';
14 var IE_PROTO = sharedKey('IE_PROTO');
15
16 var EmptyConstructor = function () { /* empty */ };
17
18 var scriptTag = function (content) {
19   return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
20 };
21
22 // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
23 var NullProtoObjectViaActiveX = function (activeXDocument) {
24   activeXDocument.write(scriptTag(''));
25   activeXDocument.close();
26   var temp = activeXDocument.parentWindow.Object;
27   activeXDocument = null; // avoid memory leak
28   return temp;
29 };
30
31 // Create object with fake `null` prototype: use iframe Object with cleared prototype
32 var NullProtoObjectViaIFrame = function () {
33   // Thrash, waste and sodomy: IE GC bug
34   var iframe = documentCreateElement('iframe');
35   var JS = 'java' + SCRIPT + ':';
36   var iframeDocument;
37   iframe.style.display = 'none';
38   html.appendChild(iframe);
39   // https://github.com/zloirock/core-js/issues/475
40   iframe.src = String(JS);
41   iframeDocument = iframe.contentWindow.document;
42   iframeDocument.open();
43   iframeDocument.write(scriptTag('document.F=Object'));
44   iframeDocument.close();
45   return iframeDocument.F;
46 };
47
48 // Check for document.domain and active x support
49 // No need to use active x approach when document.domain is not set
50 // see https://github.com/es-shims/es5-shim/issues/150
51 // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
52 // avoid IE GC bug
53 var activeXDocument;
54 var NullProtoObject = function () {
55   try {
56     activeXDocument = new ActiveXObject('htmlfile');
57   } catch (error) { /* ignore */ }
58   NullProtoObject = typeof document != 'undefined'
59     ? document.domain && activeXDocument
60       ? NullProtoObjectViaActiveX(activeXDocument) // old IE
61       : NullProtoObjectViaIFrame()
62     : NullProtoObjectViaActiveX(activeXDocument); // WSH
63   var length = enumBugKeys.length;
64   while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
65   return NullProtoObject();
66 };
67
68 hiddenKeys[IE_PROTO] = true;
69
70 // `Object.create` method
71 // https://tc39.es/ecma262/#sec-object.create
72 module.exports = Object.create || function create(O, Properties) {
73   var result;
74   if (O !== null) {
75     EmptyConstructor[PROTOTYPE] = anObject(O);
76     result = new EmptyConstructor();
77     EmptyConstructor[PROTOTYPE] = null;
78     // add "__proto__" for Object.getPrototypeOf polyfill
79     result[IE_PROTO] = O;
80   } else result = NullProtoObject();
81   return Properties === undefined ? result : defineProperties(result, Properties);
82 };