| 19 | |
| 20 | |
| 21 | def make_command(filename, engine, args=None): |
| 22 | args = args or [] |
| 23 | # if no engine is needed, indicated by None, then there is a native executable |
| 24 | # provided which we can just run |
| 25 | if engine[0] is None: |
| 26 | executable = utils.replace_suffix(os.path.abspath(filename), '.exe') |
| 27 | return [executable] + args |
| 28 | # Emscripten supports multiple javascript runtimes. The default is nodejs but |
| 29 | # it can also use d8 (the v8 engine shell) or jsc (JavaScript Core aka |
| 30 | # Safari). Both d8 and jsc require a '--' to delimit arguments to be passed |
| 31 | # to the executed script from d8/jsc options. Node does not require a |
| 32 | # delimiter--arguments after the filename are passed to the script. |
| 33 | # |
| 34 | # Check only the last part of the engine path to ensure we don't accidentally |
| 35 | # label a path to nodejs containing a 'd8' as spidermonkey instead. |
| 36 | jsengine = os.path.basename(engine[0]) |
| 37 | # Use "'d8' in" because the name can vary, e.g. d8_g, d8, etc. |
| 38 | is_d8 = 'd8' in jsengine or 'v8' in jsengine |
| 39 | is_jsc = 'jsc' in jsengine or 'javascriptcore' in jsengine |
| 40 | is_wasmer = 'wasmer' in jsengine |
| 41 | is_wasmtime = 'wasmtime' in jsengine |
| 42 | command_flags = [] |
| 43 | if is_wasmer: |
| 44 | command_flags += ['run'] |
| 45 | if is_wasmer or is_wasmtime: |
| 46 | # in a wasm runtime, run the wasm, not the js |
| 47 | filename = utils.replace_suffix(filename, '.wasm') |
| 48 | # Separates engine flags from script flags |
| 49 | flag_separator = ['--'] if is_d8 or is_jsc else [] |
| 50 | return engine + command_flags + [filename] + flag_separator + args |
| 51 | |
| 52 | |
| 53 | def check_engine(engine): |