docs: public static Callable getValueFunctionAndThis(Object value, Context cx)
      {
          if (!(value instanceof Callable)) {
              throw notFunctionError(value);
          }
  
          Callable f = (Callable)value;
          Scriptable thisObj = null;
          if (f instanceof Scriptable) {
              thisObj = ((Scriptable)f).getParentScope();
          }
          if (thisObj == null) {
              if (cx.topCallScope == null) throw new IllegalStateException();
              thisObj = cx.topCallScope;
          }
          if (thisObj.getParentScope() != null) {
              if (thisObj instanceof NativeWith) {
                  // functions defined inside with should have with target
                  // as their thisObj
              } else if (thisObj instanceof NativeCall) {
                  // nested functions should have top scope as their thisObj
                  thisObj = ScriptableObject.getTopLevelScope(thisObj);
              }
          }
          storeScriptable(cx, thisObj);
          return f;
      }