Welcome! Log In Create A New Profile

Advanced

[njs] Introduced SpeciesConstructor() from the specification.

Alexander Borisov
December 03, 2019 09:14AM
details: https://hg.nginx.org/njs/rev/904333a40816
branches:
changeset: 1275:904333a40816
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Tue Dec 03 17:13:34 2019 +0300
description:
Introduced SpeciesConstructor() from the specification.

diffstat:

src/njs_value.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/njs_value.h | 3 +++
2 files changed, 56 insertions(+), 0 deletions(-)

diffs (73 lines):

diff -r da7cff928b80 -r 904333a40816 src/njs_value.c
--- a/src/njs_value.c Tue Dec 03 16:44:03 2019 +0300
+++ b/src/njs_value.c Tue Dec 03 17:13:34 2019 +0300
@@ -1259,3 +1259,56 @@ njs_symbol_conversion_failed(njs_vm_t *v
? "Cannot convert a Symbol value to a string"
: "Cannot convert a Symbol value to a number");
}
+
+
+njs_int_t
+njs_value_species_constructor(njs_vm_t *vm, njs_value_t *object,
+ njs_value_t *default_constructor, njs_value_t *dst)
+{
+ njs_int_t ret;
+ njs_value_t constructor, retval;
+
+ static const njs_value_t string_constructor = njs_string("constructor");
+ static const njs_value_t string_species =
+ njs_wellknown_symbol(NJS_SYMBOL_SPECIES);
+
+ ret = njs_value_property(vm, object, njs_value_arg(&string_constructor),
+ &constructor);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return NJS_ERROR;
+ }
+
+ if (njs_is_undefined(&constructor)) {
+ goto default_сonstructor;
+ }
+
+ if (njs_slow_path(!njs_is_object(&constructor))) {
+ njs_type_error(vm, "constructor is not object");
+ return NJS_ERROR;
+ }
+
+ ret = njs_value_property(vm, &constructor, njs_value_arg(&string_species),
+ &retval);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return NJS_ERROR;
+ }
+
+ if (njs_value_is_null_or_undefined(&retval)) {
+ goto default_сonstructor;
+ }
+
+ if (!njs_is_function(&retval)) {
+ njs_type_error(vm, "object does not contain a constructor");
+ return NJS_ERROR;
+ }
+
+ *dst = retval;
+
+ return NJS_OK;
+
+default_сonstructor:
+
+ *dst = *default_constructor;
+
+ return NJS_OK;
+}
diff -r da7cff928b80 -r 904333a40816 src/njs_value.h
--- a/src/njs_value.h Tue Dec 03 16:44:03 2019 +0300
+++ b/src/njs_value.h Tue Dec 03 17:13:34 2019 +0300
@@ -909,6 +909,9 @@ njs_int_t njs_value_to_object(njs_vm_t *

void njs_symbol_conversion_failed(njs_vm_t *vm, njs_bool_t to_string);

+njs_int_t njs_value_species_constructor(njs_vm_t *vm, njs_value_t *object,
+ njs_value_t *default_constructor, njs_value_t *dst);
+

#include "njs_number.h"

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Introduced SpeciesConstructor() from the specification.

Alexander Borisov 47 December 03, 2019 09:14AM



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

Online Users

Guests: 70
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