Skip to content

Commit

Permalink
#454@major: Makes the Window instance a VM context. Adds support for …
Browse files Browse the repository at this point in the history
…a new window called GlobalWindow, that will run in the global context. Changes target language from ES5 to ES2020 (module resolvement will still be CommonJS).
  • Loading branch information
davidortnercybercom committed Apr 26, 2022
1 parent 6e2b915 commit 0957ed5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/happy-dom/README.md
Expand Up @@ -77,9 +77,9 @@ console.log(document.body.innerHTML);



## Run in a VM Context
## VM Context

The default Window class is a [VM context](https://nodejs.org/api/vm.html#vm_vm_createcontext_sandbox_options). A [VM context](https://nodejs.org/api/vm.html#vm_vm_createcontext_sandbox_options) will execute JavaScript code scoped within the context and the Window instance will be the global object.
The default Window class is a [VM context](https://nodejs.org/api/vm.html#vm_vm_createcontext_sandbox_options). A [VM context](https://nodejs.org/api/vm.html#vm_vm_createcontext_sandbox_options) will execute JavaScript code scoped within the context where the Window instance will be the global object.

```javascript
import { Window } from 'happy-dom';
Expand Down Expand Up @@ -112,12 +112,10 @@ document.write(`
console.log(document.querySelector('.container div').innerHTML);
```

## Run in the Global Context
## Global Context

Happy DOM exports a class called GlobalWindow, which can be used to run Happy DOM in the global context instead of the default behaviour of running in a [VM context](https://nodejs.org/api/vm.html#vm_vm_createcontext_sandbox_options).

This is useful if you want to run Happy DOM directly in a Node environment.

```javascript
import { Window, GlobalWindow } from 'happy-dom';

Expand All @@ -129,6 +127,11 @@ console.log(vmWindow.Array === global.Array);

// Will output "true"
console.log(globalWindow.Array === global.Array);

globalWindow.eval('global.test = 1');

// Will output "1"
console.log(global.test);
```

## Server-Side Rendering of Web Components
Expand Down

0 comments on commit 0957ed5

Please sign in to comment.