source: trip-planner-front/node_modules/core-js/internals/object-create.js

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

initial commit

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[6a3a178]1/* global ActiveXObject -- old IE, WSH */
2var anObject = require('../internals/an-object');
3var defineProperties = require('../internals/object-define-properties');
4var enumBugKeys = require('../internals/enum-bug-keys');
5var hiddenKeys = require('../internals/hidden-keys');
6var html = require('../internals/html');
7var documentCreateElement = require('../internals/document-create-element');
8var sharedKey = require('../internals/shared-key');
9
10var GT = '>';
11var LT = '<';
12var PROTOTYPE = 'prototype';
13var SCRIPT = 'script';
14var IE_PROTO = sharedKey('IE_PROTO');
15
16var EmptyConstructor = function () { /* empty */ };
17
18var 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
23var 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
32var NullProtoObjectViaIFrame = function () {
33 // Thrash, waste and sodomy: IE GC bug
34 var iframe = documentCreateElement('iframe');
35 var JS = 'java' + SCRIPT + ':';
36 var iframeDocument;
37 if (iframe.style) {
38 iframe.style.display = 'none';
39 html.appendChild(iframe);
40 // https://github.com/zloirock/core-js/issues/475
41 iframe.src = String(JS);
42 iframeDocument = iframe.contentWindow.document;
43 iframeDocument.open();
44 iframeDocument.write(scriptTag('document.F=Object'));
45 iframeDocument.close();
46 return iframeDocument.F;
47 }
48};
49
50// Check for document.domain and active x support
51// No need to use active x approach when document.domain is not set
52// see https://github.com/es-shims/es5-shim/issues/150
53// variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
54// avoid IE GC bug
55var activeXDocument;
56var NullProtoObject = function () {
57 try {
58 activeXDocument = new ActiveXObject('htmlfile');
59 } catch (error) { /* ignore */ }
60 NullProtoObject = document.domain && activeXDocument ?
61 NullProtoObjectViaActiveX(activeXDocument) : // old IE
62 NullProtoObjectViaIFrame() ||
63 NullProtoObjectViaActiveX(activeXDocument); // WSH
64 var length = enumBugKeys.length;
65 while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
66 return NullProtoObject();
67};
68
69hiddenKeys[IE_PROTO] = true;
70
71// `Object.create` method
72// https://tc39.es/ecma262/#sec-object.create
73module.exports = Object.create || function create(O, Properties) {
74 var result;
75 if (O !== null) {
76 EmptyConstructor[PROTOTYPE] = anObject(O);
77 result = new EmptyConstructor();
78 EmptyConstructor[PROTOTYPE] = null;
79 // add "__proto__" for Object.getPrototypeOf polyfill
80 result[IE_PROTO] = O;
81 } else result = NullProtoObject();
82 return Properties === undefined ? result : defineProperties(result, Properties);
83};
Note: See TracBrowser for help on using the repository browser.