use of org.mozilla.javascript.NativeFunction in project Auto.js by hyb1996.
the class ProxyJavaObject method put.
@Override
public void put(String name, Scriptable start, Object value) {
if (name.equals("__proxy__")) {
NativeObject proxy = (NativeObject) value;
Object getter = proxy.get("get", start);
if (getter instanceof NativeFunction) {
mGetter = (NativeFunction) getter;
}
Object setter = proxy.get("set", start);
if (setter instanceof NativeFunction) {
mSetter = (NativeFunction) setter;
}
} else if (mSetter != null) {
mSetter.call(Context.getCurrentContext(), start, start, new Object[] { name, value });
} else {
super.put(name, start, value);
}
}
use of org.mozilla.javascript.NativeFunction in project LoboEvolution by LoboEvolution.
the class Codegen method createFunctionObject.
@Override
public Function createFunctionObject(Context cx, Scriptable scope, Object bytecode, Object staticSecurityDomain) {
Class<?> cl = defineClass(bytecode, staticSecurityDomain);
NativeFunction f;
try {
Constructor<?> ctor = cl.getConstructors()[0];
Object[] initArgs = { scope, cx, Integer.valueOf(0) };
f = (NativeFunction) ctor.newInstance(initArgs);
} catch (Exception ex) {
throw new RuntimeException("Unable to instantiate compiled class:" + ex.toString());
}
return f;
}
use of org.mozilla.javascript.NativeFunction in project servoy-client by Servoy.
the class ServoyFunctionPropertyType method toJSON.
public JSONWriter toJSON(JSONWriter writer, String key, Object object, PropertyDescription pd, DataConversion clientConversion, FlattenedSolution fs, FormElement fe, WebFormComponent formComponent) throws JSONException {
Map<String, Object> map = new HashMap<>();
if (object != null && fs != null) {
// $NON-NLS-1$
String[] components = object.toString().split("-");
if (components.length == 5) {
String scriptString = null;
// this is a uuid
ScriptMethod sm = fs.getScriptMethod(object.toString());
if (sm != null) {
ISupportChilds parent = sm.getParent();
if (parent instanceof Solution) {
scriptString = "scopes." + sm.getScopeName() + "." + sm.getName();
} else if (parent instanceof Form) {
if (formComponent != null) {
// use the real, runtime form
scriptString = formComponent.getDataAdapterList().getForm().getForm().getName() + "." + sm.getName();
} else {
scriptString = ((Form) parent).getName() + "." + sm.getName();
}
} else if (parent instanceof TableNode && fe != null) {
scriptString = "entity." + fe.getForm().getName() + "." + sm.getName();
}
object = scriptString;
} else
Debug.log("can't find a scriptmethod for: " + object);
}
}
try {
if (object instanceof String) {
addScriptToMap((String) object, map);
} else if (object instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) object, map);
} else if (object instanceof FunctionWrapper && ((FunctionWrapper) object).getWrappedFunction() instanceof NativeFunction) {
nativeFunctionToJSON((NativeFunction) ((FunctionWrapper) object).getWrappedFunction(), map);
} else if (object instanceof Map) {
map = new HashMap<String, Object>((Map<String, Object>) object);
if (map.get("script") instanceof String)
addScriptToMap((String) map.get("script"), map);
}
} catch (Exception ex) {
Debug.error(ex);
}
return JSONUtils.toBrowserJSONFullValue(writer, key, map.size() == 0 ? null : map, null, clientConversion, null);
}
use of org.mozilla.javascript.NativeFunction in project BPjs by bThink-BGU.
the class ContinuationProgramState method collectJsValue.
/**
* Take a Javascript value from Rhino, build a Java value for it.
* @param jsValue
* @return
*/
private Object collectJsValue(Object jsValue) {
if (jsValue == null) {
return null;
} else if (jsValue instanceof NativeFunction) {
return ((NativeFunction) jsValue).getEncodedSource();
} else if (jsValue instanceof NativeArray) {
NativeArray jsArr = (NativeArray) jsValue;
List<Object> retVal = new ArrayList<>((int) jsArr.getLength());
for (int idx = 0; idx < jsArr.getLength(); idx++) {
retVal.add(collectJsValue(jsArr.get(idx)));
}
return retVal;
} else if (jsValue instanceof ScriptableObject) {
ScriptableObject jsObj = (ScriptableObject) jsValue;
Map<Object, Object> retVal = new HashMap<>();
for (Object key : jsObj.getIds()) {
retVal.put(key, collectJsValue(jsObj.get(key)));
}
return retVal;
} else if (jsValue instanceof ConsString) {
return ((ConsString) jsValue).toString();
} else if (jsValue instanceof NativeJavaObject) {
NativeJavaObject jsJavaObj = (NativeJavaObject) jsValue;
Object obj = jsJavaObj.unwrap();
return obj;
} else {
String cn = jsValue.getClass().getCanonicalName();
if (!cn.startsWith("java.") && (!cn.startsWith("il.ac.bgu"))) {
System.out.println("collectJsValue: blind translation to java: " + jsValue + " (" + jsValue.getClass() + ")");
}
return jsValue;
}
}
use of org.mozilla.javascript.NativeFunction in project Auto.js by hyb1996.
the class ProxyObject method put.
@Override
public void put(String name, Scriptable start, Object value) {
if (name.equals("__proxy__")) {
NativeObject proxy = (NativeObject) value;
Object getter = proxy.get("get", start);
if (getter instanceof NativeFunction) {
mGetter = (NativeFunction) getter;
}
Object setter = proxy.get("set", start);
if (setter instanceof NativeFunction) {
mSetter = (NativeFunction) setter;
}
} else if (mSetter != null) {
mSetter.call(Context.getCurrentContext(), start, start, new Object[] { name, value });
} else {
super.put(name, start, value);
}
}
Aggregations