| 198 | } |
| 199 | |
| 200 | GJS_JSAPI_RETURN_CONVENTION |
| 201 | static bool getDeviceScale_func(JSContext* cx, unsigned argc, JS::Value* vp) { |
| 202 | GJS_GET_THIS(cx, argc, vp, args, obj); |
| 203 | |
| 204 | if (argc > 0) { |
| 205 | gjs_throw(cx, "Surface.getDeviceScale() takes no arguments"); |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | cairo_surface_t* surface = CairoSurface::for_js(cx, obj); |
| 210 | if (!surface) |
| 211 | return false; |
| 212 | |
| 213 | double x_scale, y_scale; |
| 214 | cairo_surface_get_device_scale(surface, &x_scale, &y_scale); |
| 215 | // cannot error |
| 216 | |
| 217 | JS::RootedValueArray<2> elements(cx); |
| 218 | elements[0].setNumber(JS::CanonicalizeNaN(x_scale)); |
| 219 | elements[1].setNumber(JS::CanonicalizeNaN(y_scale)); |
| 220 | JS::RootedObject retval(cx, JS::NewArrayObject(cx, elements)); |
| 221 | if (!retval) |
| 222 | return false; |
| 223 | |
| 224 | args.rval().setObject(*retval); |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | const JSFunctionSpec CairoSurface::proto_funcs[] = { |
| 229 | JS_FN("flush", flush_func, 0, 0), |
nothing calls this directly
no test coverage detected