Skip to content

Commit

Permalink
simulate object.create via ActiveXObject under IE8 zloirock#727
Browse files Browse the repository at this point in the history
  • Loading branch information
aleen42 committed Dec 14, 2019
1 parent 6dcf223 commit b8e5c5d
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions packages/core-js/internals/object-create.js
Expand Up @@ -8,16 +8,25 @@ var sharedKey = require('../internals/shared-key');

var IE_PROTO = sharedKey('IE_PROTO');
var PROTOTYPE = 'prototype';
var SCRIPT = 'script';
var EmptyConstructor = function () { /* empty */ };
var scriptTag = function (content) {
var GT = '>';
var LT = '<';
return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
};

// Create object with fake `null` prototype: use ActiveX Object with cleared prototype
var NullProtoObjectViaActiveX = function (activeXDocument) {
activeXDocument.write(scriptTag(''));
activeXDocument.close();
return activeXDocument.parentWindow.Object;
};

// Create object with fake `null` prototype: use iframe Object with cleared prototype
var NullProtoObject = function () {
var NullProtoObjectViaIFrame = function () {
// Thrash, waste and sodomy: IE GC bug
var iframe = documentCreateElement('iframe');
var length = enumBugKeys.length;
var GT = '>';
var LT = '<';
var SCRIPT = 'script';
var JS = 'java' + SCRIPT + ':';
var iframeDocument;
iframe.style.display = 'none';
Expand All @@ -26,13 +35,28 @@ var NullProtoObject = function () {
iframe.src = String(JS);
iframeDocument = iframe.contentWindow.document;
iframeDocument.open();
iframeDocument.write(LT + SCRIPT + GT + 'document.F=Object' + LT + '/' + SCRIPT + GT);
iframeDocument.write(scriptTag('document.F=Object'));
iframeDocument.close();
NullProtoObject = iframeDocument.F;
while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
return NullProtoObject();
return iframeDocument.F;
};

// Check for document.domain and active x support
// No need to use active x approach when document.domain is not set
// see https://github.com/es-shims/es5-shim/issues/150
// variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
var activeXDocument;
try {
activeXDocument = document.domain && new ActiveXObject('htmlfile');
} catch (ignore) {}

// IE8 cannot run released script when `activeXDocument` is generated inside the following IIFE
var NullProtoObject = (function () {
var ProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
var length = enumBugKeys.length;
while (length--) delete ProtoObject[PROTOTYPE][enumBugKeys[length]];
return ProtoObject;
})();

hiddenKeys[IE_PROTO] = true;

// `Object.create` method
Expand Down

0 comments on commit b8e5c5d

Please sign in to comment.