From 4453356fa3f615d7d6b62dbc27984556a373dbc0 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Fri, 12 Dec 2014 19:34:25 +0200 Subject: [PATCH 1/4] Implement DUK_OPT_NO_STRICT_DECL --- src/duk_features.h.in | 5 +++++ src/duk_js_compiler.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/duk_features.h.in b/src/duk_features.h.in index 2c744ebc..88b39f97 100644 --- a/src/duk_features.h.in +++ b/src/duk_features.h.in @@ -2260,6 +2260,11 @@ typedef FILE duk_file; #define DUK_USE_MATH_BUILTIN #endif +#define DUK_USE_STRICT_DECL +#if defined(DUK_OPT_NO_STRICT_DECL) +#undef DUK_USE_STRICT_DECL +#endif + #define DUK_USE_REGEXP_SUPPORT #if defined(DUK_OPT_NO_REGEXP_SUPPORT) #undef DUK_USE_REGEXP_SUPPORT diff --git a/src/duk_js_compiler.c b/src/duk_js_compiler.c index 01c0f7f2..30c328b6 100644 --- a/src/duk_js_compiler.c +++ b/src/duk_js_compiler.c @@ -6172,18 +6172,20 @@ DUK_LOCAL void duk__parse_stmt(duk_compiler_ctx *comp_ctx, duk_ivalue *res, duk_ DUK_DDD(DUK_DDDPRINT("directive contains escapes: valid directive " "but we ignore such directives")); } else { - /* XXX: how to compare 'use strict' most compactly? - * We don't necessarily want to add it to the built-ins - * because it's not needed at run time. + /* * The length comparisons are present to handle * strings like "use strict\u0000foo" as required. */ if (DUK_HSTRING_GET_BYTELEN(h_dir) == 10 && DUK_STRNCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use strict", 10) == 0) { +#if defined(DUK_USE_STRICT_DECL) DUK_DDD(DUK_DDDPRINT("use strict directive detected: strict flag %ld -> %ld", (long) comp_ctx->curr_func.is_strict, (long) 1)); comp_ctx->curr_func.is_strict = 1; +#else + DUK_DDD(DUK_DDDPRINT("use strict detected but strict declarations disabled, ignoring")); +#endif } else if (DUK_HSTRING_GET_BYTELEN(h_dir) == 14 && DUK_STRNCMP((const char *) DUK_HSTRING_GET_DATA(h_dir), "use duk notail", 14) == 0) { DUK_DDD(DUK_DDDPRINT("use duk notail directive detected: notail flag %ld -> %ld", From 13e03cb1434b5e41725a0c951ed98c59ab0ec133 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Fri, 12 Dec 2014 19:34:49 +0200 Subject: [PATCH 2/4] Document DUK_OPT_NO_STRICT_DECL --- doc/feature-options.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/feature-options.rst b/doc/feature-options.rst index b5ac1c6d..9b7bff74 100644 --- a/doc/feature-options.rst +++ b/doc/feature-options.rst @@ -412,6 +412,14 @@ exceptions won't have meaningful line numbers (virtual machine program counter values cannot be translated to line numbers) but function instances will have a smaller footprint. +DUK_OPT_NO_STRICT_DECL +---------------------- + +**Experimental.** + +Disable support for ``"use strict"`` declaration so that Ecmascript code is +always executed in non-strict mode. Duktape/C functions remain strict. + DUK_OPT_NO_REGEXP_SUPPORT ------------------------- From 716b6691207c093224d1c26c9a9dbfb11aceecd0 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Fri, 12 Dec 2014 19:35:10 +0200 Subject: [PATCH 3/4] Release note: DUK_OPT_NO_STRICT_DECL --- RELEASES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASES.rst b/RELEASES.rst index 1901b4f9..d14a23cf 100644 --- a/RELEASES.rst +++ b/RELEASES.rst @@ -667,6 +667,9 @@ Planned to allow application code to e.g. log more detailed version information relevant for non-official snapshot builds +* Add feature option DUK_OPT_NO_STRICT_DECL to disable support for "use + strict" declarations which may be useful with legacy code bases + * Change buffer maximum size check to compare against allocated size (including spare) instead of requested size (without spare), this has a practical impact only when using 16-bit buffer size field From 5088317ddfb62e73c99e690636cfe5958f053f6d Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Fri, 12 Dec 2014 19:38:18 +0200 Subject: [PATCH 4/4] Add DUK_OPT_NO_STRICT_DECL to makefile (commented) --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 8f06e2c2..f9dd09ae 100644 --- a/Makefile +++ b/Makefile @@ -189,6 +189,7 @@ CCOPTS_FEATURES += -DDUK_OPT_SELF_TESTS #CCOPTS_FEATURES += -DDUK_OPT_GC_TORTURE #CCOPTS_FEATURES += -DDUK_OPT_NO_MS_RESIZE_STRINGTABLE CCOPTS_FEATURES += -DDUK_OPT_DEBUG_BUFSIZE=512 +#CCOPTS_FEATURES += -DDUK_OPT_NO_STRICT_DECL #CCOPTS_FEATURES += -DDUK_OPT_NO_REGEXP_SUPPORT #CCOPTS_FEATURES += -DDUK_OPT_NO_OCTAL_SUPPORT #CCOPTS_FEATURES += -DDUK_OPT_NO_SOURCE_NONBMP