@@ -75,6 +75,8 @@ static PyObject *DukPy_eval_string(PyObject *self, PyObject *args) {
7575 JSValue jsvars ;
7676 JSValue json_result ;
7777 JSValue global ;
78+ int eval_is_null ;
79+ int eval_is_undefined ;
7880
7981 if (!PyArg_ParseTuple (args , "Oy#y#" , & interpreter , & command , & command_len ,
8082 & vars , & vars_len ))
@@ -141,22 +143,27 @@ static PyObject *DukPy_eval_string(PyObject *self, PyObject *args) {
141143 return raise_js_exception (ctx );
142144 }
143145
146+ eval_is_null = JS_IsNull (eval_result );
147+ eval_is_undefined = JS_IsUndefined (eval_result );
148+ if (eval_is_null || eval_is_undefined ) {
149+ JS_FreeValue (ctx , eval_result );
150+ result = Py_BuildValue ("y" , "{}" );
151+ Py_XDECREF (pyctx );
152+ return result ;
153+ }
154+
144155 json_result = JS_JSONStringify (ctx , eval_result , JS_UNDEFINED , JS_UNDEFINED );
145156 JS_FreeValue (ctx , eval_result );
146157 if (JS_IsException (json_result )) {
147158 Py_XDECREF (pyctx );
148159 return raise_js_exception (ctx );
149160 }
150161
151- if (JS_IsNull (json_result )) {
152- JS_FreeValue (ctx , json_result );
153- json_result = JS_NewString (ctx , "{}" );
154- }
155-
156162 if (JS_IsUndefined (json_result )) {
157163 JS_FreeValue (ctx , json_result );
158- PyErr_SetString ( DukPyError , "Invalid Result Value" );
164+ JS_FreeValue ( ctx , eval_result );
159165 Py_XDECREF (pyctx );
166+ PyErr_SetString (DukPyError , "Invalid Result Value" );
160167 return NULL ;
161168 }
162169
0 commit comments