showModalDialog icon indicating copy to clipboard operation
showModalDialog copied to clipboard

showModalDialog calls inside another function causes script to break

Open u4yk opened this issue 5 years ago • 3 comments

If window.showModalDialog call is nested inside another function call, your script will break since there will be a parenthesis at the end that will have already been escaped. For example, when trying to apply this polyfill to the following line:

var val = String(window.showModalDialog(url, "", feature));`

causes an error since it's replacing everything from (window.)showModalDialog onward even though there's a parenthesis before it for the outer function call. Replacing the regex on line 55 to the below will handle this use case:

nextStmts[0] = nextStmts[0].replace(/(window\.)?showModalDialog\([^\)]*\)/g,JSON.stringify(returnValue));

https://github.com/niutech/showModalDialog/blob/198b9f8d5be73eed1e36ebbfa811ba5f13caaa4d/showModalDialog.js#L55

u4yk avatar Mar 07 '19 21:03 u4yk

You can use yield and await version instead of eval, like this:

var val = String(await window.showModalDialog(url, "", feature));

or:

var val = window.showModalDialog(url, "", feature);
val = String(val)

macmessa avatar Jul 11 '19 00:07 macmessa

Yes, I understand that yield and await are options, but we still have to support older versions of IE (we're talking IE5) as well -- and Babel is out of the question. Using generators and async will just mean we'd have to build two separate codebases at that point.

Regardless, I mentioned the issue in case someone else ran into it with a possible means to fix it. We have it fixed in our version of the polyfill.

u4yk avatar Jul 11 '19 01:07 u4yk

Is nested calls more than 1 level working? If not how to make it work?

ziamohamed avatar Oct 25 '21 11:10 ziamohamed