Skip to content

Commit 91355f2

Browse files
committed
fix(pyTypeFactory): we shouldn't use printf here. Print to the Python error message instead.
1 parent 61eeead commit 91355f2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/pyTypeFactory.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include <js/ValueArray.h>
3838

3939
PyObject *pyTypeFactory(JSContext *cx, JS::HandleValue rval) {
40+
std::string errorString;
41+
4042
if (rval.isUndefined()) {
4143
return NoneType::getPyObject();
4244
}
@@ -53,7 +55,7 @@ PyObject *pyTypeFactory(JSContext *cx, JS::HandleValue rval) {
5355
return StrType::getPyObject(cx, rval);
5456
}
5557
else if (rval.isSymbol()) {
56-
printf("symbol type is not handled by PythonMonkey yet\n");
58+
errorString = "symbol type is not handled by PythonMonkey yet.\n";
5759
}
5860
else if (rval.isBigInt()) {
5961
return IntType::getPyObject(cx, rval.toBigInt());
@@ -117,10 +119,10 @@ PyObject *pyTypeFactory(JSContext *cx, JS::HandleValue rval) {
117119
return DictType::getPyObject(cx, rval);
118120
}
119121
else if (rval.isMagic()) {
120-
printf("magic type is not handled by PythonMonkey yet\n");
122+
errorString = "magic type is not handled by PythonMonkey yet.\n";
121123
}
122124

123-
std::string errorString("pythonmonkey cannot yet convert Javascript value of: ");
125+
errorString += "pythonmonkey cannot yet convert Javascript value of: ";
124126
JSString *valToStr = JS::ToString(cx, rval);
125127
if (!valToStr) { // `JS::ToString` returns `nullptr` for JS symbols, see https://hg.mozilla.org/releases/mozilla-esr102/file/3b574e1/js/src/vm/StringType.cpp#l2208
126128
// TODO (Tom Tang): Revisit this once we have Symbol coercion support

0 commit comments

Comments
 (0)