[njs] Introduced SpeciesConstructor() from the specification.

Alexander Borisov alexander.borisov at nginx.com
Tue Dec 3 14:14:04 UTC 2019


details:   https://hg.nginx.org/njs/rev/904333a40816
branches:  
changeset: 1275:904333a40816
user:      Alexander Borisov <alexander.borisov at 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"
 


More information about the nginx-devel mailing list