core-js icon indicating copy to clipboard operation
core-js copied to clipboard

object-create在非浏览器环境下会报错

Open rabit2022 opened this issue 10 months ago • 3 comments

iframe.style.display = 'none'; html.appendChild(iframe); iframeDocument = iframe.contentWindow.document; iframeDocument.open(); iframeDocument.write(scriptTag('document.F=Object')); iframeDocument.close();

这个分支的代码会报错,es3非浏览器环境下,没有处理iframe={}的情况,html为空的情况,

NullProtoObject = typeof document != 'undefined' ? document.domain && activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) // old IE : NullProtoObjectViaIFrame() : NullProtoObjectViaActiveX(activeXDocument); // WSH

没有考虑更多情况

rabit2022 avatar Mar 03 '25 12:03 rabit2022

Translation:


object-create will error in non-browser environments

iframe.style.display = 'none';
html.appendChild(iframe);
iframeDocument = iframe.contentWindow.document;
iframeDocument.open();
iframeDocument.write(scriptTag('document.F=Object'));
iframeDocument.close();

This branch of code will error, under a non-browser es3 environment, there's no processing of the case where iframe={}, and html is empty.

NullProtoObject = typeof document != 'undefined' ?
document.domain && activeXDocument ?
NullProtoObjectViaActiveX(activeXDocument) // old IE
:
NullProtoObjectViaIFrame() :
NullProtoObjectViaActiveX(activeXDocument); // WSH

No more situations considered

johnzhou721 avatar Jul 01 '25 22:07 johnzhou721

It is likely that an attempt was made to use the "htmlfile" object in a non-browser environment.

In my case, I discovered that on one of the four computers I regularly use to check the results of my development, it was not possible to create an "htmlfile" object.

I suspect that software interacting with internal systems has damaged the operating system’s registration related to the htmlfile object. (The most likely culprit is security software.)

On PCs where the htmlfile object has been damaged, the same issue occurs, and since this is not a common case, I am still looking into how to fix it. Attempting to modify the known related registry entries did not resolve the problem.

In fact, to speak more fundamentally, in a non-browser environment it is unnecessary to import an iframe object and define Object.create() in the process. Even if the relevant operating system component is damaged, there should be no error.

However, it seems that the IE-related code snippets inside core-js were designed with “web browsers” in mind, and thus did not account for separate JavaScript runtimes that have no need to use a DOM with IE-like specifications.

gnh1201 avatar Aug 09 '25 00:08 gnh1201

Previously, I submitted a PR regarding an issue related to that code snippet (#966, #970).

If you could provide a more detailed description of the problem you are currently experiencing, I will consider creating and submitting an additional PR.

gnh1201 avatar Aug 09 '25 00:08 gnh1201