Welcome! Log In Create A New Profile

Advanced

[njs] RegExp.prototype.toString() should be applied only to RegExp.

December 05, 2016 10:20AM
details: http://hg.nginx.org/njs/rev/709ac03a4bfd
branches:
changeset: 274:709ac03a4bfd
user: Igor Sysoev <igor@sysoev.ru>
date: Mon Dec 05 17:47:00 2016 +0300
description:
RegExp.prototype.toString() should be applied only to RegExp.

diffstat:

njs/njs_regexp.c | 19 ++++++++++++++-----
njs/test/njs_unit_test.c | 3 +++
2 files changed, 17 insertions(+), 5 deletions(-)

diffs (46 lines):

diff -r 15ec6a09cece -r 709ac03a4bfd njs/njs_regexp.c
--- a/njs/njs_regexp.c Mon Dec 05 17:45:02 2016 +0300
+++ b/njs/njs_regexp.c Mon Dec 05 17:47:00 2016 +0300
@@ -560,15 +560,24 @@ njs_regexp_prototype_to_string(njs_vm_t
u_char *source;
int32_t length;
uint32_t size;
+ njs_value_t *value;
njs_regexp_pattern_t *pattern;

- pattern = args[0].data.u.regexp->pattern;
- source = pattern->source;
+ value = &args[0];

- size = strlen((char *) source);
- length = nxt_utf8_length(source, size);
+ if (value->type == NJS_REGEXP) {
+ pattern = value->data.u.regexp->pattern;
+ source = pattern->source;

- return njs_regexp_string_create(vm, &vm->retval, source, size, length);
+ size = strlen((char *) source);
+ length = nxt_utf8_length(source, size);
+
+ return njs_regexp_string_create(vm, &vm->retval, source, size, length);
+ }
+
+ vm->exception = &njs_exception_type_error;
+
+ return NXT_ERROR;
}


diff -r 15ec6a09cece -r 709ac03a4bfd njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Mon Dec 05 17:45:02 2016 +0300
+++ b/njs/test/njs_unit_test.c Mon Dec 05 17:47:00 2016 +0300
@@ -4410,6 +4410,9 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var r = new RegExp('abc', 'i'); r.test('00ABC11')"),
nxt_string("true") },

+ { nxt_string("[0].map(RegExp().toString)"),
+ nxt_string("TypeError") },
+
/* Non-standard ECMA-262 features. */

/* 0x10400 is not a surrogate pair of 0xD801 and 0xDC00. */
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] RegExp.prototype.toString() should be applied only to RegExp.

Igor Sysoev 597 December 05, 2016 10:20AM



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

Online Users

Guests: 89
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready