code: public static Object sync(Context cx, Scriptable thisObj, Object[] args,
              Function funObj) {
          if (args.length == 1 && args[0] instanceof Function) {
              return new Synchronizer((Function)args[0]);
          } else {
              throw Context.reportRuntimeError("wrong argument(s) for sync");
          }
      }
docs: The sync function creates a synchronized function (in the sense
  of a Java synchronized method) from an existing function. The
  new function synchronizes on the <code>this</code> object of
  its invocation.
  js> var o = { f : sync(function(x) {
  print("entry");
  Packages.java.lang.Thread.sleep(x*1000);
  print("exit");
  })};
  js> thread(function() {o.f(5);});
  entry
  js> thread(function() {o.f(5);});
  js>
  exit
  entry
  exit