private void importConsole(@NonNull ScriptableObject scope) throws StethoJsException { // Set the `console` object try { ScriptableObject.defineClass(scope, JsConsole.class); JsConsole console = new JsConsole(scope); scope.defineProperty("console", console, ScriptableObject.DONTENUM); } catch (Exception e) { throw new StethoJsException(e, "Failed to setup javascript console"); } }
public class RJsDemo { @Test public void simpleRhinoTest() throws FileNotFoundException, IOException { Context cx = Context.enter(); final JsRuntimeSupport browserSupport = new JsRuntimeSupport(); final ScriptableObject sharedScope = cx.initStandardObjects(browserSupport, true); String[] names = { "print", "load" }; sharedScope.defineFunctionProperties(names, sharedScope.getClass(), ScriptableObject.DONTENUM); Scriptable argsObj = cx.newArray(sharedScope, new Object[] {}); sharedScope.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); cx.evaluateReader(sharedScope, new FileReader("./r.js"), "require", 1, null); cx.evaluateReader(sharedScope, new FileReader("./loader.js"), "loader", 1, null); Context.exit(); } }
public final void addAsProperty(Scriptable target) { ScriptableObject.defineProperty(target, functionName, this, ScriptableObject.DONTENUM); }
public final void addAsProperty(Scriptable target) { ScriptableObject.defineProperty(target, functionName, this, ScriptableObject.DONTENUM); }
public final void addAsProperty(Scriptable target) { ScriptableObject.defineProperty(target, functionName, this, ScriptableObject.DONTENUM); }
public final void addAsProperty(Scriptable target) { ScriptableObject.defineProperty(target, functionName, this, ScriptableObject.DONTENUM); }
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; }
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; }
@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; }
public static void init(Context cx, Scriptable scope, boolean sealed) throws RhinoException { JSAdapter obj = new JSAdapter(cx.newObject(scope)); obj.setParentScope(scope); obj.setPrototype(getFunctionPrototype(scope)); obj.isPrototype = true; ScriptableObject.defineProperty(scope, "JSAdapter", obj, ScriptableObject.DONTENUM); }
static void init(Scriptable scope, boolean sealed) { NativeMath obj = new NativeMath(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "Math", obj, ScriptableObject.DONTENUM); }
static void init(Scriptable scope, boolean sealed) { NativeJSON obj = new NativeJSON(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "JSON", obj, ScriptableObject.DONTENUM); }
static void init(Scriptable scope, boolean sealed) { NativeMath obj = new NativeMath(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "Math", obj, ScriptableObject.DONTENUM); }
static void init(Scriptable scope, boolean sealed) { NativeMath obj = new NativeMath(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "Math", obj, ScriptableObject.DONTENUM); }
static void init(Scriptable scope, boolean sealed) { NativeJSON obj = new NativeJSON(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "JSON", obj, ScriptableObject.DONTENUM); }
static void init(Scriptable scope, boolean sealed) { NativeJSON obj = new NativeJSON(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "JSON", obj, ScriptableObject.DONTENUM); }
static void init(Scriptable scope, boolean sealed) { NativeMath obj = new NativeMath(); obj.activatePrototypeMap(MAX_ID); obj.setPrototype(getObjectPrototype(scope)); obj.setParentScope(scope); if (sealed) { obj.sealObject(); } ScriptableObject.defineProperty(scope, "Math", obj, ScriptableObject.DONTENUM); }