Skip to content

Commit

Permalink
Initial JS iteration of Python objects.
Browse files Browse the repository at this point in the history
This passes the basic tests. I need to add a check to detect if we're doing 'for
v in obj' vs 'for each (v in obj)' iteration as they behave differently in
JavaScript.
  • Loading branch information
Paul Davis authored and Paul Davis committed May 10, 2009
1 parent 1a1300a commit 0d2d6d1
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 68 deletions.
4 changes: 2 additions & 2 deletions go
@@ -1,3 +1,3 @@
#! /bin/bash
python setup.py build
gdb --command=go.comm --batch python2.5
#python setup.py build
gdb --command=go.comm --batch python
24 changes: 14 additions & 10 deletions spidermonkey/integer.c
Expand Up @@ -12,35 +12,39 @@ jsval
py2js_integer(Context* cx, PyObject* obj)
{
long pyval;
jsval ret = JSVAL_VOID;

if(PyInt_Check(obj))
{
pyval = PyInt_AsLong(obj);
if(PyErr_Occurred()) goto error;
if(PyErr_Occurred()) return JSVAL_VOID;
}
else
{
pyval = PyLong_AsLong(obj);
if(PyErr_Occurred()) goto error;
if(PyErr_Occurred()) return JSVAL_VOID;
}


return long2js_integer(cx, pyval);
}

jsval
long2js_integer(Context* cx, long pyval)
{
jsval ret = JSVAL_VOID;

if(INT_FITS_IN_JSVAL(pyval))
{
ret = INT_TO_JSVAL(pyval);
goto success;
goto done;
}

if(!JS_NewNumberValue(cx->cx, pyval, &ret))
{
PyErr_SetString(PyExc_ValueError, "Failed to convert number.");
goto error;
goto done;
}

goto success;

error:
success:
done:
return ret;
}

Expand Down
1 change: 1 addition & 0 deletions spidermonkey/integer.h
Expand Up @@ -10,6 +10,7 @@
#define PYSM_INTEGER_H

jsval py2js_integer(Context* cx, PyObject* obj);
jsval long2js_integer(Context* cx, long val);
PyObject* js2py_integer(Context* cx, jsval val);

#endif

0 comments on commit 0d2d6d1

Please sign in to comment.