Closed
Description
Describe your feature request here.
The pattern I've been using to instantiate new JS objects from classes is to wrap the call to "new" in a function:
module = pm.eval("(bufferSource) => new WebAssembly.Module(bufferSource)")(file_buffer)
This gets uglier when you need to pass more things to a constructor:
wasm_instance = pm.eval("(module, importObject) => new WebAssembly.Instance(module, importObject)")(module, import_object)
I think it would be nicer to have some better way of doing "new" since its such a commonly used operator.
WebAssembly = pm.eval("WebAssembly")
module = pm.new(WebAssembly.Module)(file_buffer)
wasm_instance = pm.new(WebAssembly.Instance)(module, import_object)
I'm not sure if this is the best approach, but just an idea
NOTE: some JS constructors don't require the use of the 'new' keyword... but others like WebAssembly.Module
will and will report the following error if not used with new Uncaught TypeError: WebAssembly.Module(): WebAssembly.Module must be invoked with 'new'
Code example
API idea:
new method: pm.new
parameters: a function which is a constructor
return: a function which calls the constructor
---
Usage: pm.new(SomeConstructor)(parameters...)
pm.new(Function)(