]> git.kaiwu.me - njs.git/commitdiff
Riddance of NJS_NATIVE type.
authorIgor Sysoev <igor@sysoev.ru>
Fri, 11 Dec 2015 15:41:10 +0000 (18:41 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 11 Dec 2015 15:41:10 +0000 (18:41 +0300)
njs/njs_array.c
njs/njs_boolean.c
njs/njs_function.c
njs/njs_number.c
njs/njs_object.c
njs/njs_regexp.c
njs/njs_string.c
njs/njs_vm.c
njs/njs_vm.h

index 51fd43579f436b7410c59a688843c49e7293757e..788907c18cff89bc66160ee1df2a6ca7d76857d8 100644 (file)
@@ -231,7 +231,7 @@ static const njs_object_prop_t  njs_array_constructor_properties[] =
       NJS_PROPERTY, 0, 0, 0, },
 
     /* Array.prototype. */
-    { njs_getter(njs_object_prototype_create),
+    { njs_native_getter(njs_object_prototype_create),
       njs_string("prototype"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 };
@@ -470,10 +470,7 @@ njs_array_prototype_to_string(njs_vm_t *vm, njs_param_t *param)
 
     prop = njs_object_property(vm, object, &lhq);
 
-    if (nxt_fast_path(prop != NULL
-                      && (njs_is_function(&prop->value)
-                          || njs_is_native(&prop->value))))
-    {
+    if (nxt_fast_path(prop != NULL && njs_is_function(&prop->value))) {
         return njs_function_apply(vm, &prop->value, param);
     }
 
@@ -889,7 +886,7 @@ njs_array_next(njs_value_t *value, nxt_uint_t n, nxt_uint_t length)
 
 static const njs_object_prop_t  njs_array_prototype_properties[] =
 {
-    { njs_getter(njs_array_prototype_length),
+    { njs_native_getter(njs_array_prototype_length),
       njs_string("length"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
index 05c0e64980d7fd4f2b6051598c10edb39a9ebb47..56793251c94fd33c0445575f3509147e72e898e5 100644 (file)
@@ -62,7 +62,7 @@ static const njs_object_prop_t  njs_boolean_constructor_properties[] =
       NJS_PROPERTY, 0, 0, 0, },
 
     /* Boolean.prototype. */
-    { njs_getter(njs_object_prototype_create),
+    { njs_native_getter(njs_object_prototype_create),
       njs_string("prototype"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 };
@@ -124,7 +124,7 @@ njs_boolean_prototype_to_string(njs_vm_t *vm, njs_param_t *param)
 
 static const njs_object_prop_t  njs_boolean_prototype_properties[] =
 {
-    { njs_getter(njs_primitive_prototype_get_proto),
+    { njs_native_getter(njs_primitive_prototype_get_proto),
       njs_string("__proto__"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
index bca792cb5c6bee2f9bf00b29242f3fce740cb27e..b452aac5e9f332ac6401549cbcb5fc45f88e7bc4 100644 (file)
@@ -120,17 +120,14 @@ njs_function_constructor(njs_vm_t *vm, njs_param_t *param)
 
 
 nxt_noinline njs_ret_t
-njs_function_apply(njs_vm_t *vm, njs_value_t *name, njs_param_t *param)
+njs_function_apply(njs_vm_t *vm, njs_value_t *value, njs_param_t *param)
 {
     njs_ret_t       ret;
     njs_function_t  *function;
 
-    if (njs_is_native(name)) {
-        return name->data.u.method(vm, param);
+    if (njs_is_function(value)) {
 
-    } else if (njs_is_function(name)) {
-
-        function = name->data.u.function;
+        function = value->data.u.function;
 
         if (function->native) {
             return function->u.native(vm, param);
@@ -249,7 +246,7 @@ static const njs_object_prop_t  njs_function_constructor_properties[] =
       NJS_PROPERTY, 0, 0, 0, },
 
     /* Function.prototype. */
-    { njs_getter(njs_object_prototype_create),
+    { njs_native_getter(njs_object_prototype_create),
       njs_string("prototype"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 };
@@ -267,30 +264,16 @@ njs_function_prototype_call(njs_vm_t *vm, njs_param_t *param)
     uintptr_t                   nargs;
     njs_ret_t                   ret;
     njs_param_t                 p;
-    njs_value_t                 *func;
+    njs_value_t                 *value;
     njs_function_t              *function;
     njs_vmcode_function_call_t  *call;
 
     p.object = &param->args[0];
     p.args = &param->args[1];
 
-    func = param->object;
     nargs = param->nargs;
-
-    if (njs_is_native(func)) {
-
-        if (nargs != 0) {
-            p.nargs = nargs - 1;
-            p.retval = param->retval;
-
-            return func->data.u.method(vm, &p);
-        }
-
-        vm->exception = &njs_exception_type_error;
-        return NXT_ERROR;
-    }
-
-    function = func->data.u.function;
+    value = param->object;
+    function = value->data.u.function;
 
     if (function->native) {
 
@@ -336,7 +319,7 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_param_t *param)
     njs_ret_t                   ret;
     njs_param_t                 p;
     njs_array_t                 *array;
-    njs_value_t                 *func, *args;
+    njs_value_t                 *value, *args;
     njs_function_t              *function;
     njs_vmcode_function_call_t  *code;
 
@@ -356,25 +339,8 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_param_t *param)
         p.nargs = array->length;
     }
 
-    func = param->object;
-
-    if (njs_is_native(func)) {
-        p.retval = param->retval;
-
-        if (nargs < 2) {
-            if (nargs != 0) {
-                p.args = &args[1];
-                p.nargs = nargs - 1;
-
-            } else {
-                goto type_error;
-            }
-        }
-
-        return func->data.u.method(vm, &p);
-    }
-
-    function = func->data.u.function;
+    value = param->object;
+    function = value->data.u.function;
 
     if (function->native) {
         p.retval = param->retval;
@@ -425,7 +391,6 @@ type_error:
 static njs_ret_t
 njs_function_prototype_bind(njs_vm_t *vm, njs_param_t *param)
 {
-    njs_value_t     *func;
     njs_function_t  *bound;
 
     bound = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_function_t));
@@ -435,9 +400,7 @@ njs_function_prototype_bind(njs_vm_t *vm, njs_param_t *param)
         nxt_lvlhsh_init(&bound->object.shared_hash);
         bound->object.__proto__ = &vm->prototypes[NJS_PROTOTYPE_FUNCTION];
         bound->args_offset = 1;
-
-        func = param->object;
-        bound->u.lambda = func->data.u.function->u.lambda;
+        bound->u.lambda = param->object->data.u.function->u.lambda;
 
         vm->retval.data.u.function = bound;
         vm->retval.type = NJS_FUNCTION;
index a8687a0308316ff288ac40893233b8957844c69d..89cefc0390982572fdfa84f8cb62360ac95b3072 100644 (file)
@@ -257,7 +257,7 @@ static const njs_object_prop_t  njs_number_constructor_properties[] =
       NJS_PROPERTY, 0, 0, 0, },
 
     /* Number.prototype. */
-    { njs_getter(njs_object_prototype_create),
+    { njs_native_getter(njs_object_prototype_create),
       njs_string("prototype"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 };
@@ -317,7 +317,7 @@ njs_number_prototype_to_string(njs_vm_t *vm, njs_param_t *param)
 
 static const njs_object_prop_t  njs_number_prototype_properties[] =
 {
-    { njs_getter(njs_primitive_prototype_get_proto),
+    { njs_native_getter(njs_primitive_prototype_get_proto),
       njs_string("__proto__"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
index 9f01f4c4903fe5bc09cb4e43898ab7b36e0c47fe..a0e37795df1588f75e866883a1976d7095945103 100644 (file)
@@ -399,7 +399,7 @@ static const njs_object_prop_t  njs_object_constructor_properties[] =
       NJS_PROPERTY, 0, 0, 0, },
 
     /* Object.prototype. */
-    { njs_getter(njs_object_prototype_create),
+    { njs_native_getter(njs_object_prototype_create),
       njs_string("prototype"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
@@ -552,7 +552,7 @@ njs_object_prototype_to_string(njs_vm_t *vm, njs_param_t *param)
         &njs_object_number_string,
         &njs_object_string_string,
 
-        &njs_object_function_string,
+        &njs_string_empty,
         &njs_object_function_string,
         &njs_string_empty,
 
@@ -599,11 +599,11 @@ found:
 
 static const njs_object_prop_t  njs_object_prototype_properties[] =
 {
-    { njs_getter(njs_object_prototype_get_proto),
+    { njs_native_getter(njs_object_prototype_get_proto),
       njs_string("__proto__"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
-    { njs_getter(njs_object_prototype_create_constructor),
+    { njs_native_getter(njs_object_prototype_create_constructor),
       njs_string("constructor"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
index c9c3f403d418317f27dcdb2ac5aca3b615415263..2415bfc667f86cb2f7ba1195e416bac6980b5f83 100644 (file)
@@ -676,7 +676,7 @@ static const njs_object_prop_t  njs_regexp_constructor_properties[] =
       NJS_PROPERTY, 0, 0, 0, },
 
     /* RegExp.prototype. */
-    { njs_getter(njs_object_prototype_create),
+    { njs_native_getter(njs_object_prototype_create),
       njs_string("prototype"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 };
@@ -690,23 +690,23 @@ const njs_object_init_t  njs_regexp_constructor_init = {
 
 static const njs_object_prop_t  njs_regexp_prototype_properties[] =
 {
-    { njs_getter(njs_regexp_prototype_last_index),
+    { njs_native_getter(njs_regexp_prototype_last_index),
       njs_string("lastIndex"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
-    { njs_getter(njs_regexp_prototype_global),
+    { njs_native_getter(njs_regexp_prototype_global),
       njs_string("global"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
-    { njs_getter(njs_regexp_prototype_ignore_case),
+    { njs_native_getter(njs_regexp_prototype_ignore_case),
       njs_string("ignoreCase"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
-    { njs_getter(njs_regexp_prototype_multiline),
+    { njs_native_getter(njs_regexp_prototype_multiline),
       njs_string("multiline"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
-    { njs_getter(njs_regexp_prototype_source),
+    { njs_native_getter(njs_regexp_prototype_source),
       njs_string("source"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
index bdc45b721c99f49891a617d2b5eaa4dbd8b08746..5416b9c552f31984d5029a1a9e565aef3f067f71 100644 (file)
@@ -295,7 +295,7 @@ static const njs_object_prop_t  njs_string_constructor_properties[] =
       NJS_PROPERTY, 0, 0, 0, },
 
     /* String.prototype. */
-    { njs_getter(njs_object_prototype_create),
+    { njs_native_getter(njs_object_prototype_create),
       njs_string("prototype"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 };
@@ -1478,7 +1478,6 @@ njs_value_to_string(njs_vm_t *vm, njs_value_t *dst, const njs_value_t *src)
          *      regex:    full regexp text like "/regexp/gim".
          */
 
-    case NJS_NATIVE:
     case NJS_EXTERNAL:
         value = &njs_string_native;
         break;
@@ -1597,11 +1596,11 @@ njs_string_to_number(njs_value_t *value)
 
 static const njs_object_prop_t  njs_string_prototype_properties[] =
 {
-    { njs_getter(njs_primitive_prototype_get_proto),
+    { njs_native_getter(njs_primitive_prototype_get_proto),
       njs_string("__proto__"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
-    { njs_getter(njs_string_prototype_length),
+    { njs_native_getter(njs_string_prototype_length),
       njs_string("length"),
       NJS_NATIVE_GETTER, 0, 0, 0, },
 
index 3b30a0318bf8e087223744d4f41ceadfc737bd63..9c48f5a7803f829eef6e71f423ca75d3a8d440ca 100644 (file)
@@ -904,10 +904,6 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
         obj = object->data.u.object;
         break;
 
-    case NJS_NATIVE:
-        obj = &vm->prototypes[NJS_PROTOTYPE_FUNCTION];
-        break;
-
     case NJS_EXTERNAL:
         ext = object->data.u.external;
 
@@ -1206,7 +1202,7 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs_value_t *object,
     const njs_value_t   *retval;
     nxt_lvlhsh_query_t  lhq;
 
-    if (!njs_is_function(constructor) && !njs_is_native(constructor)) {
+    if (!njs_is_function(constructor)) {
         vm->exception = &njs_exception_type_error;
         return NXT_ERROR;
     }
index 3ba172106924e74bb7cbb1a4d0b7fac4c9d07748..14aa9f79f099d38a7979281f630d308dfc46b0b4 100644 (file)
@@ -42,16 +42,16 @@ typedef enum {
 
     /* The order of the above type is used in njs_is_primitive(). */
 
-    /* The type is native code. */
-    NJS_NATIVE          = 0x05,
+    /* Reserved           0x05, */
 
     /* The type is external code. */
     NJS_EXTERNAL        = 0x06,
 
     /*
-     * A special value type for uninitialized array members.
-     * It is also used to detect variable non-declared explicitly
-     * or implicitly and to throw ReferenceError exception.
+     * The invalid value type is used:
+     *   for uninitialized array members,
+     *   to detect non-declared explicitly or implicitly variables,
+     *   for native property getters.
      */
     NJS_INVALID         = 0x07,
 
@@ -170,7 +170,6 @@ union njs_value_s {
             njs_function_lambda_t      *lambda;
             njs_regexp_t               *regexp;
             njs_getter_t               getter;
-            njs_native_t               method;
             njs_extern_t               *external;
             njs_value_t                *value;
             void                       *data;
@@ -241,11 +240,13 @@ union njs_value_s {
 }
 
 
-#define njs_getter(_getter)                                                   \
-    { .data = { .type = NJS_NATIVE,                                           \
-                .truth = 1,                                                   \
-                .u = { .getter = _getter }                                    \
-    } }
+#define njs_native_getter(_getter) {                                          \
+    .data = {                                                                 \
+        .type = NJS_INVALID,                                                  \
+        .truth = 1,                                                           \
+        .u = { .getter = _getter }                                            \
+    }                                                                         \
+}
 
 
 typedef njs_ret_t (*njs_vmcode_operation_t)(njs_vm_t *vm, njs_value_t *value1,
@@ -322,10 +323,6 @@ typedef njs_ret_t (*njs_vmcode_operation_t)(njs_vm_t *vm, njs_value_t *value1,
     ((value)->type == NJS_REGEXP)
 
 
-#define njs_is_native(value)                                                  \
-    ((value)->type == NJS_NATIVE)
-
-
 #define njs_is_external(value)                                                \
     ((value)->type == NJS_EXTERNAL)