(
&self,
args: PosArgs<PyJsValueRef>,
opts: NewObjectOptions,
vm: &VirtualMachine,
)
| 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> { |
nothing calls this directly
no test coverage detected