@@ -68,7 +68,7 @@ static PyObject *object_call(ObjectData *self, PyObject *args, PyObject *kwds) {
6868 PyObject * item = PyTuple_GetItem (args , i );
6969 if (PyLong_Check (item )) {
7070 } else if (PyUnicode_Check (item )) {
71- } else if (PyObject_IsInstance (item , & Object )) {
71+ } else if (PyObject_IsInstance (item , ( PyObject * ) & Object )) {
7272 } else {
7373 PyErr_Format (PyExc_ValueError , "Unsupported type when calling quickjs object" );
7474 return NULL ;
@@ -81,7 +81,7 @@ static PyObject *object_call(ObjectData *self, PyObject *args, PyObject *kwds) {
8181 jsargs [i ] = JS_MKVAL (JS_TAG_INT , PyLong_AsLong (item ));
8282 } else if (PyUnicode_Check (item )) {
8383 jsargs [i ] = JS_NewString (self -> context , PyUnicode_AsUTF8 (item ));
84- } else if (PyObject_IsInstance (item , & Object )) {
84+ } else if (PyObject_IsInstance (item , ( PyObject * ) & Object )) {
8585 jsargs [i ] = JS_DupValue (self -> context , ((ObjectData * )item )-> object );
8686 }
8787 }
@@ -105,8 +105,6 @@ static PyObject *quickjs_to_python(JSContext *context, JSValue value) {
105105 return_value = Py_None ;
106106 } else if (tag == JS_TAG_UNDEFINED ) {
107107 return_value = Py_None ;
108- } else if (tag == JS_TAG_UNINITIALIZED ) {
109- return_value = Py_None ;
110108 } else if (tag == JS_TAG_EXCEPTION ) {
111109 JSValue exception = JS_GetException (context );
112110 JSValue error_string = JS_ToString (context , exception );
@@ -125,8 +123,7 @@ static PyObject *quickjs_to_python(JSContext *context, JSValue value) {
125123 return_value = PyObject_CallObject ((PyObject * )& Object , NULL );
126124 ObjectData * object = (ObjectData * )return_value ;
127125 object -> context = context ;
128- object -> object = value ;
129- return return_value ;
126+ object -> object = JS_DupValue (context , value );
130127 } else {
131128 PyErr_Format (PyExc_ValueError , "Unknown quickjs tag: %d" , tag );
132129 }
@@ -177,8 +174,20 @@ static PyObject *context_eval(ContextData *self, PyObject *args) {
177174 return quickjs_to_python (self -> context , value );
178175}
179176
177+ static PyObject * context_get (ContextData * self , PyObject * args ) {
178+ const char * name ;
179+ if (!PyArg_ParseTuple (args , "s" , & name )) {
180+ return NULL ;
181+ }
182+ JSValue global = JS_GetGlobalObject (self -> context );
183+ JSValue value = JS_GetPropertyStr (self -> context , global , name );
184+ JS_FreeValue (self -> context , global );
185+ return quickjs_to_python (self -> context , value );
186+ }
187+
180188static PyMethodDef context_methods [] = {
181189 {"eval" , (PyCFunction )context_eval , METH_VARARGS , "Evaluates a Javascript string." },
190+ {"get" , (PyCFunction )context_get , METH_VARARGS , "Gets a Javascript global variable." },
182191 {NULL } /* Sentinel */
183192};
184193
0 commit comments