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

showModalDialog calls inside another function causes script to break #41

Open
u4yk opened this issue Mar 7, 2019 · 3 comments
Open

Comments

@u4yk
Copy link

u4yk commented Mar 7, 2019

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));

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

@macmessa
Copy link

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)

@u4yk
Copy link
Author

u4yk commented Jul 11, 2019

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.

macmessa pushed a commit to macmessa/showModalDialog that referenced this issue Jul 11, 2019
Prevent showModalDialog from breaking when used inside another function.

Reference: niutech#41
macmessa pushed a commit to macmessa/showModalDialog that referenced this issue Jul 11, 2019
Prevent showModalDialog from breaking when used inside another function.

Reference: niutech#41
@ziamohamed
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants