org.mozilla.javascript.Undefined Java Examples
The following examples show how to use
org.mozilla.javascript.Undefined.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsRuntimeReplFactoryBuilder.java From stetho with MIT License | 6 votes |
private void importVariables(@NonNull ScriptableObject scope) throws StethoJsException { // Define the variables for (Map.Entry<String, Object> entrySet : mVariables.entrySet()) { String varName = entrySet.getKey(); Object varValue = entrySet.getValue(); try { Object jsValue; if (varValue instanceof Scriptable || varValue instanceof Undefined) { jsValue = varValue; } else { jsValue = Context.javaToJS(varValue, scope); } ScriptableObject.putProperty(scope, varName, jsValue); } catch (Exception e) { throw new StethoJsException(e, "Failed to setup variable: %s", varName); } } }
Example #2
Source File: XmlNode.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
void addToList(Object toAdd) { if (toAdd instanceof Undefined) { // Missing argument do nothing... return; } if (toAdd instanceof XMLList) { XMLList xmlSrc = (XMLList)toAdd; for (int i = 0; i < xmlSrc.length(); i++) { this._add((xmlSrc.item(i)).getAnnotation()); } } else if (toAdd instanceof XML) { this._add(((XML)(toAdd)).getAnnotation()); } else if (toAdd instanceof XmlNode) { this._add((XmlNode)toAdd); } }
Example #3
Source File: NativeRegExp.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
Scriptable compile(Context cx, Scriptable scope, Object[] args) { if (args.length > 0 && args[0] instanceof NativeRegExp) { if (args.length > 1 && args[1] != Undefined.instance) { // report error throw ScriptRuntime.typeError0("msg.bad.regexp.compile"); } NativeRegExp thatObj = (NativeRegExp) args[0]; this.re = thatObj.re; this.lastIndex = thatObj.lastIndex; return this; } String s = args.length == 0 || args[0] instanceof Undefined ? "" : escapeRegExp(args[0]); String global = args.length > 1 && args[1] != Undefined.instance ? ScriptRuntime.toString(args[1]) : null; this.re = compileRE(cx, s, global, false); this.lastIndex = 0d; return this; }
Example #4
Source File: JsGlobal.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { String key = Context.toString(args[0]); try { IConfigService config = ProxyServiceManager.getService(pkg + ".config", IConfigService.class); if (config != null) { Object ret = config.read(key); if (ret != null) { return ret.toString(); } } } catch (Exception e) { } return Undefined.instance; }
Example #5
Source File: NativeRegExp.java From astor with GNU General Public License v2.0 | 6 votes |
Scriptable compile(Context cx, Scriptable scope, Object[] args) { if (args.length > 0 && args[0] instanceof NativeRegExp) { if (args.length > 1 && args[1] != Undefined.instance) { // report error throw ScriptRuntime.typeError0("msg.bad.regexp.compile"); } NativeRegExp thatObj = (NativeRegExp) args[0]; this.re = thatObj.re; this.lastIndex = thatObj.lastIndex; return this; } String s = args.length == 0 ? "" : escapeRegExp(args[0]); String global = args.length > 1 && args[1] != Undefined.instance ? ScriptRuntime.toString(args[1]) : null; this.re = compileRE(cx, s, global, false); this.lastIndex = 0; return this; }
Example #6
Source File: JsFunction.java From spork with Apache License 2.0 | 6 votes |
private Object jsToPigMap(Scriptable object, Schema schema, int depth) { debugConvertJSToPig(depth, "Map", object, schema); Map<String, Object> map = new HashMap<String, Object>(); Object[] ids = object.getIds(); for (Object id : ids) { if (id instanceof String) { String name = (String) id; Object value = object.get(name, object); if (value instanceof NativeJavaObject) { value = ((NativeJavaObject)value).unwrap(); } else if (value instanceof Undefined) { value = null; } map.put(name, value); } } debugReturn(depth, map); return map; }
Example #7
Source File: JsFunction.java From spork with Apache License 2.0 | 6 votes |
public JsFunction(String functionName) { this.jsScriptEngine = JsScriptEngine.getInstance(); this.functionName = functionName; Object outputSchemaObj = jsScriptEngine.jsEval(this.getClass().getName() + "(String)", functionName + ".outputSchema"); //if no schema defined, fall back to bytearray if (outputSchemaObj == null || outputSchemaObj instanceof Undefined) { this.outputSchema = new Schema(new Schema.FieldSchema(null, DataType.BYTEARRAY)); } else { try { this.outputSchema = Utils.getSchemaFromString(outputSchemaObj.toString()); } catch (ParserException e) { throw new IllegalArgumentException(functionName + ".outputSchema is not a valid schema: " + e.getMessage(), e); } } }
Example #8
Source File: XmlNode.java From astor with GNU General Public License v2.0 | 6 votes |
void addToList(Object toAdd) { if (toAdd instanceof Undefined) { // Missing argument do nothing... return; } if (toAdd instanceof XMLList) { XMLList xmlSrc = (XMLList)toAdd; for (int i = 0; i < xmlSrc.length(); i++) { this._add((xmlSrc.item(i)).getAnnotation()); } } else if (toAdd instanceof XML) { this._add(((XML)(toAdd)).getAnnotation()); } else if (toAdd instanceof XmlNode) { this._add((XmlNode)toAdd); } }
Example #9
Source File: ScriptedOutgoingMapping.java From ditto with Eclipse Public License 2.0 | 5 votes |
private ExternalMessage getExternalMessageFromObject(final Adaptable adaptable, final NativeObject result) { final Object contentType = result.get(EXTERNAL_MESSAGE_CONTENT_TYPE); final Object textPayload = result.get(EXTERNAL_MESSAGE_TEXT_PAYLOAD); final Object bytePayload = result.get(EXTERNAL_MESSAGE_BYTE_PAYLOAD); final Object mappingHeaders = result.get(EXTERNAL_MESSAGE_HEADERS); final Map<String, String> headers; if (mappingHeaders != null && !(mappingHeaders instanceof Undefined)) { headers = new HashMap<>(); final Map jsHeaders = (Map) mappingHeaders; jsHeaders.forEach((key, value) -> headers.put(String.valueOf(key), String.valueOf(value))); } else { headers = Collections.emptyMap(); } final ExternalMessageBuilder messageBuilder = ExternalMessageFactory.newExternalMessageBuilder(headers); if (!(contentType instanceof Undefined)) { messageBuilder.withAdditionalHeaders(ExternalMessage.CONTENT_TYPE_HEADER, ((CharSequence) contentType).toString()); } final Optional<ByteBuffer> byteBuffer = convertToByteBuffer(bytePayload); if (byteBuffer.isPresent()) { messageBuilder.withBytes(byteBuffer.get()); } else if (!(textPayload instanceof Undefined)) { messageBuilder.withText(((CharSequence) textPayload).toString()); } else { throw MessageMappingFailedException.newBuilder("") .description("Neither <bytePayload> nor <textPayload> were defined in the outgoing script") .dittoHeaders(adaptable.getHeaders().orElse(DittoHeaders.empty())) .build(); } return messageBuilder.build(); }
Example #10
Source File: JsValue.java From birt with Eclipse Public License 1.0 | 5 votes |
static boolean isValidJsValue( Object val ) { return ( val != Scriptable.NOT_FOUND && !( val instanceof Undefined ) && !( val instanceof NativeJavaMethod ) && !( val instanceof NativeJavaConstructor ) && !( val instanceof NativeJavaPackage ) ); }
Example #11
Source File: NativeRegExp.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
private Object execSub(Context cx, Scriptable scopeObj, Object[] args, int matchType) { RegExpImpl reImpl = getImpl(cx); String str; if (args.length == 0) { str = reImpl.input; if (str == null) { str = ScriptRuntime.toString(Undefined.instance); } } else { str = ScriptRuntime.toString(args[0]); } double d = 0; if ((re.flags & JSREG_GLOB) != 0) { d = ScriptRuntime.toInteger(lastIndex); } Object rval; if (d < 0 || str.length() < d) { lastIndex = 0d; rval = null; } else { int indexp[] = { (int)d }; rval = executeRegExp(cx, scopeObj, reImpl, str, indexp, matchType); if ((re.flags & JSREG_GLOB) != 0) { lastIndex = (rval == null || rval == Undefined.instance) ? 0d : (double)indexp[0]; } } return rval; }
Example #12
Source File: JsGlobal.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { BySelector by = (BySelector) Context.jsToJava(args[0], BySelector.class); Object ret = UiDevice.getInstance().findObject(by); if (ret != null) { return ret; } return Undefined.instance; }
Example #13
Source File: JsGlobal.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { BySelector by = (BySelector) Context.jsToJava(args[0], BySelector.class); Object ret = UiDevice.getInstance().findObjects(by); if (ret != null) { return ret; } return Undefined.instance; }
Example #14
Source File: JsGlobal.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { UiDevice.getInstance().takeScreenshot( new File(Context.toString(args[0]))); return Undefined.instance; }
Example #15
Source File: JsFunction.java From spork with Apache License 2.0 | 5 votes |
private Tuple jsToPigTuple(Scriptable object, Schema schema, int depth) throws FrontendException, ExecException { debugConvertJSToPig(depth, "Tuple", object, schema); Tuple t = TupleFactory.getInstance().newTuple(schema.size()); for (int i = 0; i < schema.size(); i++) { FieldSchema field = schema.getField(i); if (object.has(field.alias, jsScriptEngine.getScope())) { Object attr = object.get(field.alias, object); Object value; if (field.type == DataType.BAG) { value = jsToPigBag((Scriptable)attr, field.schema, depth + 1); } else if (field.type == DataType.TUPLE) { value = jsToPigTuple((Scriptable)attr, field.schema, depth + 1); } else if (field.type == DataType.MAP) { value = jsToPigMap((Scriptable)attr, field.schema, depth + 1); } else if (attr instanceof NativeJavaObject) { value = ((NativeJavaObject)attr).unwrap(); } else if (attr instanceof Undefined) { value = null; } else { value = attr; } t.set(i, value); } else { if (LOG.isDebugEnabled()) { LOG.debug("X( "+field.alias+" NOT FOUND"); } } } debugReturn(depth, t); return t; }
Example #16
Source File: JsGlobal.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { try { String key = Context.toString(args[0]); String value = Context.toString(args[1]); IConfigService config = ProxyServiceManager.getService(pkg + ".config", IConfigService.class); if (config != null) { config.save(key, value); } } catch (Exception e) { } return Undefined.instance; }
Example #17
Source File: Bug687669Test.java From rhino-android with Apache License 2.0 | 5 votes |
@Test public void testEval() { // test EmptyStatement node doesn't infer with return values (in // contrast to wrapping EmptyExpression into an ExpressionStatement) assertEquals(1d, eval("1;;;;")); assertEquals(Undefined.instance, eval("(function(){1;;;;})()")); assertEquals(1d, eval("(function(){return 1;;;;})()")); }
Example #18
Source File: Rhino.java From helloiot with GNU General Public License v3.0 | 5 votes |
@Override public Object exec(String script) throws ScriptExecException { try { Context cx = Context.enter(); cx.setOptimizationLevel(-1); // always interpretive mode Object result = cx.evaluateString(scope, script, "<cmd>", 1, null); if (result instanceof Undefined) { return null; } else { return result; } } finally { Context.exit(); } }
Example #19
Source File: NativeInt16Array.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override protected Object js_get(int index) { if (checkIndex(index)) { return Undefined.instance; } return ByteIo.readInt16(arrayBuffer.buffer, (index * BYTES_PER_ELEMENT) + offset, false); }
Example #20
Source File: NativeRegExp.java From astor with GNU General Public License v2.0 | 5 votes |
private Object execSub(Context cx, Scriptable scopeObj, Object[] args, int matchType) { RegExpImpl reImpl = getImpl(cx); String str; if (args.length == 0) { str = reImpl.input; if (str == null) { reportError("msg.no.re.input.for", toString()); } } else { str = ScriptRuntime.toString(args[0]); } double d = ((re.flags & JSREG_GLOB) != 0) ? lastIndex : 0; Object rval; if (d < 0 || str.length() < d) { lastIndex = 0; rval = null; } else { int indexp[] = { (int)d }; rval = executeRegExp(cx, scopeObj, reImpl, str, indexp, matchType); if ((re.flags & JSREG_GLOB) != 0) { lastIndex = (rval == null || rval == Undefined.instance) ? 0 : indexp[0]; } } return rval; }
Example #21
Source File: Bug687669Test.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testEval() { // test EmptyStatement node doesn't infer with return values (in // contrast to wrapping EmptyExpression into an ExpressionStatement) assertEquals(1d, eval("1;;;;")); assertEquals(Undefined.instance, eval("(function(){1;;;;})()")); assertEquals(1d, eval("(function(){return 1;;;;})()")); }
Example #22
Source File: XMLName.java From astor with GNU General Public License v2.0 | 5 votes |
public Object get(Context cx) { if (xmlObject == null) { throw ScriptRuntime.undefReadError(Undefined.instance, toString()); } return xmlObject.getXMLProperty(this); }
Example #23
Source File: XMLName.java From astor with GNU General Public License v2.0 | 5 votes |
public Object set(Context cx, Object value) { if (xmlObject == null) { throw ScriptRuntime.undefWriteError(Undefined.instance, toString(), value); } // Assignment to descendants causes parse error on bad reference // and this should not be called if (isDescendants) throw Kit.codeBug(); xmlObject.putXMLProperty(this, value); return value; }
Example #24
Source File: NativeUint32Array.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override protected Object js_set(int index, Object c) { if (checkIndex(index)) { return Undefined.instance; } long val = Conversions.toUint32(c); ByteIo.writeUint32(arrayBuffer.buffer, (index * BYTES_PER_ELEMENT) + offset, val, false); return null; }
Example #25
Source File: NativeUint8Array.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override protected Object js_set(int index, Object c) { if (checkIndex(index)) { return Undefined.instance; } int val = Conversions.toUint8(c); ByteIo.writeUint8(arrayBuffer.buffer, index + offset, val); return null; }
Example #26
Source File: NativeFloat64Array.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override protected Object js_get(int index) { if (checkIndex(index)) { return Undefined.instance; } long base = ByteIo.readUint64Primitive(arrayBuffer.buffer, (index * BYTES_PER_ELEMENT) + offset, false); return Double.longBitsToDouble(base); }
Example #27
Source File: NativeFloat64Array.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override protected Object js_set(int index, Object c) { if (checkIndex(index)) { return Undefined.instance; } double val = ScriptRuntime.toNumber(c); long base = Double.doubleToLongBits(val); ByteIo.writeUint64(arrayBuffer.buffer, (index * BYTES_PER_ELEMENT) + offset, base, false); return null; }
Example #28
Source File: NativeUint8Array.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override protected Object js_get(int index) { if (checkIndex(index)) { return Undefined.instance; } return ByteIo.readUint8(arrayBuffer.buffer, index + offset); }
Example #29
Source File: NativeDataView.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
private void checkOffset(Object[] args, int pos) { if (args.length <= pos) { throw ScriptRuntime.constructError("TypeError", "missing required offset parameter"); } if (Undefined.instance.equals(args[pos])) { throw ScriptRuntime.constructError("RangeError", "invalid offset"); } }
Example #30
Source File: NativeDataView.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
private void checkValue(Object[] args, int pos) { if (args.length <= pos) { throw ScriptRuntime.constructError("TypeError", "missing required value parameter"); } if (Undefined.instance.equals(args[pos])) { throw ScriptRuntime.constructError("RangeError", "invalid value parameter"); } }