Skip to content

Commit 1df3a57

Browse files
Paul DavisPaul Davis
Paul Davis
authored and
Paul Davis
committed
Initial JS iteration of Python objects.
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.
1 parent 2afa3de commit 1df3a57

File tree

8 files changed

+451
-68
lines changed

8 files changed

+451
-68
lines changed

go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#! /bin/bash
2-
python setup.py build
3-
gdb --command=go.comm --batch python2.5
2+
#python setup.py build
3+
gdb --command=go.comm --batch python

spidermonkey/integer.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,39 @@ jsval
1212
py2js_integer(Context* cx, PyObject* obj)
1313
{
1414
long pyval;
15-
jsval ret = JSVAL_VOID;
1615

1716
if(PyInt_Check(obj))
1817
{
1918
pyval = PyInt_AsLong(obj);
20-
if(PyErr_Occurred()) goto error;
19+
if(PyErr_Occurred()) return JSVAL_VOID;
2120
}
2221
else
2322
{
2423
pyval = PyLong_AsLong(obj);
25-
if(PyErr_Occurred()) goto error;
24+
if(PyErr_Occurred()) return JSVAL_VOID;
2625
}
27-
26+
27+
return long2js_integer(cx, pyval);
28+
}
29+
30+
jsval
31+
long2js_integer(Context* cx, long pyval)
32+
{
33+
jsval ret = JSVAL_VOID;
34+
2835
if(INT_FITS_IN_JSVAL(pyval))
2936
{
3037
ret = INT_TO_JSVAL(pyval);
31-
goto success;
38+
goto done;
3239
}
3340

3441
if(!JS_NewNumberValue(cx->cx, pyval, &ret))
3542
{
3643
PyErr_SetString(PyExc_ValueError, "Failed to convert number.");
37-
goto error;
44+
goto done;
3845
}
3946

40-
goto success;
41-
42-
error:
43-
success:
47+
done:
4448
return ret;
4549
}
4650

spidermonkey/integer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define PYSM_INTEGER_H
1111

1212
jsval py2js_integer(Context* cx, PyObject* obj);
13+
jsval long2js_integer(Context* cx, long val);
1314
PyObject* js2py_integer(Context* cx, jsval val);
1415

1516
#endif

0 commit comments

Comments
 (0)