[njs] Fixed keyword list.
Dmitry Volyntsev
xeioex at nginx.com
Mon Oct 21 12:11:08 UTC 2019
details: https://hg.nginx.org/njs/rev/f01ee3828b15
branches:
changeset: 1190:f01ee3828b15
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon Oct 21 15:10:34 2019 +0300
description:
Fixed keyword list.
"undefined", "NaN" and "Infinity" are not keywords.
This closes #219 issue on Github.
diffstat:
src/njs_builtin.c | 2 +-
src/njs_generator.c | 1 -
src/njs_lexer.h | 3 +-
src/njs_lexer_keyword.c | 4 +--
src/njs_parser_expression.c | 1 -
src/njs_parser_terminal.c | 6 -----
src/test/njs_unit_test.c | 54 ++++++++++++++++++++++++++++++++++++--------
7 files changed, 47 insertions(+), 24 deletions(-)
diffs (205 lines):
diff -r c86310ffb38a -r f01ee3828b15 src/njs_builtin.c
--- a/src/njs_builtin.c Fri Oct 18 16:38:55 2019 +0300
+++ b/src/njs_builtin.c Mon Oct 21 15:10:34 2019 +0300
@@ -1021,7 +1021,7 @@ static const njs_object_prop_t njs_glob
{
.type = NJS_PROPERTY,
.name = njs_string("Infinity"),
- .value = njs_value(NJS_NUMBER, 0, INFINITY),
+ .value = njs_value(NJS_NUMBER, 1, INFINITY),
},
{
diff -r c86310ffb38a -r f01ee3828b15 src/njs_generator.c
--- a/src/njs_generator.c Fri Oct 18 16:38:55 2019 +0300
+++ b/src/njs_generator.c Mon Oct 21 15:10:34 2019 +0300
@@ -383,7 +383,6 @@ njs_generate(njs_vm_t *vm, njs_generator
case NJS_TOKEN_POST_DECREMENT:
return njs_generate_inc_dec_operation(vm, generator, node, 1);
- case NJS_TOKEN_UNDEFINED:
case NJS_TOKEN_NULL:
case NJS_TOKEN_BOOLEAN:
case NJS_TOKEN_NUMBER:
diff -r c86310ffb38a -r f01ee3828b15 src/njs_lexer.h
--- a/src/njs_lexer.h Fri Oct 18 16:38:55 2019 +0300
+++ b/src/njs_lexer.h Mon Oct 21 15:10:34 2019 +0300
@@ -106,9 +106,8 @@ typedef enum {
NJS_TOKEN_DIGIT,
NJS_TOKEN_LETTER,
-#define NJS_TOKEN_FIRST_CONST NJS_TOKEN_UNDEFINED
+#define NJS_TOKEN_FIRST_CONST NJS_TOKEN_NULL
- NJS_TOKEN_UNDEFINED,
NJS_TOKEN_NULL,
NJS_TOKEN_NUMBER,
NJS_TOKEN_BOOLEAN,
diff -r c86310ffb38a -r f01ee3828b15 src/njs_lexer_keyword.c
--- a/src/njs_lexer_keyword.c Fri Oct 18 16:38:55 2019 +0300
+++ b/src/njs_lexer_keyword.c Mon Oct 21 15:10:34 2019 +0300
@@ -12,12 +12,9 @@ static const njs_keyword_t njs_keywords
/* Values. */
- { njs_str("undefined"), NJS_TOKEN_UNDEFINED, 0 },
{ njs_str("null"), NJS_TOKEN_NULL, 0 },
{ njs_str("false"), NJS_TOKEN_BOOLEAN, 0 },
{ njs_str("true"), NJS_TOKEN_BOOLEAN, 1 },
- { njs_str("NaN"), NJS_TOKEN_NUMBER, NAN },
- { njs_str("Infinity"), NJS_TOKEN_NUMBER, INFINITY },
/* Operators. */
@@ -79,6 +76,7 @@ static const njs_keyword_t njs_keywords
{ njs_str("MemoryError"), NJS_TOKEN_MEMORY_ERROR_CONSTRUCTOR, 0 },
/* Module. */
+
{ njs_str("import"), NJS_TOKEN_IMPORT, 0 },
{ njs_str("export"), NJS_TOKEN_EXPORT, 0 },
diff -r c86310ffb38a -r f01ee3828b15 src/njs_parser_expression.c
--- a/src/njs_parser_expression.c Fri Oct 18 16:38:55 2019 +0300
+++ b/src/njs_parser_expression.c Mon Oct 21 15:10:34 2019 +0300
@@ -617,7 +617,6 @@ njs_parser_unary_expression(njs_vm_t *vm
return next;
case NJS_TOKEN_NAME:
- case NJS_TOKEN_UNDEFINED:
njs_parser_syntax_error(vm, parser,
"Delete of an unqualified identifier");
diff -r c86310ffb38a -r f01ee3828b15 src/njs_parser_terminal.c
--- a/src/njs_parser_terminal.c Fri Oct 18 16:38:55 2019 +0300
+++ b/src/njs_parser_terminal.c Mon Oct 21 15:10:34 2019 +0300
@@ -224,12 +224,6 @@ njs_parser_reference(njs_vm_t *vm, njs_p
node->u.value = njs_value_null;
break;
- case NJS_TOKEN_UNDEFINED:
- njs_thread_log_debug("JS: undefined");
-
- njs_set_undefined(&node->u.value);
- break;
-
case NJS_TOKEN_THIS:
njs_thread_log_debug("JS: this");
diff -r c86310ffb38a -r f01ee3828b15 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Oct 18 16:38:55 2019 +0300
+++ b/src/test/njs_unit_test.c Mon Oct 21 15:10:34 2019 +0300
@@ -108,9 +108,6 @@ static njs_unit_test_t njs_test[] =
#if 0 /* TODO */
{ njs_str("var a; Object.getOwnPropertyDescriptor(this, 'a').value"),
njs_str("undefined") },
-
- { njs_str("this.a = 1; a"),
- njs_str("1") },
#endif
{ njs_str("f() = 1"),
@@ -766,6 +763,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("undefined + undefined"),
njs_str("NaN") },
+ { njs_str("var undefined"),
+ njs_str("undefined") },
+
{ njs_str("1.2 + 5.7"),
njs_str("6.9") },
@@ -1705,6 +1705,20 @@ static njs_unit_test_t njs_test[] =
{ njs_str("-Infinity >= Infinity"),
njs_str("false") },
+ { njs_str("Boolean(Infinity)"),
+ njs_str("true") },
+
+ { njs_str("!Infinity === false"),
+ njs_str("true") },
+
+ { njs_str("var Infinity"),
+ njs_str("undefined") },
+
+#if 0 /* ES5FIX */
+ { njs_str("Infinity = 1"),
+ njs_str("TypeError: Cannot assign to read-only property "Infinity" of object") },
+#endif
+
/**/
{ njs_str("NaN === NaN"),
@@ -1731,6 +1745,14 @@ static njs_unit_test_t njs_test[] =
{ njs_str("NaN <= NaN"),
njs_str("false") },
+ { njs_str("var NaN"),
+ njs_str("undefined") },
+
+#if 0 /* ES5FIX */
+ { njs_str("NaN = 1"),
+ njs_str("TypeError: Cannot assign to read-only property "NaN" of object") },
+#endif
+
/**/
{ njs_str("null < 0"),
@@ -3215,8 +3237,10 @@ static njs_unit_test_t njs_test[] =
{ njs_str("null = 1"),
njs_str("ReferenceError: Invalid left-hand side in assignment in 1") },
+#if 0 /* ES5FIX */
{ njs_str("undefined = 1"),
- njs_str("ReferenceError: Invalid left-hand side in assignment in 1") },
+ njs_str("TypeError: Cannot assign to read-only property "undefined" of object") },
+#endif
{ njs_str("null++"),
njs_str("ReferenceError: Invalid left-hand side in postfix operation in 1") },
@@ -3462,15 +3486,11 @@ static njs_unit_test_t njs_test[] =
{ njs_str("var o = { [new Number(12345)]: 1000 }; o[12345]"),
njs_str("1000") },
- /* ES5FIX: "SyntaxError". */
-
{ njs_str("delete NaN"),
- njs_str("true") },
-
- /* ES5FIX: "SyntaxError". */
+ njs_str("SyntaxError: Delete of an unqualified identifier in 1") },
{ njs_str("delete Infinity"),
- njs_str("true") },
+ njs_str("SyntaxError: Delete of an unqualified identifier in 1") },
{ njs_str("delete -Infinity"),
njs_str("true") },
@@ -7255,6 +7275,12 @@ static njs_unit_test_t njs_test[] =
{ njs_str("[0].some(function(){return Array.call.bind(isNaN)}())"),
njs_str("false") },
+ { njs_str("(function (undefined, NaN, Infinity){ return undefined + NaN + Infinity})('x', 'y', 'z')"),
+ njs_str("xyz") },
+
+ { njs_str("function f(undefined,NaN, Infinity){ return undefined + NaN + Infinity}; f('x', 'y', 'z')"),
+ njs_str("xyz") },
+
/* Recursive factorial. */
{ njs_str("function f(a) {"
@@ -9335,6 +9361,14 @@ static njs_unit_test_t njs_test[] =
{ njs_str("this.a = ()=>1; a()"),
njs_str("1") },
+ { njs_str("var global = this;"
+ "function isImmutableConstant(v) {"
+ " var d = Object.getOwnPropertyDescriptor(global, v);"
+ " return !d.writable && !d.enumerable && !d.configurable;"
+ "};"
+ "['undefined', 'NaN', 'Infinity'].every((v)=>isImmutableConstant(v))"),
+ njs_str("true") },
+
{ njs_str("this.undefined = 42"),
njs_str("TypeError: Cannot assign to read-only property \"undefined\" of object") },
More information about the nginx-devel
mailing list