From a94c4e2420166f309809730c4004d8a1bc222030 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Thu, 7 Feb 2013 14:24:51 +0200 Subject: [PATCH] testcase for 'inheriting' strictness from containing function --- testcases/test-dev-strict-inherit.js | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 testcases/test-dev-strict-inherit.js diff --git a/testcases/test-dev-strict-inherit.js b/testcases/test-dev-strict-inherit.js new file mode 100644 index 00000000..4588720b --- /dev/null +++ b/testcases/test-dev-strict-inherit.js @@ -0,0 +1,48 @@ +/*=== +true +SyntaxError +true +===*/ + +/* An inner function or an eval call of a strict function is automatically + * strict, even without an explicit use strict declaration. + * + * A strict function 'this' binding is undefined; a non-strict function has + * the global object as its 'this' binding (when called as a plain function). + * Thus, '!this' is true for strict code, and false for non-strict code. + * + * Also, 'delete' for an unresolvable identifier is a SyntaxError in strict + * code but returns false in non-strict code. + */ + +//print=console.log; + +function outer_strict() { + 'use strict'; + var foo = 1; + + try { + print(!this); + } catch (e) { + print(e.name); + } + + try { + print(eval("delete foo")); + } catch (e) { + print(e.name); + } + + function inner() { + try { + print(!this); + } catch (e) { + print(e.name); + } + } + + inner(); +} + +outer_strict(); +