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');
12 var PROTOTYPE = 'prototype';
13 var SCRIPT = 'script';
14 var IE_PROTO = sharedKey('IE_PROTO');
16 var EmptyConstructor = function () { /* empty */ };
18 var scriptTag = function (content) {
19 return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
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
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 + ':';
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;
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
54 var NullProtoObject = function () {
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();
68 hiddenKeys[IE_PROTO] = true;
70 // `Object.create` method
71 // https://tc39.es/ecma262/#sec-object.create
72 module.exports = Object.create || function create(O, Properties) {
75 EmptyConstructor[PROTOTYPE] = anObject(O);
76 result = new EmptyConstructor();
77 EmptyConstructor[PROTOTYPE] = null;
78 // add "__proto__" for Object.getPrototypeOf polyfill
80 } else result = NullProtoObject();
81 return Properties === undefined ? result : defineProperties(result, Properties);