aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Van de Gejuchte <anthonyvdgent@gmail.com>2016-06-12 18:58:20 +0200
committerAnthony Van de Gejuchte <anthonyvdgent@gmail.com>2016-06-12 19:08:16 +0200
commitbb9c9707aa6b4c625ad985798aea879080411ce1 (patch)
treedafd9b5d908ab28a352d6e31fefa29f1ad09a9b8
parent6c8e001feeeb957279814aa58be44d1ece8bdb6e (diff)
downloadtracifyjs-bb9c9707aa6b4c625ad985798aea879080411ce1.tar.gz
tracifyjs-bb9c9707aa6b4c625ad985798aea879080411ce1.zip
Don't allow with statements in strict mode
-rw-r--r--lib/parse.js3
-rw-r--r--test/mocha/with.js16
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/parse.js b/lib/parse.js
index 4530c2d9..2c007965 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -928,6 +928,9 @@ function parse($TEXT, options) {
return tmp = const_(), semicolon(), tmp;
case "with":
+ if (S.input.has_directive("use strict")) {
+ croak("Strict mode may not include a with statement");
+ }
return new AST_With({
expression : parenthesised(),
body : statement()
diff --git a/test/mocha/with.js b/test/mocha/with.js
new file mode 100644
index 00000000..d284f1c2
--- /dev/null
+++ b/test/mocha/with.js
@@ -0,0 +1,16 @@
+var assert = require("assert");
+var uglify = require("../../");
+
+describe("With", function() {
+ it ("Should throw syntaxError when using with statement in strict mode", function() {
+ var code = '"use strict";\nthrow NotEarlyError;\nwith ({}) { }';
+ var test = function() {
+ uglify.parse(code);
+ }
+ var error = function(e) {
+ return e instanceof uglify.JS_Parse_Error &&
+ e.message === "Strict mode may not include a with statement";
+ }
+ assert.throws(test, error);
+ });
+}); \ No newline at end of file