// build a Map Map<String, String> map = new HashMap<String, String>(); map.put("bye", "now"); // Convert it to a NativeObject (yes, this could have been done directly) NativeObject nobj = new NativeObject(); for (Map.Entry<String, String> entry : map.entrySet()) { nobj.defineProperty(entry.getKey(), entry.getValue(), NativeObject.READONLY); } // Get Engine and place native object into the context ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("javascript"); engine.put("map", nobj); // Standard Javascript dot notation prints 'now' (as it should!) engine.eval("println(map.bye);");
static void init(Scriptable scope, boolean sealed) { NativeObject obj = new NativeObject(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
static void init(Scriptable scope, boolean sealed) { NativeObject obj = new NativeObject(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
NativeObject toNativeObject() { NativeObject obj = new NativeObject(); for (Map.Entry<String,String> ent : optMap.entrySet()) { obj.put(ent.getKey(), obj, ent.getValue()); } return obj; } }
NativeObject toNativeObject() { NativeObject obj = new NativeObject(); for (Map.Entry<String,String> ent : optMap.entrySet()) { obj.put(ent.getKey(), obj, ent.getValue()); } return obj; } }
static void init(Scriptable scope, boolean sealed) { NativeObject obj = new NativeObject(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
static void init(Scriptable scope, boolean sealed) { NativeObject obj = new NativeObject(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
static void init(Scriptable scope, boolean sealed) { NativeObject obj = new NativeObject(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
static void init(Scriptable scope, boolean sealed) { NativeObject obj = new NativeObject(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
@Override public Scriptable getConsoleAsScriptable(Scriptable scope) { NativeObject consoleNativeObject = new NativeObject(); Map<String, LogFunctionWrapper> functionWrapperMap = new HashMap<String, LogFunctionWrapper>(); for (Method method : Console.class.getDeclaredMethods()) { functionWrapperMap.put(method.getName(), LogFunctionWrapper.fromMethodWithDebugging(console, method, scope)); } for (Map.Entry<String, LogFunctionWrapper> stringFunctionWrapperEntry : functionWrapperMap.entrySet()) { consoleNativeObject.put(stringFunctionWrapperEntry.getKey(), consoleNativeObject, stringFunctionWrapperEntry.getValue()); } return consoleNativeObject; }
protected static ScriptableObject buildDataDescriptor(Scriptable scope, Object value, int attributes) { ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", (attributes & READONLY) == 0, EMPTY); desc.defineProperty("enumerable", (attributes & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attributes & PERMANENT) == 0, EMPTY); return desc; }
protected static ScriptableObject buildDataDescriptor(Scriptable scope, Object value, int attributes) { ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", (attributes & READONLY) == 0, EMPTY); desc.defineProperty("enumerable", (attributes & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attributes & PERMANENT) == 0, EMPTY); return desc; }
protected static ScriptableObject buildDataDescriptor(Scriptable scope, Object value, int attributes) { ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", (attributes & READONLY) == 0, EMPTY); desc.defineProperty("enumerable", (attributes & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attributes & PERMANENT) == 0, EMPTY); return desc; }
@Override ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) { int attr = getAttributes(); ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("enumerable", (attr & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attr & PERMANENT) == 0, EMPTY); if (getter != null) desc.defineProperty("get", getter, EMPTY); if (setter != null) desc.defineProperty("set", setter, EMPTY); return desc; }
@Override ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) { int attr = getAttributes(); ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("enumerable", (attr & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attr & PERMANENT) == 0, EMPTY); if (getter != null) desc.defineProperty("get", getter, EMPTY); if (setter != null) desc.defineProperty("set", setter, EMPTY); return desc; }
@Override ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) { int attr = getAttributes(); ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("enumerable", (attr & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attr & PERMANENT) == 0, EMPTY); if (getter != null) desc.defineProperty("get", getter, EMPTY); if (setter != null) desc.defineProperty("set", setter, EMPTY); return desc; }
private ScriptableObject defaultIndexPropertyDescriptor(Object value) { Scriptable scope = getParentScope(); if (scope == null) scope = this; ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", true, EMPTY); desc.defineProperty("enumerable", true, EMPTY); desc.defineProperty("configurable", true, EMPTY); return desc; }
private ScriptableObject defaultIndexPropertyDescriptor(Object value) { Scriptable scope = getParentScope(); if (scope == null) scope = this; ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", true, EMPTY); desc.defineProperty("enumerable", true, EMPTY); desc.defineProperty("configurable", true, EMPTY); return desc; }
private ScriptableObject defaultIndexPropertyDescriptor(Object value) { Scriptable scope = getParentScope(); if (scope == null) scope = this; ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", true, EMPTY); desc.defineProperty("enumerable", true, EMPTY); desc.defineProperty("configurable", true, EMPTY); return desc; }
@Override ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) { int attr = getAttributes(); ScriptableObject desc = new NativeObject(); ScriptRuntime.setBuiltinProtoAndParent(desc, scope, TopLevel.Builtins.Object); desc.defineProperty("enumerable", (attr & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attr & PERMANENT) == 0, EMPTY); if (getter != null) desc.defineProperty("get", getter, EMPTY); if (setter != null) desc.defineProperty("set", setter, EMPTY); return desc; }