Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternative for object.create under IE8 #727 #728

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions packages/core-js/internals/object-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@ 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();
var temp = activeXDocument.parentWindow.Object;
activeXDocument = null; // avoid memory leak
return temp;
};

// 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,9 +37,24 @@ 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;
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
// avoid IE GC bug
var activeXDocument;
aleen42 marked this conversation as resolved.
Show resolved Hide resolved
var NullProtoObject = function () {
try {
/* global ActiveXObject */
activeXDocument = document.domain && new ActiveXObject('htmlfile');
} catch (error) { /* ignore */ }
NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
var length = enumBugKeys.length;
while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
return NullProtoObject();
};
Expand Down