Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2019-11-12 09:30:02 +0300
committerGus Caplan <me@gus.host>2020-05-14 20:39:23 +0300
commit5ae5262f448295e314393dad4c491259793cea3f (patch)
tree412178bf21e1eb5e5727fcad1744233c0931ef5e /doc/api/vm.md
parent241ed44a0b06db45c97681c164fc1098e7c9f0d2 (diff)
src: add support for TLA
PR-URL: https://github.com/nodejs/node/pull/30370 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'doc/api/vm.md')
-rw-r--r--doc/api/vm.md32
1 files changed, 14 insertions, 18 deletions
diff --git a/doc/api/vm.md b/doc/api/vm.md
index 986e2c50b1d..982ec8412d5 100644
--- a/doc/api/vm.md
+++ b/doc/api/vm.md
@@ -402,7 +402,10 @@ support is planned.
```js
const vm = require('vm');
-const contextifiedObject = vm.createContext({ secret: 42 });
+const contextifiedObject = vm.createContext({
+ secret: 42,
+ print: console.log,
+});
(async () => {
// Step 1
@@ -418,6 +421,7 @@ const contextifiedObject = vm.createContext({ secret: 42 });
const bar = new vm.SourceTextModule(`
import s from 'foo';
s;
+ print(s);
`, { context: contextifiedObject });
// Step 2
@@ -460,16 +464,11 @@ const contextifiedObject = vm.createContext({ secret: 42 });
// Step 3
//
- // Evaluate the Module. The evaluate() method returns a Promise with a single
- // property "result" that contains the result of the very last statement
- // executed in the Module. In the case of `bar`, it is `s;`, which refers to
- // the default export of the `foo` module, the `secret` we set in the
- // beginning to 42.
+ // Evaluate the Module. The evaluate() method returns a promise which will
+ // resolve after the module has finished evaluating.
- const { result } = await bar.evaluate();
-
- console.log(result);
// Prints 42.
+ await bar.evaluate();
})();
```
@@ -512,17 +511,14 @@ in the ECMAScript specification.
Evaluate the module.
-This must be called after the module has been linked; otherwise it will
-throw an error. It could be called also when the module has already been
-evaluated, in which case it will do one of the following two things:
-
-* return `undefined` if the initial evaluation ended in success (`module.status`
- is `'evaluated'`)
-* rethrow the same exception the initial evaluation threw if the initial
- evaluation ended in an error (`module.status` is `'errored'`)
+This must be called after the module has been linked; otherwise it will reject.
+It could be called also when the module has already been evaluated, in which
+case it will either do nothing if the initial evaluation ended in success
+(`module.status` is `'evaluated'`) or it will re-throw the exception that the
+initial evaluation resulted in (`module.status` is `'errored'`).
This method cannot be called while the module is being evaluated
-(`module.status` is `'evaluating'`) to prevent infinite recursion.
+(`module.status` is `'evaluating'`).
Corresponds to the [Evaluate() concrete method][] field of [Cyclic Module
Record][]s in the ECMAScript specification.