org.mozilla.javascript.Context.getUndefinedValue()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(11.4k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.mozilla.javascript.Context.getUndefinedValue()方法的一些代码示例,展示了Context.getUndefinedValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getUndefinedValue()方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:getUndefinedValue

Context.getUndefinedValue介绍

[英]Get the singleton object that represents the JavaScript Undefined value.
[中]获取表示JavaScript未定义值的singleton对象。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

private static boolean isUndefined( Object[] ArgList, int[] iArrToCheck ) {
 for ( int i = 0; i < iArrToCheck.length; i++ ) {
  if ( ArgList[iArrToCheck[i]].equals( Context.getUndefinedValue() ) ) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: facebook/stetho

public JsRuntimeReplFactoryBuilder(@NonNull android.content.Context context) {
 mContext = context;
 // We import the app's package name by default
 mPackages.add(context.getPackageName());
 // Predefine $_ which holds the value of the last expression evaluated
 mVariables.put("$_", Context.getUndefinedValue());
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object isRegExp( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 if ( ArgList.length >= 2 ) {
  if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
   return null;
  } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
   return Context.getUndefinedValue();
  }
  String strToMatch = Context.toString( ArgList[0] );
  for ( int i = 1; i < ArgList.length; i++ ) {
   Pattern p = Pattern.compile( Context.toString( ArgList[i] ) );
   Matcher m = p.matcher( strToMatch );
   if ( m.matches() ) {
    return new Double( i );
   }
  }
 }
 return new Double( -1 );
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object week( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 try {
  if ( ArgList.length == 1 ) {
   if ( isNull( ArgList[0] ) ) {
    return new Double( Double.NaN );
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   }
   java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
   Calendar cal = Calendar.getInstance();
   cal.setTime( dArg1 );
   return new Double( cal.get( Calendar.WEEK_OF_YEAR ) );
  } else {
   throw Context.reportRuntimeError( "The function call week requires 1 argument." );
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( e.toString() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object year( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 try {
  if ( ArgList.length == 1 ) {
   if ( isNull( ArgList[0] ) ) {
    return new Double( Double.NaN );
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   }
   java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
   Calendar cal = Calendar.getInstance();
   cal.setTime( dArg1 );
   return new Double( cal.get( Calendar.YEAR ) );
  } else {
   throw Context.reportRuntimeError( "The function call year requires 1 argument." );
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( e.toString() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object month( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 try {
  if ( ArgList.length == 1 ) {
   if ( isNull( ArgList[0] ) ) {
    return new Double( Double.NaN );
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   }
   java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
   Calendar cal = Calendar.getInstance();
   cal.setTime( dArg1 );
   return new Double( cal.get( Calendar.MONTH ) );
  } else {
   throw Context.reportRuntimeError( "The function call month requires 1 argument." );
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( e.toString() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object abs( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return new Double( Double.NaN );
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   } else {
    return new Double( Math.abs( Context.toNumber( ArgList[0] ) ) );
   }
  } catch ( Exception e ) {
   return null;
  }
 } else {
  throw Context.reportRuntimeError( "The function call abs requires 1 argument." );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object floor( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return new Double( Double.NaN );
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   } else {
    return new Double( Math.floor( Context.toNumber( ArgList[0] ) ) );
   }
  } catch ( Exception e ) {
   return null;
   // throw Context.reportRuntimeError(e.toString());
  }
 } else {
  throw Context.reportRuntimeError( "The function call floor requires 1 argument." );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object trunc( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 try {
  // 1 argument: normal truncation of numbers
  //
  if ( ArgList.length == 1 ) {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   }
   // This is the truncation of a number...
   //
   Double dArg1 = (Double) Context.jsToJava( ArgList[0], Double.class );
   return Double.valueOf( Math.floor( dArg1 ) );
  } else {
   throw Context.reportRuntimeError( "The function call trunc requires 1 argument, a number." );
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( e.toString() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object ceil( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return Double.NaN;
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   } else {
    return Math.ceil( Context.toNumber( ArgList[ 0 ] ) );
   }
  } catch ( Exception e ) {
   return null;
  }
 } else {
  throw Context.reportRuntimeError( "The function call ceil requires 1 argument." );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String ltrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 try {
  if ( ArgList.length == 1 ) {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return (String) Context.getUndefinedValue();
   }
   String strValueToTrim = Context.toString( ArgList[0] );
   return strValueToTrim.replaceAll( "^\\s+", "" );
  } else {
   throw Context.reportRuntimeError( "The function call ltrim requires 1 argument." );
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( "The function call ltrim is not valid : " + e.getMessage() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String rtrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 try {
  if ( ArgList.length == 1 ) {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return (String) Context.getUndefinedValue();
   }
   String strValueToTrim = Context.toString( ArgList[0] );
   return strValueToTrim.replaceAll( "\\s+$", "" );
  } else {
   throw Context.reportRuntimeError( "The function call rtrim requires 1 argument." );
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( "The function call rtrim is not valid : " + e.getMessage() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String lower( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 String sRC = "";
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return (String) Context.getUndefinedValue();
   }
   sRC = Context.toString( ArgList[0] );
   sRC = sRC.toLowerCase();
  } catch ( Exception e ) {
   throw Context.reportRuntimeError( "The function call lower is not valid : " + e.getMessage() );
  }
 } else {
  throw Context.reportRuntimeError( "The function call lower requires 1 argument." );
 }
 return sRC;
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String upper( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 String sRC = "";
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return (String) Context.getUndefinedValue();
   }
   sRC = Context.toString( ArgList[0] );
   sRC = sRC.toUpperCase();
  } catch ( Exception e ) {
   throw Context.reportRuntimeError( "The function call upper is not valid : " + e.getMessage() );
  }
 } else {
  throw Context.reportRuntimeError( "The function call upper requires 1 argument." );
 }
 return sRC;
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object isNum( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   }
   double sArg1 = Context.toNumber( ArgList[0] );
   if ( Double.isNaN( sArg1 ) ) {
    return Boolean.FALSE;
   } else {
    return Boolean.TRUE;
   }
  } catch ( Exception e ) {
   return Boolean.FALSE;
  }
 } else {
  throw Context.reportRuntimeError( "The function call isNum requires 1 argument." );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object isDate( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return Context.getUndefinedValue();
   }
   /* java.util.Date d = (java.util.Date) */Context.jsToJava( ArgList[0], java.util.Date.class );
   return Boolean.TRUE;
  } catch ( Exception e ) {
   return Boolean.FALSE;
  }
 } else {
  throw Context.reportRuntimeError( "The function call isDate requires 1 argument." );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String replace( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 try {
  if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) {
   if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
    return null;
   } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
    return (String) Context.getUndefinedValue();
   }
   String objForReplace = Context.toString( ArgList[0] );
   for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
    objForReplace =
     objForReplace.replaceAll( Context.toString( ArgList[i] ), Context.toString( ArgList[i + 1] ) );
   }
   return objForReplace;
  } else {
   throw Context.reportRuntimeError( "The function call replace is not valid (wrong number of arguments)" );
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( "Function call replace is not valid : " + e.getMessage() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String trim( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 String sRC = "";
 if ( ArgList.length == 1 ) {
  try {
   if ( isNull( ArgList[0] ) ) {
    return null;
   } else if ( isUndefined( ArgList[0] ) ) {
    return (String) Context.getUndefinedValue();
   }
   sRC = Context.toString( ArgList[0] );
   sRC = Const.trim( sRC );
  } catch ( Exception e ) {
   throw Context.reportRuntimeError( "The function call trim is not valid : " + e.getMessage() );
  }
 } else {
  throw Context.reportRuntimeError( "The function call trim requires 1 argument." );
 }
 return sRC;
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String lpad( Context actualContext, Scriptable actualObject, Object[] ArgList,
 Function FunctionContext ) {
 // (String valueToPad, String filler, int size) {
 try {
  if ( ArgList.length == 3 ) {
   if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
    return null;
   } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
    return (String) Context.getUndefinedValue();
   }
   String valueToPad = Context.toString( ArgList[0] );
   String filler = Context.toString( ArgList[1] );
   int size = (int) Context.toNumber( ArgList[2] );
   while ( valueToPad.length() < size ) {
    valueToPad = filler + valueToPad;
   }
   return valueToPad;
  }
 } catch ( Exception e ) {
  throw Context.reportRuntimeError( "The function call lpad requires 3 arguments." );
 }
 return null;
}

代码示例来源:origin: pentaho/pentaho-kettle

public static String removeCRLF( Context actualContext, Scriptable actualObject, Object[] ArgList,
  Function FunctionContext ) {
  if ( ArgList.length == 1 ) {
   try {
    if ( isNull( ArgList[0] ) ) {
     return null;
    } else if ( isUndefined( ArgList[0] ) ) {
     return (String) Context.getUndefinedValue();
    }

    return Const.removeCRLF( Context.toString( ArgList[0] ) );
   } catch ( Exception e ) {
    throw Context.reportRuntimeError( "The function call removeCRLF is not valid" );
   }
  } else {
   throw Context.reportRuntimeError( "The function call removeCRLF is not valid" );
  }
 }
}

相关文章

微信公众号

Context类方法