From: Igor Sysoev Date: Mon, 23 Nov 2015 19:37:01 +0000 (+0300) Subject: eval() placeholders update. X-Git-Tag: 0.1.0~110 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=1d4fae95d0316ed6f92c2916dee3f89024284558;p=njs.git eval() placeholders update. --- diff --git a/njs/njs_function.c b/njs/njs_function.c index 4239499e..ed1c3279 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -202,6 +202,13 @@ njs_vmcode_trap(njs_vm_t *vm, nxt_uint_t trap, njs_value_t *value1, } +njs_ret_t +njs_function_function(njs_vm_t *vm, njs_param_t *param) +{ + return NXT_ERROR; +} + + nxt_noinline njs_ret_t njs_function_apply(njs_vm_t *vm, njs_value_t *name, njs_param_t *param) { @@ -573,3 +580,32 @@ njs_function_prototype_hash(njs_vm_t *vm, nxt_lvlhsh_t *hash) return njs_object_hash_create(vm, hash, njs_function_prototype_properties, nxt_nitems(njs_function_prototype_properties)); } + + +njs_ret_t +njs_eval_function(njs_vm_t *vm, njs_param_t *param) +{ + return NXT_ERROR; +} + + +static const njs_object_prop_t njs_eval_function_properties[] = +{ + /* eval.name == "eval". */ + { njs_string("eval"), + njs_string("name"), + NJS_PROPERTY, 0, 0, 0, }, + + /* eval.length == 1. */ + { njs_value(NJS_NUMBER, 0, 1.0), + njs_string("length"), + NJS_PROPERTY, 0, 0, 0, }, +}; + + +nxt_int_t +njs_eval_function_hash(njs_vm_t *vm, nxt_lvlhsh_t *hash) +{ + return njs_object_hash_create(vm, hash, njs_eval_function_properties, + nxt_nitems(njs_eval_function_properties)); +} diff --git a/njs/njs_function.h b/njs/njs_function.h index 24453c02..1a9f607d 100644 --- a/njs/njs_function.h +++ b/njs/njs_function.h @@ -115,6 +115,7 @@ typedef struct { njs_function_t *njs_function_alloc(njs_vm_t *vm); +njs_ret_t njs_function_function(njs_vm_t *vm, njs_param_t *param); njs_ret_t njs_function_apply(njs_vm_t *vm, njs_value_t *name, njs_param_t *param); njs_value_t *njs_vmcode_native_frame(njs_vm_t *vm, njs_value_t *method, @@ -128,5 +129,8 @@ njs_ret_t njs_function_call(njs_vm_t *vm, njs_function_t *func, nxt_int_t njs_function_function_hash(njs_vm_t *vm, nxt_lvlhsh_t *hash); nxt_int_t njs_function_prototype_hash(njs_vm_t *vm, nxt_lvlhsh_t *hash); +njs_ret_t njs_eval_function(njs_vm_t *vm, njs_param_t *param); +nxt_int_t njs_eval_function_hash(njs_vm_t *vm, nxt_lvlhsh_t *hash); + #endif /* _NJS_FUNCTION_H_INCLUDED_ */ diff --git a/njs/njs_shared.c b/njs/njs_shared.c index b6d064b3..b01bfcb5 100644 --- a/njs/njs_shared.c +++ b/njs/njs_shared.c @@ -25,20 +25,6 @@ typedef nxt_int_t (*njs_shared_hash_t) (njs_vm_t *vm, nxt_lvlhsh_t *hash); -/* STUB */ -static nxt_int_t -njs_stub_hash(njs_vm_t *vm, nxt_lvlhsh_t *hash) -{ - return NXT_OK; -} -static njs_ret_t -njs_stub_function(njs_vm_t *vm, njs_param_t *param) -{ - return NXT_ERROR; -} -/**/ - - nxt_int_t njs_shared_objects_create(njs_vm_t *vm) { @@ -66,18 +52,20 @@ njs_shared_objects_create(njs_vm_t *vm) njs_string_function_hash, njs_function_function_hash, njs_regexp_function_hash, - njs_stub_hash, + + njs_eval_function_hash, }; - static const njs_native_t native_functions[] = { + static const njs_native_t native_functions[] = { njs_object_function, njs_array_function, njs_boolean_function, njs_number_function, njs_string_ctor_function, - njs_stub_function, + njs_function_function, njs_regexp_function, - njs_stub_function, + + njs_eval_function, }; size = NJS_PROTOTYPE_MAX * sizeof(njs_object_t); @@ -136,13 +124,28 @@ njs_shared_objects_create(njs_vm_t *vm) * Array.__proto__ -> Function_Prototype, * Array_Prototype.__proto__ -> Object_Prototype, * + * Boolean(), + * Boolean.__proto__ -> Function_Prototype, + * Boolean_Prototype.__proto__ -> Object_Prototype, + * + * Number(), + * Number.__proto__ -> Function_Prototype, + * Number_Prototype.__proto__ -> Object_Prototype, + * + * String(), + * String.__proto__ -> Function_Prototype, + * String_Prototype.__proto__ -> Object_Prototype, + * * Function(), * Function.__proto__ -> Function_Prototype, * Function_Prototype.__proto__ -> Object_Prototype, * - * [...] + * RegExp(), + * RegExp.__proto__ -> Function_Prototype, + * RegExp_Prototype.__proto__ -> Object_Prototype, * - * eval(). + * eval(), + * eval.__proto__ -> Function_Prototype. */ nxt_int_t diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 4e5da512..17621802 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -2967,6 +2967,26 @@ static njs_unit_test_t njs_test[] = { nxt_string("var o = Object.create(null); '__proto__' in o"), nxt_string("false") }, + /* eval(). */ + + { nxt_string("eval.name"), + nxt_string("eval") }, + + { nxt_string("eval.length"), + nxt_string("1") }, + + { nxt_string("eval.prototype"), + nxt_string("undefined") }, + + { nxt_string("eval.__proto__ === Function.prototype"), + nxt_string("true") }, + + { nxt_string("eval.constructor === Function"), + nxt_string("true") }, + + { nxt_string("eval()"), + nxt_string("") }, + /* es5id: 8.2_A1_T1 */ /* es5id: 8.2_A1_T2 */