source: imaps-frontend/node_modules/core-js/internals/object-create.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 3.1 KB
Line 
1'use strict';
2/* global ActiveXObject -- old IE, WSH */
3var anObject = require('../internals/an-object');
4var definePropertiesModule = require('../internals/object-define-properties');
5var enumBugKeys = require('../internals/enum-bug-keys');
6var hiddenKeys = require('../internals/hidden-keys');
7var html = require('../internals/html');
8var documentCreateElement = require('../internals/document-create-element');
9var sharedKey = require('../internals/shared-key');
10
11var GT = '>';
12var LT = '<';
13var PROTOTYPE = 'prototype';
14var SCRIPT = 'script';
15var IE_PROTO = sharedKey('IE_PROTO');
16
17var EmptyConstructor = function () { /* empty */ };
18
19var scriptTag = function (content) {
20 return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
21};
22
23// Create object with fake `null` prototype: use ActiveX Object with cleared prototype
24var NullProtoObjectViaActiveX = function (activeXDocument) {
25 activeXDocument.write(scriptTag(''));
26 activeXDocument.close();
27 var temp = activeXDocument.parentWindow.Object;
28 // eslint-disable-next-line no-useless-assignment -- avoid memory leak
29 activeXDocument = null;
30 return temp;
31};
32
33// Create object with fake `null` prototype: use iframe Object with cleared prototype
34var NullProtoObjectViaIFrame = function () {
35 // Thrash, waste and sodomy: IE GC bug
36 var iframe = documentCreateElement('iframe');
37 var JS = 'java' + SCRIPT + ':';
38 var iframeDocument;
39 iframe.style.display = 'none';
40 html.appendChild(iframe);
41 // https://github.com/zloirock/core-js/issues/475
42 iframe.src = String(JS);
43 iframeDocument = iframe.contentWindow.document;
44 iframeDocument.open();
45 iframeDocument.write(scriptTag('document.F=Object'));
46 iframeDocument.close();
47 return iframeDocument.F;
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 = typeof document != 'undefined'
61 ? document.domain && activeXDocument
62 ? NullProtoObjectViaActiveX(activeXDocument) // old IE
63 : NullProtoObjectViaIFrame()
64 : NullProtoObjectViaActiveX(activeXDocument); // WSH
65 var length = enumBugKeys.length;
66 while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
67 return NullProtoObject();
68};
69
70hiddenKeys[IE_PROTO] = true;
71
72// `Object.create` method
73// https://tc39.es/ecma262/#sec-object.create
74// eslint-disable-next-line es/no-object-create -- safe
75module.exports = Object.create || function create(O, Properties) {
76 var result;
77 if (O !== null) {
78 EmptyConstructor[PROTOTYPE] = anObject(O);
79 result = new EmptyConstructor();
80 EmptyConstructor[PROTOTYPE] = null;
81 // add "__proto__" for Object.getPrototypeOf polyfill
82 result[IE_PROTO] = O;
83 } else result = NullProtoObject();
84 return Properties === undefined ? result : definePropertiesModule.f(result, Properties);
85};
Note: See TracBrowser for help on using the repository browser.