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

happy-dom window eval "is not a function" in Bun #16363

Open
canadaduane opened this issue Jan 12, 2025 · 1 comment
Open

happy-dom window eval "is not a function" in Bun #16363

canadaduane opened this issue Jan 12, 2025 · 1 comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue

Comments

@canadaduane
Copy link

canadaduane commented Jan 12, 2025

What version of Bun is running?

1.1.43+76800b049

What platform is your computer?

Linux 6.9.3-76060903-generic x86_64 x86_64

What steps can reproduce the bug?

When asking happy-dom to eval a script, it fails to do so.

It fails with the following error: TypeError: this[PropertySymbol.window].eval is not a function:

I've written a reproducible example of the error at https://github.com/canadaduane/happy-dom-eval-issue

What is the expected behavior?

Bun should evaluate the script module offered in the happy-dom script tag. When running with node 23.2.0, the repro prints "hello world" as expected.

What do you see instead?

$ bun happy-test.js
274 |             if (browserSettings.disableErrorCapturing ||
275 |                 browserSettings.errorCapture !== BrowserErrorCaptureEnum.tryAndCatch) {
276 |                 this[PropertySymbol.window].eval(code);
277 |             }
278 |             else {
279 |                 WindowErrorUtility.captureError(this[PropertySymbol.window], () => this[PropertySymbol.window].eval(code));
                                                                                                                     ^
TypeError: this[PropertySymbol.window].eval is not a function. (In 'this[PropertySymbol.window].eval(code)', 'this[PropertySymbol.window].eval' is undefined)
      at <anonymous> (/home/duane/Projects/elsync/node_modules/.pnpm/happy-dom@16.5.3/node_modules/happy-dom/lib/nodes/html-script-element/HTMLScriptElement.js:279:112)
      at captureError (/home/duane/Projects/elsync/node_modules/.pnpm/happy-dom@16.5.3/node_modules/happy-dom/lib/window/WindowErrorUtility.js:21:22)
      at <anonymous> (/home/duane/Projects/elsync/node_modules/.pnpm/happy-dom@16.5.3/node_modules/happy-dom/lib/nodes/html-script-element/HTMLScriptElement.js:279:36)

Additional information

No response

@paperclover
Copy link
Member

minimum reproduction:

import * as vm from 'node:vm';

class A {
    globalThis = this;
    constructor() {
        vm.createContext(this);
        new vm.Script('this.eval = globalThis.eval').runInContext(this);
    }
}

console.log(new A());
expect(new A().eval).toBe(eval);

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

No branches or pull requests

3 participants