[79a0317] | 1 | 'use strict';
|
---|
| 2 | /* global ActiveXObject -- old IE, WSH */
|
---|
| 3 | var anObject = require('../internals/an-object');
|
---|
| 4 | var definePropertiesModule = require('../internals/object-define-properties');
|
---|
| 5 | var enumBugKeys = require('../internals/enum-bug-keys');
|
---|
| 6 | var hiddenKeys = require('../internals/hidden-keys');
|
---|
| 7 | var html = require('../internals/html');
|
---|
| 8 | var documentCreateElement = require('../internals/document-create-element');
|
---|
| 9 | var sharedKey = require('../internals/shared-key');
|
---|
| 10 |
|
---|
| 11 | var GT = '>';
|
---|
| 12 | var LT = '<';
|
---|
| 13 | var PROTOTYPE = 'prototype';
|
---|
| 14 | var SCRIPT = 'script';
|
---|
| 15 | var IE_PROTO = sharedKey('IE_PROTO');
|
---|
| 16 |
|
---|
| 17 | var EmptyConstructor = function () { /* empty */ };
|
---|
| 18 |
|
---|
| 19 | var 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
|
---|
| 24 | var 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
|
---|
| 34 | var 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
|
---|
| 55 | var activeXDocument;
|
---|
| 56 | var 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 |
|
---|
| 70 | hiddenKeys[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
|
---|
| 75 | module.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 | };
|
---|