| 67 | } |
| 68 | |
| 69 | static bool toPrimitive(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 70 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 71 | |
| 72 | JS::RootedObject proxy(cx, JS::ToObject(cx, args.thisv())); |
| 73 | if (!proxy) { |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | PyObject *self = JS::GetMaybePtrFromReservedSlot<PyObject>(proxy, PyObjectSlot); |
| 78 | |
| 79 | _PyUnicodeWriter writer; |
| 80 | |
| 81 | _PyUnicodeWriter_Init(&writer); |
| 82 | |
| 83 | PyObject *s = PyObject_Repr(self); |
| 84 | |
| 85 | if (s == nullptr) { |
| 86 | args.rval().setString(JS_NewStringCopyZ(cx, "<cannot repr type>")); |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | int res = _PyUnicodeWriter_WriteStr(&writer, s); |
| 91 | Py_DECREF(s); |
| 92 | |
| 93 | if (res < 0) { |
| 94 | args.rval().setString(JS_NewStringCopyZ(cx, "<cannot repr type>")); |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | PyObject *repr = _PyUnicodeWriter_Finish(&writer); |
| 99 | |
| 100 | args.rval().set(jsTypeFactory(cx, repr)); |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | static bool iterable_valueOf(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 105 | return toPrimitive(cx, argc, vp); |
no test coverage detected