MCPcopy Index your code
hub / github.com/RustPython/RustPython / as_js

Method as_js

crates/wasm/src/js_module.rs:406–432  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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")?;

Callers 1

py_to_jsFunction · 0.80

Calls 8

newFunction · 0.85
py_to_jsFunction · 0.85
py_err_to_js_errFunction · 0.85
rejectFunction · 0.85
new_functionMethod · 0.80
resolveFunction · 0.50
cloneMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected