mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
974 B
62 lines
974 B
12 years ago
|
/*
|
||
|
* With statement (E5 Section 12.10).
|
||
|
*/
|
||
|
|
||
|
var obj;
|
||
|
|
||
|
/*===
|
||
|
undefined
|
||
|
10
|
||
|
===*/
|
||
|
|
||
|
/* Since 'with' does not alter the variable environment (which is
|
||
|
* used for variable declarations), any declarations should go to
|
||
|
* the function level instead.
|
||
|
*/
|
||
|
|
||
|
obj = { x: 100 };
|
||
|
|
||
|
function f_decl1() {
|
||
|
with (obj) {
|
||
|
eval("var foo = 10;"); /* created in function */
|
||
|
}
|
||
|
print(obj.foo); // -> undefined
|
||
|
print(foo); // 10
|
||
|
}
|
||
|
|
||
12 years ago
|
try {
|
||
12 years ago
|
f_decl1();
|
||
|
} catch (e) {
|
||
|
print(e.name);
|
||
|
}
|
||
|
|
||
|
/*===
|
||
|
100
|
||
|
undefined
|
||
|
===*/
|
||
|
|
||
|
/* Since 'with' delete operations walk through the lexical environment
|
||
|
* (same as variable lookup) and not the variable environment (for
|
||
|
* declarations), deleting properties of the bound object should be
|
||
|
* possible.
|
||
|
*/
|
||
|
|
||
|
obj = { x: 100 };
|
||
|
|
||
|
function f_del1() {
|
||
|
var x = 200; /* should not affect anything */
|
||
|
print(obj.x);
|
||
|
with (obj) {
|
||
|
delete x;
|
||
|
}
|
||
|
print(obj.x);
|
||
|
}
|
||
|
|
||
12 years ago
|
try {
|
||
12 years ago
|
f_del1();
|
||
|
} catch (e) {
|
||
|
print(e.name);
|
||
|
}
|
||
|
|
||
|
|