Welcome! Log In Create A New Profile

Advanced

[njs] Making function expression binding immutable according the specs.

Dmitry Volyntsev
May 12, 2022 12:14AM
details: https://hg.nginx.org/njs/rev/6a28cdbc8cb6
branches:
changeset: 1855:6a28cdbc8cb6
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Wed May 11 21:08:21 2022 -0700
description:
Making function expression binding immutable according the specs.

This closes #56 issue on Github.

diffstat:

src/njs_parser.c | 7 ++++++-
src/test/njs_unit_test.c | 6 ++++++
2 files changed, 12 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r 4c8487fb0ca8 -r 6a28cdbc8cb6 src/njs_parser.c
--- a/src/njs_parser.c Wed May 11 17:51:17 2022 -0700
+++ b/src/njs_parser.c Wed May 11 21:08:21 2022 -0700
@@ -6954,8 +6954,13 @@ njs_parser_function_expression_after(njs

var = (njs_variable_t *) parser->target;

+ if (var->self) {
+ var->init = 1;
+ var->type = NJS_VARIABLE_CONST;
+ }
+
var->index = njs_scope_index(var->scope->type, var->scope->items,
- NJS_LEVEL_LOCAL, NJS_VARIABLE_VAR);
+ NJS_LEVEL_LOCAL, var->type);
var->scope->items++;

if (var->self) {
diff -r 4c8487fb0ca8 -r 6a28cdbc8cb6 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Wed May 11 17:51:17 2022 -0700
+++ b/src/test/njs_unit_test.c Wed May 11 21:08:21 2022 -0700
@@ -197,6 +197,12 @@ static njs_unit_test_t njs_test[] =
{ njs_str("var func = function x(x) {return x}; func()"),
njs_str("undefined") },

+ { njs_str("var func = function f() {f = null; return f;}; func()"),
+ njs_str("TypeError: assignment to constant variable") },
+
+ { njs_str("var func = function f() {let f = null; return f;}; func()"),
+ njs_str("null") },
+
#if 0 /* TODO */
{ njs_str("var a; Object.getOwnPropertyDescriptor(this, 'a').value"),
njs_str("undefined") },
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Making function expression binding immutable according the specs.

Dmitry Volyntsev 398 May 12, 2022 12:14AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 290
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready