aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/lvlhsh_unit_test.c6
-rw-r--r--src/test/njs_externals_test.c8
-rw-r--r--src/test/njs_unit_test.c126
3 files changed, 124 insertions, 16 deletions
diff --git a/src/test/lvlhsh_unit_test.c b/src/test/lvlhsh_unit_test.c
index 6172c1c7..0e334c5d 100644
--- a/src/test/lvlhsh_unit_test.c
+++ b/src/test/lvlhsh_unit_test.c
@@ -11,7 +11,7 @@
static njs_int_t
lvlhsh_unit_test_key_test(njs_lvlhsh_query_t *lhq, void *data)
{
- if (*(uintptr_t *) lhq->key.start == (uintptr_t) data) {
+ if (*(uintptr_t *) lhq->key.start == *(uintptr_t *) data) {
return NJS_OK;
}
@@ -51,13 +51,13 @@ lvlhsh_unit_test_add(njs_lvlhsh_t *lh, const njs_lvlhsh_proto_t *proto,
lhq.replace = 0;
lhq.key.length = sizeof(uintptr_t);
lhq.key.start = (u_char *) &key;
- lhq.value = (void *) key;
lhq.proto = proto;
lhq.pool = pool;
switch (njs_lvlhsh_insert(lh, &lhq)) {
case NJS_OK:
+ ((njs_flathsh_elt_t *) lhq.value)->value[0] = (void *) key;
return NJS_OK;
case NJS_DECLINED:
@@ -84,7 +84,7 @@ lvlhsh_unit_test_get(njs_lvlhsh_t *lh, const njs_lvlhsh_proto_t *proto,
if (njs_lvlhsh_find(lh, &lhq) == NJS_OK) {
- if (key == (uintptr_t) lhq.value) {
+ if (key == (uintptr_t) ((njs_flathsh_elt_t *) lhq.value)->value[0]) {
return NJS_OK;
}
}
diff --git a/src/test/njs_externals_test.c b/src/test/njs_externals_test.c
index 8d71aae7..d3d3f1c1 100644
--- a/src/test/njs_externals_test.c
+++ b/src/test/njs_externals_test.c
@@ -61,7 +61,7 @@ lvlhsh_unit_test_key_test(njs_lvlhsh_query_t *lhq, void *data)
njs_str_t name;
njs_unit_test_prop_t *prop;
- prop = data;
+ prop = *(njs_unit_test_prop_t **) data;
name = prop->name;
if (name.length != lhq->key.length) {
@@ -129,13 +129,13 @@ lvlhsh_unit_test_add(njs_mp_t *pool, njs_unit_test_req_t *r,
lhq.key_hash = njs_djb_hash(lhq.key.start, lhq.key.length);
lhq.replace = 1;
- lhq.value = (void *) prop;
lhq.proto = &lvlhsh_proto;
lhq.pool = pool;
switch (njs_lvlhsh_insert(&r->hash, &lhq)) {
case NJS_OK:
+ ((njs_flathsh_elt_t *) lhq.value)->value[0] = (void *) prop;
return NJS_OK;
case NJS_DECLINED:
@@ -291,9 +291,9 @@ njs_unit_test_r_vars(njs_vm_t *vm, njs_object_prop_t *self, uint32_t atom_id,
ret = njs_lvlhsh_find(&r->hash, &lhq);
- prop = lhq.value;
-
if (ret == NJS_OK) {
+ prop = ((njs_flathsh_elt_t *) lhq.value)->value[0];
+
if (retval == NULL) {
njs_value_invalid_set(njs_value_arg(&prop->value));
return NJS_OK;
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 2227c0a6..78e12197 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -3923,6 +3923,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("delete this !== true"),
njs_str("false") },
+ { njs_str("undefined[Symbol()]"),
+ njs_str("TypeError: cannot get property \"Symbol()\" of undefined") },
+
/* Object shorthand methods. */
{ njs_str("var o = {m(){}}; new o.m();"),
@@ -5906,6 +5909,12 @@ static njs_unit_test_t njs_test[] =
njs_str("true") },
{ njs_str(NJS_TYPED_ARRAY_LIST
+ ".every(v=>{Object.defineProperty(v.prototype, '0', {set(){ throw 'Oops' }});"
+ " var t = new v([0]); var r = Object.create(t);"
+ " r[0] = 1; return true})"),
+ njs_str("true") },
+
+ { njs_str(NJS_TYPED_ARRAY_LIST
".every(v=>{try {var a = new v([1,1]); Object.defineProperty(a, '1', {get(){return 22}})} "
" catch (e) { return e.message == 'Cannot redefine property: \"1\"'}})"),
njs_str("true") },
@@ -9553,6 +9562,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("/["),
njs_str("SyntaxError: Unterminated RegExp \"/[\" in 1") },
+ { njs_str("/[][a"),
+ njs_str("SyntaxError: Unterminated RegExp \"/[][a\" in 1") },
+
{ njs_str("/[\\"),
njs_str("SyntaxError: Unterminated RegExp \"/[\\\" in 1") },
@@ -9588,11 +9600,24 @@ static njs_unit_test_t njs_test[] =
njs_str("/\\]cd/") },
#endif
+ { njs_str("RegExp('[][a')"),
+ njs_str("SyntaxError: "
+ njs_pcre_var("pcre_compile2(\"(?!)[a\") failed: missing terminating ] for character class at \"\"",
+ "pcre_compile(\"[][a\") failed: missing terminating ] for character class")) },
+
+ { njs_str("RegExp('[][a][a')"),
+ njs_str("SyntaxError: "
+ njs_pcre_var("pcre_compile2(\"(?!)[a][a\") failed: missing terminating ] for character class at \"\"",
+ "pcre_compile(\"[][a][a\") failed: missing terminating ] for character class")) },
+
{ njs_str("RegExp('[\\\\')"),
njs_str("SyntaxError: "
njs_pcre_var("pcre_compile2(\"[\\\") failed: \\ at end of pattern at \"\"",
"pcre_compile(\"[\\\") failed: \\ at end of pattern")) },
+ { njs_str("RegExp('[][a]')"),
+ njs_str(njs_pcre_var("/(?!)[a]/", "/[][a]/")) },
+
{ njs_str("RegExp('\\\\0').source[1]"),
njs_str("0") },
@@ -10984,6 +11009,30 @@ static njs_unit_test_t njs_test[] =
"f.apply(123, {})"),
njs_str("123") },
+ { njs_str("'Hello'.concat(' ', 'World')"),
+ njs_str("Hello World") },
+
+ { njs_str("'Value: '.concat(42, ' and ', 3.14)"),
+ njs_str("Value: 42 and 3.14") },
+
+ { njs_str("'Flags: '.concat(true, ' and ', false)"),
+ njs_str("Flags: true and false") },
+
+ { njs_str("'Values: '.concat(null, ' and ', undefined)"),
+ njs_str("Values: null and undefined") },
+
+ { njs_str("'Mixed: '.concat(123, ' ', true, ' ', null, ' ', undefined)"),
+ njs_str("Mixed: 123 true null undefined") },
+
+ { njs_str("'Special: '.concat(NaN, ' ', Infinity, ' ', -Infinity)"),
+ njs_str("Special: NaN Infinity -Infinity") },
+
+ { njs_str("'Numbers: '.concat(1234567890, ' ', 0.123456789, ' ', 1.23e-10)"),
+ njs_str("Numbers: 1234567890 0.123456789 1.23e-10") },
+
+ { njs_str("'Zero: '.concat(0, ' ', -0)"),
+ njs_str("Zero: 0 0") },
+
{ njs_str("(function(index, ...rest){ return rest[index];})"
".apply({}, [1022].concat(Array(1023).fill(1).map((v,i)=>i.toString(16))))"),
njs_str("3fe") },
@@ -11033,6 +11082,15 @@ static njs_unit_test_t njs_test[] =
{ njs_str("''.concat.apply('a', [ 'b', 'c' ], 'd')"),
njs_str("abc") },
+ { njs_str("''.concat.apply('', Array(128).fill(1.23456789123e14)) == '123456789123000'.repeat(128)"),
+ njs_str("true") },
+
+ { njs_str("''.concat.apply('', Array(128).fill(0).map((v,i)=>Math.log2(i))).startsWith('-Infinity')"),
+ njs_str("true") },
+
+ { njs_str("''.concat.apply('', Array(256).fill(0).map((v,i)=> !(i % 2) ? Math.exp(i) : 'α'.repeat(Math.log2(i)))).endsWith('110ααααααα')"),
+ njs_str("true") },
+
{ njs_str("[].join.call([1,2,3])"),
njs_str("1,2,3") },
@@ -11966,6 +12024,48 @@ static njs_unit_test_t njs_test[] =
{ njs_str("/[]a/.test('a')"),
njs_str("false") },
+ { njs_str("/[#[]/.test('[')"),
+ njs_str("true") },
+
+ { njs_str("/[\\s[]/.test('[')"),
+ njs_str("true") },
+
+ { njs_str("/[#[^]/.test('[')"),
+ njs_str("true") },
+
+ { njs_str("/[#\\[]/.test('[')"),
+ njs_str("true") },
+
+ { njs_str("/[\\[^]/.test('[')"),
+ njs_str("true") },
+
+ { njs_str("/[^]abc]/.test('#abc]')"),
+ njs_str("true") },
+
+ { njs_str("/[[^]abc]/.test('[abc]')"),
+ njs_str("true") },
+
+ { njs_str("/[[^]abc]/.test('^abc]')"),
+ njs_str("true") },
+
+ { njs_str("/[]/.test('[]')"),
+ njs_str("false") },
+
+ { njs_str("/[[]/.test('[')"),
+ njs_str("true") },
+
+ { njs_str("/\\[]/.test('[]')"),
+ njs_str("true") },
+
+ { njs_str("/[]abc]/.test('abc]')"),
+ njs_str("false") },
+
+ { njs_str("/abc]/.test('abc]')"),
+ njs_str("true") },
+
+ { njs_str("/\\\\\\[]/.test('\\\\[]')"),
+ njs_str("true") },
+
#ifdef NJS_HAVE_PCRE2
{ njs_str("/[]*a/.test('a')"),
njs_str("true") },
@@ -14186,22 +14286,22 @@ static njs_unit_test_t njs_test[] =
njs_str("true") },
{ njs_str("new Function('('.repeat(2**13));"),
- njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") },
+ njs_str("SyntaxError: Unexpected token \"}\" in runtime") },
{ njs_str("new Function('{'.repeat(2**13));"),
- njs_str("SyntaxError: Unexpected token \")\" in runtime:1") },
+ njs_str("SyntaxError: Unexpected token \")\" in runtime") },
{ njs_str("new Function('['.repeat(2**13));"),
- njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") },
+ njs_str("SyntaxError: Unexpected token \"}\" in runtime") },
{ njs_str("new Function('`'.repeat(2**13));"),
njs_str("[object Function]") },
{ njs_str("new Function('{['.repeat(2**13));"),
- njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") },
+ njs_str("SyntaxError: Unexpected token \"}\" in runtime") },
{ njs_str("new Function('{;'.repeat(2**13));"),
- njs_str("SyntaxError: Unexpected token \")\" in runtime:1") },
+ njs_str("SyntaxError: Unexpected token \")\" in runtime") },
{ njs_str("(new Function('1;'.repeat(2**13) + 'return 2'))()"),
njs_str("2") },
@@ -14213,7 +14313,7 @@ static njs_unit_test_t njs_test[] =
njs_str("-4") },
{ njs_str("new Function('new '.repeat(2**13));"),
- njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") },
+ njs_str("SyntaxError: Unexpected token \"}\" in runtime") },
{ njs_str("(new Function('return ' + 'typeof '.repeat(2**13) + 'x'))()"),
njs_str("string") },
@@ -14279,7 +14379,13 @@ static njs_unit_test_t njs_test[] =
njs_str("ReferenceError: \"foo\" is not defined") },
{ njs_str("this.NN = {}; var f = Function('eval = 42;'); f()"),
- njs_str("SyntaxError: Identifier \"eval\" is forbidden as left-hand in assignment in runtime:1") },
+ njs_str("SyntaxError: Identifier \"eval\" is forbidden as left-hand in assignment in runtime") },
+
+ { njs_str("new Function('}); let a; a; function o(){}; //')"),
+ njs_str("SyntaxError: Unexpected token \"}\" in runtime") },
+
+ { njs_str("new Function('}); let a; a; function o(){}; ({')"),
+ njs_str("SyntaxError: single function literal required") },
{ njs_str("RegExp()"),
njs_str("/(?:)/") },
@@ -19808,7 +19914,7 @@ static njs_unit_test_t njs_test[] =
njs_str("[object AsyncFunction]") },
{ njs_str("let f = new Function('x', 'await 1; return x'); f(1)"),
- njs_str("SyntaxError: await is only valid in async functions in runtime:1") },
+ njs_str("SyntaxError: await is only valid in async functions in runtime") },
{ njs_str("new AsyncFunction()"),
njs_str("ReferenceError: \"AsyncFunction\" is not defined") },
@@ -21673,7 +21779,9 @@ done:
return NJS_ERROR;
}
- success = njs_strstr_eq(&expected->ret, &s);
+ success = expected->ret.length <= s.length
+ && (memcmp(expected->ret.start, s.start, expected->ret.length)
+ == 0);
if (!success) {
njs_stderror("njs(\"%V\")\nexpected: \"%V\"\n got: \"%V\"\n",
&expected->script, &expected->ret, &s);