[6a3a178] | 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 | 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
|
---|
| 55 | var activeXDocument;
|
---|
| 56 | var 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 |
|
---|
| 69 | hiddenKeys[IE_PROTO] = true;
|
---|
| 70 |
|
---|
| 71 | // `Object.create` method
|
---|
| 72 | // https://tc39.es/ecma262/#sec-object.create
|
---|
| 73 | module.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 | };
|
---|