MicroScript to JavaScript from JavaScript

This JavaScript code snippet will convert a MicroScript function (Routine) into a JavaScript function (Function):

function ms_to_js(func) {
  if(!(func instanceof Routine)) {
    return func;
  }
  let vm = player.runtime.vm;
  return vm.runner.main_thread.processor.argToNative(func, vm.context)
}

If there's a better way to do this, or there's a case where the code above doesn't work, please tell me.