new function - emits function which wraps JS new operator, emitting a lambda which constructs a new JS object upon invocation.
(ctor)
| 24 | |
| 25 | |
| 26 | def new(ctor): |
| 27 | """ |
| 28 | new function - emits function which wraps JS new operator, emitting a lambda which constructs a new |
| 29 | JS object upon invocation. |
| 30 | """ |
| 31 | if (typeof(ctor) == 'string'): |
| 32 | ctor = pm.eval(ctor) |
| 33 | |
| 34 | newCtor = pm.eval("""'use strict'; ( |
| 35 | function pmNewFactory(ctor) |
| 36 | { |
| 37 | return function newCtor(args) { |
| 38 | args = Array.from(args || []); |
| 39 | return new ctor(...args); |
| 40 | }; |
| 41 | } |
| 42 | )""", evalOpts)(ctor) |
| 43 | return (lambda *args: newCtor(list(args))) |
| 44 | |
| 45 | |
| 46 | def simpleUncaughtExceptionHandler(loop, context): |