@@ -39,7 +39,13 @@ ddwaf_object* to_ddwaf_object_array(
3939 if (!ignoreToJSON) {
4040 Napi::Value toJSON = arr.Get (" toJSON" );
4141 if (toJSON.IsFunction ()) {
42- return to_ddwaf_object (object, env, toJSON.As <Napi::Function>().Call (arr, {}), depth, lim, true , stack, metrics);
42+ Napi::Value toJSONResult = toJSON.As <Napi::Function>().Call (arr, {});
43+ if (env.IsExceptionPending ()) {
44+ mlog (" Exception pending" );
45+ env.GetAndClearPendingException ();
46+ return ddwaf_object_invalid (object);
47+ }
48+ return to_ddwaf_object (object, env, toJSONResult, depth, lim, true , stack, metrics);
4349 }
4450 }
4551
@@ -88,7 +94,13 @@ ddwaf_object* to_ddwaf_object_object(
8894 if (!ignoreToJSON) {
8995 Napi::Value toJSON = obj.Get (" toJSON" );
9096 if (toJSON.IsFunction ()) {
91- return to_ddwaf_object (object, env, toJSON.As <Napi::Function>().Call (obj, {}), depth, lim, true , stack, metrics);
97+ Napi::Value toJSONResult = toJSON.As <Napi::Function>().Call (obj, {});
98+ if (env.IsExceptionPending ()) {
99+ mlog (" Exception pending" );
100+ env.GetAndClearPendingException ();
101+ return ddwaf_object_invalid (object);
102+ }
103+ return to_ddwaf_object (object, env, toJSONResult, depth, lim, true , stack, metrics);
92104 }
93105 }
94106
0 commit comments