code: private static File checkInstance(Scriptable obj) {
          if (obj == null || !(obj instanceof File)) {
              throw Context.reportRuntimeError("called on incompatible object");
          }
          return (File) obj;
      }
docs: Perform the instanceof check and return the downcasted File object.
  
  This is necessary since methods may reside in the File.prototype
  object and scripts can dynamically alter prototype chains. For example:
  <pre>
  js> defineClass("File");
  js> o = {};
  [object Object]
  js> o.__proto__ = File.prototype;
  [object File]
  js> o.write("hi");
  js: called on incompatible object
  </pre>
  The runtime will take care of such checks when non-static Java methods
  are defined as JavaScript functions.