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

Method construct

crates/wasm/src/js_module.rs:207–231  ·  view source on GitHub ↗
(
            &self,
            args: PosArgs<PyJsValueRef>,
            opts: NewObjectOptions,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

205
206 #[pymethod]
207 fn construct(
208 &self,
209 args: PosArgs<PyJsValueRef>,
210 opts: NewObjectOptions,
211 vm: &VirtualMachine,
212 ) -> PyResult<PyJsValue> {
213 let ctor = self
214 .value
215 .dyn_ref::<js_sys::Function>()
216 .ok_or_else(|| vm.new_type_error("JS value is not callable"))?;
217 let proto = opts
218 .prototype
219 .as_ref()
220 .and_then(|proto| proto.value.dyn_ref::<js_sys::Function>());
221 let js_args = args.iter().map(|x| -> &PyJsValue { x }).collect::<Array>();
222 let constructed_result = if let Some(proto) = proto {
223 Reflect::construct_with_new_target(ctor, &js_args, proto)
224 } else {
225 Reflect::construct(ctor, &js_args)
226 };
227
228 constructed_result
229 .map(PyJsValue::new)
230 .map_err(|err| new_js_error(vm, err))
231 }
232
233 #[pymethod]
234 fn as_str(&self) -> Option<String> {

Callers

nothing calls this directly

Calls 5

new_js_errorFunction · 0.85
ok_or_elseMethod · 0.80
as_refMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected