]> git.kaiwu.me - njs.git/commitdiff
Fixed keyword list.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 21 Oct 2019 12:10:34 +0000 (15:10 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 21 Oct 2019 12:10:34 +0000 (15:10 +0300)
"undefined", "NaN" and "Infinity" are not keywords.

This closes #219 issue on Github.

src/njs_builtin.c
src/njs_generator.c
src/njs_lexer.h
src/njs_lexer_keyword.c
src/njs_parser_expression.c
src/njs_parser_terminal.c
src/test/njs_unit_test.c

index 38eca6c947cccf7d10d5d4c7a19fa92e3186c44a..58269e6babd47172b5a3abd2d44c1cc4d27efc27 100644 (file)
@@ -1021,7 +1021,7 @@ static const njs_object_prop_t  njs_global_this_object_properties[] =
     {
         .type = NJS_PROPERTY,
         .name = njs_string("Infinity"),
-        .value = njs_value(NJS_NUMBER, 0, INFINITY),
+        .value = njs_value(NJS_NUMBER, 1, INFINITY),
     },
 
     {
index 139748f1308f8c0622f998cf3c336c8de4f7d238..a4b43ce4fed7dcf0f540a3e1430623053c8eb5df 100644 (file)
@@ -383,7 +383,6 @@ njs_generate(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node)
     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:
index 61775b61df51797f1aee796343807427a1d11276..d14e93a19297de00b3e4315525048d3ca2c098ce 100644 (file)
@@ -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,
index 59d7224e67e62c5e3ff6d64758a0fea9663527de..c7e74c830f73c1288d9b44d248a20fd98cc239df 100644 (file)
@@ -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 },
 
index cb1c247c23dc500dc9cde10acde2cf9ca07f08d5..ab59c4aa0b2b9ddd41ddee0325e7cf258d0d7a48 100644 (file)
@@ -617,7 +617,6 @@ njs_parser_unary_expression(njs_vm_t *vm, njs_parser_t *parser,
             return next;
 
         case NJS_TOKEN_NAME:
-        case NJS_TOKEN_UNDEFINED:
             njs_parser_syntax_error(vm, parser,
                                     "Delete of an unqualified identifier");
 
index 2dacd195ce8d7d47edadceb91a39ebc6708b99c6..24e74a7c94f10b3642e52aef187afb57345a3be6 100644 (file)
@@ -224,12 +224,6 @@ njs_parser_reference(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token,
         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");
 
index 77972c4f30ddfa46b202e5fac4de240da09ad2a3..59b538d84daab9c277c522aa3901fd9f8815dcca 100644 (file)
@@ -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") },