From 21dba0ba1f73d1173387e746218b2e80a3091708 Mon Sep 17 00:00:00 2001
From: Sami Vaarala The source code being compiled may be: All of these have slightly different semantics in Ecmascript. See
Establishing an Execution Context
for a detailed discussion.
- One major difference is that program and eval contexts have an implicit
+ One major difference is that global and eval contexts have an implicit
return value: the last non-empty statement value is an automatic
return value for the program or eval code, whereas functions don't have
an automatic return value.
Program and eval code don't have an explicit Global and eval code don't have an explicit The bytecode generated for program and eval code is currently slower
+ The bytecode generated for global and eval code is currently slower
than that generated for functions: a "slow path" is used for all variable
accesses in program and eval code, and the implicit return value handling
of program and eval code generates some unnecessary bytecode. From a
performance point of view (both memory and execution performance) it is
thus preferable to have as much code inside functions as possible. When compiling eval and program expressions, be careful to avoid the
+ When compiling eval and global expressions, be careful to avoid the
usual Ecmascript gotchas, such as:
-
eval
call
@@ -39,14 +39,14 @@ summary: |
function
syntax.
- For instance, the following can be compiled both as a program and as an
+ function
syntax.
+ For instance, the following can be compiled both as a global and as an
eval expression:
print("Hello world!");
@@ -71,14 +71,14 @@ summary: |
})
-
/* Function at top level is a function declaration which registers a global
@@ -101,12 +101,12 @@ summary: |
example: |
- /* Program code. Note that the hello() function is a function
+ /* Global code. Note that the hello() function is a function
* declaration which gets registered into the global object when
* executed. Implicit return value is 123.
*/
- duk_push_string(ctx, "print('program');\n"
+ duk_push_string(ctx, "print('global');\n"
"function hello() { print('Hello world!'); }\n"
"123;");
duk_push_string(ctx, "hello");
diff --git a/website/guide/performance.html b/website/guide/performance.html
index 1f8e981d..a4137839 100644
--- a/website/guide/performance.html
+++ b/website/guide/performance.html
@@ -157,7 +157,7 @@ slower.
To keep identifier accesses in the fast path: