details:   http://hg.nginx.org/njs/rev/0a9fbf9e925f
branches:  
changeset: 439:0a9fbf9e925f
user:      Dmitry Volyntsev <xei...@nginx.com>
date:      Fri Feb 09 20:12:41 2018 +0300
description:
Fixed Object's methods for the undefined value.

diffstat:

 njs/njs_object.c         |  24 ++++++++++++------------
 njs/test/njs_unit_test.c |  40 ++++++++++++++++++++++++++++++++--------
 2 files changed, 44 insertions(+), 20 deletions(-)

diffs (166 lines):

diff -r 03eebf0e08cc -r 0a9fbf9e925f njs/njs_object.c
--- a/njs/njs_object.c  Fri Feb 09 20:11:17 2018 +0300
+++ b/njs/njs_object.c  Fri Feb 09 20:12:41 2018 +0300
@@ -741,8 +741,8 @@ njs_object_freeze(njs_vm_t *vm, njs_valu
     nxt_lvlhsh_each_t  lhe;
 
     if (nargs < 2 || !njs_is_object(&args[1])) {
-        njs_exception_type_error(vm, NULL, NULL);
-        return NXT_ERROR;
+        vm->retval = njs_value_void;
+        return NXT_OK;
     }
 
     object = args[1].data.u.object;
@@ -780,8 +780,8 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v
     const njs_value_t  *retval;
 
     if (nargs < 2 || !njs_is_object(&args[1])) {
-        njs_exception_type_error(vm, NULL, NULL);
-        return NXT_ERROR;
+        vm->retval = njs_string_true;
+        return NXT_OK;
     }
 
     retval = &njs_string_false;
@@ -827,8 +827,8 @@ njs_object_seal(njs_vm_t *vm, njs_value_
     nxt_lvlhsh_each_t  lhe;
 
     if (nargs < 2 || !njs_is_object(&args[1])) {
-        njs_exception_type_error(vm, NULL, NULL);
-        return NXT_ERROR;
+        vm->retval = (nargs < 2) ? njs_value_void : args[1];
+        return NXT_OK;
     }
 
     object = args[1].data.u.object;
@@ -865,8 +865,8 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v
     const njs_value_t  *retval;
 
     if (nargs < 2 || !njs_is_object(&args[1])) {
-        njs_exception_type_error(vm, NULL, NULL);
-        return NXT_ERROR;
+        vm->retval = njs_string_true;
+        return NXT_OK;
     }
 
     retval = &njs_string_false;
@@ -907,8 +907,8 @@ njs_object_prevent_extensions(njs_vm_t *
     njs_index_t unused)
 {
     if (nargs < 2 || !njs_is_object(&args[1])) {
-        njs_exception_type_error(vm, NULL, NULL);
-        return NXT_ERROR;
+        vm->retval = (nargs < 2) ? njs_value_void : args[1];
+        return NXT_OK;
     }
 
     args[1].data.u.object->extensible = 0;
@@ -926,8 +926,8 @@ njs_object_is_extensible(njs_vm_t *vm, n
     const njs_value_t  *retval;
 
     if (nargs < 2 || !njs_is_object(&args[1])) {
-        njs_exception_type_error(vm, NULL, NULL);
-        return NXT_ERROR;
+        vm->retval = njs_string_false;
+        return NXT_OK;
     }
 
     retval = args[1].data.u.object->extensible ? &njs_string_true
diff -r 03eebf0e08cc -r 0a9fbf9e925f njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c  Fri Feb 09 20:11:17 2018 +0300
+++ b/njs/test/njs_unit_test.c  Fri Feb 09 20:12:41 2018 +0300
@@ -6433,6 +6433,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Object.defineProperties(Object.freeze({}), {b:{}})"),
       nxt_string("TypeError") },
 
+    { nxt_string("Object.freeze()"),
+      nxt_string("undefined") },
+
     { nxt_string("var o = Object.freeze({a:1}); o.a = 2; o.a"),
       nxt_string("1") },
 
@@ -6535,11 +6538,14 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Object.isFrozen(new RegExp(''))"),
       nxt_string("false") },
 
+    { nxt_string("Object.isFrozen()"),
+      nxt_string("true") },
+
     { nxt_string("Object.isFrozen(1)"),
-      nxt_string("TypeError") },
+      nxt_string("true") },
 
     { nxt_string("Object.isFrozen('')"),
-      nxt_string("TypeError") },
+      nxt_string("true") },
 
     { nxt_string("Object.isFrozen(Object.defineProperties({}, 
{a:{value:1}}))"),
       nxt_string("false") },
@@ -6586,11 +6592,14 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var o = Object.seal({a:{b:1}}); o.a.b = 2; o.a.b"),
       nxt_string("2") },
 
+    { nxt_string("Object.seal()"),
+      nxt_string("undefined") },
+
     { nxt_string("Object.seal(1)"),
-      nxt_string("TypeError") },
+      nxt_string("1") },
 
     { nxt_string("Object.seal('')"),
-      nxt_string("TypeError") },
+      nxt_string("") },
 
     { nxt_string("Object.isSealed({a:1})"),
       nxt_string("false") },
@@ -6607,11 +6616,14 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Object.isSealed(new RegExp(''))"),
       nxt_string("false") },
 
+    { nxt_string("Object.isSealed()"),
+      nxt_string("true") },
+
     { nxt_string("Object.isSealed(1)"),
-      nxt_string("TypeError") },
+      nxt_string("true") },
 
     { nxt_string("Object.isSealed('')"),
-      nxt_string("TypeError") },
+      nxt_string("true") },
 
     { nxt_string("Object.isSealed(Object.defineProperties({}, 
{a:{value:1}}))"),
       nxt_string("false") },
@@ -6660,6 +6672,15 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var o = Object.preventExtensions({a:1}); o.b = 1; o.b"),
       nxt_string("undefined") },
 
+    { nxt_string("Object.preventExtensions()"),
+      nxt_string("undefined") },
+
+    { nxt_string("Object.preventExtensions(1)"),
+      nxt_string("1") },
+
+    { nxt_string("Object.preventExtensions('')"),
+      nxt_string("") },
+
     { nxt_string("Object.isExtensible({})"),
       nxt_string("true") },
 
@@ -6675,11 +6696,14 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Object.isExtensible(new RegExp(''))"),
       nxt_string("true") },
 
+    { nxt_string("Object.isExtensible()"),
+      nxt_string("false") },
+
     { nxt_string("Object.isExtensible(1)"),
-      nxt_string("TypeError") },
+      nxt_string("false") },
 
     { nxt_string("Object.isExtensible('')"),
-      nxt_string("TypeError") },
+      nxt_string("false") },
 
     { nxt_string("Object.isExtensible(Object.preventExtensions({}))"),
       nxt_string("false") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

Reply via email to