forked from davisp/python-spidermonkey
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdouble.c
More file actions
43 lines (35 loc) · 817 Bytes
/
Copy pathdouble.c
File metadata and controls
43 lines (35 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Copyright 2009 Paul J. Davis <paul.joseph.davis@gmail.com>
*
* This file is part of the python-spidermonkey package released
* under the MIT license.
*
*/
#include "spidermonkey.h"
jsval
py2js_double(Context* cx, PyObject* obj)
{
jsval rval = JSVAL_VOID;
double pyval = PyFloat_AsDouble(obj);
if(PyErr_Occurred()) goto error;
if(!JS_NewNumberValue(cx->cx, pyval, &rval))
{
PyErr_SetString(PyExc_ValueError, "Failed to convert number.");
goto error;
}
goto success;
error:
success:
return rval;
}
PyObject*
js2py_double(Context* cx, jsval val)
{
double rval;
if(!JS_ValueToNumber(cx->cx, val, &rval))
{
PyErr_SetString(PyExc_TypeError, "Invalid JS number value.");
return NULL;
}
return PyFloat_FromDouble(rval);
}