From: Dmitry Volyntsev Date: Mon, 21 Oct 2019 12:10:34 +0000 (+0300) Subject: Fixed keyword list. X-Git-Tag: 0.3.6~2 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=6db0a2f597cc54a54f5126c34ff0b3a01714029d;p=njs.git Fixed keyword list. "undefined", "NaN" and "Infinity" are not keywords. This closes #219 issue on Github. --- diff --git a/src/njs_builtin.c b/src/njs_builtin.c index 38eca6c9..58269e6b 100644 --- a/src/njs_builtin.c +++ b/src/njs_builtin.c @@ -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), }, { diff --git a/src/njs_generator.c b/src/njs_generator.c index 139748f1..a4b43ce4 100644 --- a/src/njs_generator.c +++ b/src/njs_generator.c @@ -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: diff --git a/src/njs_lexer.h b/src/njs_lexer.h index 61775b61..d14e93a1 100644 --- a/src/njs_lexer.h +++ b/src/njs_lexer.h @@ -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 --git a/src/njs_lexer_keyword.c b/src/njs_lexer_keyword.c index 59d7224e..c7e74c83 100644 --- a/src/njs_lexer_keyword.c +++ b/src/njs_lexer_keyword.c @@ -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 --git a/src/njs_parser_expression.c b/src/njs_parser_expression.c index cb1c247c..ab59c4aa 100644 --- a/src/njs_parser_expression.c +++ b/src/njs_parser_expression.c @@ -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"); diff --git a/src/njs_parser_terminal.c b/src/njs_parser_terminal.c index 2dacd195..24e74a7c 100644 --- a/src/njs_parser_terminal.c +++ b/src/njs_parser_terminal.c @@ -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"); diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 77972c4f..59b538d8 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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") },