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