]> git.kaiwu.me - njs.git/commitdiff
eval() placeholders update.
authorIgor Sysoev <igor@sysoev.ru>
Mon, 23 Nov 2015 19:37:01 +0000 (22:37 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 23 Nov 2015 19:37:01 +0000 (22:37 +0300)
njs/njs_function.c
njs/njs_function.h
njs/njs_shared.c
njs/test/njs_unit_test.c

index 4239499e5761cdab59b6475a76182842986a6746..ed1c3279fdf83f614fa88324dd00a6e9228111c9 100644 (file)
@@ -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));
+}
index 24453c02fd890457a2890016a499d244d98bc45d..1a9f607d4a14b3e8dbe816d5f11fe8dcdd67ae8e 100644 (file)
@@ -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_ */
index b6d064b3458331835d9eb7113d05fea55a8fa21b..b01bfcb593fbe024351c6452ad254c0fa7a4c9e8 100644 (file)
 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
index 4e5da51258a1186d2037c71e684b5b8827f27079..17621802dfd5520c6a222a632206d85a21df4247 100644 (file)
@@ -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 */