一、前言
基于mozilla的js.jar包中org.mozilla.javascript.Kit系统内核类及org.mozilla.javascript.ScriptRuntime实时脚本解析执行器类,实现javascript脚本在java后台解析执行,详情参见源码示例。
二、源码说明
1. Kit系统内核类
package org.mozilla.javascript;@b@@b@import java.io.IOException;@b@import java.io.InputStream;@b@import java.io.Reader;@b@import java.lang.reflect.Method;@b@import java.util.Map;@b@@b@public class Kit@b@{@b@ private static Method Throwable_initCause = null;@b@@b@ public static Class<?> classOrNull(String className)@b@ {@b@ try@b@ {@b@ return Class.forName(className);@b@ } catch (ClassNotFoundException ex) {@b@ } catch (SecurityException ex) {@b@ }@b@ catch (LinkageError ex) {@b@ }@b@ catch (IllegalArgumentException e) {@b@ }@b@ return null;@b@ }@b@@b@ public static Class<?> classOrNull(ClassLoader loader, String className)@b@ {@b@ try@b@ {@b@ return loader.loadClass(className);@b@ } catch (ClassNotFoundException ex) {@b@ } catch (SecurityException ex) {@b@ }@b@ catch (LinkageError ex) {@b@ }@b@ catch (IllegalArgumentException e) {@b@ }@b@ return null;@b@ }@b@@b@ static Object newInstanceOrNull(Class<?> cl)@b@ {@b@ try {@b@ return cl.newInstance();@b@ } catch (SecurityException x) {@b@ } catch (LinkageError ex) {@b@ } catch (InstantiationException x) {@b@ } catch (IllegalAccessException x) {@b@ }@b@ return null;@b@ }@b@@b@ static boolean testIfCanLoadRhinoClasses(ClassLoader loader)@b@ {@b@ Class testClass = ScriptRuntime.ContextFactoryClass;@b@ Class x = classOrNull(loader, testClass.getName());@b@@b@ return (x == testClass);@b@ }@b@@b@ public static RuntimeException initCause(RuntimeException ex, Throwable cause)@b@ {@b@ if (Throwable_initCause != null) {@b@ Object[] args = { cause };@b@ try {@b@ Throwable_initCause.invoke(ex, args);@b@ }@b@ catch (Exception e) {@b@ }@b@ }@b@ return ex;@b@ }@b@@b@ public static int xDigitToInt(int c, int accumulator)@b@ {@b@ if (c <= 57) { c -= 48;@b@ if (0 <= c);@b@ }@b@ else if (c <= 70) {@b@ if (65 <= c)@b@ c -= 55;@b@@b@ }@b@ else if ((c <= 102) && @b@ (97 <= c)) {@b@ c -= 87;@b@ }@b@ else@b@ {@b@ return -1;@b@ }@b@ return (accumulator << 4 | c);@b@ }@b@@b@ public static Object addListener(Object bag, Object listener)@b@ {@b@ if (listener == null) throw new IllegalArgumentException();@b@ if (listener instanceof Object[]) throw new IllegalArgumentException();@b@@b@ if (bag == null) {@b@ bag = listener;@b@ } else if (!(bag instanceof Object[])) {@b@ bag = new Object[] { bag, listener };@b@ } else {@b@ Object[] array = (Object[])(Object[])bag;@b@ int L = array.length;@b@@b@ if (L < 2) throw new IllegalArgumentException();@b@ Object[] tmp = new Object[L + 1];@b@ System.arraycopy(array, 0, tmp, 0, L);@b@ tmp[L] = listener;@b@ bag = tmp;@b@ }@b@@b@ return bag;@b@ }@b@@b@ public static Object removeListener(Object bag, Object listener)@b@ {@b@ if (listener == null) throw new IllegalArgumentException();@b@ if (listener instanceof Object[]) throw new IllegalArgumentException();@b@@b@ if (bag == listener) {@b@ bag = null;@b@ } else if (bag instanceof Object[]) {@b@ Object[] array = (Object[])(Object[])bag;@b@ int L = array.length;@b@@b@ if (L < 2) throw new IllegalArgumentException();@b@ if (L == 2) {@b@ if (array[1] == listener)@b@ bag = array[0];@b@ else if (array[0] == listener)@b@ bag = array[1];@b@ }@b@ else {@b@ int i = L;@b@ do {@b@ --i;@b@ if (array[i] == listener) {@b@ Object[] tmp = new Object[L - 1];@b@ System.arraycopy(array, 0, tmp, 0, i);@b@ System.arraycopy(array, i + 1, tmp, i, L - i + 1);@b@ bag = tmp;@b@ break; }@b@ }@b@ while (i != 0);@b@ }@b@ }@b@@b@ return bag;@b@ }@b@@b@ public static Object getListener(Object bag, int index)@b@ {@b@ if (index == 0) {@b@ if (bag == null)@b@ return null;@b@ if (!(bag instanceof Object[]))@b@ return bag;@b@ array = (Object[])(Object[])bag;@b@@b@ if (array.length < 2) throw new IllegalArgumentException();@b@ return array[0]; }@b@ if (index == 1) {@b@ if (!(bag instanceof Object[])) {@b@ if (bag == null) throw new IllegalArgumentException();@b@ return null;@b@ }@b@ array = (Object[])(Object[])bag;@b@@b@ return array[1];@b@ }@b@@b@ Object[] array = (Object[])(Object[])bag;@b@ int L = array.length;@b@ if (L < 2) throw new IllegalArgumentException();@b@ if (index == L)@b@ return null;@b@ return array[index];@b@ }@b@@b@ static Object initHash(Map<Object, Object> h, Object key, Object initialValue)@b@ {@b@ synchronized (h) {@b@ Object current = h.get(key);@b@ if (current == null)@b@ h.put(key, initialValue);@b@ else@b@ initialValue = current;@b@ }@b@@b@ return initialValue;@b@ }@b@@b@ public static Object makeHashKeyFromPair(Object key1, Object key2)@b@ {@b@ if (key1 == null) throw new IllegalArgumentException();@b@ if (key2 == null) throw new IllegalArgumentException();@b@ return new ComplexKey(key1, key2);@b@ }@b@@b@ public static String readReader(Reader r)@b@ throws IOException@b@ {@b@ char[] buffer = new char[512];@b@ int cursor = 0;@b@ while (true) {@b@ int n = r.read(buffer, cursor, buffer.length - cursor);@b@ if (n < 0) break;@b@ cursor += n;@b@ if (cursor == buffer.length) {@b@ char[] tmp = new char[buffer.length * 2];@b@ System.arraycopy(buffer, 0, tmp, 0, cursor);@b@ buffer = tmp;@b@ }@b@ }@b@ return new String(buffer, 0, cursor);@b@ }@b@@b@ public static byte[] readStream(InputStream is, int initialBufferCapacity)@b@ throws IOException@b@ {@b@ if (initialBufferCapacity <= 0) {@b@ throw new IllegalArgumentException("Bad initialBufferCapacity: " + initialBufferCapacity);@b@ }@b@@b@ byte[] buffer = new byte[initialBufferCapacity];@b@ int cursor = 0;@b@ while (true) {@b@ int n = is.read(buffer, cursor, buffer.length - cursor);@b@ if (n < 0) break;@b@ cursor += n;@b@ if (cursor == buffer.length) {@b@ byte[] tmp = new byte[buffer.length * 2];@b@ System.arraycopy(buffer, 0, tmp, 0, cursor);@b@ buffer = tmp;@b@ }@b@ }@b@ if (cursor != buffer.length) {@b@ byte[] tmp = new byte[cursor];@b@ System.arraycopy(buffer, 0, tmp, 0, cursor);@b@ buffer = tmp;@b@ }@b@ return buffer;@b@ }@b@@b@ public static RuntimeException codeBug()@b@ throws RuntimeException@b@ {@b@ RuntimeException ex = new IllegalStateException("FAILED ASSERTION");@b@@b@ ex.printStackTrace(System.err);@b@ throw ex;@b@ }@b@@b@ static@b@ {@b@ try@b@ {@b@ Class ThrowableClass = classOrNull("java.lang.Throwable");@b@ Class[] signature = { ThrowableClass };@b@ Throwable_initCause = ThrowableClass.getMethod("initCause", signature);@b@ }@b@ catch (Exception ex)@b@ {@b@ }@b@ }@b@@b@ private static final class ComplexKey@b@ {@b@ private Object key1;@b@ private Object key2;@b@ private int hash;@b@@b@ ComplexKey(Object key1, Object key2)@b@ {@b@ this.key1 = key1;@b@ this.key2 = key2;@b@ }@b@@b@ public boolean equals(Object anotherObj)@b@ {@b@ if (!(anotherObj instanceof ComplexKey))@b@ return false;@b@ ComplexKey another = (ComplexKey)anotherObj;@b@ return ((this.key1.equals(another.key1)) && (this.key2.equals(another.key2)));@b@ }@b@@b@ public int hashCode()@b@ {@b@ if (this.hash == 0)@b@ this.hash = (this.key1.hashCode() ^ this.key2.hashCode());@b@@b@ return this.hash;@b@ }@b@ }@b@}
2. ScriptRuntime运行解析主题类
package org.mozilla.javascript;@b@@b@import java.io.PrintStream;@b@import java.io.Serializable;@b@import java.lang.reflect.Constructor;@b@import java.text.MessageFormat;@b@import java.util.Locale;@b@import java.util.MissingResourceException;@b@import java.util.ResourceBundle;@b@import org.mozilla.javascript.xml.XMLLib;@b@import org.mozilla.javascript.xml.XMLLib.Factory;@b@import org.mozilla.javascript.xml.XMLObject;@b@@b@public class ScriptRuntime@b@{@b@ public static final Class<?> BooleanClass = Kit.classOrNull("java.lang.Boolean");@b@ public static final Class<?> ByteClass = Kit.classOrNull("java.lang.Byte");@b@ public static final Class<?> CharacterClass = Kit.classOrNull("java.lang.Character");@b@ public static final Class<?> ClassClass = Kit.classOrNull("java.lang.Class");@b@ public static final Class<?> DoubleClass = Kit.classOrNull("java.lang.Double");@b@ public static final Class<?> FloatClass = Kit.classOrNull("java.lang.Float");@b@ public static final Class<?> IntegerClass = Kit.classOrNull("java.lang.Integer");@b@ public static final Class<?> LongClass = Kit.classOrNull("java.lang.Long");@b@ public static final Class<?> NumberClass = Kit.classOrNull("java.lang.Number");@b@ public static final Class<?> ObjectClass = Kit.classOrNull("java.lang.Object");@b@ public static final Class<?> ShortClass = Kit.classOrNull("java.lang.Short");@b@ public static final Class<?> StringClass = Kit.classOrNull("java.lang.String");@b@ public static final Class<?> DateClass = Kit.classOrNull("java.util.Date");@b@ public static final Class<?> ContextClass = Kit.classOrNull("org.mozilla.javascript.Context");@b@ public static final Class<?> ContextFactoryClass = Kit.classOrNull("org.mozilla.javascript.ContextFactory");@b@ public static final Class<?> FunctionClass = Kit.classOrNull("org.mozilla.javascript.Function");@b@ public static final Class<?> ScriptableObjectClass = Kit.classOrNull("org.mozilla.javascript.ScriptableObject");@b@ public static final Class<Scriptable> ScriptableClass = Scriptable.class;@b@ private static final String[] lazilyNames = { "RegExp", "org.mozilla.javascript.regexp.NativeRegExp", "Packages", "org.mozilla.javascript.NativeJavaTopPackage", "java", "org.mozilla.javascript.NativeJavaTopPackage", "javax", "org.mozilla.javascript.NativeJavaTopPackage", "org", "org.mozilla.javascript.NativeJavaTopPackage", "com", "org.mozilla.javascript.NativeJavaTopPackage", "edu", "org.mozilla.javascript.NativeJavaTopPackage", "net", "org.mozilla.javascript.NativeJavaTopPackage", "getClass", "org.mozilla.javascript.NativeJavaTopPackage", "JavaAdapter", "org.mozilla.javascript.JavaAdapter", "JavaImporter", "org.mozilla.javascript.ImporterTopLevel", "Continuation", "org.mozilla.javascript.NativeContinuation", "XML", "(xml)", "XMLList", "(xml)", "Namespace", "(xml)", "QName", "(xml)" };@b@ private static final Object LIBRARY_SCOPE_KEY = "LIBRARY_SCOPE";@b@ public static final double NaN = Double.longBitsToDouble(9221120237041090560L);@b@ public static final double negativeZero = Double.longBitsToDouble(-9223372036854775808L);@b@ public static final Double NaNobj = new Double(NaN);@b@ private static final boolean MSJVM_BUG_WORKAROUNDS = 1;@b@ private static final String DEFAULT_NS_TAG = "__default_namespace__";@b@ public static final int ENUMERATE_KEYS = 0;@b@ public static final int ENUMERATE_VALUES = 1;@b@ public static final int ENUMERATE_ARRAY = 2;@b@ public static final int ENUMERATE_KEYS_NO_ITERATOR = 3;@b@ public static final int ENUMERATE_VALUES_NO_ITERATOR = 4;@b@ public static final int ENUMERATE_ARRAY_NO_ITERATOR = 5;@b@ public static MessageProvider messageProvider = new DefaultMessageProvider(null);@b@ public static final Object[] emptyArgs = new Object[0];@b@ public static final String[] emptyStrings = new String[0];@b@@b@ public static boolean isRhinoRuntimeType(Class<?> cl)@b@ {@b@ if (cl.isPrimitive())@b@ return (cl != Character.TYPE);@b@@b@ return ((cl == StringClass) || (cl == BooleanClass) || (NumberClass.isAssignableFrom(cl)) || (ScriptableClass.isAssignableFrom(cl)));@b@ }@b@@b@ public static ScriptableObject initStandardObjects(Context cx, ScriptableObject scope, boolean sealed)@b@ {@b@ if (scope == null)@b@ scope = new NativeObject();@b@@b@ scope.associateValue(LIBRARY_SCOPE_KEY, scope);@b@ new ClassCache().associate(scope);@b@@b@ BaseFunction.init(scope, sealed);@b@ NativeObject.init(scope, sealed);@b@@b@ Scriptable objectProto = ScriptableObject.getObjectPrototype(scope);@b@@b@ Scriptable functionProto = ScriptableObject.getFunctionPrototype(scope);@b@ functionProto.setPrototype(objectProto);@b@@b@ if (scope.getPrototype() == null) {@b@ scope.setPrototype(objectProto);@b@ }@b@@b@ NativeError.init(scope, sealed);@b@ NativeGlobal.init(cx, scope, sealed);@b@@b@ NativeArray.init(scope, sealed);@b@ if (cx.getOptimizationLevel() > 0)@b@ {@b@ NativeArray.setMaximumInitialCapacity(200000);@b@ }@b@ NativeString.init(scope, sealed);@b@ NativeBoolean.init(scope, sealed);@b@ NativeNumber.init(scope, sealed);@b@ NativeDate.init(scope, sealed);@b@ NativeMath.init(scope, sealed);@b@@b@ NativeWith.init(scope, sealed);@b@ NativeCall.init(scope, sealed);@b@ NativeScript.init(scope, sealed);@b@@b@ NativeIterator.init(scope, sealed);@b@@b@ boolean withXml = (cx.hasFeature(6)) && (cx.getE4xImplementationFactory() != null);@b@@b@ for (int i = 0; i != lazilyNames.length; i += 2) {@b@ String topProperty = lazilyNames[i];@b@ String className = lazilyNames[(i + 1)];@b@ if ((!(withXml)) && (className.equals("(xml)")))@b@ break label256:@b@ if ((withXml) && (className.equals("(xml)"))) {@b@ className = cx.getE4xImplementationFactory().getImplementationClassName();@b@ }@b@@b@ new LazilyLoadedCtor(scope, topProperty, className, sealed);@b@ }@b@@b@ label256: return scope;@b@ }@b@@b@ public static ScriptableObject getLibraryScopeOrNull(Scriptable scope)@b@ {@b@ ScriptableObject libScope = (ScriptableObject)ScriptableObject.getTopScopeValue(scope, LIBRARY_SCOPE_KEY);@b@@b@ return libScope;@b@ }@b@@b@ public static boolean isJSLineTerminator(int c)@b@ {@b@ if ((c & 0xDFD0) != 0)@b@ return false;@b@@b@ return ((c == 10) || (c == 13) || (c == 8232) || (c == 8233));@b@ }@b@@b@ public static Boolean wrapBoolean(boolean b)@b@ {@b@ return ((b) ? Boolean.TRUE : Boolean.FALSE);@b@ }@b@@b@ public static Integer wrapInt(int i)@b@ {@b@ return new Integer(i);@b@ }@b@@b@ public static Number wrapNumber(double x)@b@ {@b@ if (x != x)@b@ return NaNobj;@b@@b@ return new Double(x);@b@ }@b@@b@ public static boolean toBoolean(Object val)@b@ {@b@ do@b@ {@b@ if (val instanceof Boolean)@b@ return ((Boolean)val).booleanValue();@b@ if ((val == null) || (val == Undefined.instance))@b@ return false;@b@ if (val instanceof String)@b@ return (((String)val).length() != 0);@b@ if (val instanceof Number) {@b@ double d = ((Number)val).doubleValue();@b@ return ((d == d) && (d != 0.0D));@b@ }@b@ if (!(val instanceof Scriptable)) break label148;@b@ if ((val instanceof ScriptableObject) && (((ScriptableObject)val).avoidObjectDetection()))@b@ {@b@ return false;@b@ }@b@ if (Context.getContext().isVersionECMA1())@b@ {@b@ return true;@b@ }@b@@b@ val = ((Scriptable)val).getDefaultValue(BooleanClass); }@b@ while (!(val instanceof Scriptable));@b@ throw errorWithClassName("msg.primitive.expected", val);@b@@b@ label148: warnAboutNonJSObject(val);@b@ return true;@b@ }@b@@b@ public static double toNumber(Object val)@b@ {@b@ do@b@ {@b@ if (val instanceof Number)@b@ return ((Number)val).doubleValue();@b@ if (val == null)@b@ return 0.0D;@b@ if (val == Undefined.instance)@b@ return NaN;@b@ if (val instanceof String)@b@ return toNumber((String)val);@b@ if (val instanceof Boolean)@b@ return ((((Boolean)val).booleanValue()) ? 1.0D : 0.0D);@b@ if (!(val instanceof Scriptable)) break label104;@b@ val = ((Scriptable)val).getDefaultValue(NumberClass); }@b@ while (!(val instanceof Scriptable));@b@ throw errorWithClassName("msg.primitive.expected", val);@b@@b@ label104: warnAboutNonJSObject(val);@b@ return NaN;@b@ }@b@@b@ public static double toNumber(Object[] args, int index)@b@ {@b@ return ((index < args.length) ? toNumber(args[index]) : NaN);@b@ }@b@@b@ static double stringToNumber(String s, int start, int radix)@b@ {@b@ char digitMax = '9';@b@ char lowerCaseBound = 'a';@b@ char upperCaseBound = 'A';@b@ int len = s.length();@b@ if (radix < 10)@b@ digitMax = (char)(48 + radix - 1);@b@@b@ if (radix > 10) {@b@ lowerCaseBound = (char)(97 + radix - 10);@b@ upperCaseBound = (char)(65 + radix - 10);@b@ }@b@@b@ double sum = 0.0D;@b@ for (int end = start; end < len; ++end) {@b@ int newDigit;@b@ char c = s.charAt(end);@b@@b@ if (('0' <= c) && (c <= digitMax)) {@b@ newDigit = c - '0';@b@ } else if (('a' <= c) && (c < lowerCaseBound)) {@b@ newDigit = c - 'a' + 10; } else {@b@ if (('A' > c) || (c >= upperCaseBound)) break;@b@ newDigit = c - 'A' + 10;@b@ }@b@@b@ sum = sum * radix + newDigit;@b@ }@b@ if (start == end)@b@ return NaN;@b@@b@ if (sum >= 9007199254740992.0D) {@b@ if (radix == 10)@b@ {@b@ try@b@ {@b@ return Double.valueOf(s.substring(start, end)).doubleValue();@b@ } catch (NumberFormatException nfe) {@b@ return NaN; }@b@ }@b@ if ((radix == 2) || (radix == 4) || (radix == 8) || (radix == 16) || (radix == 32))@b@ {@b@ int bitShiftInChar = 1;@b@ int digit = 0;@b@@b@ int SKIP_LEADING_ZEROS = 0;@b@ int FIRST_EXACT_53_BITS = 1;@b@ int AFTER_BIT_53 = 2;@b@ int ZEROS_AFTER_54 = 3;@b@ int MIXED_AFTER_54 = 4;@b@@b@ int state = 0;@b@ int exactBitsLimit = 53;@b@ double factor = 0.0D;@b@ boolean bit53 = false;@b@@b@ boolean bit54 = false;@b@ while (true)@b@ {@b@ if (bitShiftInChar == 1) {@b@ if (start == end)@b@ break;@b@ digit = s.charAt(start++);@b@ if ((48 <= digit) && (digit <= 57))@b@ digit -= 48;@b@ else if ((97 <= digit) && (digit <= 122))@b@ digit -= 87;@b@ else@b@ digit -= 55;@b@ bitShiftInChar = radix;@b@ }@b@ bitShiftInChar >>= 1;@b@ boolean bit = (digit & bitShiftInChar) != 0;@b@@b@ switch (state)@b@ {@b@ case 0:@b@ if (bit) {@b@ --exactBitsLimit;@b@ sum = 1.0D;@b@ state = 1; } break;@b@ case 1:@b@ sum *= 2.0D;@b@ if (bit)@b@ sum += 1.0D;@b@ --exactBitsLimit;@b@ if (exactBitsLimit == 0) {@b@ bit53 = bit;@b@ state = 2; } break;@b@ case 2:@b@ bit54 = bit;@b@ factor = 2.0D;@b@ state = 3;@b@ break;@b@ case 3:@b@ if (bit) {@b@ state = 4;@b@ }@b@@b@ case 4:@b@ factor *= 2.0D;@b@ }@b@ }@b@@b@ switch (state)@b@ {@b@ case 0:@b@ sum = 0.0D;@b@ break;@b@ case 1:@b@ case 2:@b@ break;@b@ case 3:@b@ if ((bit54 & bit53))@b@ sum += 1.0D;@b@ sum *= factor;@b@ break;@b@ case 4:@b@ if (bit54)@b@ sum += 1.0D;@b@ sum *= factor;@b@ }@b@ }@b@@b@ }@b@@b@ return sum;@b@ }@b@@b@ public static double toNumber(String s)@b@ {@b@ char startChar;@b@ char endChar;@b@ int len = s.length();@b@ int start = 0;@b@ while (true)@b@ {@b@ if (start == len)@b@ {@b@ return 0.0D;@b@ }@b@ startChar = s.charAt(start);@b@ if (!(Character.isWhitespace(startChar)))@b@ break;@b@ ++start;@b@ }@b@@b@ if (startChar == '0') {@b@ if (start + 2 < len) {@b@ int c1 = s.charAt(start + 1);@b@ if ((c1 == 120) || (c1 == 88))@b@ {@b@ return stringToNumber(s, start + 2, 16);@b@ }@b@ }@b@ } else if ((((startChar == '+') || (startChar == '-'))) && @b@ (start + 3 < len) && (s.charAt(start + 1) == '0')) {@b@ int c2 = s.charAt(start + 2);@b@ if ((c2 == 120) || (c2 == 88))@b@ {@b@ double val = stringToNumber(s, start + 3, 16);@b@ return ((startChar == '-') ? -val : val);@b@ }@b@@b@ }@b@@b@ int end = len - 1;@b@@b@ while (Character.isWhitespace(endChar = s.charAt(end)))@b@ --end;@b@ if (endChar == 'y')@b@ {@b@ if ((startChar == '+') || (startChar == '-'))@b@ ++start;@b@ if ((start + 7 == end) && (s.regionMatches(start, "Infinity", 0, 8))) {@b@ return ((startChar == '-') ? (-1.0D / 0.0D) : (1.0D / 0.0D));@b@ }@b@@b@ return NaN;@b@ }@b@@b@ String sub = s.substring(start, end + 1);@b@@b@ for (int i = sub.length() - 1; i >= 0; --i) {@b@ char c = sub.charAt(i);@b@ if (((('0' > c) || (c > '9'))) && (c != '.') && (c != 'e') && (c != 'E') && (c != '+')) { if (c == '-')@b@ {@b@ break label345: }@b@ return NaN;@b@ }@b@ }@b@ try {@b@ label345: return Double.valueOf(sub).doubleValue(); } catch (NumberFormatException ex) {@b@ }@b@ return NaN;@b@ }@b@@b@ public static Object[] padArguments(Object[] args, int count)@b@ {@b@ if (count < args.length) {@b@ return args;@b@ }@b@@b@ Object[] result = new Object[count];@b@ for (int i = 0; i < args.length; ++i) {@b@ result[i] = args[i];@b@ }@b@@b@ for (; i < count; ++i) {@b@ result[i] = Undefined.instance;@b@ }@b@@b@ return result;@b@ }@b@@b@ public static String escapeString(String s)@b@ {@b@ return escapeString(s, '"');@b@ }@b@@b@ public static String escapeString(String s, char escapeQuote)@b@ {@b@ if ((escapeQuote != '"') && (escapeQuote != '\'')) Kit.codeBug();@b@ StringBuffer sb = null;@b@@b@ int i = 0; for (int L = s.length(); i != L; ++i) {@b@ int shift;@b@ int c = s.charAt(i);@b@@b@ if ((32 <= c) && (c <= 126) && (c != escapeQuote) && (c != 92))@b@ {@b@ if (sb != null)@b@ sb.append((char)c);@b@ }@b@ else@b@ {@b@ if (sb == null) {@b@ sb = new StringBuffer(L + 3);@b@ sb.append(s);@b@ sb.setLength(i);@b@ }@b@@b@ int escape = -1;@b@ switch (c) {@b@ case 8:@b@ escape = 98; break;@b@ case 12:@b@ escape = 102; break;@b@ case 10:@b@ escape = 110; break;@b@ case 13:@b@ escape = 114; break;@b@ case 9:@b@ escape = 116; break;@b@ case 11:@b@ escape = 118; break;@b@ case 32:@b@ escape = 32; break;@b@ case 92:@b@ escape = 92;@b@ }@b@ if (escape >= 0)@b@ {@b@ sb.append('\\');@b@ sb.append((char)escape);@b@ } else if (c == escapeQuote) {@b@ sb.append('\\');@b@ sb.append(escapeQuote);@b@ }@b@ else {@b@ int hexSize;@b@ if (c < 256)@b@ {@b@ sb.append("\\x");@b@ hexSize = 2;@b@ }@b@ else {@b@ sb.append("\\u");@b@ hexSize = 4;@b@ }@b@@b@ for (shift = (hexSize - 1) * 4; shift >= 0; shift -= 4) {@b@ int digit = 0xF & c >> shift;@b@ int hc = (digit < 10) ? 48 + digit : 87 + digit;@b@ sb.append((char)hc); }@b@ }@b@ }@b@ }@b@ return ((sb == null) ? s : sb.toString());@b@ }@b@@b@ static boolean isValidIdentifierName(String s)@b@ {@b@ int L = s.length();@b@ if (L == 0)@b@ return false;@b@ if (!(Character.isJavaIdentifierStart(s.charAt(0))))@b@ return false;@b@ for (int i = 1; i != L; ++i)@b@ if (!(Character.isJavaIdentifierPart(s.charAt(i))))@b@ return false;@b@@b@ return (!(TokenStream.isKeyword(s)));@b@ }@b@@b@ public static String toString(Object val)@b@ {@b@ do@b@ {@b@ if (val == null)@b@ return "null";@b@@b@ if (val == Undefined.instance)@b@ return "undefined";@b@@b@ if (val instanceof String)@b@ return ((String)val);@b@@b@ if (val instanceof Number)@b@ {@b@ return numberToString(((Number)val).doubleValue(), 10);@b@ }@b@ if (!(val instanceof Scriptable)) break label83;@b@ val = ((Scriptable)val).getDefaultValue(StringClass); }@b@ while (!(val instanceof Scriptable));@b@ throw errorWithClassName("msg.primitive.expected", val);@b@@b@ label83: return val.toString();@b@ }@b@@b@ static String defaultObjectToString(Scriptable obj)@b@ {@b@ return "[object " + obj.getClassName() + ']';@b@ }@b@@b@ public static String toString(Object[] args, int index)@b@ {@b@ return ((index < args.length) ? toString(args[index]) : "undefined");@b@ }@b@@b@ public static String toString(double val)@b@ {@b@ return numberToString(val, 10);@b@ }@b@@b@ public static String numberToString(double d, int base) {@b@ if (d != d)@b@ return "NaN";@b@ if (d == (1.0D / 0.0D))@b@ return "Infinity";@b@ if (d == (-1.0D / 0.0D))@b@ return "-Infinity";@b@ if (d == 0.0D)@b@ return "0";@b@@b@ if ((base < 2) || (base > 36)) {@b@ throw Context.reportRuntimeError1("msg.bad.radix", Integer.toString(base));@b@ }@b@@b@ if (base != 10)@b@ return DToA.JS_dtobasestr(base, d);@b@@b@ StringBuffer result = new StringBuffer();@b@ DToA.JS_dtostr(result, 0, 0, d);@b@ return result.toString();@b@ }@b@@b@ static String uneval(Context cx, Scriptable scope, Object value)@b@ {@b@ if (value == null)@b@ return "null";@b@@b@ if (value == Undefined.instance)@b@ return "undefined";@b@@b@ if (value instanceof String) {@b@ String escaped = escapeString((String)value);@b@ StringBuffer sb = new StringBuffer(escaped.length() + 2);@b@ sb.append('"');@b@ sb.append(escaped);@b@ sb.append('"');@b@ return sb.toString();@b@ }@b@ if (value instanceof Number) {@b@ double d = ((Number)value).doubleValue();@b@ if ((d == 0.0D) && (1.0D / d < 0.0D))@b@ return "-0";@b@@b@ return toString(d);@b@ }@b@ if (value instanceof Boolean)@b@ return toString(value);@b@@b@ if (value instanceof Scriptable) {@b@ Scriptable obj = (Scriptable)value;@b@@b@ if (ScriptableObject.hasProperty(obj, "toSource")) {@b@ Object v = ScriptableObject.getProperty(obj, "toSource");@b@ if (v instanceof Function) {@b@ Function f = (Function)v;@b@ return toString(f.call(cx, scope, obj, emptyArgs));@b@ }@b@ }@b@ return toString(value);@b@ }@b@ warnAboutNonJSObject(value);@b@ return value.toString();@b@ }@b@@b@ static String defaultObjectToSource(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)@b@ {@b@ boolean toplevel;@b@ boolean iterating;@b@ Object[] ids;@b@ int i;@b@ if (cx.iterating == null) {@b@ toplevel = true;@b@ iterating = false;@b@ cx.iterating = new ObjToIntMap(31);@b@ } else {@b@ toplevel = false;@b@ iterating = cx.iterating.has(thisObj);@b@ }@b@@b@ StringBuffer result = new StringBuffer(128);@b@ if (toplevel)@b@ result.append("(");@b@@b@ result.append('{');@b@ try@b@ {@b@ if (!(iterating)) {@b@ cx.iterating.intern(thisObj);@b@ ids = thisObj.getIds();@b@ for (i = 0; i < ids.length; ++i) {@b@ Object value;@b@ Object id = ids[i];@b@@b@ if (id instanceof Integer) {@b@ int intId = ((Integer)id).intValue();@b@ value = thisObj.get(intId, thisObj);@b@ if (value == Scriptable.NOT_FOUND)@b@ break label290:@b@ if (i > 0)@b@ result.append(", ");@b@ result.append(intId);@b@ } else {@b@ String strId = (String)id;@b@ value = thisObj.get(strId, thisObj);@b@ if (value == Scriptable.NOT_FOUND)@b@ break label290:@b@ if (i > 0)@b@ result.append(", ");@b@ if (isValidIdentifierName(strId)) {@b@ result.append(strId);@b@ } else {@b@ result.append('\'');@b@ result.append(escapeString(strId, '\''));@b@@b@ result.append('\'');@b@ }@b@ }@b@ result.append(':');@b@ result.append(uneval(cx, scope, value));@b@ }@b@ }@b@ } finally {@b@ if (toplevel)@b@ label290: cx.iterating = null;@b@@b@ }@b@@b@ result.append('}');@b@ if (toplevel)@b@ result.append(')');@b@@b@ return result.toString();@b@ }@b@@b@ public static Scriptable toObject(Scriptable scope, Object val)@b@ {@b@ if (val instanceof Scriptable)@b@ return ((Scriptable)val);@b@@b@ return toObject(Context.getContext(), scope, val);@b@ }@b@@b@ public static Scriptable toObjectOrNull(Context cx, Object obj)@b@ {@b@ if (obj instanceof Scriptable)@b@ return ((Scriptable)obj);@b@ if ((obj != null) && (obj != Undefined.instance))@b@ return toObject(cx, getTopCallScope(cx), obj);@b@@b@ return null;@b@ }@b@@b@ public static Scriptable toObjectOrNull(Context cx, Object obj, Scriptable scope)@b@ {@b@ if (obj instanceof Scriptable)@b@ return ((Scriptable)obj);@b@ if ((obj != null) && (obj != Undefined.instance))@b@ return toObject(cx, scope, obj);@b@@b@ return null;@b@ }@b@@b@ /**@b@ * @deprecated@b@ */@b@ public static Scriptable toObject(Scriptable scope, Object val, Class<?> staticClass)@b@ {@b@ if (val instanceof Scriptable)@b@ return ((Scriptable)val);@b@@b@ return toObject(Context.getContext(), scope, val);@b@ }@b@@b@ public static Scriptable toObject(Context cx, Scriptable scope, Object val)@b@ {@b@ if (val instanceof Scriptable)@b@ return ((Scriptable)val);@b@@b@ if (val == null)@b@ throw typeError0("msg.null.to.object");@b@@b@ if (val == Undefined.instance)@b@ throw typeError0("msg.undef.to.object");@b@@b@ String className = (val instanceof Boolean) ? "Boolean" : (val instanceof Number) ? "Number" : (val instanceof String) ? "String" : null;@b@@b@ if (className != null) {@b@ Object[] args = { val };@b@ scope = ScriptableObject.getTopLevelScope(scope);@b@ return newObject(cx, scope, className, args);@b@ }@b@@b@ Object wrapped = cx.getWrapFactory().wrap(cx, scope, val, null);@b@ if (wrapped instanceof Scriptable)@b@ return ((Scriptable)wrapped);@b@ throw errorWithClassName("msg.invalid.type", val);@b@ }@b@@b@ /**@b@ * @deprecated@b@ */@b@ public static Scriptable toObject(Context cx, Scriptable scope, Object val, Class<?> staticClass)@b@ {@b@ return toObject(cx, scope, val);@b@ }@b@@b@ /**@b@ * @deprecated@b@ */@b@ public static Object call(Context cx, Object fun, Object thisArg, Object[] args, Scriptable scope)@b@ {@b@ if (!(fun instanceof Function))@b@ throw notFunctionError(toString(fun));@b@@b@ Function function = (Function)fun;@b@ Scriptable thisObj = toObjectOrNull(cx, thisArg);@b@ if (thisObj == null)@b@ throw undefCallError(thisObj, "function");@b@@b@ return function.call(cx, scope, thisObj, args);@b@ }@b@@b@ public static Scriptable newObject(Context cx, Scriptable scope, String constructorName, Object[] args)@b@ {@b@ scope = ScriptableObject.getTopLevelScope(scope);@b@ Function ctor = getExistingCtor(cx, scope, constructorName);@b@ if (args == null) args = emptyArgs;@b@ return ctor.construct(cx, scope, args);@b@ }@b@@b@ public static double toInteger(Object val)@b@ {@b@ return toInteger(toNumber(val));@b@ }@b@@b@ public static double toInteger(double d)@b@ {@b@ if (d != d)@b@ return 0.0D;@b@@b@ if ((d == 0.0D) || (d == (1.0D / 0.0D)) || (d == (-1.0D / 0.0D)))@b@ {@b@ return d;@b@ }@b@ if (d > 0.0D)@b@ return Math.floor(d);@b@@b@ return Math.ceil(d);@b@ }@b@@b@ public static double toInteger(Object[] args, int index) {@b@ return ((index < args.length) ? toInteger(args[index]) : 0.0D);@b@ }@b@@b@ public static int toInt32(Object val)@b@ {@b@ if (val instanceof Integer)@b@ return ((Integer)val).intValue();@b@@b@ return toInt32(toNumber(val));@b@ }@b@@b@ public static int toInt32(Object[] args, int index) {@b@ return ((index < args.length) ? toInt32(args[index]) : 0);@b@ }@b@@b@ public static int toInt32(double d) {@b@ int id = (int)d;@b@ if (id == d)@b@ {@b@ return id;@b@ }@b@@b@ if ((d != d) || (d == (1.0D / 0.0D)) || (d == (-1.0D / 0.0D)))@b@ {@b@ return 0;@b@ }@b@@b@ d = (d >= 0.0D) ? Math.floor(d) : Math.ceil(d);@b@@b@ double two32 = 4294967296.0D;@b@ d = Math.IEEEremainder(d, two32);@b@@b@ long l = ()d;@b@@b@ return (int)l;@b@ }@b@@b@ public static long toUint32(double d)@b@ {@b@ long l = ()d;@b@ if (l == d)@b@ {@b@ return (l & 0xFFFFFFFF);@b@ }@b@@b@ if ((d != d) || (d == (1.0D / 0.0D)) || (d == (-1.0D / 0.0D)))@b@ {@b@ return 0L;@b@ }@b@@b@ d = (d >= 0.0D) ? Math.floor(d) : Math.ceil(d);@b@@b@ double two32 = 4294967296.0D;@b@ l = ()Math.IEEEremainder(d, two32);@b@@b@ return (l & 0xFFFFFFFF);@b@ }@b@@b@ public static long toUint32(Object val) {@b@ return toUint32(toNumber(val));@b@ }@b@@b@ public static char toUint16(Object val)@b@ {@b@ double d = toNumber(val);@b@@b@ int i = (int)d;@b@ if (i == d) {@b@ return (char)i;@b@ }@b@@b@ if ((d != d) || (d == (1.0D / 0.0D)) || (d == (-1.0D / 0.0D)))@b@ {@b@ return ';@b@ }@b@@b@ d = (d >= 0.0D) ? Math.floor(d) : Math.ceil(d);@b@@b@ int int16 = 65536;@b@ i = (int)Math.IEEEremainder(d, int16);@b@@b@ return (char)i;@b@ }@b@@b@ public static Object setDefaultNamespace(Object namespace, Context cx)@b@ {@b@ Scriptable scope = cx.currentActivationCall;@b@ if (scope == null) {@b@ scope = getTopCallScope(cx);@b@ }@b@@b@ XMLLib xmlLib = currentXMLLib(cx);@b@ Object ns = xmlLib.toDefaultXmlNamespace(cx, namespace);@b@@b@ if (!(scope.has("__default_namespace__", scope)))@b@ {@b@ ScriptableObject.defineProperty(scope, "__default_namespace__", ns, 6);@b@ }@b@ else@b@ {@b@ scope.put("__default_namespace__", scope, ns);@b@ }@b@@b@ return Undefined.instance;@b@ }@b@@b@ public static Object searchDefaultNamespace(Context cx)@b@ {@b@ Object nsObject;@b@ Scriptable scope = cx.currentActivationCall;@b@ if (scope == null)@b@ scope = getTopCallScope(cx);@b@@b@ while (true)@b@ {@b@ Scriptable parent = scope.getParentScope();@b@ if (parent == null) {@b@ nsObject = ScriptableObject.getProperty(scope, "__default_namespace__");@b@ if (nsObject != Scriptable.NOT_FOUND) break;@b@ return null;@b@ }@b@@b@ nsObject = scope.get("__default_namespace__", scope);@b@ if (nsObject != Scriptable.NOT_FOUND)@b@ break;@b@@b@ scope = parent;@b@ }@b@ return nsObject;@b@ }@b@@b@ public static Object getTopLevelProp(Scriptable scope, String id) {@b@ scope = ScriptableObject.getTopLevelScope(scope);@b@ return ScriptableObject.getProperty(scope, id);@b@ }@b@@b@ static Function getExistingCtor(Context cx, Scriptable scope, String constructorName)@b@ {@b@ Object ctorVal = ScriptableObject.getProperty(scope, constructorName);@b@ if (ctorVal instanceof Function)@b@ return ((Function)ctorVal);@b@@b@ if (ctorVal == Scriptable.NOT_FOUND) {@b@ throw Context.reportRuntimeError1("msg.ctor.not.found", constructorName);@b@ }@b@@b@ throw Context.reportRuntimeError1("msg.not.ctor", constructorName);@b@ }@b@@b@ private static long indexFromString(String str)@b@ {@b@ int MAX_VALUE_LENGTH = 10;@b@@b@ int len = str.length();@b@ if (len > 0) {@b@ int i = 0;@b@ boolean negate = false;@b@ int c = str.charAt(0);@b@ if ((c == 45) && @b@ (len > 1)) {@b@ c = str.charAt(1);@b@ i = 1;@b@ negate = true;@b@ }@b@@b@ c -= 48;@b@ if ((0 <= c) && (c <= 9)) if (len <= ((negate) ? 11 : 10))@b@ {@b@ int index = -c;@b@ int oldIndex = 0;@b@ ++i;@b@ while ((index != 0) && @b@ (i != len)) { if ((0 > (c = str.charAt(i) - '0')) || (c > 9))@b@ break;@b@ oldIndex = index;@b@ index = 10 * index - c;@b@ ++i;@b@ }@b@@b@ if (i == len) { if (oldIndex <= -214748364) { if (oldIndex != -214748364) break label198; if (c > ((negate) ? 8 : 7)) {@b@ break label198;@b@ }@b@@b@ }@b@@b@ return (0xFFFFFFFF & ((negate) ? index : -index));@b@ }@b@ }@b@ }@b@ label198: return -1L;@b@ }@b@@b@ public static long testUint32String(String str)@b@ {@b@ int MAX_VALUE_LENGTH = 10;@b@@b@ int len = str.length();@b@ if ((1 <= len) && (len <= 10)) {@b@ int c = str.charAt(0);@b@ c -= 48;@b@ if (c == 0)@b@ {@b@ return ((len == 1) ? 0L : -1L);@b@ }@b@ if ((1 <= c) && (c <= 9)) {@b@ long v = c;@b@ for (int i = 1; i != len; ++i) {@b@ c = str.charAt(i) - '0';@b@ if ((0 > c) || (c > 9))@b@ return -1L;@b@@b@ v = 10L * v + c;@b@ }@b@@b@ if (v >>> 32 == 0L)@b@ return v;@b@ }@b@ }@b@@b@ return -1L;@b@ }@b@@b@ static Object getIndexObject(String s)@b@ {@b@ long indexTest = indexFromString(s);@b@ if (indexTest >= 0L)@b@ return new Integer((int)indexTest);@b@@b@ return s;@b@ }@b@@b@ static Object getIndexObject(double d)@b@ {@b@ int i = (int)d;@b@ if (i == d)@b@ return new Integer(i);@b@@b@ return toString(d);@b@ }@b@@b@ static String toStringIdOrIndex(Context cx, Object id)@b@ {@b@ String s;@b@ if (id instanceof Number) {@b@ double d = ((Number)id).doubleValue();@b@ int index = (int)d;@b@ if (index == d) {@b@ storeIndexResult(cx, index);@b@ return null;@b@ }@b@ return toString(id);@b@ }@b@@b@ if (id instanceof String)@b@ s = (String)id;@b@ else@b@ s = toString(id);@b@@b@ long indexTest = indexFromString(s);@b@ if (indexTest >= 0L) {@b@ storeIndexResult(cx, (int)indexTest);@b@ return null;@b@ }@b@ return s;@b@ }@b@@b@ public static Object getObjectElem(Object obj, Object elem, Context cx)@b@ {@b@ return getObjectElem(obj, elem, cx, getTopCallScope(cx));@b@ }@b@@b@ public static Object getObjectElem(Object obj, Object elem, Context cx, Scriptable scope)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj, scope);@b@ if (sobj == null)@b@ throw undefReadError(obj, elem);@b@@b@ return getObjectElem(sobj, elem, cx);@b@ }@b@@b@ public static Object getObjectElem(Scriptable obj, Object elem, Context cx)@b@ {@b@ Object result;@b@ if (obj instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)obj;@b@ return xmlObject.ecmaGet(cx, elem);@b@ }@b@@b@ String s = toStringIdOrIndex(cx, elem);@b@ if (s == null) {@b@ int index = lastIndexResult(cx);@b@ result = ScriptableObject.getProperty(obj, index);@b@ } else {@b@ result = ScriptableObject.getProperty(obj, s);@b@ }@b@@b@ if (result == Scriptable.NOT_FOUND) {@b@ result = Undefined.instance;@b@ }@b@@b@ return result;@b@ }@b@@b@ public static Object getObjectProp(Object obj, String property, Context cx)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null)@b@ throw undefReadError(obj, property);@b@@b@ return getObjectProp(sobj, property, cx);@b@ }@b@@b@ public static Object getObjectProp(Object obj, String property, Context cx, Scriptable scope)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj, scope);@b@ if (sobj == null)@b@ throw undefReadError(obj, property);@b@@b@ return getObjectProp(sobj, property, cx);@b@ }@b@@b@ public static Object getObjectProp(Scriptable obj, String property, Context cx)@b@ {@b@ if (obj instanceof XMLObject)@b@ {@b@ XMLObject xmlObject = (XMLObject)obj;@b@ return xmlObject.ecmaGet(cx, property);@b@ }@b@@b@ Object result = ScriptableObject.getProperty(obj, property);@b@ if (result == Scriptable.NOT_FOUND) {@b@ if (cx.hasFeature(11)) {@b@ Context.reportWarning(getMessage1("msg.ref.undefined.prop", property));@b@ }@b@@b@ result = Undefined.instance;@b@ }@b@@b@ return result;@b@ }@b@@b@ public static Object getObjectPropNoWarn(Object obj, String property, Context cx)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null)@b@ throw undefReadError(obj, property);@b@@b@ if (obj instanceof XMLObject)@b@ {@b@ getObjectProp(sobj, property, cx);@b@ }@b@ Object result = ScriptableObject.getProperty(sobj, property);@b@ if (result == Scriptable.NOT_FOUND)@b@ return Undefined.instance;@b@@b@ return result;@b@ }@b@@b@ public static Object getObjectIndex(Object obj, double dblIndex, Context cx)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null) {@b@ throw undefReadError(obj, toString(dblIndex));@b@ }@b@@b@ int index = (int)dblIndex;@b@ if (index == dblIndex)@b@ return getObjectIndex(sobj, index, cx);@b@@b@ String s = toString(dblIndex);@b@ return getObjectProp(sobj, s, cx);@b@ }@b@@b@ public static Object getObjectIndex(Scriptable obj, int index, Context cx)@b@ {@b@ if (obj instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)obj;@b@ return xmlObject.ecmaGet(cx, new Integer(index));@b@ }@b@@b@ Object result = ScriptableObject.getProperty(obj, index);@b@ if (result == Scriptable.NOT_FOUND) {@b@ result = Undefined.instance;@b@ }@b@@b@ return result;@b@ }@b@@b@ public static Object setObjectElem(Object obj, Object elem, Object value, Context cx)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null)@b@ throw undefWriteError(obj, elem, value);@b@@b@ return setObjectElem(sobj, elem, value, cx);@b@ }@b@@b@ public static Object setObjectElem(Scriptable obj, Object elem, Object value, Context cx)@b@ {@b@ if (obj instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)obj;@b@ xmlObject.ecmaPut(cx, elem, value);@b@ return value;@b@ }@b@@b@ String s = toStringIdOrIndex(cx, elem);@b@ if (s == null) {@b@ int index = lastIndexResult(cx);@b@ ScriptableObject.putProperty(obj, index, value);@b@ } else {@b@ ScriptableObject.putProperty(obj, s, value);@b@ }@b@@b@ return value;@b@ }@b@@b@ public static Object setObjectProp(Object obj, String property, Object value, Context cx)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null)@b@ throw undefWriteError(obj, property, value);@b@@b@ return setObjectProp(sobj, property, value, cx);@b@ }@b@@b@ public static Object setObjectProp(Scriptable obj, String property, Object value, Context cx)@b@ {@b@ if (obj instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)obj;@b@ xmlObject.ecmaPut(cx, property, value);@b@ } else {@b@ ScriptableObject.putProperty(obj, property, value);@b@ }@b@ return value;@b@ }@b@@b@ public static Object setObjectIndex(Object obj, double dblIndex, Object value, Context cx)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null) {@b@ throw undefWriteError(obj, String.valueOf(dblIndex), value);@b@ }@b@@b@ int index = (int)dblIndex;@b@ if (index == dblIndex)@b@ return setObjectIndex(sobj, index, value, cx);@b@@b@ String s = toString(dblIndex);@b@ return setObjectProp(sobj, s, value, cx);@b@ }@b@@b@ public static Object setObjectIndex(Scriptable obj, int index, Object value, Context cx)@b@ {@b@ if (obj instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)obj;@b@ xmlObject.ecmaPut(cx, new Integer(index), value);@b@ } else {@b@ ScriptableObject.putProperty(obj, index, value);@b@ }@b@ return value;@b@ }@b@@b@ public static boolean deleteObjectElem(Scriptable target, Object elem, Context cx)@b@ {@b@ boolean result;@b@ if (target instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)target;@b@ result = xmlObject.ecmaDelete(cx, elem);@b@ } else {@b@ String s = toStringIdOrIndex(cx, elem);@b@ if (s == null) {@b@ int index = lastIndexResult(cx);@b@ result = ScriptableObject.deleteProperty(target, index);@b@ } else {@b@ result = ScriptableObject.deleteProperty(target, s);@b@ }@b@ }@b@ return result;@b@ }@b@@b@ public static boolean hasObjectElem(Scriptable target, Object elem, Context cx)@b@ {@b@ boolean result;@b@ if (target instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)target;@b@ result = xmlObject.ecmaHas(cx, elem);@b@ } else {@b@ String s = toStringIdOrIndex(cx, elem);@b@ if (s == null) {@b@ int index = lastIndexResult(cx);@b@ result = ScriptableObject.hasProperty(target, index);@b@ } else {@b@ result = ScriptableObject.hasProperty(target, s);@b@ }@b@ }@b@@b@ return result;@b@ }@b@@b@ public static Object refGet(Ref ref, Context cx)@b@ {@b@ return ref.get(cx);@b@ }@b@@b@ public static Object refSet(Ref ref, Object value, Context cx)@b@ {@b@ return ref.set(cx, value);@b@ }@b@@b@ public static Object refDel(Ref ref, Context cx)@b@ {@b@ return wrapBoolean(ref.delete(cx));@b@ }@b@@b@ static boolean isSpecialProperty(String s)@b@ {@b@ return ((s.equals("__proto__")) || (s.equals("__parent__")));@b@ }@b@@b@ public static Ref specialRef(Object obj, String specialProperty, Context cx)@b@ {@b@ return SpecialRef.createSpecial(cx, obj, specialProperty);@b@ }@b@@b@ public static Object delete(Object obj, Object id, Context cx)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null) {@b@ String idStr = (id == null) ? "null" : id.toString();@b@ throw typeError2("msg.undef.prop.delete", toString(obj), idStr);@b@ }@b@ boolean result = deleteObjectElem(sobj, id, cx);@b@ return wrapBoolean(result);@b@ }@b@@b@ public static Object name(Context cx, Scriptable scope, String name)@b@ {@b@ Scriptable parent = scope.getParentScope();@b@ if (parent == null) {@b@ Object result = topScopeName(cx, scope, name);@b@ if (result == Scriptable.NOT_FOUND)@b@ throw notFoundError(scope, name);@b@@b@ return result;@b@ }@b@@b@ return nameOrFunction(cx, scope, parent, name, false);@b@ }@b@@b@ private static Object nameOrFunction(Context cx, Scriptable scope, Scriptable parentScope, String name, boolean asFunctionCall)@b@ {@b@ Scriptable thisObj = scope;@b@@b@ XMLObject firstXMLObject = null;@b@ do {@b@ if (scope instanceof NativeWith) {@b@ Scriptable withObj = scope.getPrototype();@b@ if (withObj instanceof XMLObject) {@b@ XMLObject xmlObj = (XMLObject)withObj;@b@ if (xmlObj.ecmaHas(cx, name))@b@ {@b@ thisObj = xmlObj;@b@ result = xmlObj.ecmaGet(cx, name);@b@ break label220:@b@ }@b@ if (firstXMLObject == null)@b@ firstXMLObject = xmlObj;@b@ }@b@ else {@b@ result = ScriptableObject.getProperty(withObj, name);@b@ if (result != Scriptable.NOT_FOUND)@b@ {@b@ thisObj = withObj;@b@ break label220: }@b@ }@b@ } else {@b@ if (scope instanceof NativeCall)@b@ {@b@ result = scope.get(name, scope);@b@ if (result == Scriptable.NOT_FOUND) break label160;@b@ if (!(asFunctionCall))@b@ break label220;@b@@b@ thisObj = ScriptableObject.getTopLevelScope(parentScope); break label220:@b@ }@b@@b@ result = ScriptableObject.getProperty(scope, name);@b@ if (result != Scriptable.NOT_FOUND) {@b@ thisObj = scope;@b@ break label220:@b@ }@b@ }@b@ label160: scope = parentScope;@b@ parentScope = parentScope.getParentScope(); }@b@ while (parentScope != null);@b@ Object result = topScopeName(cx, scope, name);@b@ if (result == Scriptable.NOT_FOUND) {@b@ if ((firstXMLObject == null) || (asFunctionCall)) {@b@ throw notFoundError(scope, name);@b@ }@b@@b@ result = firstXMLObject.ecmaGet(cx, name);@b@ }@b@@b@ thisObj = scope;@b@@b@ if (asFunctionCall) {@b@ if (!(result instanceof Callable))@b@ label220: throw notFunctionError(result, name);@b@@b@ storeScriptable(cx, thisObj);@b@ }@b@@b@ return result;@b@ }@b@@b@ private static Object topScopeName(Context cx, Scriptable scope, String name)@b@ {@b@ if (cx.useDynamicScope)@b@ scope = checkDynamicScope(cx.topCallScope, scope);@b@@b@ return ScriptableObject.getProperty(scope, name);@b@ }@b@@b@ public static Scriptable bind(Context cx, Scriptable scope, String id)@b@ {@b@ Scriptable firstXMLObject = null;@b@ Scriptable parent = scope.getParentScope();@b@ if (parent != null)@b@ {@b@ while (scope instanceof NativeWith) {@b@ Scriptable withObj = scope.getPrototype();@b@ if (withObj instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)withObj;@b@ if (xmlObject.ecmaHas(cx, id))@b@ return xmlObject;@b@@b@ if (firstXMLObject == null)@b@ firstXMLObject = xmlObject;@b@@b@ }@b@ else if (ScriptableObject.hasProperty(withObj, id)) {@b@ return withObj;@b@ }@b@@b@ scope = parent;@b@ parent = parent.getParentScope();@b@ if (parent == null)@b@ break label133:@b@ }@b@ do@b@ {@b@ if (ScriptableObject.hasProperty(scope, id))@b@ return scope;@b@@b@ scope = parent;@b@ parent = parent.getParentScope(); }@b@ while (parent != null);@b@ }@b@@b@ if (cx.useDynamicScope)@b@ label133: scope = checkDynamicScope(cx.topCallScope, scope);@b@@b@ if (ScriptableObject.hasProperty(scope, id)) {@b@ return scope;@b@ }@b@@b@ return firstXMLObject;@b@ }@b@@b@ public static Object setName(Scriptable bound, Object value, Context cx, Scriptable scope, String id)@b@ {@b@ if (bound != null) {@b@ if (bound instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)bound;@b@ xmlObject.ecmaPut(cx, id, value);@b@ } else {@b@ ScriptableObject.putProperty(bound, id, value);@b@ }@b@@b@ }@b@ else@b@ {@b@ if ((cx.hasFeature(11)) || (cx.hasFeature(8)))@b@ {@b@ Context.reportWarning(getMessage1("msg.assn.create.strict", id));@b@ }@b@@b@ bound = ScriptableObject.getTopLevelScope(scope);@b@ if (cx.useDynamicScope)@b@ bound = checkDynamicScope(cx.topCallScope, bound);@b@@b@ bound.put(id, bound, value);@b@ }@b@ return value;@b@ }@b@@b@ public static Object setConst(Scriptable bound, Object value, Context cx, String id)@b@ {@b@ if (bound instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)bound;@b@ xmlObject.ecmaPut(cx, id, value);@b@ } else {@b@ ScriptableObject.putConstProperty(bound, id, value);@b@ }@b@ return value;@b@ }@b@@b@ public static Scriptable toIterator(Context cx, Scriptable scope, Scriptable obj, boolean keyOnly)@b@ {@b@ if (ScriptableObject.hasProperty(obj, "__iterator__"))@b@ {@b@ Object v = ScriptableObject.getProperty(obj, "__iterator__");@b@@b@ if (!(v instanceof Callable))@b@ throw typeError0("msg.invalid.iterator");@b@@b@ Callable f = (Callable)v;@b@ Object[] args = { (keyOnly) ? Boolean.TRUE : Boolean.FALSE };@b@@b@ v = f.call(cx, scope, obj, args);@b@ if (!(v instanceof Scriptable))@b@ throw typeError0("msg.iterator.primitive");@b@@b@ return ((Scriptable)v);@b@ }@b@ return null;@b@ }@b@@b@ public static Object enumInit(Object value, Context cx, boolean enumValues)@b@ {@b@ return enumInit(value, cx, (enumValues) ? 1 : 0);@b@ }@b@@b@ public static Object enumInit(Object value, Context cx, int enumType)@b@ {@b@ IdEnumeration x = new IdEnumeration(null);@b@ x.obj = toObjectOrNull(cx, value);@b@ if (x.obj == null)@b@ {@b@ return x;@b@ }@b@ x.enumType = enumType;@b@ x.iterator = null;@b@ if ((enumType != 3) && (enumType != 4) && (enumType != 5))@b@ {@b@ x.iterator = toIterator(cx, x.obj.getParentScope(), x.obj, true);@b@ }@b@ if (x.iterator == null)@b@ {@b@ enumChangeObject(x);@b@ }@b@@b@ return x;@b@ }@b@@b@ public static void setEnumNumbers(Object enumObj, boolean enumNumbers) {@b@ ((IdEnumeration)enumObj).enumNumbers = enumNumbers;@b@ }@b@@b@ public static Boolean enumNext(Object enumObj)@b@ {@b@ label217: int intId;@b@ IdEnumeration x = (IdEnumeration)enumObj;@b@ if (x.iterator != null) {@b@ Object v = ScriptableObject.getProperty(x.iterator, "next");@b@ if (!(v instanceof Callable))@b@ return Boolean.FALSE;@b@ Callable f = (Callable)v;@b@ Context cx = Context.getContext();@b@ try {@b@ x.currentId = f.call(cx, x.iterator.getParentScope(), x.iterator, emptyArgs);@b@@b@ return Boolean.TRUE;@b@ } catch (JavaScriptException e) {@b@ if (e.getValue() instanceof NativeIterator.StopIteration)@b@ return Boolean.FALSE;@b@@b@ throw e; } }@b@ while (true) {@b@ Object id;@b@ String strId;@b@ while (true) { while (true) { while (true) { if (x.obj == null)@b@ return Boolean.FALSE;@b@@b@ if (x.index != x.ids.length) break;@b@ x.obj = x.obj.getPrototype();@b@ enumChangeObject(x);@b@ }@b@@b@ id = x.ids[(x.index++)];@b@ if ((x.used == null) || (!(x.used.has(id))))@b@ break;@b@ }@b@ if (!(id instanceof String)) break label217;@b@ strId = (String)id;@b@ if (x.obj.has(strId, x.obj)) break;@b@ }@b@ x.currentId = strId;@b@ break label271:@b@ intId = ((Number)id).intValue();@b@ if (x.obj.has(intId, x.obj)) break;@b@ }@b@ x.currentId = ((x.enumNumbers) ? new Integer(intId) : String.valueOf(intId));@b@@b@ label271: return Boolean.TRUE;@b@ }@b@@b@ public static Object enumId(Object enumObj, Context cx)@b@ {@b@ IdEnumeration x = (IdEnumeration)enumObj;@b@ if (x.iterator != null)@b@ return x.currentId;@b@@b@ switch (x.enumType)@b@ {@b@ case 0:@b@ case 3:@b@ return x.currentId;@b@ case 1:@b@ case 4:@b@ return enumValue(enumObj, cx);@b@ case 2:@b@ case 5:@b@ Object[] elements = { x.currentId, enumValue(enumObj, cx) };@b@ return cx.newArray(x.obj, elements);@b@ }@b@ throw Kit.codeBug();@b@ }@b@@b@ public static Object enumValue(Object enumObj, Context cx)@b@ {@b@ Object result;@b@ IdEnumeration x = (IdEnumeration)enumObj;@b@@b@ String s = toStringIdOrIndex(cx, x.currentId);@b@ if (s == null) {@b@ int index = lastIndexResult(cx);@b@ result = x.obj.get(index, x.obj);@b@ } else {@b@ result = x.obj.get(s, x.obj);@b@ }@b@@b@ return result;@b@ }@b@@b@ private static void enumChangeObject(IdEnumeration x)@b@ {@b@ Object[] previous;@b@ int i;@b@ Object[] ids = null;@b@ while (x.obj != null) {@b@ ids = x.obj.getIds();@b@ if (ids.length != 0)@b@ break;@b@@b@ x.obj = x.obj.getPrototype();@b@ }@b@ if ((x.obj != null) && (x.ids != null)) {@b@ previous = x.ids;@b@ int L = previous.length;@b@ if (x.used == null)@b@ x.used = new ObjToIntMap(L);@b@@b@ for (i = 0; i != L; ++i)@b@ x.used.intern(previous[i]);@b@ }@b@@b@ x.ids = ids;@b@ x.index = 0;@b@ }@b@@b@ public static Callable getNameFunctionAndThis(String name, Context cx, Scriptable scope)@b@ {@b@ Scriptable parent = scope.getParentScope();@b@ if (parent == null) {@b@ Object result = topScopeName(cx, scope, name);@b@ if (!(result instanceof Callable)) {@b@ if (result == Scriptable.NOT_FOUND)@b@ throw notFoundError(scope, name);@b@@b@ throw notFunctionError(result, name);@b@ }@b@@b@ Scriptable thisObj = scope;@b@ storeScriptable(cx, thisObj);@b@ return ((Callable)result);@b@ }@b@@b@ return ((Callable)nameOrFunction(cx, scope, parent, name, true));@b@ }@b@@b@ public static Callable getElemFunctionAndThis(Object obj, Object elem, Context cx)@b@ {@b@ Object value;@b@ String s = toStringIdOrIndex(cx, elem);@b@ if (s != null)@b@ return getPropFunctionAndThis(obj, s, cx);@b@@b@ int index = lastIndexResult(cx);@b@@b@ Scriptable thisObj = toObjectOrNull(cx, obj);@b@ if (thisObj == null) {@b@ throw undefCallError(obj, String.valueOf(index));@b@ }@b@@b@ while (true)@b@ {@b@ value = ScriptableObject.getProperty(thisObj, index);@b@ if (value != Scriptable.NOT_FOUND)@b@ break;@b@@b@ if (!(thisObj instanceof XMLObject))@b@ break;@b@@b@ XMLObject xmlObject = (XMLObject)thisObj;@b@ Scriptable extra = xmlObject.getExtraMethodSource(cx);@b@ if (extra == null)@b@ break;@b@@b@ thisObj = extra;@b@ }@b@ if (!(value instanceof Callable)) {@b@ throw notFunctionError(value, elem);@b@ }@b@@b@ storeScriptable(cx, thisObj);@b@ return ((Callable)value);@b@ }@b@@b@ public static Callable getPropFunctionAndThis(Object obj, String property, Context cx)@b@ {@b@ Scriptable thisObj = toObjectOrNull(cx, obj);@b@ return getPropFunctionAndThisHelper(obj, property, cx, thisObj);@b@ }@b@@b@ public static Callable getPropFunctionAndThis(Object obj, String property, Context cx, Scriptable scope)@b@ {@b@ Scriptable thisObj = toObjectOrNull(cx, obj, scope);@b@ return getPropFunctionAndThisHelper(obj, property, cx, thisObj);@b@ }@b@@b@ private static Callable getPropFunctionAndThisHelper(Object obj, String property, Context cx, Scriptable thisObj)@b@ {@b@ Object value;@b@ if (thisObj == null) {@b@ throw undefCallError(obj, property);@b@ }@b@@b@ while (true)@b@ {@b@ value = ScriptableObject.getProperty(thisObj, property);@b@ if (value != Scriptable.NOT_FOUND)@b@ break;@b@@b@ if (!(thisObj instanceof XMLObject))@b@ break;@b@@b@ XMLObject xmlObject = (XMLObject)thisObj;@b@ Scriptable extra = xmlObject.getExtraMethodSource(cx);@b@ if (extra == null)@b@ break;@b@@b@ thisObj = extra;@b@ }@b@@b@ if (!(value instanceof Callable)) {@b@ Object noSuchMethod = ScriptableObject.getProperty(thisObj, "__noSuchMethod__");@b@ if (noSuchMethod instanceof Callable)@b@ value = new NoSuchMethodShim((Callable)noSuchMethod, property);@b@ else@b@ throw notFunctionError(thisObj, value, property);@b@ }@b@@b@ storeScriptable(cx, thisObj);@b@ return ((Callable)value);@b@ }@b@@b@ public static Callable getValueFunctionAndThis(Object value, Context cx)@b@ {@b@ if (!(value instanceof Callable)) {@b@ throw notFunctionError(value);@b@ }@b@@b@ Callable f = (Callable)value;@b@ Scriptable thisObj = null;@b@ if (f instanceof Scriptable)@b@ thisObj = ((Scriptable)f).getParentScope();@b@@b@ if (thisObj == null) {@b@ if (cx.topCallScope == null) throw new IllegalStateException();@b@ thisObj = cx.topCallScope;@b@ }@b@ if (thisObj.getParentScope() != null) {@b@ if (thisObj instanceof NativeWith) { break label91:@b@ }@b@@b@ if (thisObj instanceof NativeCall)@b@ {@b@ thisObj = ScriptableObject.getTopLevelScope(thisObj);@b@ }@b@ }@b@ label91: storeScriptable(cx, thisObj);@b@ return f;@b@ }@b@@b@ public static Ref callRef(Callable function, Scriptable thisObj, Object[] args, Context cx)@b@ {@b@ if (function instanceof RefCallable) {@b@ RefCallable rfunction = (RefCallable)function;@b@ Ref ref = rfunction.refCall(cx, thisObj, args);@b@ if (ref == null)@b@ throw new IllegalStateException(rfunction.getClass().getName() + ".refCall() returned null");@b@@b@ return ref;@b@ }@b@@b@ String msg = getMessage1("msg.no.ref.from.function", toString(function));@b@@b@ throw constructError("ReferenceError", msg);@b@ }@b@@b@ public static Scriptable newObject(Object fun, Context cx, Scriptable scope, Object[] args)@b@ {@b@ if (!(fun instanceof Function))@b@ throw notFunctionError(fun);@b@@b@ Function function = (Function)fun;@b@ return function.construct(cx, scope, args);@b@ }@b@@b@ public static Object callSpecial(Context cx, Callable fun, Scriptable thisObj, Object[] args, Scriptable scope, Scriptable callerThis, int callType, String filename, int lineNumber)@b@ {@b@ if (callType == 1) {@b@ if (!(NativeGlobal.isEvalFunction(fun))) break label54;@b@ return evalSpecial(cx, scope, callerThis, args, filename, lineNumber);@b@ }@b@@b@ if (callType == 2) {@b@ if (!(NativeWith.isWithFunction(fun))) break label54;@b@ throw Context.reportRuntimeError1("msg.only.from.new", "With");@b@ }@b@@b@ throw Kit.codeBug();@b@@b@ label54: return fun.call(cx, scope, thisObj, args);@b@ }@b@@b@ public static Object newSpecial(Context cx, Object fun, Object[] args, Scriptable scope, int callType)@b@ {@b@ if (callType == 1) {@b@ if (!(NativeGlobal.isEvalFunction(fun))) break label46;@b@ throw typeError1("msg.not.ctor", "eval");@b@ }@b@ if (callType == 2) {@b@ if (!(NativeWith.isWithFunction(fun))) break label46;@b@ return NativeWith.newWithSpecial(cx, scope, args);@b@ }@b@@b@ throw Kit.codeBug();@b@@b@ label46: return newObject(fun, cx, scope, args);@b@ }@b@@b@ public static Object applyOrCall(boolean isApply, Context cx, Scriptable scope, Scriptable thisObj, Object[] args)@b@ {@b@ Object[] callArgs;@b@ int L = args.length;@b@ Callable function = getCallable(thisObj);@b@@b@ Scriptable callThis = null;@b@ if (L != 0)@b@ callThis = toObjectOrNull(cx, args[0]);@b@@b@ if (callThis == null)@b@ {@b@ callThis = getTopCallScope(cx);@b@ }@b@@b@ if (isApply)@b@ {@b@ callArgs = (L <= 1) ? emptyArgs : getApplyArguments(cx, args[1]);@b@ }@b@ else if (L <= 1) {@b@ callArgs = emptyArgs;@b@ } else {@b@ callArgs = new Object[L - 1];@b@ System.arraycopy(args, 1, callArgs, 0, L - 1);@b@ }@b@@b@ return function.call(cx, scope, callThis, callArgs);@b@ }@b@@b@ static Object[] getApplyArguments(Context cx, Object arg1)@b@ {@b@ if ((arg1 == null) || (arg1 == Undefined.instance))@b@ return emptyArgs;@b@ if ((arg1 instanceof NativeArray) || (arg1 instanceof Arguments))@b@ return cx.getElements((Scriptable)arg1);@b@@b@ throw typeError0("msg.arg.isnt.array");@b@ }@b@@b@ static Callable getCallable(Scriptable thisObj)@b@ {@b@ Callable function;@b@ if (thisObj instanceof Callable) {@b@ function = (Callable)thisObj;@b@ } else {@b@ Object value = thisObj.getDefaultValue(FunctionClass);@b@ if (!(value instanceof Callable))@b@ throw notFunctionError(value, thisObj);@b@@b@ function = (Callable)value;@b@ }@b@ return function;@b@ }@b@@b@ public static Object evalSpecial(Context cx, Scriptable scope, Object thisArg, Object[] args, String filename, int lineNumber)@b@ {@b@ if (args.length < 1)@b@ return Undefined.instance;@b@ Object x = args[0];@b@ if (!(x instanceof String)) {@b@ if ((cx.hasFeature(11)) || (cx.hasFeature(9)))@b@ {@b@ throw Context.reportRuntimeError0("msg.eval.nonstring.strict");@b@ }@b@ String message = getMessage0("msg.eval.nonstring");@b@ Context.reportWarning(message);@b@ return x;@b@ }@b@ if (filename == null) {@b@ int[] linep = new int[1];@b@ filename = Context.getSourcePositionFromStack(linep);@b@ if (filename != null)@b@ lineNumber = linep[0];@b@ else@b@ filename = "";@b@ }@b@@b@ String sourceName = makeUrlForGeneratedScript(true, filename, lineNumber);@b@@b@ ErrorReporter reporter = DefaultErrorReporter.forEval(cx.getErrorReporter());@b@@b@ Evaluator evaluator = Context.createInterpreter();@b@ if (evaluator == null) {@b@ throw new JavaScriptException("Interpreter not present", filename, lineNumber);@b@ }@b@@b@ Script script = cx.compileString((String)x, evaluator, reporter, sourceName, 1, null);@b@@b@ evaluator.setEvalScriptFlag(script);@b@ Callable c = (Callable)script;@b@ return c.call(cx, scope, (Scriptable)thisArg, emptyArgs);@b@ }@b@@b@ public static String typeof(Object value)@b@ {@b@ if (value == null)@b@ return "object";@b@ if (value == Undefined.instance)@b@ return "undefined";@b@ if (value instanceof Scriptable)@b@ {@b@ if ((value instanceof ScriptableObject) && (((ScriptableObject)value).avoidObjectDetection()))@b@ {@b@ return "undefined";@b@ }@b@ if (value instanceof XMLObject)@b@ return "xml";@b@ return ((value instanceof Callable) ? "function" : "object");@b@ }@b@ if (value instanceof String)@b@ return "string";@b@ if (value instanceof Number)@b@ return "number";@b@ if (value instanceof Boolean)@b@ return "boolean";@b@ throw errorWithClassName("msg.invalid.type", value);@b@ }@b@@b@ public static String typeofName(Scriptable scope, String id)@b@ {@b@ Context cx = Context.getContext();@b@ Scriptable val = bind(cx, scope, id);@b@ if (val == null)@b@ return "undefined";@b@ return typeof(getObjectProp(val, id, cx));@b@ }@b@@b@ public static Object add(Object val1, Object val2, Context cx)@b@ {@b@ Object test;@b@ if ((val1 instanceof Number) && (val2 instanceof Number)) {@b@ return wrapNumber(((Number)val1).doubleValue() + ((Number)val2).doubleValue());@b@ }@b@@b@ if (val1 instanceof XMLObject) {@b@ test = ((XMLObject)val1).addValues(cx, true, val2);@b@ if (test != Scriptable.NOT_FOUND)@b@ return test;@b@ }@b@@b@ if (val2 instanceof XMLObject) {@b@ test = ((XMLObject)val2).addValues(cx, false, val1);@b@ if (test != Scriptable.NOT_FOUND)@b@ return test;@b@ }@b@@b@ if (val1 instanceof Scriptable)@b@ val1 = ((Scriptable)val1).getDefaultValue(null);@b@ if (val2 instanceof Scriptable)@b@ val2 = ((Scriptable)val2).getDefaultValue(null);@b@ if ((!(val1 instanceof String)) && (!(val2 instanceof String))) {@b@ if ((val1 instanceof Number) && (val2 instanceof Number)) {@b@ return wrapNumber(((Number)val1).doubleValue() + ((Number)val2).doubleValue());@b@ }@b@@b@ return wrapNumber(toNumber(val1) + toNumber(val2)); }@b@ return toString(val1).concat(toString(val2));@b@ }@b@@b@ public static String add(String val1, Object val2) {@b@ return val1.concat(toString(val2));@b@ }@b@@b@ public static String add(Object val1, String val2) {@b@ return toString(val1).concat(val2);@b@ }@b@@b@ /**@b@ * @deprecated@b@ */@b@ public static Object nameIncrDecr(Scriptable scopeChain, String id, int incrDecrMask)@b@ {@b@ return nameIncrDecr(scopeChain, id, Context.getContext(), incrDecrMask);@b@ }@b@@b@ public static Object nameIncrDecr(Scriptable scopeChain, String id, Context cx, int incrDecrMask)@b@ {@b@ Scriptable target;@b@ Object value;@b@ do@b@ {@b@ if ((cx.useDynamicScope) && (scopeChain.getParentScope() == null))@b@ scopeChain = checkDynamicScope(cx.topCallScope, scopeChain);@b@@b@ target = scopeChain;@b@ do {@b@ value = target.get(id, scopeChain);@b@ if (value != Scriptable.NOT_FOUND)@b@ break label81:@b@@b@ target = target.getPrototype(); }@b@ while (target != null);@b@ scopeChain = scopeChain.getParentScope(); }@b@ while (scopeChain != null);@b@ throw notFoundError(scopeChain, id);@b@@b@ label81: return doScriptableIncrDecr(target, id, scopeChain, value, incrDecrMask);@b@ }@b@@b@ public static Object propIncrDecr(Object obj, String id, Context cx, int incrDecrMask)@b@ {@b@ Object value;@b@ Scriptable start = toObjectOrNull(cx, obj);@b@ if (start == null) {@b@ throw undefReadError(obj, id);@b@ }@b@@b@ Scriptable target = start;@b@ do@b@ {@b@ value = target.get(id, start);@b@ if (value != Scriptable.NOT_FOUND)@b@ break label76:@b@@b@ target = target.getPrototype(); }@b@ while (target != null);@b@ start.put(id, start, NaNobj);@b@ return NaNobj;@b@@b@ label76: return doScriptableIncrDecr(target, id, start, value, incrDecrMask);@b@ }@b@@b@ private static Object doScriptableIncrDecr(Scriptable target, String id, Scriptable protoChainStart, Object value, int incrDecrMask)@b@ {@b@ double number;@b@ boolean post = (incrDecrMask & 0x2) != 0;@b@@b@ if (value instanceof Number) {@b@ number = ((Number)value).doubleValue();@b@ } else {@b@ number = toNumber(value);@b@ if (post)@b@ {@b@ value = wrapNumber(number);@b@ }@b@ }@b@ if ((incrDecrMask & 0x1) == 0)@b@ number += 1.0D;@b@ else@b@ number -= 1.0D;@b@@b@ Number result = wrapNumber(number);@b@ target.put(id, protoChainStart, result);@b@ if (post)@b@ return value;@b@@b@ return result;@b@ }@b@@b@ public static Object elemIncrDecr(Object obj, Object index, Context cx, int incrDecrMask)@b@ {@b@ double number;@b@ Object value = getObjectElem(obj, index, cx);@b@ boolean post = (incrDecrMask & 0x2) != 0;@b@@b@ if (value instanceof Number) {@b@ number = ((Number)value).doubleValue();@b@ } else {@b@ number = toNumber(value);@b@ if (post)@b@ {@b@ value = wrapNumber(number);@b@ }@b@ }@b@ if ((incrDecrMask & 0x1) == 0)@b@ number += 1.0D;@b@ else@b@ number -= 1.0D;@b@@b@ Number result = wrapNumber(number);@b@ setObjectElem(obj, index, result, cx);@b@ if (post)@b@ return value;@b@@b@ return result;@b@ }@b@@b@ public static Object refIncrDecr(Ref ref, Context cx, int incrDecrMask)@b@ {@b@ double number;@b@ Object value = ref.get(cx);@b@ boolean post = (incrDecrMask & 0x2) != 0;@b@@b@ if (value instanceof Number) {@b@ number = ((Number)value).doubleValue();@b@ } else {@b@ number = toNumber(value);@b@ if (post)@b@ {@b@ value = wrapNumber(number);@b@ }@b@ }@b@ if ((incrDecrMask & 0x1) == 0)@b@ number += 1.0D;@b@ else@b@ number -= 1.0D;@b@@b@ Number result = wrapNumber(number);@b@ ref.set(cx, result);@b@ if (post)@b@ return value;@b@@b@ return result;@b@ }@b@@b@ private static Object toPrimitive(Object val)@b@ {@b@ if (!(val instanceof Scriptable))@b@ return val;@b@@b@ Scriptable s = (Scriptable)val;@b@ Object result = s.getDefaultValue(null);@b@ if (result instanceof Scriptable)@b@ throw typeError0("msg.bad.default.value");@b@ return result;@b@ }@b@@b@ public static boolean eq(Object x, Object y)@b@ {@b@ Object test;@b@ if ((x == null) || (x == Undefined.instance)) {@b@ if ((y == null) || (y == Undefined.instance))@b@ return true;@b@@b@ if (y instanceof ScriptableObject) {@b@ test = ((ScriptableObject)y).equivalentValues(x);@b@ if (test != Scriptable.NOT_FOUND)@b@ return ((Boolean)test).booleanValue();@b@ }@b@@b@ return false; }@b@ if (x instanceof Number)@b@ return eqNumber(((Number)x).doubleValue(), y);@b@ if (x instanceof String)@b@ return eqString((String)x, y);@b@ if (x instanceof Boolean) {@b@ boolean b = ((Boolean)x).booleanValue();@b@ if (y instanceof Boolean)@b@ return (b == ((Boolean)y).booleanValue());@b@@b@ if (y instanceof ScriptableObject) {@b@ Object test = ((ScriptableObject)y).equivalentValues(x);@b@ if (test != Scriptable.NOT_FOUND)@b@ return ((Boolean)test).booleanValue();@b@ }@b@@b@ return eqNumber((b) ? 1.0D : 0.0D, y); }@b@ if (x instanceof Scriptable) {@b@ if (y instanceof Scriptable) {@b@ if (x == y)@b@ return true;@b@@b@ if (x instanceof ScriptableObject) {@b@ test = ((ScriptableObject)x).equivalentValues(y);@b@ if (test != Scriptable.NOT_FOUND)@b@ return ((Boolean)test).booleanValue();@b@ }@b@@b@ if (y instanceof ScriptableObject) {@b@ test = ((ScriptableObject)y).equivalentValues(x);@b@ if (test != Scriptable.NOT_FOUND)@b@ return ((Boolean)test).booleanValue();@b@ }@b@@b@ if ((x instanceof Wrapper) && (y instanceof Wrapper))@b@ {@b@ Object unwrappedX = ((Wrapper)x).unwrap();@b@ Object unwrappedY = ((Wrapper)y).unwrap();@b@ return ((unwrappedX == unwrappedY) || ((isPrimitive(unwrappedX)) && (isPrimitive(unwrappedY)) && (eq(unwrappedX, unwrappedY))));@b@ }@b@@b@ return false; }@b@ if (y instanceof Boolean) {@b@ if (x instanceof ScriptableObject) {@b@ test = ((ScriptableObject)x).equivalentValues(y);@b@ if (test != Scriptable.NOT_FOUND)@b@ return ((Boolean)test).booleanValue();@b@ }@b@@b@ double d = (((Boolean)y).booleanValue()) ? 1.0D : 0.0D;@b@ return eqNumber(d, x); }@b@ if (y instanceof Number)@b@ return eqNumber(((Number)y).doubleValue(), x);@b@ if (y instanceof String) {@b@ return eqString((String)y, x);@b@ }@b@@b@ return false;@b@ }@b@ warnAboutNonJSObject(x);@b@ return (x == y);@b@ }@b@@b@ private static boolean isPrimitive(Object obj)@b@ {@b@ return ((obj instanceof Number) || (obj instanceof String) || (obj instanceof Boolean));@b@ }@b@@b@ static boolean eqNumber(double x, Object y)@b@ {@b@ while (true)@b@ {@b@ if ((y == null) || (y == Undefined.instance))@b@ return false;@b@ if (y instanceof Number)@b@ return (x == ((Number)y).doubleValue());@b@ if (y instanceof String)@b@ return (x == toNumber(y));@b@ if (y instanceof Boolean)@b@ return (x == ((((Boolean)y).booleanValue()) ? 1.0D : 0.0D));@b@ if (!(y instanceof Scriptable)) break;@b@ if (y instanceof ScriptableObject) {@b@ Object xval = wrapNumber(x);@b@ Object test = ((ScriptableObject)y).equivalentValues(xval);@b@ if (test != Scriptable.NOT_FOUND)@b@ return ((Boolean)test).booleanValue();@b@ }@b@@b@ y = toPrimitive(y);@b@ }@b@ warnAboutNonJSObject(y);@b@ return false;@b@ }@b@@b@ private static boolean eqString(String x, Object y)@b@ {@b@ while (true)@b@ {@b@ if ((y == null) || (y == Undefined.instance))@b@ return false;@b@ if (y instanceof String)@b@ return x.equals(y);@b@ if (y instanceof Number)@b@ return (toNumber(x) == ((Number)y).doubleValue());@b@ if (y instanceof Boolean)@b@ return (toNumber(x) == ((((Boolean)y).booleanValue()) ? 1.0D : 0.0D));@b@ if (!(y instanceof Scriptable)) break;@b@ if (y instanceof ScriptableObject) {@b@ Object test = ((ScriptableObject)y).equivalentValues(x);@b@ if (test != Scriptable.NOT_FOUND)@b@ return ((Boolean)test).booleanValue();@b@ }@b@@b@ y = toPrimitive(y);@b@ }@b@@b@ warnAboutNonJSObject(y);@b@ return false;@b@ }@b@@b@ public static boolean shallowEq(Object x, Object y)@b@ {@b@ if (x == y) {@b@ if (!(x instanceof Number)) {@b@ return true;@b@ }@b@@b@ double d = ((Number)x).doubleValue();@b@ return (d == d);@b@ }@b@ if ((x == null) || (x == Undefined.instance))@b@ return false;@b@ if (x instanceof Number) {@b@ if (!(y instanceof Number)) break label188;@b@ return (((Number)x).doubleValue() == ((Number)y).doubleValue());@b@ }@b@ if (x instanceof String) {@b@ if (!(y instanceof String)) break label188;@b@ return x.equals(y);@b@ }@b@ if (x instanceof Boolean) {@b@ if (!(y instanceof Boolean)) break label188;@b@ return x.equals(y);@b@ }@b@ if (x instanceof Scriptable) {@b@ if ((!(x instanceof Wrapper)) || (!(y instanceof Wrapper))) break label188;@b@ return (((Wrapper)x).unwrap() == ((Wrapper)y).unwrap());@b@ }@b@@b@ warnAboutNonJSObject(x);@b@ return (x == y);@b@@b@ label188: return false;@b@ }@b@@b@ public static boolean instanceOf(Object a, Object b, Context cx)@b@ {@b@ if (!(b instanceof Scriptable)) {@b@ throw typeError0("msg.instanceof.not.object");@b@ }@b@@b@ if (!(a instanceof Scriptable))@b@ return false;@b@@b@ return ((Scriptable)b).hasInstance((Scriptable)a);@b@ }@b@@b@ public static boolean jsDelegatesTo(Scriptable lhs, Scriptable rhs)@b@ {@b@ Scriptable proto = lhs.getPrototype();@b@@b@ while (proto != null) {@b@ if (proto.equals(rhs)) return true;@b@ proto = proto.getPrototype();@b@ }@b@@b@ return false;@b@ }@b@@b@ public static boolean in(Object a, Object b, Context cx)@b@ {@b@ if (!(b instanceof Scriptable)) {@b@ throw typeError0("msg.instanceof.not.object");@b@ }@b@@b@ return hasObjectElem((Scriptable)b, a, cx);@b@ }@b@@b@ public static boolean cmp_LT(Object val1, Object val2)@b@ {@b@ double d1;@b@ double d2;@b@ if ((val1 instanceof Number) && (val2 instanceof Number)) {@b@ d1 = ((Number)val1).doubleValue();@b@ d2 = ((Number)val2).doubleValue();@b@ } else {@b@ if (val1 instanceof Scriptable)@b@ val1 = ((Scriptable)val1).getDefaultValue(NumberClass);@b@ if (val2 instanceof Scriptable)@b@ val2 = ((Scriptable)val2).getDefaultValue(NumberClass);@b@ if ((val1 instanceof String) && (val2 instanceof String))@b@ return (((String)val1).compareTo((String)val2) < 0);@b@@b@ d1 = toNumber(val1);@b@ d2 = toNumber(val2);@b@ }@b@ return (d1 < d2);@b@ }@b@@b@ public static boolean cmp_LE(Object val1, Object val2)@b@ {@b@ double d1;@b@ double d2;@b@ if ((val1 instanceof Number) && (val2 instanceof Number)) {@b@ d1 = ((Number)val1).doubleValue();@b@ d2 = ((Number)val2).doubleValue();@b@ } else {@b@ if (val1 instanceof Scriptable)@b@ val1 = ((Scriptable)val1).getDefaultValue(NumberClass);@b@ if (val2 instanceof Scriptable)@b@ val2 = ((Scriptable)val2).getDefaultValue(NumberClass);@b@ if ((val1 instanceof String) && (val2 instanceof String))@b@ return (((String)val1).compareTo((String)val2) <= 0);@b@@b@ d1 = toNumber(val1);@b@ d2 = toNumber(val2);@b@ }@b@ return (d1 <= d2);@b@ }@b@@b@ public static ScriptableObject getGlobal(Context cx)@b@ {@b@ String GLOBAL_CLASS = "org.mozilla.javascript.tools.shell.Global";@b@ Class globalClass = Kit.classOrNull("org.mozilla.javascript.tools.shell.Global");@b@ if (globalClass != null)@b@ try {@b@ Class[] parm = { ContextClass };@b@ Constructor globalClassCtor = globalClass.getConstructor(parm);@b@ Object[] arg = { cx };@b@ return ((ScriptableObject)globalClassCtor.newInstance(arg));@b@ }@b@ catch (Exception e)@b@ {@b@ }@b@ return new ImporterTopLevel(cx);@b@ }@b@@b@ public static boolean hasTopCall(Context cx)@b@ {@b@ return (cx.topCallScope != null);@b@ }@b@@b@ public static Scriptable getTopCallScope(Context cx)@b@ {@b@ Scriptable scope = cx.topCallScope;@b@ if (scope == null)@b@ throw new IllegalStateException();@b@@b@ return scope;@b@ }@b@@b@ public static Object doTopCall(Callable callable, Context cx, Scriptable scope, Scriptable thisObj, Object[] args)@b@ {@b@ Object result;@b@ if (scope == null)@b@ throw new IllegalArgumentException();@b@ if (cx.topCallScope != null) { throw new IllegalStateException();@b@ }@b@@b@ cx.topCallScope = ScriptableObject.getTopLevelScope(scope);@b@ cx.useDynamicScope = cx.hasFeature(7);@b@ ContextFactory f = cx.getFactory();@b@ try@b@ {@b@ throw new IllegalStateException();@b@ }@b@ finally@b@ {@b@ cx.topCallScope = null;@b@@b@ cx.cachedXMLLib = null;@b@@b@ if (cx.currentActivationCall != null)@b@ {@b@ throw new IllegalStateException();@b@ }@b@ }@b@ return result;@b@ }@b@@b@ static Scriptable checkDynamicScope(Scriptable possibleDynamicScope, Scriptable staticTopScope)@b@ {@b@ if (possibleDynamicScope == staticTopScope)@b@ return possibleDynamicScope;@b@@b@ Scriptable proto = possibleDynamicScope;@b@ do {@b@ proto = proto.getPrototype();@b@ if (proto == staticTopScope)@b@ return possibleDynamicScope;@b@ }@b@ while (proto != null);@b@ return staticTopScope;@b@ }@b@@b@ public static void addInstructionCount(Context cx, int instructionsToAdd)@b@ {@b@ cx.instructionCount += instructionsToAdd;@b@ if (cx.instructionCount > cx.instructionThreshold)@b@ {@b@ cx.observeInstructionCount(cx.instructionCount);@b@ cx.instructionCount = 0;@b@ }@b@ }@b@@b@ public static void initScript(NativeFunction funObj, Scriptable thisObj, Context cx, Scriptable scope, boolean evalScript)@b@ {@b@ Scriptable varScope;@b@ int i;@b@ if (cx.topCallScope == null)@b@ throw new IllegalStateException();@b@@b@ int varCount = funObj.getParamAndVarCount();@b@ if (varCount != 0)@b@ {@b@ varScope = scope;@b@@b@ while (varScope instanceof NativeWith) {@b@ varScope = varScope.getParentScope();@b@ }@b@@b@ for (i = varCount; i-- != 0; ) {@b@ String name = funObj.getParamOrVarName(i);@b@ boolean isConst = funObj.getParamOrVarConst(i);@b@@b@ if (!(ScriptableObject.hasProperty(scope, name)))@b@ if (!(evalScript))@b@ {@b@ if (isConst)@b@ ScriptableObject.defineConstProperty(varScope, name);@b@ else@b@ ScriptableObject.defineProperty(varScope, name, Undefined.instance, 4);@b@@b@ }@b@ else@b@ varScope.put(name, varScope, Undefined.instance);@b@@b@ else@b@ ScriptableObject.redefineProperty(scope, name, isConst);@b@ }@b@ }@b@ }@b@@b@ public static Scriptable createFunctionActivation(NativeFunction funObj, Scriptable scope, Object[] args)@b@ {@b@ return new NativeCall(funObj, scope, args);@b@ }@b@@b@ public static void enterActivationFunction(Context cx, Scriptable scope)@b@ {@b@ if (cx.topCallScope == null)@b@ throw new IllegalStateException();@b@ NativeCall call = (NativeCall)scope;@b@ call.parentActivationCall = cx.currentActivationCall;@b@ cx.currentActivationCall = call;@b@ }@b@@b@ public static void exitActivationFunction(Context cx)@b@ {@b@ NativeCall call = cx.currentActivationCall;@b@ cx.currentActivationCall = call.parentActivationCall;@b@ call.parentActivationCall = null;@b@ }@b@@b@ static NativeCall findFunctionActivation(Context cx, Function f)@b@ {@b@ NativeCall call = cx.currentActivationCall;@b@ while (call != null) {@b@ if (call.function == f)@b@ return call;@b@ call = call.parentActivationCall;@b@ }@b@ return null;@b@ }@b@@b@ public static Scriptable newCatchScope(Throwable t, Scriptable lastCatchScope, String exceptionName, Context cx, Scriptable scope)@b@ {@b@ Object obj;@b@ boolean cacheObj;@b@ if (t instanceof JavaScriptException) {@b@ cacheObj = false;@b@ obj = ((JavaScriptException)t).getValue();@b@ } else {@b@ cacheObj = true;@b@@b@ if (lastCatchScope != null) {@b@ NativeObject last = (NativeObject)lastCatchScope;@b@ obj = last.getAssociatedValue(t);@b@ if (obj == null) { Kit.codeBug();@b@ }@b@@b@ }@b@ else@b@ {@b@ RhinoException re;@b@ String errorName;@b@ String errorMsg;@b@ Object[] args;@b@ Object wrap;@b@ Throwable javaException = null;@b@@b@ if (t instanceof EcmaError) {@b@ EcmaError ee = (EcmaError)t;@b@ re = ee;@b@ errorName = ee.getName();@b@ errorMsg = ee.getErrorMessage();@b@ } else if (t instanceof WrappedException) {@b@ WrappedException we = (WrappedException)t;@b@ re = we;@b@ javaException = we.getWrappedException();@b@ errorName = "JavaException";@b@ errorMsg = javaException.getClass().getName() + ": " + javaException.getMessage();@b@ }@b@ else if (t instanceof EvaluatorException)@b@ {@b@ EvaluatorException ee = (EvaluatorException)t;@b@ re = ee;@b@ errorName = "InternalError";@b@ errorMsg = ee.getMessage();@b@ } else if (cx.hasFeature(13))@b@ {@b@ re = new WrappedException(t);@b@ errorName = "JavaException";@b@ errorMsg = t.toString();@b@ }@b@ else@b@ {@b@ throw Kit.codeBug();@b@ }@b@@b@ String sourceUri = re.sourceName();@b@ if (sourceUri == null)@b@ sourceUri = "";@b@@b@ int line = re.lineNumber();@b@@b@ if (line > 0)@b@ args = new Object[] { errorMsg, sourceUri, new Integer(line) };@b@ else {@b@ args = new Object[] { errorMsg, sourceUri };@b@ }@b@@b@ Scriptable errorObject = cx.newObject(scope, errorName, args);@b@ ScriptableObject.putProperty(errorObject, "name", errorName);@b@@b@ if ((javaException != null) && (isVisible(cx, javaException))) {@b@ wrap = cx.getWrapFactory().wrap(cx, scope, javaException, null);@b@@b@ ScriptableObject.defineProperty(errorObject, "javaException", wrap, 5);@b@ }@b@@b@ if (isVisible(cx, re)) {@b@ wrap = cx.getWrapFactory().wrap(cx, scope, re, null);@b@ ScriptableObject.defineProperty(errorObject, "rhinoException", wrap, 5);@b@ }@b@@b@ obj = errorObject;@b@ }@b@ }@b@ NativeObject catchScopeObject = new NativeObject();@b@@b@ catchScopeObject.defineProperty(exceptionName, obj, 4);@b@@b@ if (isVisible(cx, t))@b@ {@b@ catchScopeObject.defineProperty("__exception__", Context.javaToJS(t, scope), 6);@b@ }@b@@b@ if (cacheObj)@b@ catchScopeObject.associateValue(t, obj);@b@@b@ return catchScopeObject;@b@ }@b@@b@ private static boolean isVisible(Context cx, Object obj) {@b@ ClassShutter shutter = cx.getClassShutter();@b@ return ((shutter == null) || (shutter.visibleToScripts(obj.getClass().getName())));@b@ }@b@@b@ public static Scriptable enterWith(Object obj, Context cx, Scriptable scope)@b@ {@b@ Scriptable sobj = toObjectOrNull(cx, obj);@b@ if (sobj == null)@b@ throw typeError1("msg.undef.with", toString(obj));@b@@b@ if (sobj instanceof XMLObject) {@b@ XMLObject xmlObject = (XMLObject)sobj;@b@ return xmlObject.enterWith(scope);@b@ }@b@ return new NativeWith(scope, sobj);@b@ }@b@@b@ public static Scriptable leaveWith(Scriptable scope)@b@ {@b@ NativeWith nw = (NativeWith)scope;@b@ return nw.getParentScope();@b@ }@b@@b@ public static Scriptable enterDotQuery(Object value, Scriptable scope)@b@ {@b@ if (!(value instanceof XMLObject))@b@ throw notXmlError(value);@b@@b@ XMLObject object = (XMLObject)value;@b@ return object.enterDotQuery(scope);@b@ }@b@@b@ public static Object updateDotQuery(boolean value, Scriptable scope)@b@ {@b@ NativeWith nw = (NativeWith)scope;@b@ return nw.updateDotQuery(value);@b@ }@b@@b@ public static Scriptable leaveDotQuery(Scriptable scope)@b@ {@b@ NativeWith nw = (NativeWith)scope;@b@ return nw.getParentScope();@b@ }@b@@b@ public static void setFunctionProtoAndParent(BaseFunction fn, Scriptable scope)@b@ {@b@ fn.setParentScope(scope);@b@ fn.setPrototype(ScriptableObject.getFunctionPrototype(scope));@b@ }@b@@b@ public static void setObjectProtoAndParent(ScriptableObject object, Scriptable scope)@b@ {@b@ scope = ScriptableObject.getTopLevelScope(scope);@b@ object.setParentScope(scope);@b@ Scriptable proto = ScriptableObject.getClassPrototype(scope, object.getClassName());@b@@b@ object.setPrototype(proto);@b@ }@b@@b@ public static void initFunction(Context cx, Scriptable scope, NativeFunction function, int type, boolean fromEvalCode)@b@ {@b@ String name;@b@ if (type == 1) {@b@ name = function.getFunctionName();@b@ if ((name != null) && (name.length() != 0))@b@ if (!(fromEvalCode))@b@ {@b@ ScriptableObject.defineProperty(scope, name, function, 4);@b@ }@b@ else@b@ scope.put(name, scope, function);@b@@b@ }@b@ else if (type == 3) {@b@ name = function.getFunctionName();@b@ if ((name != null) && (name.length() != 0))@b@ {@b@ while (scope instanceof NativeWith)@b@ scope = scope.getParentScope();@b@@b@ scope.put(name, scope, function);@b@ }@b@ } else {@b@ throw Kit.codeBug();@b@ }@b@ }@b@@b@ public static Scriptable newArrayLiteral(Object[] objects, int[] skipIndices, Context cx, Scriptable scope)@b@ {@b@ int SKIP_DENSITY = 2;@b@ int count = objects.length;@b@ int skipCount = 0;@b@ if (skipIndices != null)@b@ skipCount = skipIndices.length;@b@@b@ int length = count + skipCount;@b@ if ((length > 1) && (skipCount * 2 < length))@b@ {@b@ Object[] sparse;@b@ if (skipCount == 0) {@b@ sparse = objects;@b@ } else {@b@ sparse = new Object[length];@b@ skip = 0;@b@ i = 0; for (j = 0; i != length; ++i)@b@ if ((skip != skipCount) && (skipIndices[skip] == i)) {@b@ sparse[i] = Scriptable.NOT_FOUND;@b@ ++skip;@b@ }@b@ else {@b@ sparse[i] = objects[j];@b@ ++j;@b@ }@b@ }@b@ return cx.newObject(scope, "Array", sparse);@b@ }@b@@b@ Scriptable arrayObj = cx.newObject(scope, "Array", emptyArgs);@b@@b@ int skip = 0;@b@ int i = 0; for (int j = 0; i != length; ++i)@b@ if ((skip != skipCount) && (skipIndices[skip] == i)) {@b@ ++skip;@b@ }@b@ else {@b@ ScriptableObject.putProperty(arrayObj, i, objects[j]);@b@ ++j;@b@ }@b@ return arrayObj;@b@ }@b@@b@ /**@b@ * @deprecated@b@ */@b@ public static Scriptable newObjectLiteral(Object[] propertyIds, Object[] propertyValues, Context cx, Scriptable scope)@b@ {@b@ int[] getterSetters = new int[propertyIds.length];@b@ return newObjectLiteral(propertyIds, propertyValues, getterSetters, cx, scope);@b@ }@b@@b@ public static Scriptable newObjectLiteral(Object[] propertyIds, Object[] propertyValues, int[] getterSetters, Context cx, Scriptable scope)@b@ {@b@ Scriptable object = cx.newObject(scope);@b@ int i = 0; for (int end = propertyIds.length; i != end; ++i) {@b@ Object id = propertyIds[i];@b@ int getterSetter = getterSetters[i];@b@ Object value = propertyValues[i];@b@ if (id instanceof String) {@b@ if (getterSetter == 0) {@b@ ScriptableObject.putProperty(object, (String)id, value);@b@ }@b@ else@b@ {@b@ String definer;@b@ if (getterSetter < 0)@b@ definer = "__defineGetter__";@b@ else@b@ definer = "__defineSetter__";@b@ Callable fun = getPropFunctionAndThis(object, definer, cx);@b@@b@ lastStoredScriptable(cx);@b@ Object[] outArgs = new Object[2];@b@ outArgs[0] = id;@b@ outArgs[1] = value;@b@ fun.call(cx, scope, object, outArgs);@b@ }@b@ } else {@b@ int index = ((Integer)id).intValue();@b@ ScriptableObject.putProperty(object, index, value);@b@ }@b@ }@b@ return object;@b@ }@b@@b@ public static boolean isArrayObject(Object obj)@b@ {@b@ return ((obj instanceof NativeArray) || (obj instanceof Arguments));@b@ }@b@@b@ public static Object[] getArrayElements(Scriptable object)@b@ {@b@ Context cx = Context.getContext();@b@ long longLen = NativeArray.getLengthProperty(cx, object);@b@ if (longLen > 2147483647L)@b@ {@b@ throw new IllegalArgumentException();@b@ }@b@ int len = (int)longLen;@b@ if (len == 0)@b@ return emptyArgs;@b@@b@ Object[] result = new Object[len];@b@ for (int i = 0; i < len; ++i) {@b@ Object elem = ScriptableObject.getProperty(object, i);@b@ result[i] = ((elem == Scriptable.NOT_FOUND) ? Undefined.instance : elem);@b@ }@b@@b@ return result;@b@ }@b@@b@ static void checkDeprecated(Context cx, String name)@b@ {@b@ int version = cx.getLanguageVersion();@b@ if ((version >= 140) || (version == 0)) {@b@ String msg = getMessage1("msg.deprec.ctor", name);@b@ if (version == 0)@b@ Context.reportWarning(msg);@b@ else@b@ throw Context.reportRuntimeError(msg);@b@ }@b@ }@b@@b@ public static String getMessage0(String messageId)@b@ {@b@ return getMessage(messageId, null);@b@ }@b@@b@ public static String getMessage1(String messageId, Object arg1)@b@ {@b@ Object[] arguments = { arg1 };@b@ return getMessage(messageId, arguments);@b@ }@b@@b@ public static String getMessage2(String messageId, Object arg1, Object arg2)@b@ {@b@ Object[] arguments = { arg1, arg2 };@b@ return getMessage(messageId, arguments);@b@ }@b@@b@ public static String getMessage3(String messageId, Object arg1, Object arg2, Object arg3)@b@ {@b@ Object[] arguments = { arg1, arg2, arg3 };@b@ return getMessage(messageId, arguments);@b@ }@b@@b@ public static String getMessage4(String messageId, Object arg1, Object arg2, Object arg3, Object arg4)@b@ {@b@ Object[] arguments = { arg1, arg2, arg3, arg4 };@b@ return getMessage(messageId, arguments);@b@ }@b@@b@ public static String getMessage(String messageId, Object[] arguments)@b@ {@b@ return messageProvider.getMessage(messageId, arguments);@b@ }@b@@b@ public static EcmaError constructError(String error, String message)@b@ {@b@ int[] linep = new int[1];@b@ String filename = Context.getSourcePositionFromStack(linep);@b@ return constructError(error, message, filename, linep[0], null, 0);@b@ }@b@@b@ public static EcmaError constructError(String error, String message, int lineNumberDelta)@b@ {@b@ int[] linep = new int[1];@b@ String filename = Context.getSourcePositionFromStack(linep);@b@ if (linep[0] != 0)@b@ linep[0] += lineNumberDelta;@b@@b@ return constructError(error, message, filename, linep[0], null, 0);@b@ }@b@@b@ public static EcmaError constructError(String error, String message, String sourceName, int lineNumber, String lineSource, int columnNumber)@b@ {@b@ return new EcmaError(error, message, sourceName, lineNumber, lineSource, columnNumber);@b@ }@b@@b@ public static EcmaError typeError(String message)@b@ {@b@ return constructError("TypeError", message);@b@ }@b@@b@ public static EcmaError typeError0(String messageId)@b@ {@b@ String msg = getMessage0(messageId);@b@ return typeError(msg);@b@ }@b@@b@ public static EcmaError typeError1(String messageId, String arg1)@b@ {@b@ String msg = getMessage1(messageId, arg1);@b@ return typeError(msg);@b@ }@b@@b@ public static EcmaError typeError2(String messageId, String arg1, String arg2)@b@ {@b@ String msg = getMessage2(messageId, arg1, arg2);@b@ return typeError(msg);@b@ }@b@@b@ public static EcmaError typeError3(String messageId, String arg1, String arg2, String arg3)@b@ {@b@ String msg = getMessage3(messageId, arg1, arg2, arg3);@b@ return typeError(msg);@b@ }@b@@b@ public static RuntimeException undefReadError(Object object, Object id)@b@ {@b@ String idStr = (id == null) ? "null" : id.toString();@b@ return typeError2("msg.undef.prop.read", toString(object), idStr);@b@ }@b@@b@ public static RuntimeException undefCallError(Object object, Object id)@b@ {@b@ String idStr = (id == null) ? "null" : id.toString();@b@ return typeError2("msg.undef.method.call", toString(object), idStr);@b@ }@b@@b@ public static RuntimeException undefWriteError(Object object, Object id, Object value)@b@ {@b@ String idStr = (id == null) ? "null" : id.toString();@b@ String valueStr = (value instanceof Scriptable) ? value.toString() : toString(value);@b@@b@ return typeError3("msg.undef.prop.write", toString(object), idStr, valueStr);@b@ }@b@@b@ public static RuntimeException notFoundError(Scriptable object, String property)@b@ {@b@ String msg = getMessage1("msg.is.not.defined", property);@b@ throw constructError("ReferenceError", msg);@b@ }@b@@b@ public static RuntimeException notFunctionError(Object value)@b@ {@b@ return notFunctionError(value, value);@b@ }@b@@b@ public static RuntimeException notFunctionError(Object value, Object messageHelper)@b@ {@b@ String msg = (messageHelper == null) ? "null" : messageHelper.toString();@b@@b@ if (value == Scriptable.NOT_FOUND)@b@ return typeError1("msg.function.not.found", msg);@b@@b@ return typeError2("msg.isnt.function", msg, typeof(value));@b@ }@b@@b@ public static RuntimeException notFunctionError(Object obj, Object value, String propertyName)@b@ {@b@ String objString = toString(obj);@b@ if (value == Scriptable.NOT_FOUND) {@b@ return typeError2("msg.function.not.found.in", propertyName, objString);@b@ }@b@@b@ return typeError3("msg.isnt.function.in", propertyName, objString, typeof(value));@b@ }@b@@b@ private static RuntimeException notXmlError(Object value)@b@ {@b@ throw typeError1("msg.isnt.xml.object", toString(value));@b@ }@b@@b@ private static void warnAboutNonJSObject(Object nonJSObject)@b@ {@b@ String message = "RHINO USAGE WARNING: Missed Context.javaToJS() conversion:\nRhino runtime detected object " + nonJSObject + " of class " + nonJSObject.getClass().getName() + " where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.";@b@@b@ Context.reportWarning(message);@b@@b@ System.err.println(message);@b@ }@b@@b@ public static RegExpProxy getRegExpProxy(Context cx)@b@ {@b@ return cx.getRegExpProxy();@b@ }@b@@b@ public static void setRegExpProxy(Context cx, RegExpProxy proxy)@b@ {@b@ if (proxy == null) throw new IllegalArgumentException();@b@ cx.regExpProxy = proxy;@b@ }@b@@b@ public static RegExpProxy checkRegExpProxy(Context cx)@b@ {@b@ RegExpProxy result = getRegExpProxy(cx);@b@ if (result == null)@b@ throw Context.reportRuntimeError0("msg.no.regexp");@b@@b@ return result;@b@ }@b@@b@ private static XMLLib currentXMLLib(Context cx)@b@ {@b@ if (cx.topCallScope == null)@b@ throw new IllegalStateException();@b@@b@ XMLLib xmlLib = cx.cachedXMLLib;@b@ if (xmlLib == null) {@b@ xmlLib = XMLLib.extractFromScope(cx.topCallScope);@b@ if (xmlLib == null)@b@ throw new IllegalStateException();@b@ cx.cachedXMLLib = xmlLib;@b@ }@b@@b@ return xmlLib;@b@ }@b@@b@ public static String escapeAttributeValue(Object value, Context cx)@b@ {@b@ XMLLib xmlLib = currentXMLLib(cx);@b@ return xmlLib.escapeAttributeValue(value);@b@ }@b@@b@ public static String escapeTextValue(Object value, Context cx)@b@ {@b@ XMLLib xmlLib = currentXMLLib(cx);@b@ return xmlLib.escapeTextValue(value);@b@ }@b@@b@ public static Ref memberRef(Object obj, Object elem, Context cx, int memberTypeFlags)@b@ {@b@ if (!(obj instanceof XMLObject))@b@ throw notXmlError(obj);@b@@b@ XMLObject xmlObject = (XMLObject)obj;@b@ return xmlObject.memberRef(cx, elem, memberTypeFlags);@b@ }@b@@b@ public static Ref memberRef(Object obj, Object namespace, Object elem, Context cx, int memberTypeFlags)@b@ {@b@ if (!(obj instanceof XMLObject))@b@ throw notXmlError(obj);@b@@b@ XMLObject xmlObject = (XMLObject)obj;@b@ return xmlObject.memberRef(cx, namespace, elem, memberTypeFlags);@b@ }@b@@b@ public static Ref nameRef(Object name, Context cx, Scriptable scope, int memberTypeFlags)@b@ {@b@ XMLLib xmlLib = currentXMLLib(cx);@b@ return xmlLib.nameRef(cx, name, scope, memberTypeFlags);@b@ }@b@@b@ public static Ref nameRef(Object namespace, Object name, Context cx, Scriptable scope, int memberTypeFlags)@b@ {@b@ XMLLib xmlLib = currentXMLLib(cx);@b@ return xmlLib.nameRef(cx, namespace, name, scope, memberTypeFlags);@b@ }@b@@b@ private static void storeIndexResult(Context cx, int index)@b@ {@b@ cx.scratchIndex = index;@b@ }@b@@b@ static int lastIndexResult(Context cx)@b@ {@b@ return cx.scratchIndex;@b@ }@b@@b@ public static void storeUint32Result(Context cx, long value)@b@ {@b@ if (value >>> 32 != 0L)@b@ throw new IllegalArgumentException();@b@ cx.scratchUint32 = value;@b@ }@b@@b@ public static long lastUint32Result(Context cx)@b@ {@b@ long value = cx.scratchUint32;@b@ if (value >>> 32 != 0L)@b@ throw new IllegalStateException();@b@ return value;@b@ }@b@@b@ private static void storeScriptable(Context cx, Scriptable value)@b@ {@b@ if (cx.scratchScriptable != null)@b@ throw new IllegalStateException();@b@ cx.scratchScriptable = value;@b@ }@b@@b@ public static Scriptable lastStoredScriptable(Context cx)@b@ {@b@ Scriptable result = cx.scratchScriptable;@b@ cx.scratchScriptable = null;@b@ return result;@b@ }@b@@b@ static String makeUrlForGeneratedScript(boolean isEval, String masterScriptUrl, int masterScriptLine)@b@ {@b@ if (isEval)@b@ return masterScriptUrl + '#' + masterScriptLine + "(eval)";@b@@b@ return masterScriptUrl + '#' + masterScriptLine + "(Function)";@b@ }@b@@b@ static boolean isGeneratedScript(String sourceUrl)@b@ {@b@ return ((sourceUrl.indexOf("(eval)") >= 0) || (sourceUrl.indexOf("(Function)") >= 0));@b@ }@b@@b@ private static RuntimeException errorWithClassName(String msg, Object val)@b@ {@b@ return Context.reportRuntimeError1(msg, val.getClass().getName());@b@ }@b@@b@ private static class DefaultMessageProvider@b@ implements ScriptRuntime.MessageProvider@b@ {@b@ public String getMessage(String messageId, Object[] arguments)@b@ {@b@ String formatString;@b@ String defaultResource = "org.mozilla.javascript.resources.Messages";@b@@b@ Context cx = Context.getCurrentContext();@b@ Locale locale = (cx != null) ? cx.getLocale() : Locale.getDefault();@b@@b@ ResourceBundle rb = ResourceBundle.getBundle("org.mozilla.javascript.resources.Messages", locale);@b@ try@b@ {@b@ formatString = rb.getString(messageId);@b@ } catch (MissingResourceException mre) {@b@ throw new RuntimeException("no message resource found for message property " + messageId);@b@ }@b@@b@ MessageFormat formatter = new MessageFormat(formatString);@b@ return formatter.format(arguments);@b@ }@b@ }@b@@b@ public static abstract interface MessageProvider@b@ {@b@ public abstract String getMessage(String paramString, Object[] paramArrayOfObject);@b@ }@b@@b@ private static class IdEnumeration@b@ implements Serializable@b@ {@b@ private static final long serialVersionUID = 1L;@b@ Scriptable obj;@b@ Object[] ids;@b@ int index;@b@ ObjToIntMap used;@b@ Object currentId;@b@ int enumType;@b@ boolean enumNumbers;@b@ Scriptable iterator;@b@ }@b@@b@ static class NoSuchMethodShim@b@ implements Callable@b@ {@b@ String methodName;@b@ Callable noSuchMethodMethod;@b@@b@ NoSuchMethodShim(Callable noSuchMethodMethod, String methodName)@b@ {@b@ this.noSuchMethodMethod = noSuchMethodMethod;@b@ this.methodName = methodName;@b@ }@b@@b@ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)@b@ {@b@ Object[] nestedArgs = new Object[2];@b@@b@ nestedArgs[0] = this.methodName;@b@ nestedArgs[1] = ScriptRuntime.newArrayLiteral(args, null, cx, scope);@b@ return this.noSuchMethodMethod.call(cx, scope, thisObj, nestedArgs);@b@ }@b@ }@b@}