Browse Source

Merge branch 'ignore-strict-decl-option'

Add DUK_OPT_NO_STRICT_DECL as an experimental feature option to disable
processing "use strict" directives which can be useful when working with
legacy code (for instance, code that has "use strict" declarations but
has only been executed with an engine without strict mode support).
pull/92/head
Sami Vaarala 10 years ago
parent
commit
36aaec29d0
  1. 1
      Makefile
  2. 3
      RELEASES.rst
  3. 8
      doc/feature-options.rst
  4. 5
      src/duk_features.h.in
  5. 8
      src/duk_js_compiler.c

1
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

3
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

8
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
-------------------------

5
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

8
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",

Loading…
Cancel
Save