Esempio n. 1
0
 private static ObjToIntMap getObjectFunctionNames(Scriptable obj) {
   Object[] ids = ScriptableObject.getPropertyIds(obj);
   ObjToIntMap map = new ObjToIntMap(ids.length);
   for (int i = 0; i != ids.length; ++i) {
     if (!(ids[i] instanceof String)) continue;
     String id = (String) ids[i];
     Object value = ScriptableObject.getProperty(obj, id);
     if (value instanceof Function) {
       Function f = (Function) value;
       int length = ScriptRuntime.toInt32(ScriptableObject.getProperty(f, "length"));
       if (length < 0) {
         length = 0;
       }
       map.put(id, length);
     }
   }
   return map;
 }
Esempio n. 2
0
  public static Function getFunction(Scriptable obj, String functionName) {
    Object x = ScriptableObject.getProperty(obj, functionName);
    if (x == Scriptable.NOT_FOUND) {
      // This method used to swallow the exception from calling
      // an undefined method. People have come to depend on this
      // somewhat dubious behavior. It allows people to avoid
      // implementing listener methods that they don't care about,
      // for instance.
      return null;
    }
    if (!(x instanceof Function)) throw ScriptRuntime.notFunctionError(x, functionName);

    return (Function) x;
  }
Esempio n. 3
0
 public static Scriptable createAdapterWrapper(Scriptable obj, Object adapter) {
   Scriptable scope = ScriptableObject.getTopLevelScope(obj);
   NativeJavaObject res = new NativeJavaObject(scope, adapter, null, true);
   res.setPrototype(obj);
   return res;
 }