@@ -54,28 +54,28 @@ PyType *pyTypeFactory(PyObject *object) {
5454}
5555
5656PyType *pyTypeFactory (JSContext *cx, JS ::Rooted<JSObject *> *global, JS ::Rooted<JS ::Value> *rval) {
57- PyType *returnValue = NULL ;
5857 if (rval->isUndefined ()) {
59- returnValue = new NoneType ();
58+ return new NoneType ();
6059 }
6160 else if (rval->isNull ()) {
62- returnValue = new NullType ();
61+ return new NullType ();
6362 }
6463 else if (rval->isBoolean ()) {
65- returnValue = new BoolType (rval->toBoolean ());
64+ return new BoolType (rval->toBoolean ());
6665 }
6766 else if (rval->isNumber ()) {
68- returnValue = new FloatType (rval->toNumber ());
67+ return new FloatType (rval->toNumber ());
6968 }
7069 else if (rval->isString ()) {
71- returnValue = new StrType (cx, rval->toString ());
72- memoizePyTypeAndGCThing (returnValue, *rval); // TODO (Caleb Aikens) consider putting this in the StrType constructor
70+ StrType *s = new StrType (cx, rval->toString ());
71+ memoizePyTypeAndGCThing (s, *rval); // TODO (Caleb Aikens) consider putting this in the StrType constructor
72+ return s;
7373 }
7474 else if (rval->isSymbol ()) {
7575 printf (" symbol type is not handled by PythonMonkey yet" );
7676 }
7777 else if (rval->isBigInt ()) {
78- returnValue = new IntType (cx, rval->toBigInt ());
78+ return new IntType (cx, rval->toBigInt ());
7979 }
8080 else if (rval->isObject ()) {
8181 JS ::Rooted<JSObject *> obj (cx);
@@ -88,40 +88,38 @@ PyType *pyTypeFactory(JSContext *cx, JS::Rooted<JSObject *> *global, JS::Rooted<
8888 // TODO (Caleb Aikens): refactor using recursive call to `pyTypeFactory`
8989 JS ::RootedValue unboxed (cx);
9090 js::Unbox (cx, obj, &unboxed);
91- returnValue = new BoolType (unboxed.toBoolean ());
92- break ;
91+ return new BoolType (unboxed.toBoolean ());
9392 }
9493 case js::ESClass::Date: {
95- JS ::RootedValue unboxed (cx);
96- js::Unbox (cx, obj, &unboxed);
97- returnValue = new DateType (cx, obj);
98- break ;
94+ return new DateType (cx, obj);
9995 }
10096 case js::ESClass::Function: {
10197 PyObject *JSCxGlobalFuncTuple = Py_BuildValue (" (lll)" , (uint64_t )cx, (uint64_t )global, (uint64_t )rval);
10298 PyObject *pyFunc = PyCFunction_New (&callJSFuncDef, JSCxGlobalFuncTuple);
103- returnValue = new FuncType (pyFunc);
104- memoizePyTypeAndGCThing (returnValue , *rval); // TODO (Caleb Aikens) consider putting this in the FuncType constructor
105- break ;
99+ FuncType *f = new FuncType (pyFunc);
100+ memoizePyTypeAndGCThing (f , *rval); // TODO (Caleb Aikens) consider putting this in the FuncType constructor
101+ return f ;
106102 }
107103 case js::ESClass::Number: {
108104 JS ::RootedValue unboxed (cx);
109105 js::Unbox (cx, obj, &unboxed);
110- returnValue = new FloatType (unboxed.toNumber ());
111- break ;
106+ return new FloatType (unboxed.toNumber ());
112107 }
113108 case js::ESClass::BigInt: {
114109 JS ::RootedValue unboxed (cx);
115110 js::Unbox (cx, obj, &unboxed);
116- returnValue = new IntType (cx, unboxed.toBigInt ());
117- break ;
111+ return new IntType (cx, unboxed.toBigInt ());
118112 }
119113 case js::ESClass::String: {
120114 JS ::RootedValue unboxed (cx);
121115 js::Unbox (cx, obj, &unboxed);
122- returnValue = new StrType (cx, unboxed.toString ());
123- memoizePyTypeAndGCThing (returnValue, *rval); // TODO (Caleb Aikens) consider putting this in the StrType constructor
124- break ;
116+ StrType *s = new StrType (cx, unboxed.toString ());
117+ memoizePyTypeAndGCThing (s, *rval); // TODO (Caleb Aikens) consider putting this in the StrType constructor
118+ return s;
119+ }
120+ case js::ESClass::Object: {
121+ // this is a generic non-boxing object
122+ return new DictType (cx, *global, *rval);
125123 }
126124 default : {
127125 printf (" objects of this type are not handled by PythonMonkey yet" );
@@ -131,8 +129,6 @@ PyType *pyTypeFactory(JSContext *cx, JS::Rooted<JSObject *> *global, JS::Rooted<
131129 else if (rval->isMagic ()) {
132130 printf (" magic type is not handled by PythonMonkey yet" );
133131 }
134-
135- return returnValue;
136132}
137133
138134static PyObject *callJSFunc (PyObject *JSCxGlobalFuncTuple, PyObject *args) {
0 commit comments