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
path: root/doc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2012-01-12 17:41:04 +0400
committerBen Noordhuis <info@bnoordhuis.nl>2012-01-12 17:44:41 +0400
commit465e22e62f8eb927464bb6210ec786ab289813f9 (patch)
tree4a629f996b47183bec52d8ae5ca960708ba9d758 /doc
parent247d0da188e70949a48739fc42dbf5da4d7b8b40 (diff)
docs: clarify filename argument of vm.* functions
Diffstat (limited to 'doc')
-rw-r--r--doc/api/vm.markdown34
1 files changed, 18 insertions, 16 deletions
diff --git a/doc/api/vm.markdown b/doc/api/vm.markdown
index d3e3606ef2f..3d3c1684591 100644
--- a/doc/api/vm.markdown
+++ b/doc/api/vm.markdown
@@ -9,8 +9,9 @@ JavaScript code can be compiled and run immediately or compiled, saved, and run
### vm.runInThisContext(code, [filename])
-`vm.runInThisContext()` compiles `code` as if it were loaded from `filename`,
-runs it and returns the result. Running code does not have access to local scope. `filename` is optional.
+`vm.runInThisContext()` compiles `code`, runs it and returns the result. Running
+code does not have access to local scope. `filename` is optional, it's used only
+in stack traces.
Example of using `vm.runInThisContext` and `eval` to run the same code:
@@ -38,10 +39,10 @@ and throws an exception.
### vm.runInNewContext(code, [sandbox], [filename])
-`vm.runInNewContext` compiles `code` to run in `sandbox` as if it were loaded from `filename`,
-then runs it and returns the result. Running code does not have access to local scope and
-the object `sandbox` will be used as the global object for `code`.
-`sandbox` and `filename` are optional.
+`vm.runInNewContext` compiles `code`, then runs it in `sandbox` and returns the
+result. Running code does not have access to local scope. The object `sandbox`
+will be used as the global object for `code`.
+`sandbox` and `filename` are optional, `filename` is only used in stack traces.
Example: compile and execute code that increments a global variable and sets a new one.
These globals are contained in the sandbox.
@@ -67,11 +68,12 @@ and throws an exception.
### vm.runInContext(code, context, [filename])
-`vm.runInContext` compiles `code` to run in context `context` as if it were loaded from `filename`,
-then runs it and returns the result. A (V8) context comprises a global object, together with a
-set of built-in objects and functions. Running code does not have access to local scope and
-the global object held within `context` will be used as the global object for `code`.
-`filename` is optional.
+`vm.runInContext` compiles `code`, then runs it in `context` and returns the
+result. A (V8) context comprises a global object, together with a set of
+built-in objects and functions. Running code does not have access to local scope
+and the global object held within `context` will be used as the global object
+for `code`.
+`filename` is optional, it's used only in stack traces.
Example: compile and execute code in a existing context.
@@ -107,11 +109,11 @@ to seed the initial contents of the global object used by the context.
### vm.createScript(code, [filename])
-`createScript` compiles `code` as if it were loaded from `filename`,
-but does not run it. Instead, it returns a `vm.Script` object representing this compiled code.
-This script can be run later many times using methods below.
-The returned script is not bound to any global object.
-It is bound before each run, just for that run. `filename` is optional.
+`createScript` compiles `code` but does not run it. Instead, it returns a
+`vm.Script` object representing this compiled code. This script can be run
+later many times using methods below. The returned script is not bound to any
+global object. It is bound before each run, just for that run. `filename` is
+optional, it's only used in stack traces.
In case of syntax error in `code`, `createScript` prints the syntax error to stderr
and throws an exception.