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

eval should be returning the result #396

Closed
dylang opened this issue Mar 9, 2022 · 2 comments
Closed

eval should be returning the result #396

dylang opened this issue Mar 9, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@dylang
Copy link

dylang commented Mar 9, 2022

https://github.com/capricorn86/happy-dom/blob/master/packages/happy-dom/src/window/Window.ts#L328-L330

Example:

const x = eval('() => 5');
x();
\\ => 5

This is causing packages that depend on https://github.com/dougwilson/nodejs-depd to fail because it returns a new function generated using eval.

Possible fix:

		if (global && vm && vm.isContext(this)) {
			return vm.runInContext(code, this);
		} else if (global && global.eval) {
			return global.eval(code);
		}

Typing for eval will need to be updated as well.

@capricorn86 capricorn86 self-assigned this Mar 10, 2022
@capricorn86 capricorn86 added the bug Something isn't working label Mar 10, 2022
capricorn86 added a commit that referenced this issue Mar 10, 2022
…result

#396@patch: Bugfix for Window.eval() not returning its result.
@capricorn86
Copy link
Owner

Thanks for reporting @dylang! 🙂

I have made a fix for it now.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v2.46.3

@KlausEverWalkingDev
Copy link

Hello @capricorn86, I apologize in advance for taking advantage of the interation in this issue. @dylang, could you please give a look on dylang/npm-check#397? Someboby made a nice PR with some lovely additions and updates on npm-check package, a project that I greatly recommend. Have a nice day, folks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants