]> git.kaiwu.me - njs.git/commitdiff
Using njs_object() macro where applicable.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 8 Jul 2019 14:49:43 +0000 (17:49 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 8 Jul 2019 14:49:43 +0000 (17:49 +0300)
16 files changed:
njs/njs_array.c
njs/njs_boolean.c
njs/njs_builtin.c
njs/njs_crypto.c
njs/njs_error.c
njs/njs_fs.c
njs/njs_function.c
njs/njs_json.c
njs/njs_number.c
njs/njs_object.c
njs/njs_object_property.c
njs/njs_parser_terminal.c
njs/njs_string.c
njs/njs_value.c
njs/njs_value.h
njs/njs_vm.c

index f5dc17b29ac67e831f8021635ba33cc194e9dccb..7edd538ecc1294093189019542b8ca02a7f63cc3 100644 (file)
@@ -443,7 +443,7 @@ njs_array_length(njs_vm_t *vm, njs_value_t *value, njs_value_t *setval,
     njs_array_t  *array;
     njs_object_t *proto;
 
-    proto = value->data.u.object;
+    proto = njs_object(value);
 
     if (setval == NULL) {
         do {
@@ -633,7 +633,7 @@ njs_array_prototype_slice_copy(njs_vm_t *vm, njs_value_t *this,
         } else if (njs_is_string(this) || this->type == NJS_OBJECT_STRING) {
 
             if (this->type == NJS_OBJECT_STRING) {
-                this = &this->data.u.object_value->value;
+                this = njs_object_value(this);
             }
 
             string_slice.start = start;
@@ -967,7 +967,7 @@ njs_array_prototype_to_string(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         lhq.key_hash = NJS_JOIN_HASH;
         lhq.key = nxt_string_value("join");
 
-        prop = njs_object_property(vm, args[0].data.u.object, &lhq);
+        prop = njs_object_property(vm, njs_object(&args[0]), &lhq);
 
         if (nxt_fast_path(prop != NULL && njs_is_function(&prop->value))) {
             return njs_function_replace(vm, prop->value.data.u.function,
@@ -1470,9 +1470,7 @@ njs_array_prototype_fill_continuation(njs_vm_t *vm, njs_value_t *args,
             return NXT_ERROR;
         }
 
-        vm->retval.data.u.object = object;
-        vm->retval.type = object->type;
-        vm->retval.data.truth = 1;
+        njs_set_type_object(&vm->retval, object, object->type);
 
         return NXT_OK;
     }
index 4fbc47fcb89c34d88afc0086cefdf313cb931c34..4c194a5895c1ac8b97c61b8064ad20cfa9e91295 100644 (file)
@@ -27,9 +27,7 @@ njs_boolean_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             return NXT_ERROR;
         }
 
-        vm->retval.data.u.object = object;
-        vm->retval.type = NJS_OBJECT_BOOLEAN;
-        vm->retval.data.truth = 1;
+        njs_set_type_object(&vm->retval, object, NJS_OBJECT_BOOLEAN);
 
     } else {
         vm->retval = *value;
@@ -84,7 +82,7 @@ njs_boolean_prototype_value_of(njs_vm_t *vm, njs_value_t *args,
     if (value->type != NJS_BOOLEAN) {
 
         if (value->type == NJS_OBJECT_BOOLEAN) {
-            value = &value->data.u.object_value->value;
+            value = njs_object_value(value);
 
         } else {
             njs_type_error(vm, "unexpected value type:%s",
@@ -110,7 +108,7 @@ njs_boolean_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
     if (value->type != NJS_BOOLEAN) {
 
         if (value->type == NJS_OBJECT_BOOLEAN) {
-            value = &value->data.u.object_value->value;
+            value = njs_object_value(value);
 
         } else {
             njs_type_error(vm, "unexpected value type:%s",
index 48f5878b6628c431a33b24e4b4811a153c79d9f0..8ab2c3bdf0c46f9576ac6e764cfbf8388facd129 100644 (file)
@@ -854,7 +854,7 @@ njs_vm_expression_completions(njs_vm_t *vm, nxt_str_t *expression)
         value = &prop->value;
     }
 
-    return njs_object_completions(vm, value->data.u.object);
+    return njs_object_completions(vm, njs_object(value));
 }
 
 
index 92825df17b188b8392db271bf4dec011659ddd15..d4ca5f6746a33a5824609724364ea709820a5d5f 100644 (file)
@@ -187,10 +187,7 @@ njs_crypto_create_hash(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     alg->init(&dgst->u);
 
     njs_set_data(&hash->value, dgst);
-
-    vm->retval.data.u.object_value = hash;
-    vm->retval.type = NJS_OBJECT_VALUE;
-    vm->retval.data.truth = 1;
+    njs_set_object_value(&vm->retval, hash);
 
     return NJS_OK;
 }
@@ -200,9 +197,8 @@ static njs_ret_t
 njs_hash_prototype_update(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
-    nxt_str_t           data;
-    njs_digest_t        *dgst;
-    njs_object_value_t  *hash;
+    nxt_str_t     data;
+    njs_digest_t  *dgst;
 
     if (nxt_slow_path(nargs < 2 || !njs_is_string(&args[1]))) {
         njs_type_error(vm, "data must be a string");
@@ -214,16 +210,14 @@ njs_hash_prototype_update(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NJS_ERROR;
     }
 
-    if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) {
+    if (nxt_slow_path(!njs_is_data(njs_object_value(&args[0])))) {
         njs_type_error(vm, "value of \"this\" is not a data type");
         return NJS_ERROR;
     }
 
-    hash = args[0].data.u.object_value;
-
     njs_string_get(&args[1], &data);
 
-    dgst = njs_value_data(&hash->value);
+    dgst = njs_value_data(njs_object_value(&args[0]));
 
     if (nxt_slow_path(dgst->alg == NULL)) {
         njs_error(vm, "Digest already called");
@@ -242,13 +236,12 @@ static njs_ret_t
 njs_hash_prototype_digest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
-    u_char              digest[32], *p;
-    njs_ret_t           ret;
-    nxt_str_t           enc_name, str;
-    njs_digest_t        *dgst;
-    njs_hash_alg_t      *alg;
-    njs_crypto_enc_t    *enc;
-    njs_object_value_t  *hash;
+    u_char            digest[32], *p;
+    njs_ret_t         ret;
+    nxt_str_t         enc_name, str;
+    njs_digest_t      *dgst;
+    njs_hash_alg_t    *alg;
+    njs_crypto_enc_t  *enc;
 
     if (nxt_slow_path(nargs > 1 && !njs_is_string(&args[1]))) {
         njs_type_error(vm, "encoding must be a string");
@@ -260,7 +253,7 @@ njs_hash_prototype_digest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NJS_ERROR;
     }
 
-    if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) {
+    if (nxt_slow_path(!njs_is_data(njs_object_value(&args[0])))) {
         njs_type_error(vm, "value of \"this\" is not a data type");
         return NJS_ERROR;
     }
@@ -276,9 +269,7 @@ njs_hash_prototype_digest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         }
     }
 
-    hash = args[0].data.u.object_value;
-
-    dgst = njs_value_data(&hash->value);
+    dgst = njs_value_data(njs_object_value(&args[0]));
 
     if (nxt_slow_path(dgst->alg == NULL)) {
         njs_error(vm, "Digest already called");
@@ -453,10 +444,7 @@ njs_crypto_create_hmac(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     }
 
     njs_set_data(&hmac->value, ctx);
-
-    vm->retval.data.u.object_value = hmac;
-    vm->retval.type = NJS_OBJECT_VALUE;
-    vm->retval.data.truth = 1;
+    njs_set_object_value(&vm->retval, hmac);
 
     return NJS_OK;
 }
@@ -466,9 +454,8 @@ static njs_ret_t
 njs_hmac_prototype_update(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
-    nxt_str_t           data;
-    njs_hmac_t          *ctx;
-    njs_object_value_t  *hmac;
+    nxt_str_t   data;
+    njs_hmac_t  *ctx;
 
     if (nxt_slow_path(nargs < 2 || !njs_is_string(&args[1]))) {
         njs_type_error(vm, "data must be a string");
@@ -480,16 +467,14 @@ njs_hmac_prototype_update(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NJS_ERROR;
     }
 
-    if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) {
+    if (nxt_slow_path(!njs_is_data(njs_object_value(&args[0])))) {
         njs_type_error(vm, "value of \"this\" is not a data type");
         return NJS_ERROR;
     }
 
-    hmac = args[0].data.u.object_value;
-
     njs_string_get(&args[1], &data);
 
-    ctx = njs_value_data(&hmac->value);
+    ctx = njs_value_data(njs_object_value(&args[0]));
 
     if (nxt_slow_path(ctx->alg == NULL)) {
         njs_error(vm, "Digest already called");
@@ -508,13 +493,12 @@ static njs_ret_t
 njs_hmac_prototype_digest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
-    u_char              hash1[32], digest[32], *p;
-    nxt_str_t           enc_name, str;
-    njs_ret_t           ret;
-    njs_hmac_t          *ctx;
-    njs_hash_alg_t      *alg;
-    njs_crypto_enc_t    *enc;
-    njs_object_value_t  *hmac;
+    u_char            hash1[32], digest[32], *p;
+    nxt_str_t         enc_name, str;
+    njs_ret_t         ret;
+    njs_hmac_t        *ctx;
+    njs_hash_alg_t    *alg;
+    njs_crypto_enc_t  *enc;
 
     if (nxt_slow_path(nargs > 1 && !njs_is_string(&args[1]))) {
         njs_type_error(vm, "encoding must be a string");
@@ -526,7 +510,7 @@ njs_hmac_prototype_digest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NJS_ERROR;
     }
 
-    if (nxt_slow_path(!njs_is_data(&args[0].data.u.object_value->value))) {
+    if (nxt_slow_path(!njs_is_data(njs_object_value(&args[0])))) {
         njs_type_error(vm, "value of \"this\" is not a data type");
         return NJS_ERROR;
     }
@@ -542,9 +526,7 @@ njs_hmac_prototype_digest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         }
     }
 
-    hmac = args[0].data.u.object_value;
-
-    ctx = njs_value_data(&hmac->value);
+    ctx = njs_value_data(njs_object_value(&args[0]));
 
     if (nxt_slow_path(ctx->alg == NULL)) {
         njs_error(vm, "Digest already called");
index 228d542ef112ec330589c5e66848066e6260914f..b5f897730465067a73197eb3660a6d9e47f45454 100644 (file)
@@ -29,9 +29,7 @@ njs_error_new(njs_vm_t *vm, njs_value_t *dst, njs_value_type_t type,
     error = njs_error_alloc(vm, type, NULL, &string);
 
     if (nxt_fast_path(error != NULL)) {
-        dst->data.u.object = error;
-        dst->type = type;
-        dst->data.truth = 1;
+        njs_set_type_object(dst, error, type);
     }
 }
 
@@ -148,9 +146,7 @@ njs_error_create(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NXT_ERROR;
     }
 
-    vm->retval.data.u.object = error;
-    vm->retval.type = type;
-    vm->retval.data.truth = 1;
+    njs_set_type_object(&vm->retval, error, type);
 
     return NXT_OK;
 }
@@ -513,9 +509,7 @@ njs_memory_error_set(njs_vm_t *vm, njs_value_t *value)
      */
     object->extensible = 0;
 
-    value->data.type = NJS_OBJECT_INTERNAL_ERROR;
-    value->data.truth = 1;
-    value->data.u.object = object;
+    njs_set_type_object(value, object, NJS_OBJECT_INTERNAL_ERROR);
 }
 
 
@@ -634,7 +628,7 @@ njs_error_to_string(njs_vm_t *vm, njs_value_t *retval, const njs_value_t *error)
     lhq.key = nxt_string_value("name");
     lhq.proto = &njs_object_hash_proto;
 
-    prop = njs_object_property(vm, error->data.u.object, &lhq);
+    prop = njs_object_property(vm, njs_object(error), &lhq);
 
     if (prop != NULL) {
         name_value = &prop->value;
@@ -648,7 +642,7 @@ njs_error_to_string(njs_vm_t *vm, njs_value_t *retval, const njs_value_t *error)
     lhq.key_hash = NJS_MESSAGE_HASH;
     lhq.key = nxt_string_value("message");
 
-    prop = njs_object_property(vm, error->data.u.object, &lhq);
+    prop = njs_object_property(vm, njs_object(error), &lhq);
 
     if (prop != NULL) {
         message_value = &prop->value;
@@ -773,7 +767,7 @@ njs_internal_error_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
     if (nargs >= 1 && njs_is_object(&args[0])) {
 
         /* MemoryError is a nonextensible internal error. */
-        if (!args[0].data.u.object->extensible) {
+        if (!njs_object(&args[0])->extensible) {
             static const njs_value_t name = njs_string("MemoryError");
 
             vm->retval = name;
index 983aad0686945e8cf8f2dce6eb0ae06f7be39c3d..e2bdd6fed92f91ddb56e14fdf53d851f8a611019 100644 (file)
@@ -979,9 +979,7 @@ static njs_ret_t njs_fs_error(njs_vm_t *vm, const char *syscall,
         }
     }
 
-    retval->data.u.object = error;
-    retval->type = NJS_OBJECT_ERROR;
-    retval->data.truth = 1;
+    njs_set_type_object(retval, error, NJS_OBJECT_ERROR);
 
     return NJS_OK;
 }
@@ -1007,14 +1005,14 @@ njs_fs_mode(njs_value_t *value)
 {
     switch (value->type) {
     case NJS_OBJECT_NUMBER:
-        value = &value->data.u.object_value->value;
+        value = njs_object_value(value);
         /* Fall through. */
 
     case NJS_NUMBER:
         return (mode_t) njs_number(value);
 
     case NJS_OBJECT_STRING:
-    value = &value->data.u.object_value->value;
+    value = njs_object_value(value);
         /* Fall through. */
 
     case NJS_STRING:
index 213f2243b2382855472a113c6b739cba6d36b323..6f3c7751847f4c73a4a3f8f6f06682e853b1b967 100644 (file)
@@ -910,7 +910,7 @@ njs_function_instance_length(njs_vm_t *vm, njs_value_t *value,
     njs_function_t         *function;
     njs_function_lambda_t  *lambda;
 
-    proto = value->data.u.object;
+    proto = njs_object(value);
 
     do {
         if (nxt_fast_path(proto->type == NJS_FUNCTION)) {
index 2cbe7825a877e5e49f547cc2ca66991e75bce438..2ea449b576f3a7856ee953416a904a319d98f60e 100644 (file)
@@ -1487,7 +1487,7 @@ njs_object_to_json_function(njs_vm_t *vm, njs_value_t *value)
     lhq.key_hash = NJS_TO_JSON_HASH;
     lhq.key = nxt_string_value("toJSON");
 
-    prop = njs_object_property(vm, value->data.u.object, &lhq);
+    prop = njs_object_property(vm, njs_object(value), &lhq);
 
     if (prop != NULL && njs_is_function(&prop->value)) {
         return prop->value.data.u.function;
@@ -1622,7 +1622,7 @@ njs_json_stringify_array(njs_vm_t *vm, njs_json_stringify_t  *stringify)
 
         switch (value->type) {
         case NJS_OBJECT_NUMBER:
-            value = &value->data.u.object_value->value;
+            value = njs_object_value(value);
             /* Fall through. */
 
         case NJS_NUMBER:
@@ -1635,7 +1635,7 @@ njs_json_stringify_array(njs_vm_t *vm, njs_json_stringify_t  *stringify)
             break;
 
         case NJS_OBJECT_STRING:
-            value = &value->data.u.object_value->value;
+            value = njs_object_value(value);
             break;
 
         case NJS_STRING:
@@ -1736,21 +1736,21 @@ njs_json_append_value(njs_json_stringify_t *stringify, const njs_value_t *value)
 {
     switch (value->type) {
     case NJS_OBJECT_STRING:
-        value = &value->data.u.object_value->value;
+        value = njs_object_value(value);
         /* Fall through. */
 
     case NJS_STRING:
         return njs_json_append_string(stringify, value, '\"');
 
     case NJS_OBJECT_NUMBER:
-        value = &value->data.u.object_value->value;
+        value = njs_object_value(value);
         /* Fall through. */
 
     case NJS_NUMBER:
         return njs_json_append_number(stringify, value);
 
     case NJS_OBJECT_BOOLEAN:
-        value = &value->data.u.object_value->value;
+        value = njs_object_value(value);
         /* Fall through. */
 
     case NJS_BOOLEAN:
@@ -1924,7 +1924,7 @@ njs_json_wrap_value(njs_vm_t *vm, const njs_value_t *value)
     }
 
     wrapper->data.u.object = njs_object_alloc(vm);
-    if (nxt_slow_path(wrapper->data.u.object == NULL)) {
+    if (nxt_slow_path(njs_object(wrapper) == NULL)) {
         return NULL;
     }
 
@@ -2134,7 +2134,7 @@ njs_dump_value(njs_json_stringify_t *stringify, const njs_value_t *value,
 
     switch (value->type) {
     case NJS_OBJECT_STRING:
-        value = &value->data.u.object_value->value;
+        value = njs_object_value(value);
 
         njs_string_get(value, &str);
 
@@ -2155,7 +2155,7 @@ njs_dump_value(njs_json_stringify_t *stringify, const njs_value_t *value,
         break;
 
     case NJS_OBJECT_NUMBER:
-        value = &value->data.u.object_value->value;
+        value = njs_object_value(value);
 
         if (nxt_slow_path(njs_number(value) == 0.0
                           && signbit(njs_number(value))))
@@ -2178,7 +2178,7 @@ njs_dump_value(njs_json_stringify_t *stringify, const njs_value_t *value,
         break;
 
     case NJS_OBJECT_BOOLEAN:
-        value = &value->data.u.object_value->value;
+        value = njs_object_value(value);
 
         if (njs_is_true(value)) {
             njs_dump("[Boolean: true]");
@@ -2457,7 +2457,7 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_t *retval, const njs_value_t *value,
                 val = &ext_val;
 
             } else {
-                object = state->value.data.u.object;
+                object = njs_object(&state->value);
                 lhq.proto = &njs_object_hash_proto;
 
                 ret = nxt_lvlhsh_find(&object->hash, &lhq);
index d3f2abc5981fde32ffd30a9dac92c6746a32079b..2d298519bc386e7db6a4c4e64448691f26f284ec 100644 (file)
@@ -258,9 +258,7 @@ njs_number_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             return NXT_ERROR;
         }
 
-        vm->retval.data.u.object = object;
-        vm->retval.type = NJS_OBJECT_NUMBER;
-        vm->retval.data.truth = 1;
+        njs_set_type_object(&vm->retval, object, NJS_OBJECT_NUMBER);
 
     } else {
         njs_set_number(&vm->retval, njs_number(value));
@@ -490,7 +488,7 @@ njs_number_prototype_value_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     if (value->type != NJS_NUMBER) {
 
         if (value->type == NJS_OBJECT_NUMBER) {
-            value = &value->data.u.object_value->value;
+            value = njs_object_value(value);
 
         } else {
             njs_type_error(vm, "unexpected value type:%s",
@@ -517,7 +515,7 @@ njs_number_prototype_to_string(njs_vm_t *vm, njs_value_t *args,
     if (value->type != NJS_NUMBER) {
 
         if (value->type == NJS_OBJECT_NUMBER) {
-            value = &value->data.u.object_value->value;
+            value = njs_object_value(value);
 
         } else {
             njs_type_error(vm, "unexpected value type:%s",
index a5fd7f489dfca0caada30c27deb9538854660425..eafc52cfb42568cee85e1d42fabb74c72a87cf8d 100644 (file)
@@ -57,7 +57,7 @@ njs_object_value_copy(njs_vm_t *vm, njs_value_t *value)
 {
     njs_object_t  *object;
 
-    object = value->data.u.object;
+    object = njs_object(value);
 
     if (!object->shared) {
         return object;
@@ -66,7 +66,7 @@ njs_object_value_copy(njs_vm_t *vm, njs_value_t *value)
     object = nxt_mp_alloc(vm->mem_pool, sizeof(njs_object_t));
 
     if (nxt_fast_path(object != NULL)) {
-        *object = *value->data.u.object;
+        *object = *njs_object(value);
         object->__proto__ = &vm->prototypes[NJS_PROTOTYPE_OBJECT].object;
         object->shared = 0;
         value->data.u.object = object;
@@ -212,7 +212,7 @@ njs_object_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     } else {
 
         if (njs_is_object(value)) {
-            object = value->data.u.object;
+            object = njs_object(value);
 
         } else if (njs_is_primitive(value)) {
 
@@ -232,9 +232,7 @@ njs_object_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         }
     }
 
-    vm->retval.data.u.object = object;
-    vm->retval.type = type;
-    vm->retval.data.truth = 1;
+    njs_set_type_object(&vm->retval, object, type);
 
     return NXT_OK;
 }
@@ -260,7 +258,7 @@ njs_object_create(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
         if (!njs_is_null(value)) {
             /* GC */
-            object->__proto__ = value->data.u.object;
+            object->__proto__ = njs_object(value);
 
         } else {
             object->__proto__ = NULL;
@@ -1105,7 +1103,7 @@ njs_object_define_property(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     value = njs_argument(args, 1);
 
-    if (!value->data.u.object->extensible) {
+    if (!njs_object(value)->extensible) {
         njs_type_error(vm, "object is not extensible");
         return NXT_ERROR;
     }
@@ -1149,7 +1147,7 @@ njs_object_define_properties(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     value = njs_argument(args, 1);
 
-    if (!value->data.u.object->extensible) {
+    if (!njs_object(value)->extensible) {
         njs_type_error(vm, "object is not extensible");
         return NXT_ERROR;
     }
@@ -1339,7 +1337,7 @@ njs_object_freeze(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NXT_OK;
     }
 
-    object = value->data.u.object;
+    object = njs_object(value);
     object->extensible = 0;
 
     nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto);
@@ -1382,7 +1380,7 @@ njs_object_is_frozen(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     retval = &njs_value_false;
 
-    object = value->data.u.object;
+    object = njs_object(value);
     nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto);
 
     hash = &object->hash;
@@ -1434,7 +1432,7 @@ njs_object_seal(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NXT_OK;
     }
 
-    object = value->data.u.object;
+    object = njs_object(value);
     object->extensible = 0;
 
     nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto);
@@ -1476,7 +1474,7 @@ njs_object_is_sealed(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     retval = &njs_value_false;
 
-    object = value->data.u.object;
+    object = njs_object(value);
     nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto);
 
     hash = &object->hash;
@@ -1520,7 +1518,7 @@ njs_object_prevent_extensions(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NXT_OK;
     }
 
-    args[1].data.u.object->extensible = 0;
+    njs_object(&args[1])->extensible = 0;
 
     vm->retval = *value;
 
@@ -1541,8 +1539,8 @@ njs_object_is_extensible(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NXT_OK;
     }
 
-    retval = value->data.u.object->extensible ? &njs_value_true
-                                              : &njs_value_false;
+    retval = njs_object(value)->extensible ? &njs_value_true
+                                           : &njs_value_false;
 
     vm->retval = *retval;
 
@@ -1568,16 +1566,14 @@ njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value,
      * and have to return different results for primitive type and for objects.
      */
     if (njs_is_object(value)) {
-        proto = value->data.u.object->__proto__;
+        proto = njs_object(value)->__proto__;
 
     } else {
         index = njs_primitive_prototype_index(value->type);
         proto = &vm->prototypes[index].object;
     }
 
-    retval->data.u.object = proto;
-    retval->type = proto->type;
-    retval->data.truth = 1;
+    njs_set_type_object(retval, proto, proto->type);
 
     return NXT_OK;
 }
@@ -1633,9 +1629,7 @@ njs_property_prototype_create(njs_vm_t *vm, nxt_lvlhsh_t *hash,
 
     /* GC */
 
-    prop->value.data.u.object = prototype;
-    prop->value.type = prototype->type;
-    prop->value.data.truth = 1;
+    njs_set_type_object(&prop->value, prototype, prototype->type);
 
     lhq.value = prop;
     lhq.key_hash = NJS_PROTOTYPE_HASH;
@@ -1861,7 +1855,7 @@ njs_object_set_prototype_of(njs_vm_t *vm, njs_object_t *object,
 {
     const njs_object_t *proto;
 
-    proto = njs_is_object(value) ? value->data.u.object->__proto__
+    proto = njs_is_object(value) ? njs_object(value)->__proto__
                                  : NULL;
 
     if (nxt_slow_path(object->__proto__ == proto)) {
@@ -1882,7 +1876,7 @@ njs_object_set_prototype_of(njs_vm_t *vm, njs_object_t *object,
 
     } while (proto != NULL);
 
-    object->__proto__ = value->data.u.object;
+    object->__proto__ = njs_object(value);
 
     return 1;
 }
@@ -1900,7 +1894,7 @@ njs_object_prototype_proto(njs_vm_t *vm, njs_value_t *value,
         return NJS_OK;
     }
 
-    object = value->data.u.object;
+    object = njs_object(value);
 
     if (setval != NULL) {
         if (njs_is_object(setval) || njs_is_null(setval)) {
@@ -1919,9 +1913,7 @@ njs_object_prototype_proto(njs_vm_t *vm, njs_value_t *value,
     proto = object->__proto__;
 
     if (nxt_fast_path(proto != NULL)) {
-        retval->data.u.object = proto;
-        retval->type = proto->type;
-        retval->data.truth = 1;
+        njs_set_type_object(retval, proto, proto->type);
 
     } else {
         *retval = njs_value_null;
@@ -1947,7 +1939,7 @@ njs_object_prototype_create_constructor(njs_vm_t *vm, njs_value_t *value,
     njs_object_prototype_t  *prototype;
 
     if (njs_is_object(value)) {
-        object = value->data.u.object;
+        object = njs_object(value);
 
         do {
             prototype = (njs_object_prototype_t *) object;
@@ -2217,8 +2209,8 @@ njs_object_prototype_is_prototype_of(njs_vm_t *vm, njs_value_t *args,
     value = njs_arg(args, nargs, 1);
 
     if (njs_is_object(prototype) && njs_is_object(value)) {
-        proto = prototype->data.u.object;
-        object = value->data.u.object;
+        proto = njs_object(prototype);
+        object = njs_object(value);
 
         do {
             object = object->__proto__;
index 1fd1b16b2abdd8f56abb347bebf1ddcce87fd74c..79f009ae80b30e9600932127862aceb1c96c3bcb 100644 (file)
@@ -97,7 +97,7 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
     case NJS_OBJECT_TYPE_ERROR:
     case NJS_OBJECT_URI_ERROR:
     case NJS_OBJECT_VALUE:
-        obj = object->data.u.object;
+        obj = njs_object(object);
         break;
 
     case NJS_FUNCTION:
@@ -678,7 +678,7 @@ njs_value_property_set(njs_vm_t *vm, njs_value_t *object,
         return ret;
     }
 
-    if (nxt_slow_path(!object->data.u.object->extensible)) {
+    if (nxt_slow_path(!njs_object(object)->extensible)) {
         njs_type_error(vm, "Cannot add property \"%V\", "
                        "object is not extensible", &pq.lhq.key);
         return NXT_ERROR;
@@ -799,7 +799,7 @@ njs_object_prop_define(njs_vm_t *vm, njs_value_t *object,
         return ret;
     }
 
-    prop = njs_descriptor_prop(vm, name, value->data.u.object);
+    prop = njs_descriptor_prop(vm, name, njs_object(value));
     if (nxt_slow_path(prop == NULL)) {
         return NXT_ERROR;
     }
index b1c89443ac5b53d7baee54cf442f88fc490a3e54..6d9a47d4da670858c9978856494db51b35e123ea 100644 (file)
@@ -447,7 +447,7 @@ njs_parser_builtin(njs_vm_t *vm, njs_parser_t *parser, njs_parser_node_t *node,
     switch (type) {
     case NJS_OBJECT:
         index = node->token - NJS_TOKEN_FIRST_OBJECT;
-        var->value.data.u.object = &vm->shared->objects[index];
+        njs_set_object(&var->value, &vm->shared->objects[index]);
         break;
 
     case NJS_FUNCTION:
index 120f58389bf205288903606114359bd077006407..2ce4c5860bf0d2d5226351b4a2f9ce2617d9ec7b 100644 (file)
@@ -562,9 +562,7 @@ njs_string_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             return NXT_ERROR;
         }
 
-        vm->retval.data.u.object = object;
-        vm->retval.type = NJS_OBJECT_STRING;
-        vm->retval.data.truth = 1;
+        njs_set_type_object(&vm->retval, object, NJS_OBJECT_STRING);
 
     } else {
         vm->retval = *value;
@@ -652,7 +650,7 @@ njs_string_instance_length(njs_vm_t *vm, njs_value_t *value,
     length = 0;
 
     if (nxt_slow_path(njs_is_object(value))) {
-        proto = value->data.u.object;
+        proto = njs_object(value);
 
         do {
             if (nxt_fast_path(proto->type == NJS_OBJECT_STRING)) {
@@ -769,7 +767,7 @@ njs_string_prototype_value_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     if (value->type != NJS_STRING) {
 
         if (value->type == NJS_OBJECT_STRING) {
-            value = &value->data.u.object_value->value;
+            value = njs_object_value(value);
 
         } else {
             njs_type_error(vm, "unexpected value type:%s",
index 5e7d77b3df2afb1db1e22ff4f603668b85abb254..fb3e10c879e693234f0e51343c1685b206df5cfd 100644 (file)
@@ -158,7 +158,7 @@ njs_values_strict_equal(const njs_value_t *val1, const njs_value_t *val2)
         return (memcmp(start1, start2, size) == 0);
     }
 
-    return (val1->data.u.object == val2->data.u.object);
+    return (njs_object(val1) == njs_object(val2));
 }
 
 
@@ -201,7 +201,7 @@ njs_value_to_primitive(njs_vm_t *vm, njs_value_t *value, nxt_uint_t hint)
                     lhq.key_hash = hashes[hint];
                     lhq.key = names[hint];
 
-                    prop = njs_object_property(vm, value->data.u.object, &lhq);
+                    prop = njs_object_property(vm, njs_object(value), &lhq);
 
                     if (nxt_fast_path(prop != NULL)) {
 
@@ -267,7 +267,7 @@ njs_value_enumerate(njs_vm_t *vm, const njs_value_t *value,
     njs_object_value_t  obj_val;
 
     if (njs_is_object(value)) {
-        return njs_object_enumerate(vm, value->data.u.object, kind, all);
+        return njs_object_enumerate(vm, njs_object(value), kind, all);
     }
 
     if (value->type != NJS_STRING) {
@@ -288,7 +288,7 @@ njs_value_own_enumerate(njs_vm_t *vm, const njs_value_t *value,
     njs_object_value_t  obj_val;
 
     if (njs_is_object(value)) {
-        return njs_object_own_enumerate(vm, value->data.u.object, kind, all);
+        return njs_object_own_enumerate(vm, njs_object(value), kind, all);
     }
 
     if (value->type != NJS_STRING) {
index 0ac4e5745d1f4c60b314fa67e16aadafee60f20e..564d2d9fa44263290a39b52a3f32a70c5e6f8006 100644 (file)
@@ -540,6 +540,10 @@ typedef enum {
     ((value)->data.u.date)
 
 
+#define njs_object_value(_value)                                              \
+    (&(_value)->data.u.object_value->value)
+
+
 #define njs_set_undefined(value)                                              \
     *(value) = njs_value_undefined
 
@@ -583,6 +587,16 @@ njs_set_object(njs_value_t *value, njs_object_t *object)
 }
 
 
+nxt_inline void
+njs_set_type_object(njs_value_t *value, njs_object_t *object,
+    nxt_uint_t type)
+{
+    value->data.u.object = object;
+    value->type = type;
+    value->data.truth = 1;
+}
+
+
 nxt_inline void
 njs_set_array(njs_value_t *value, njs_array_t *array)
 {
@@ -601,6 +615,15 @@ njs_set_date(njs_value_t *value, njs_date_t *date)
 }
 
 
+nxt_inline void
+njs_set_object_value(njs_value_t *value, njs_object_value_t *object_value)
+{
+    value->data.u.object_value = object_value;
+    value->type = NJS_OBJECT_VALUE;
+    value->data.truth = 1;
+}
+
+
 #define njs_set_invalid(value)                                                \
     (value)->type = NJS_INVALID
 
index 19297a9863e1631173544c221b63d328d743ebcd..8a37229012fda8689de7deb3fb42dd297f6faf01 100644 (file)
@@ -523,7 +523,7 @@ njs_vmcode_property_init(njs_vm_t *vm, njs_value_t *object,
         lhq.proto = &njs_object_hash_proto;
         lhq.pool = vm->mem_pool;
 
-        obj = object->data.u.object;
+        obj = njs_object(object);
 
         ret = nxt_lvlhsh_find(&obj->__proto__->shared_hash, &lhq);
         if (ret == NXT_OK) {
@@ -865,8 +865,8 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs_value_t *object,
                 return NXT_ERROR;
             }
 
-            prototype = value.data.u.object;
-            proto = object->data.u.object;
+            prototype = njs_object(&value);
+            proto = njs_object(object);
 
             do {
                 proto = proto->__proto__;
@@ -1494,7 +1494,7 @@ njs_values_equal(njs_vm_t *vm, const njs_value_t *val1, const njs_value_t *val2)
             return njs_string_eq(val1, val2);
         }
 
-        return (val1->data.u.object == val2->data.u.object);
+        return (njs_object(val1) == njs_object(val2));
     }
 
     /* Sort values as: numeric < string < objects. */
@@ -1805,7 +1805,7 @@ njs_function_new_object(njs_vm_t *vm, njs_value_t *value)
         }
 
         if (nxt_fast_path(proto != NULL)) {
-            object->__proto__ = proto->data.u.object;
+            object->__proto__ = njs_object(proto);
             return object;
         }
    }
@@ -2685,7 +2685,7 @@ njs_vm_value_to_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src)
 
     if (nxt_slow_path(src->type == NJS_OBJECT_INTERNAL_ERROR)) {
         /* MemoryError is a nonextensible internal error. */
-        if (!src->data.u.object->extensible) {
+        if (!njs_object(src)->extensible) {
             njs_string_get(&njs_string_memory_error, dst);
             return NXT_OK;
         }