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, },
};
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);
}
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, },
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, },
};
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, },
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);
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, },
};
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) {
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;
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;
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));
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;
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, },
};
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, },
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, },
&njs_object_number_string,
&njs_object_string_string,
- &njs_object_function_string,
+ &njs_string_empty,
&njs_object_function_string,
&njs_string_empty,
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, },
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, },
};
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, },
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, },
};
* regex: full regexp text like "/regexp/gim".
*/
- case NJS_NATIVE:
case NJS_EXTERNAL:
value = &njs_string_native;
break;
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, },
obj = object->data.u.object;
break;
- case NJS_NATIVE:
- obj = &vm->prototypes[NJS_PROTOTYPE_FUNCTION];
- break;
-
case NJS_EXTERNAL:
ext = object->data.u.external;
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;
}
/* 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,
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;
}
-#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,
((value)->type == NJS_REGEXP)
-#define njs_is_native(value) \
- ((value)->type == NJS_NATIVE)
-
-
#define njs_is_external(value) \
((value)->type == NJS_EXTERNAL)