From: Igor Sysoev Date: Fri, 11 Dec 2015 15:41:10 +0000 (+0300) Subject: Riddance of NJS_NATIVE type. X-Git-Tag: 0.1.0~104 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=8edf6e2048a05e0fe0a8bc21558961875df83857;p=njs.git Riddance of NJS_NATIVE type. --- diff --git a/njs/njs_array.c b/njs/njs_array.c index 51fd4357..788907c1 100644 --- a/njs/njs_array.c +++ b/njs/njs_array.c @@ -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, }, diff --git a/njs/njs_boolean.c b/njs/njs_boolean.c index 05c0e649..56793251 100644 --- a/njs/njs_boolean.c +++ b/njs/njs_boolean.c @@ -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, }, diff --git a/njs/njs_function.c b/njs/njs_function.c index bca792cb..b452aac5 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -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 = ¶m->args[0]; p.args = ¶m->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; diff --git a/njs/njs_number.c b/njs/njs_number.c index a8687a03..89cefc03 100644 --- a/njs/njs_number.c +++ b/njs/njs_number.c @@ -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, }, diff --git a/njs/njs_object.c b/njs/njs_object.c index 9f01f4c4..a0e37795 100644 --- a/njs/njs_object.c +++ b/njs/njs_object.c @@ -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, }, diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index c9c3f403..2415bfc6 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -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, }, diff --git a/njs/njs_string.c b/njs/njs_string.c index bdc45b72..5416b9c5 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -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, }, diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 3b30a031..9c48f5a7 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -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; } diff --git a/njs/njs_vm.h b/njs/njs_vm.h index 3ba17210..14aa9f79 100644 --- a/njs/njs_vm.h +++ b/njs/njs_vm.h @@ -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)