use of org.mozilla.javascript.ScriptableObject in project hackpad by dropbox.
the class Bug466207Test method setUp.
@SuppressWarnings("unchecked")
@Override
protected void setUp() {
// set up a reference map
reference = new ArrayList<Object>();
reference.add("a");
reference.add(Boolean.TRUE);
reference.add(new HashMap<Object, Object>());
reference.add(new Integer(42));
reference.add("a");
// get a js object as map
Context context = Context.enter();
ScriptableObject scope = context.initStandardObjects();
list = (List<Object>) context.evaluateString(scope, "(['a', true, new java.util.HashMap(), 42, 'a']);", "testsrc", 1, null);
Context.exit();
}
use of org.mozilla.javascript.ScriptableObject in project scriptographer by scriptographer.
the class RhinoEngine method observe.
@Override
public boolean observe(Map object, Object key, PropertyObserver observer) {
if (object instanceof ScriptableObject) {
ScriptableObject obj = (ScriptableObject) object;
Context cx = Context.getCurrentContext();
PropertyDescriptor desc = obj.getOwnPropertyDescriptor(cx, key);
if (desc != null && desc.isDataDescriptor()) {
ObserverGetterSetter getterSetter = new ObserverGetterSetter(obj, key, desc, observer);
obj.defineOwnProperty(cx, key, new PropertyDescriptor(getterSetter, getterSetter, desc.isEnumerable(), desc.isConfigurable(), true));
}
return true;
}
return false;
}
use of org.mozilla.javascript.ScriptableObject in project scriptographer by scriptographer.
the class RhinoScope method put.
public Object put(String name, Object value, boolean readOnly) {
Object prev = get(name);
value = Context.javaToJS(value, scope);
if (scope instanceof ScriptableObject) {
// Remove READONLY attribute first if the field already existed,
// to make sure new value can be set
ScriptableObject scriptable = (ScriptableObject) scope;
if (scriptable.has(name, scriptable))
scriptable.setAttributes(name, ScriptableObject.EMPTY);
if (readOnly) {
scriptable.defineProperty(name, value, ScriptableObject.READONLY);
return prev;
}
}
scope.put(name, scope, value);
return prev;
}
use of org.mozilla.javascript.ScriptableObject in project scriptographer by scriptographer.
the class TopLevel method initStandardObjects.
public void initStandardObjects(Context cx, boolean sealed) {
super.initStandardObjects(cx, sealed);
for (int i = 0; i != topPackages.length; i += 2) new LazilyLoadedCtor(this, topPackages[i], topPackages[i + 1], false);
// define some global functions and objects:
String[] names = { "print", "evaluate" };
defineFunctionProperties(names, TopLevel.class, ScriptableObject.DONTENUM);
ScriptableObject objProto = (ScriptableObject) getObjectPrototype(this);
objProto.defineFunctionProperties(new String[] { "dontEnum", "toJava", "print", "evaluate" }, TopLevel.class, DONTENUM);
}
use of org.mozilla.javascript.ScriptableObject in project scriptographer by scriptographer.
the class TopLevel method defineProperty.
public static void defineProperty(ScriptableObject obj, String name, String getter, String setter) throws SecurityException, NoSuchMethodException {
Class<? extends ScriptableObject> cls = obj.getClass();
Method getterMethod = getter != null ? cls.getDeclaredMethod(getter, new Class[] { Scriptable.class }) : null;
Method setterMethod = setter != null ? cls.getDeclaredMethod(setter, new Class[] { Scriptable.class, Object.class }) : null;
obj.defineProperty(name, null, getterMethod, setterMethod, ScriptableObject.DONTENUM);
}
Aggregations