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 file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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';
@@ -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;
This conversation was marked as resolved by aleen42

This comment has been minimized.

Copy link
@zloirock

zloirock Dec 14, 2019

Owner

Seems it's not required in this scope.

This comment has been minimized.

Copy link
@aleen42

aleen42 Dec 16, 2019

Author Contributor

When declared inside NullProtoObject, IE8 will throw an error, which message is around "Unable to run released script". So I have to declared globally

Use activeXDocument inside NullProtoObjectViaActiveX, rather than passing through parameters, should have the same problem.

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();
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.