(&self, vm: &VirtualMachine)
| 404 | PyPromise::new(future_to_promise(future)) |
| 405 | } |
| 406 | pub fn as_js(&self, vm: &VirtualMachine) -> Promise { |
| 407 | match &self.value { |
| 408 | PromiseKind::Js(prom) => prom.clone(), |
| 409 | PromiseKind::PyProm { then } => Promise::new(&mut |js_resolve, js_reject| { |
| 410 | let resolve = move |res: PyObjectRef, vm: &VirtualMachine| { |
| 411 | let _ = js_resolve.call1(&JsValue::UNDEFINED, &convert::py_to_js(vm, res)); |
| 412 | }; |
| 413 | let reject = move |err: PyBaseExceptionRef, vm: &VirtualMachine| { |
| 414 | let _ = js_reject |
| 415 | .call1(&JsValue::UNDEFINED, &convert::py_err_to_js_err(vm, &err)); |
| 416 | }; |
| 417 | let _ = then.call( |
| 418 | ( |
| 419 | vm.new_function("resolve", resolve), |
| 420 | vm.new_function("reject", reject), |
| 421 | ), |
| 422 | vm, |
| 423 | ); |
| 424 | }), |
| 425 | PromiseKind::PyResolved(obj) => { |
| 426 | Promise::resolve(&convert::py_to_js(vm, obj.clone())) |
| 427 | } |
| 428 | PromiseKind::PyRejected(err) => { |
| 429 | Promise::reject(&convert::py_err_to_js_err(vm, err)) |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | fn cast(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<Self> { |
| 435 | let then = vm.get_attribute_opt(obj.clone(), "then")?; |
no test coverage detected