id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
21,500
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.indexFromString
public static long indexFromString(String str) { // The length of the decimal string representation of // Integer.MAX_VALUE, 2147483647 final int MAX_VALUE_LENGTH = 10; int len = str.length(); if (len > 0) { int i = 0; boolean negate = false; int c = str.charAt(0); if (c == '-') { if (len > 1) { c = str.charAt(1); if (c == '0') return -1L; // "-0" is not an index i = 1; negate = true; } } c -= '0'; if (0 <= c && c <= 9 && len <= (negate ? MAX_VALUE_LENGTH + 1 : MAX_VALUE_LENGTH)) { // Use negative numbers to accumulate index to handle // Integer.MIN_VALUE that is greater by 1 in absolute value // then Integer.MAX_VALUE int index = -c; int oldIndex = 0; i++; if (index != 0) { // Note that 00, 01, 000 etc. are not indexes while (i != len && 0 <= (c = str.charAt(i) - '0') && c <= 9) { oldIndex = index; index = 10 * index - c; i++; } } // Make sure all characters were consumed and that it couldn't // have overflowed. if (i == len && (oldIndex > (Integer.MIN_VALUE / 10) || (oldIndex == (Integer.MIN_VALUE / 10) && c <= (negate ? -(Integer.MIN_VALUE % 10) : (Integer.MAX_VALUE % 10))))) { return 0xFFFFFFFFL & (negate ? index : -index); } } } return -1L; }
java
public static long indexFromString(String str) { // The length of the decimal string representation of // Integer.MAX_VALUE, 2147483647 final int MAX_VALUE_LENGTH = 10; int len = str.length(); if (len > 0) { int i = 0; boolean negate = false; int c = str.charAt(0); if (c == '-') { if (len > 1) { c = str.charAt(1); if (c == '0') return -1L; // "-0" is not an index i = 1; negate = true; } } c -= '0'; if (0 <= c && c <= 9 && len <= (negate ? MAX_VALUE_LENGTH + 1 : MAX_VALUE_LENGTH)) { // Use negative numbers to accumulate index to handle // Integer.MIN_VALUE that is greater by 1 in absolute value // then Integer.MAX_VALUE int index = -c; int oldIndex = 0; i++; if (index != 0) { // Note that 00, 01, 000 etc. are not indexes while (i != len && 0 <= (c = str.charAt(i) - '0') && c <= 9) { oldIndex = index; index = 10 * index - c; i++; } } // Make sure all characters were consumed and that it couldn't // have overflowed. if (i == len && (oldIndex > (Integer.MIN_VALUE / 10) || (oldIndex == (Integer.MIN_VALUE / 10) && c <= (negate ? -(Integer.MIN_VALUE % 10) : (Integer.MAX_VALUE % 10))))) { return 0xFFFFFFFFL & (negate ? index : -index); } } } return -1L; }
[ "public", "static", "long", "indexFromString", "(", "String", "str", ")", "{", "// The length of the decimal string representation of", "// Integer.MAX_VALUE, 2147483647", "final", "int", "MAX_VALUE_LENGTH", "=", "10", ";", "int", "len", "=", "str", ".", "length", "(", ")", ";", "if", "(", "len", ">", "0", ")", "{", "int", "i", "=", "0", ";", "boolean", "negate", "=", "false", ";", "int", "c", "=", "str", ".", "charAt", "(", "0", ")", ";", "if", "(", "c", "==", "'", "'", ")", "{", "if", "(", "len", ">", "1", ")", "{", "c", "=", "str", ".", "charAt", "(", "1", ")", ";", "if", "(", "c", "==", "'", "'", ")", "return", "-", "1L", ";", "// \"-0\" is not an index", "i", "=", "1", ";", "negate", "=", "true", ";", "}", "}", "c", "-=", "'", "'", ";", "if", "(", "0", "<=", "c", "&&", "c", "<=", "9", "&&", "len", "<=", "(", "negate", "?", "MAX_VALUE_LENGTH", "+", "1", ":", "MAX_VALUE_LENGTH", ")", ")", "{", "// Use negative numbers to accumulate index to handle", "// Integer.MIN_VALUE that is greater by 1 in absolute value", "// then Integer.MAX_VALUE", "int", "index", "=", "-", "c", ";", "int", "oldIndex", "=", "0", ";", "i", "++", ";", "if", "(", "index", "!=", "0", ")", "{", "// Note that 00, 01, 000 etc. are not indexes", "while", "(", "i", "!=", "len", "&&", "0", "<=", "(", "c", "=", "str", ".", "charAt", "(", "i", ")", "-", "'", "'", ")", "&&", "c", "<=", "9", ")", "{", "oldIndex", "=", "index", ";", "index", "=", "10", "*", "index", "-", "c", ";", "i", "++", ";", "}", "}", "// Make sure all characters were consumed and that it couldn't", "// have overflowed.", "if", "(", "i", "==", "len", "&&", "(", "oldIndex", ">", "(", "Integer", ".", "MIN_VALUE", "/", "10", ")", "||", "(", "oldIndex", "==", "(", "Integer", ".", "MIN_VALUE", "/", "10", ")", "&&", "c", "<=", "(", "negate", "?", "-", "(", "Integer", ".", "MIN_VALUE", "%", "10", ")", ":", "(", "Integer", ".", "MAX_VALUE", "%", "10", ")", ")", ")", ")", ")", "{", "return", "0xFFFFFFFF", "L", "&", "(", "negate", "?", "index", ":", "-", "index", ")", ";", "}", "}", "}", "return", "-", "1L", ";", "}" ]
Return -1L if str is not an index, or the index value as lower 32 bits of the result. Note that the result needs to be cast to an int in order to produce the actual index, which may be negative.
[ "Return", "-", "1L", "if", "str", "is", "not", "an", "index", "or", "the", "index", "value", "as", "lower", "32", "bits", "of", "the", "result", ".", "Note", "that", "the", "result", "needs", "to", "be", "cast", "to", "an", "int", "in", "order", "to", "produce", "the", "actual", "index", "which", "may", "be", "negative", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L1363-L1414
21,501
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.getIndexObject
static Object getIndexObject(String s) { long indexTest = indexFromString(s); if (indexTest >= 0) { return Integer.valueOf((int)indexTest); } return s; }
java
static Object getIndexObject(String s) { long indexTest = indexFromString(s); if (indexTest >= 0) { return Integer.valueOf((int)indexTest); } return s; }
[ "static", "Object", "getIndexObject", "(", "String", "s", ")", "{", "long", "indexTest", "=", "indexFromString", "(", "s", ")", ";", "if", "(", "indexTest", ">=", "0", ")", "{", "return", "Integer", ".", "valueOf", "(", "(", "int", ")", "indexTest", ")", ";", "}", "return", "s", ";", "}" ]
If s represents index, then return index value wrapped as Integer and othewise return s.
[ "If", "s", "represents", "index", "then", "return", "index", "value", "wrapped", "as", "Integer", "and", "othewise", "return", "s", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L1456-L1463
21,502
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.getIndexObject
static Object getIndexObject(double d) { int i = (int)d; if (i == d) { return Integer.valueOf(i); } return toString(d); }
java
static Object getIndexObject(double d) { int i = (int)d; if (i == d) { return Integer.valueOf(i); } return toString(d); }
[ "static", "Object", "getIndexObject", "(", "double", "d", ")", "{", "int", "i", "=", "(", "int", ")", "d", ";", "if", "(", "i", "==", "d", ")", "{", "return", "Integer", ".", "valueOf", "(", "i", ")", ";", "}", "return", "toString", "(", "d", ")", ";", "}" ]
If d is exact int value, return its value wrapped as Integer and othewise return d converted to String.
[ "If", "d", "is", "exact", "int", "value", "return", "its", "value", "wrapped", "as", "Integer", "and", "othewise", "return", "d", "converted", "to", "String", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L1469-L1476
21,503
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.name
public static Object name(Context cx, Scriptable scope, String name) { Scriptable parent = scope.getParentScope(); if (parent == null) { Object result = topScopeName(cx, scope, name); if (result == Scriptable.NOT_FOUND) { throw notFoundError(scope, name); } return result; } return nameOrFunction(cx, scope, parent, name, false); }
java
public static Object name(Context cx, Scriptable scope, String name) { Scriptable parent = scope.getParentScope(); if (parent == null) { Object result = topScopeName(cx, scope, name); if (result == Scriptable.NOT_FOUND) { throw notFoundError(scope, name); } return result; } return nameOrFunction(cx, scope, parent, name, false); }
[ "public", "static", "Object", "name", "(", "Context", "cx", ",", "Scriptable", "scope", ",", "String", "name", ")", "{", "Scriptable", "parent", "=", "scope", ".", "getParentScope", "(", ")", ";", "if", "(", "parent", "==", "null", ")", "{", "Object", "result", "=", "topScopeName", "(", "cx", ",", "scope", ",", "name", ")", ";", "if", "(", "result", "==", "Scriptable", ".", "NOT_FOUND", ")", "{", "throw", "notFoundError", "(", "scope", ",", "name", ")", ";", "}", "return", "result", ";", "}", "return", "nameOrFunction", "(", "cx", ",", "scope", ",", "parent", ",", "name", ",", "false", ")", ";", "}" ]
Looks up a name in the scope chain and returns its value.
[ "Looks", "up", "a", "name", "in", "the", "scope", "chain", "and", "returns", "its", "value", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L1929-L1941
21,504
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.bind
public static Scriptable bind(Context cx, Scriptable scope, String id) { Scriptable firstXMLObject = null; Scriptable parent = scope.getParentScope(); childScopesChecks: if (parent != null) { // Check for possibly nested "with" scopes first while (scope instanceof NativeWith) { Scriptable withObj = scope.getPrototype(); if (withObj instanceof XMLObject) { XMLObject xmlObject = (XMLObject)withObj; if (xmlObject.has(cx, id)) { return xmlObject; } if (firstXMLObject == null) { firstXMLObject = xmlObject; } } else { if (ScriptableObject.hasProperty(withObj, id)) { return withObj; } } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } for (;;) { if (ScriptableObject.hasProperty(scope, id)) { return scope; } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } } // scope here is top scope if (cx.useDynamicScope) { scope = checkDynamicScope(cx.topCallScope, scope); } if (ScriptableObject.hasProperty(scope, id)) { return scope; } // Nothing was found, but since XML objects always bind // return one if found return firstXMLObject; }
java
public static Scriptable bind(Context cx, Scriptable scope, String id) { Scriptable firstXMLObject = null; Scriptable parent = scope.getParentScope(); childScopesChecks: if (parent != null) { // Check for possibly nested "with" scopes first while (scope instanceof NativeWith) { Scriptable withObj = scope.getPrototype(); if (withObj instanceof XMLObject) { XMLObject xmlObject = (XMLObject)withObj; if (xmlObject.has(cx, id)) { return xmlObject; } if (firstXMLObject == null) { firstXMLObject = xmlObject; } } else { if (ScriptableObject.hasProperty(withObj, id)) { return withObj; } } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } for (;;) { if (ScriptableObject.hasProperty(scope, id)) { return scope; } scope = parent; parent = parent.getParentScope(); if (parent == null) { break childScopesChecks; } } } // scope here is top scope if (cx.useDynamicScope) { scope = checkDynamicScope(cx.topCallScope, scope); } if (ScriptableObject.hasProperty(scope, id)) { return scope; } // Nothing was found, but since XML objects always bind // return one if found return firstXMLObject; }
[ "public", "static", "Scriptable", "bind", "(", "Context", "cx", ",", "Scriptable", "scope", ",", "String", "id", ")", "{", "Scriptable", "firstXMLObject", "=", "null", ";", "Scriptable", "parent", "=", "scope", ".", "getParentScope", "(", ")", ";", "childScopesChecks", ":", "if", "(", "parent", "!=", "null", ")", "{", "// Check for possibly nested \"with\" scopes first", "while", "(", "scope", "instanceof", "NativeWith", ")", "{", "Scriptable", "withObj", "=", "scope", ".", "getPrototype", "(", ")", ";", "if", "(", "withObj", "instanceof", "XMLObject", ")", "{", "XMLObject", "xmlObject", "=", "(", "XMLObject", ")", "withObj", ";", "if", "(", "xmlObject", ".", "has", "(", "cx", ",", "id", ")", ")", "{", "return", "xmlObject", ";", "}", "if", "(", "firstXMLObject", "==", "null", ")", "{", "firstXMLObject", "=", "xmlObject", ";", "}", "}", "else", "{", "if", "(", "ScriptableObject", ".", "hasProperty", "(", "withObj", ",", "id", ")", ")", "{", "return", "withObj", ";", "}", "}", "scope", "=", "parent", ";", "parent", "=", "parent", ".", "getParentScope", "(", ")", ";", "if", "(", "parent", "==", "null", ")", "{", "break", "childScopesChecks", ";", "}", "}", "for", "(", ";", ";", ")", "{", "if", "(", "ScriptableObject", ".", "hasProperty", "(", "scope", ",", "id", ")", ")", "{", "return", "scope", ";", "}", "scope", "=", "parent", ";", "parent", "=", "parent", ".", "getParentScope", "(", ")", ";", "if", "(", "parent", "==", "null", ")", "{", "break", "childScopesChecks", ";", "}", "}", "}", "// scope here is top scope", "if", "(", "cx", ".", "useDynamicScope", ")", "{", "scope", "=", "checkDynamicScope", "(", "cx", ".", "topCallScope", ",", "scope", ")", ";", "}", "if", "(", "ScriptableObject", ".", "hasProperty", "(", "scope", ",", "id", ")", ")", "{", "return", "scope", ";", "}", "// Nothing was found, but since XML objects always bind", "// return one if found", "return", "firstXMLObject", ";", "}" ]
Returns the object in the scope chain that has a given property. The order of evaluation of an assignment expression involves evaluating the lhs to a reference, evaluating the rhs, and then modifying the reference with the rhs value. This method is used to 'bind' the given name to an object containing that property so that the side effects of evaluating the rhs do not affect which property is modified. Typically used in conjunction with setName. See ECMA 10.1.4
[ "Returns", "the", "object", "in", "the", "scope", "chain", "that", "has", "a", "given", "property", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2048-L2096
21,505
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.enumInit
@Deprecated public static Object enumInit(Object value, Context cx, boolean enumValues) { return enumInit(value, cx, enumValues ? ENUMERATE_VALUES : ENUMERATE_KEYS); }
java
@Deprecated public static Object enumInit(Object value, Context cx, boolean enumValues) { return enumInit(value, cx, enumValues ? ENUMERATE_VALUES : ENUMERATE_KEYS); }
[ "@", "Deprecated", "public", "static", "Object", "enumInit", "(", "Object", "value", ",", "Context", "cx", ",", "boolean", "enumValues", ")", "{", "return", "enumInit", "(", "value", ",", "cx", ",", "enumValues", "?", "ENUMERATE_VALUES", ":", "ENUMERATE_KEYS", ")", ";", "}" ]
For backwards compatibility with generated class files @deprecated Use {@link #enumInit(Object, Context, Scriptable, int)} instead
[ "For", "backwards", "compatibility", "with", "generated", "class", "files" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2215-L2220
21,506
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.newObject
public static Scriptable newObject(Object fun, Context cx, Scriptable scope, Object[] args) { if (!(fun instanceof Function)) { throw notFunctionError(fun); } Function function = (Function)fun; return function.construct(cx, scope, args); }
java
public static Scriptable newObject(Object fun, Context cx, Scriptable scope, Object[] args) { if (!(fun instanceof Function)) { throw notFunctionError(fun); } Function function = (Function)fun; return function.construct(cx, scope, args); }
[ "public", "static", "Scriptable", "newObject", "(", "Object", "fun", ",", "Context", "cx", ",", "Scriptable", "scope", ",", "Object", "[", "]", "args", ")", "{", "if", "(", "!", "(", "fun", "instanceof", "Function", ")", ")", "{", "throw", "notFunctionError", "(", "fun", ")", ";", "}", "Function", "function", "=", "(", "Function", ")", "fun", ";", "return", "function", ".", "construct", "(", "cx", ",", "scope", ",", "args", ")", ";", "}" ]
Operator new. See ECMA 11.2.2
[ "Operator", "new", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2666-L2674
21,507
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.applyOrCall
public static Object applyOrCall(boolean isApply, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { int L = args.length; Callable function = getCallable(thisObj); Scriptable callThis = null; if (L != 0) { if (cx.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)) { callThis = toObjectOrNull(cx, args[0], scope); } else { callThis = args[0] == Undefined.instance ? Undefined.SCRIPTABLE_UNDEFINED : toObjectOrNull(cx, args[0], scope); } } if (callThis == null && cx.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)) { callThis = getTopCallScope(cx); // This covers the case of args[0] == (null|undefined) as well. } Object[] callArgs; if (isApply) { // Follow Ecma 15.3.4.3 callArgs = L <= 1 ? ScriptRuntime.emptyArgs : getApplyArguments(cx, args[1]); } else { // Follow Ecma 15.3.4.4 if (L <= 1) { callArgs = ScriptRuntime.emptyArgs; } else { callArgs = new Object[L - 1]; System.arraycopy(args, 1, callArgs, 0, L - 1); } } return function.call(cx, scope, callThis, callArgs); }
java
public static Object applyOrCall(boolean isApply, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { int L = args.length; Callable function = getCallable(thisObj); Scriptable callThis = null; if (L != 0) { if (cx.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)) { callThis = toObjectOrNull(cx, args[0], scope); } else { callThis = args[0] == Undefined.instance ? Undefined.SCRIPTABLE_UNDEFINED : toObjectOrNull(cx, args[0], scope); } } if (callThis == null && cx.hasFeature(Context.FEATURE_OLD_UNDEF_NULL_THIS)) { callThis = getTopCallScope(cx); // This covers the case of args[0] == (null|undefined) as well. } Object[] callArgs; if (isApply) { // Follow Ecma 15.3.4.3 callArgs = L <= 1 ? ScriptRuntime.emptyArgs : getApplyArguments(cx, args[1]); } else { // Follow Ecma 15.3.4.4 if (L <= 1) { callArgs = ScriptRuntime.emptyArgs; } else { callArgs = new Object[L - 1]; System.arraycopy(args, 1, callArgs, 0, L - 1); } } return function.call(cx, scope, callThis, callArgs); }
[ "public", "static", "Object", "applyOrCall", "(", "boolean", "isApply", ",", "Context", "cx", ",", "Scriptable", "scope", ",", "Scriptable", "thisObj", ",", "Object", "[", "]", "args", ")", "{", "int", "L", "=", "args", ".", "length", ";", "Callable", "function", "=", "getCallable", "(", "thisObj", ")", ";", "Scriptable", "callThis", "=", "null", ";", "if", "(", "L", "!=", "0", ")", "{", "if", "(", "cx", ".", "hasFeature", "(", "Context", ".", "FEATURE_OLD_UNDEF_NULL_THIS", ")", ")", "{", "callThis", "=", "toObjectOrNull", "(", "cx", ",", "args", "[", "0", "]", ",", "scope", ")", ";", "}", "else", "{", "callThis", "=", "args", "[", "0", "]", "==", "Undefined", ".", "instance", "?", "Undefined", ".", "SCRIPTABLE_UNDEFINED", ":", "toObjectOrNull", "(", "cx", ",", "args", "[", "0", "]", ",", "scope", ")", ";", "}", "}", "if", "(", "callThis", "==", "null", "&&", "cx", ".", "hasFeature", "(", "Context", ".", "FEATURE_OLD_UNDEF_NULL_THIS", ")", ")", "{", "callThis", "=", "getTopCallScope", "(", "cx", ")", ";", "// This covers the case of args[0] == (null|undefined) as well.", "}", "Object", "[", "]", "callArgs", ";", "if", "(", "isApply", ")", "{", "// Follow Ecma 15.3.4.3", "callArgs", "=", "L", "<=", "1", "?", "ScriptRuntime", ".", "emptyArgs", ":", "getApplyArguments", "(", "cx", ",", "args", "[", "1", "]", ")", ";", "}", "else", "{", "// Follow Ecma 15.3.4.4", "if", "(", "L", "<=", "1", ")", "{", "callArgs", "=", "ScriptRuntime", ".", "emptyArgs", ";", "}", "else", "{", "callArgs", "=", "new", "Object", "[", "L", "-", "1", "]", ";", "System", ".", "arraycopy", "(", "args", ",", "1", ",", "callArgs", ",", "0", ",", "L", "-", "1", ")", ";", "}", "}", "return", "function", ".", "call", "(", "cx", ",", "scope", ",", "callThis", ",", "callArgs", ")", ";", "}" ]
Function.prototype.apply and Function.prototype.call See Ecma 15.3.4.[34]
[ "Function", ".", "prototype", ".", "apply", "and", "Function", ".", "prototype", ".", "call" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2723-L2758
21,508
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.evalSpecial
public static Object evalSpecial(Context cx, Scriptable scope, Object thisArg, Object[] args, String filename, int lineNumber) { if (args.length < 1) return Undefined.instance; Object x = args[0]; if (!(x instanceof CharSequence)) { if (cx.hasFeature(Context.FEATURE_STRICT_MODE) || cx.hasFeature(Context.FEATURE_STRICT_EVAL)) { throw Context.reportRuntimeError0("msg.eval.nonstring.strict"); } String message = ScriptRuntime.getMessage0("msg.eval.nonstring"); Context.reportWarning(message); return x; } if (filename == null) { int[] linep = new int[1]; filename = Context.getSourcePositionFromStack(linep); if (filename != null) { lineNumber = linep[0]; } else { filename = ""; } } String sourceName = ScriptRuntime. makeUrlForGeneratedScript(true, filename, lineNumber); ErrorReporter reporter; reporter = DefaultErrorReporter.forEval(cx.getErrorReporter()); Evaluator evaluator = Context.createInterpreter(); if (evaluator == null) { throw new JavaScriptException("Interpreter not present", filename, lineNumber); } // Compile with explicit interpreter instance to force interpreter // mode. Script script = cx.compileString(x.toString(), evaluator, reporter, sourceName, 1, null); evaluator.setEvalScriptFlag(script); Callable c = (Callable)script; return c.call(cx, scope, (Scriptable)thisArg, ScriptRuntime.emptyArgs); }
java
public static Object evalSpecial(Context cx, Scriptable scope, Object thisArg, Object[] args, String filename, int lineNumber) { if (args.length < 1) return Undefined.instance; Object x = args[0]; if (!(x instanceof CharSequence)) { if (cx.hasFeature(Context.FEATURE_STRICT_MODE) || cx.hasFeature(Context.FEATURE_STRICT_EVAL)) { throw Context.reportRuntimeError0("msg.eval.nonstring.strict"); } String message = ScriptRuntime.getMessage0("msg.eval.nonstring"); Context.reportWarning(message); return x; } if (filename == null) { int[] linep = new int[1]; filename = Context.getSourcePositionFromStack(linep); if (filename != null) { lineNumber = linep[0]; } else { filename = ""; } } String sourceName = ScriptRuntime. makeUrlForGeneratedScript(true, filename, lineNumber); ErrorReporter reporter; reporter = DefaultErrorReporter.forEval(cx.getErrorReporter()); Evaluator evaluator = Context.createInterpreter(); if (evaluator == null) { throw new JavaScriptException("Interpreter not present", filename, lineNumber); } // Compile with explicit interpreter instance to force interpreter // mode. Script script = cx.compileString(x.toString(), evaluator, reporter, sourceName, 1, null); evaluator.setEvalScriptFlag(script); Callable c = (Callable)script; return c.call(cx, scope, (Scriptable)thisArg, ScriptRuntime.emptyArgs); }
[ "public", "static", "Object", "evalSpecial", "(", "Context", "cx", ",", "Scriptable", "scope", ",", "Object", "thisArg", ",", "Object", "[", "]", "args", ",", "String", "filename", ",", "int", "lineNumber", ")", "{", "if", "(", "args", ".", "length", "<", "1", ")", "return", "Undefined", ".", "instance", ";", "Object", "x", "=", "args", "[", "0", "]", ";", "if", "(", "!", "(", "x", "instanceof", "CharSequence", ")", ")", "{", "if", "(", "cx", ".", "hasFeature", "(", "Context", ".", "FEATURE_STRICT_MODE", ")", "||", "cx", ".", "hasFeature", "(", "Context", ".", "FEATURE_STRICT_EVAL", ")", ")", "{", "throw", "Context", ".", "reportRuntimeError0", "(", "\"msg.eval.nonstring.strict\"", ")", ";", "}", "String", "message", "=", "ScriptRuntime", ".", "getMessage0", "(", "\"msg.eval.nonstring\"", ")", ";", "Context", ".", "reportWarning", "(", "message", ")", ";", "return", "x", ";", "}", "if", "(", "filename", "==", "null", ")", "{", "int", "[", "]", "linep", "=", "new", "int", "[", "1", "]", ";", "filename", "=", "Context", ".", "getSourcePositionFromStack", "(", "linep", ")", ";", "if", "(", "filename", "!=", "null", ")", "{", "lineNumber", "=", "linep", "[", "0", "]", ";", "}", "else", "{", "filename", "=", "\"\"", ";", "}", "}", "String", "sourceName", "=", "ScriptRuntime", ".", "makeUrlForGeneratedScript", "(", "true", ",", "filename", ",", "lineNumber", ")", ";", "ErrorReporter", "reporter", ";", "reporter", "=", "DefaultErrorReporter", ".", "forEval", "(", "cx", ".", "getErrorReporter", "(", ")", ")", ";", "Evaluator", "evaluator", "=", "Context", ".", "createInterpreter", "(", ")", ";", "if", "(", "evaluator", "==", "null", ")", "{", "throw", "new", "JavaScriptException", "(", "\"Interpreter not present\"", ",", "filename", ",", "lineNumber", ")", ";", "}", "// Compile with explicit interpreter instance to force interpreter", "// mode.", "Script", "script", "=", "cx", ".", "compileString", "(", "x", ".", "toString", "(", ")", ",", "evaluator", ",", "reporter", ",", "sourceName", ",", "1", ",", "null", ")", ";", "evaluator", ".", "setEvalScriptFlag", "(", "script", ")", ";", "Callable", "c", "=", "(", "Callable", ")", "script", ";", "return", "c", ".", "call", "(", "cx", ",", "scope", ",", "(", "Scriptable", ")", "thisArg", ",", "ScriptRuntime", ".", "emptyArgs", ")", ";", "}" ]
The eval function property of the global object. See ECMA 15.1.2.1
[ "The", "eval", "function", "property", "of", "the", "global", "object", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2805-L2850
21,509
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.typeof
public static String typeof(Object value) { if (value == null) return "object"; if (value == Undefined.instance) return "undefined"; if (value instanceof ScriptableObject) return ((ScriptableObject) value).getTypeOf(); if (value instanceof Scriptable) return (value instanceof Callable) ? "function" : "object"; if (value instanceof CharSequence) return "string"; if (value instanceof Number) return "number"; if (value instanceof Boolean) return "boolean"; throw errorWithClassName("msg.invalid.type", value); }
java
public static String typeof(Object value) { if (value == null) return "object"; if (value == Undefined.instance) return "undefined"; if (value instanceof ScriptableObject) return ((ScriptableObject) value).getTypeOf(); if (value instanceof Scriptable) return (value instanceof Callable) ? "function" : "object"; if (value instanceof CharSequence) return "string"; if (value instanceof Number) return "number"; if (value instanceof Boolean) return "boolean"; throw errorWithClassName("msg.invalid.type", value); }
[ "public", "static", "String", "typeof", "(", "Object", "value", ")", "{", "if", "(", "value", "==", "null", ")", "return", "\"object\"", ";", "if", "(", "value", "==", "Undefined", ".", "instance", ")", "return", "\"undefined\"", ";", "if", "(", "value", "instanceof", "ScriptableObject", ")", "return", "(", "(", "ScriptableObject", ")", "value", ")", ".", "getTypeOf", "(", ")", ";", "if", "(", "value", "instanceof", "Scriptable", ")", "return", "(", "value", "instanceof", "Callable", ")", "?", "\"function\"", ":", "\"object\"", ";", "if", "(", "value", "instanceof", "CharSequence", ")", "return", "\"string\"", ";", "if", "(", "value", "instanceof", "Number", ")", "return", "\"number\"", ";", "if", "(", "value", "instanceof", "Boolean", ")", "return", "\"boolean\"", ";", "throw", "errorWithClassName", "(", "\"msg.invalid.type\"", ",", "value", ")", ";", "}" ]
The typeof operator
[ "The", "typeof", "operator" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2855-L2872
21,510
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.typeofName
public static String typeofName(Scriptable scope, String id) { Context cx = Context.getContext(); Scriptable val = bind(cx, scope, id); if (val == null) return "undefined"; return typeof(getObjectProp(val, id, cx)); }
java
public static String typeofName(Scriptable scope, String id) { Context cx = Context.getContext(); Scriptable val = bind(cx, scope, id); if (val == null) return "undefined"; return typeof(getObjectProp(val, id, cx)); }
[ "public", "static", "String", "typeofName", "(", "Scriptable", "scope", ",", "String", "id", ")", "{", "Context", "cx", "=", "Context", ".", "getContext", "(", ")", ";", "Scriptable", "val", "=", "bind", "(", "cx", ",", "scope", ",", "id", ")", ";", "if", "(", "val", "==", "null", ")", "return", "\"undefined\"", ";", "return", "typeof", "(", "getObjectProp", "(", "val", ",", "id", ",", "cx", ")", ")", ";", "}" ]
The typeof operator that correctly handles the undefined case
[ "The", "typeof", "operator", "that", "correctly", "handles", "the", "undefined", "case" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2877-L2884
21,511
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.nameIncrDecr
@Deprecated public static Object nameIncrDecr(Scriptable scopeChain, String id, int incrDecrMask) { return nameIncrDecr(scopeChain, id, Context.getContext(), incrDecrMask); }
java
@Deprecated public static Object nameIncrDecr(Scriptable scopeChain, String id, int incrDecrMask) { return nameIncrDecr(scopeChain, id, Context.getContext(), incrDecrMask); }
[ "@", "Deprecated", "public", "static", "Object", "nameIncrDecr", "(", "Scriptable", "scopeChain", ",", "String", "id", ",", "int", "incrDecrMask", ")", "{", "return", "nameIncrDecr", "(", "scopeChain", ",", "id", ",", "Context", ".", "getContext", "(", ")", ",", "incrDecrMask", ")", ";", "}" ]
The method is only present for compatibility. @deprecated Use {@link #nameIncrDecr(Scriptable, String, Context, int)} instead
[ "The", "method", "is", "only", "present", "for", "compatibility", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L2963-L2968
21,512
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.sameZero
public static boolean sameZero(Object x, Object y) { if (!typeof(x).equals(typeof(y))) { return false; } if (x instanceof Number) { if (isNaN(x) && isNaN(y)) { return true; } final double dx = ((Number)x).doubleValue(); if (y instanceof Number) { final double dy = ((Number)y).doubleValue(); if (((dx == negativeZero) && (dy == 0.0)) || ((dx == 0.0) && dy == negativeZero)) { return true; } } return eqNumber(dx, y); } return eq(x, y); }
java
public static boolean sameZero(Object x, Object y) { if (!typeof(x).equals(typeof(y))) { return false; } if (x instanceof Number) { if (isNaN(x) && isNaN(y)) { return true; } final double dx = ((Number)x).doubleValue(); if (y instanceof Number) { final double dy = ((Number)y).doubleValue(); if (((dx == negativeZero) && (dy == 0.0)) || ((dx == 0.0) && dy == negativeZero)) { return true; } } return eqNumber(dx, y); } return eq(x, y); }
[ "public", "static", "boolean", "sameZero", "(", "Object", "x", ",", "Object", "y", ")", "{", "if", "(", "!", "typeof", "(", "x", ")", ".", "equals", "(", "typeof", "(", "y", ")", ")", ")", "{", "return", "false", ";", "}", "if", "(", "x", "instanceof", "Number", ")", "{", "if", "(", "isNaN", "(", "x", ")", "&&", "isNaN", "(", "y", ")", ")", "{", "return", "true", ";", "}", "final", "double", "dx", "=", "(", "(", "Number", ")", "x", ")", ".", "doubleValue", "(", ")", ";", "if", "(", "y", "instanceof", "Number", ")", "{", "final", "double", "dy", "=", "(", "(", "Number", ")", "y", ")", ".", "doubleValue", "(", ")", ";", "if", "(", "(", "(", "dx", "==", "negativeZero", ")", "&&", "(", "dy", "==", "0.0", ")", ")", "||", "(", "(", "dx", "==", "0.0", ")", "&&", "dy", "==", "negativeZero", ")", ")", "{", "return", "true", ";", "}", "}", "return", "eqNumber", "(", "dx", ",", "y", ")", ";", "}", "return", "eq", "(", "x", ",", "y", ")", ";", "}" ]
Implement "SameValueZero" from ECMA 7.2.9
[ "Implement", "SameValueZero", "from", "ECMA", "7", ".", "2", ".", "9" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L3261-L3280
21,513
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.instanceOf
public static boolean instanceOf(Object a, Object b, Context cx) { // Check RHS is an object if (! (b instanceof Scriptable)) { throw typeError0("msg.instanceof.not.object"); } // for primitive values on LHS, return false if (! (a instanceof Scriptable)) return false; return ((Scriptable)b).hasInstance((Scriptable)a); }
java
public static boolean instanceOf(Object a, Object b, Context cx) { // Check RHS is an object if (! (b instanceof Scriptable)) { throw typeError0("msg.instanceof.not.object"); } // for primitive values on LHS, return false if (! (a instanceof Scriptable)) return false; return ((Scriptable)b).hasInstance((Scriptable)a); }
[ "public", "static", "boolean", "instanceOf", "(", "Object", "a", ",", "Object", "b", ",", "Context", "cx", ")", "{", "// Check RHS is an object", "if", "(", "!", "(", "b", "instanceof", "Scriptable", ")", ")", "{", "throw", "typeError0", "(", "\"msg.instanceof.not.object\"", ")", ";", "}", "// for primitive values on LHS, return false", "if", "(", "!", "(", "a", "instanceof", "Scriptable", ")", ")", "return", "false", ";", "return", "(", "(", "Scriptable", ")", "b", ")", ".", "hasInstance", "(", "(", "Scriptable", ")", "a", ")", ";", "}" ]
The instanceof operator. @return a instanceof b
[ "The", "instanceof", "operator", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L3403-L3415
21,514
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.in
public static boolean in(Object a, Object b, Context cx) { if (!(b instanceof Scriptable)) { throw typeError0("msg.in.not.object"); } return hasObjectElem((Scriptable)b, a, cx); }
java
public static boolean in(Object a, Object b, Context cx) { if (!(b instanceof Scriptable)) { throw typeError0("msg.in.not.object"); } return hasObjectElem((Scriptable)b, a, cx); }
[ "public", "static", "boolean", "in", "(", "Object", "a", ",", "Object", "b", ",", "Context", "cx", ")", "{", "if", "(", "!", "(", "b", "instanceof", "Scriptable", ")", ")", "{", "throw", "typeError0", "(", "\"msg.in.not.object\"", ")", ";", "}", "return", "hasObjectElem", "(", "(", "Scriptable", ")", "b", ",", "a", ",", "cx", ")", ";", "}" ]
The in operator. This is a new JS 1.3 language feature. The in operator mirrors the operation of the for .. in construct, and tests whether the rhs has the property given by the lhs. It is different from the for .. in construct in that: <BR> - it doesn't perform ToObject on the right hand side <BR> - it returns true for DontEnum properties. @param a the left hand operand @param b the right hand operand @return true if property name or element number a is a property of b
[ "The", "in", "operator", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L3447-L3454
21,515
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.escapeAttributeValue
public static String escapeAttributeValue(Object value, Context cx) { XMLLib xmlLib = currentXMLLib(cx); return xmlLib.escapeAttributeValue(value); }
java
public static String escapeAttributeValue(Object value, Context cx) { XMLLib xmlLib = currentXMLLib(cx); return xmlLib.escapeAttributeValue(value); }
[ "public", "static", "String", "escapeAttributeValue", "(", "Object", "value", ",", "Context", "cx", ")", "{", "XMLLib", "xmlLib", "=", "currentXMLLib", "(", "cx", ")", ";", "return", "xmlLib", ".", "escapeAttributeValue", "(", "value", ")", ";", "}" ]
Escapes the reserved characters in a value of an attribute @param value Unescaped text @return The escaped text
[ "Escapes", "the", "reserved", "characters", "in", "a", "value", "of", "an", "attribute" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L4429-L4433
21,516
mozilla/rhino
src/org/mozilla/javascript/ScriptRuntime.java
ScriptRuntime.isSymbol
static boolean isSymbol(Object obj) { return (((obj instanceof NativeSymbol) && ((NativeSymbol)obj).isSymbol())) || (obj instanceof SymbolKey); }
java
static boolean isSymbol(Object obj) { return (((obj instanceof NativeSymbol) && ((NativeSymbol)obj).isSymbol())) || (obj instanceof SymbolKey); }
[ "static", "boolean", "isSymbol", "(", "Object", "obj", ")", "{", "return", "(", "(", "(", "obj", "instanceof", "NativeSymbol", ")", "&&", "(", "(", "NativeSymbol", ")", "obj", ")", ".", "isSymbol", "(", ")", ")", ")", "||", "(", "obj", "instanceof", "SymbolKey", ")", ";", "}" ]
Not all "NativeSymbol" instances are actually symbols. So account for that here rather than just by using an "instanceof" check.
[ "Not", "all", "NativeSymbol", "instances", "are", "actually", "symbols", ".", "So", "account", "for", "that", "here", "rather", "than", "just", "by", "using", "an", "instanceof", "check", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L4541-L4544
21,517
mozilla/rhino
src/org/mozilla/javascript/MemberBox.java
MemberBox.writeMember
private static void writeMember(ObjectOutputStream out, Executable member) throws IOException { if (member == null) { out.writeBoolean(false); return; } out.writeBoolean(true); if (!(member instanceof Method || member instanceof Constructor)) throw new IllegalArgumentException("not Method or Constructor"); out.writeBoolean(member instanceof Method); out.writeObject(member.getName()); out.writeObject(member.getDeclaringClass()); writeParameters(out, member.getParameterTypes()); }
java
private static void writeMember(ObjectOutputStream out, Executable member) throws IOException { if (member == null) { out.writeBoolean(false); return; } out.writeBoolean(true); if (!(member instanceof Method || member instanceof Constructor)) throw new IllegalArgumentException("not Method or Constructor"); out.writeBoolean(member instanceof Method); out.writeObject(member.getName()); out.writeObject(member.getDeclaringClass()); writeParameters(out, member.getParameterTypes()); }
[ "private", "static", "void", "writeMember", "(", "ObjectOutputStream", "out", ",", "Executable", "member", ")", "throws", "IOException", "{", "if", "(", "member", "==", "null", ")", "{", "out", ".", "writeBoolean", "(", "false", ")", ";", "return", ";", "}", "out", ".", "writeBoolean", "(", "true", ")", ";", "if", "(", "!", "(", "member", "instanceof", "Method", "||", "member", "instanceof", "Constructor", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"not Method or Constructor\"", ")", ";", "out", ".", "writeBoolean", "(", "member", "instanceof", "Method", ")", ";", "out", ".", "writeObject", "(", "member", ".", "getName", "(", ")", ")", ";", "out", ".", "writeObject", "(", "member", ".", "getDeclaringClass", "(", ")", ")", ";", "writeParameters", "(", "out", ",", "member", ".", "getParameterTypes", "(", ")", ")", ";", "}" ]
Writes a Constructor or Method object. Methods and Constructors are not serializable, so we must serialize information about the class, the name, and the parameters and recreate upon deserialization.
[ "Writes", "a", "Constructor", "or", "Method", "object", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/MemberBox.java#L227-L241
21,518
mozilla/rhino
src/org/mozilla/javascript/MemberBox.java
MemberBox.readMember
private static Executable readMember(ObjectInputStream in) throws IOException, ClassNotFoundException { if (!in.readBoolean()) return null; boolean isMethod = in.readBoolean(); String name = (String) in.readObject(); Class<?> declaring = (Class<?>) in.readObject(); Class<?>[] parms = readParameters(in); try { if (isMethod) { return declaring.getMethod(name, parms); } return declaring.getConstructor(parms); } catch (NoSuchMethodException e) { throw new IOException("Cannot find member: " + e); } }
java
private static Executable readMember(ObjectInputStream in) throws IOException, ClassNotFoundException { if (!in.readBoolean()) return null; boolean isMethod = in.readBoolean(); String name = (String) in.readObject(); Class<?> declaring = (Class<?>) in.readObject(); Class<?>[] parms = readParameters(in); try { if (isMethod) { return declaring.getMethod(name, parms); } return declaring.getConstructor(parms); } catch (NoSuchMethodException e) { throw new IOException("Cannot find member: " + e); } }
[ "private", "static", "Executable", "readMember", "(", "ObjectInputStream", "in", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "if", "(", "!", "in", ".", "readBoolean", "(", ")", ")", "return", "null", ";", "boolean", "isMethod", "=", "in", ".", "readBoolean", "(", ")", ";", "String", "name", "=", "(", "String", ")", "in", ".", "readObject", "(", ")", ";", "Class", "<", "?", ">", "declaring", "=", "(", "Class", "<", "?", ">", ")", "in", ".", "readObject", "(", ")", ";", "Class", "<", "?", ">", "[", "]", "parms", "=", "readParameters", "(", "in", ")", ";", "try", "{", "if", "(", "isMethod", ")", "{", "return", "declaring", ".", "getMethod", "(", "name", ",", "parms", ")", ";", "}", "return", "declaring", ".", "getConstructor", "(", "parms", ")", ";", "}", "catch", "(", "NoSuchMethodException", "e", ")", "{", "throw", "new", "IOException", "(", "\"Cannot find member: \"", "+", "e", ")", ";", "}", "}" ]
Reads a Method or a Constructor from the stream.
[ "Reads", "a", "Method", "or", "a", "Constructor", "from", "the", "stream", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/MemberBox.java#L246-L263
21,519
mozilla/rhino
src/org/mozilla/javascript/MemberBox.java
MemberBox.writeParameters
private static void writeParameters(ObjectOutputStream out, Class<?>[] parms) throws IOException { out.writeShort(parms.length); outer: for (int i=0; i < parms.length; i++) { Class<?> parm = parms[i]; boolean primitive = parm.isPrimitive(); out.writeBoolean(primitive); if (!primitive) { out.writeObject(parm); continue; } for (int j=0; j < primitives.length; j++) { if (parm.equals(primitives[j])) { out.writeByte(j); continue outer; } } throw new IllegalArgumentException("Primitive " + parm + " not found"); } }
java
private static void writeParameters(ObjectOutputStream out, Class<?>[] parms) throws IOException { out.writeShort(parms.length); outer: for (int i=0; i < parms.length; i++) { Class<?> parm = parms[i]; boolean primitive = parm.isPrimitive(); out.writeBoolean(primitive); if (!primitive) { out.writeObject(parm); continue; } for (int j=0; j < primitives.length; j++) { if (parm.equals(primitives[j])) { out.writeByte(j); continue outer; } } throw new IllegalArgumentException("Primitive " + parm + " not found"); } }
[ "private", "static", "void", "writeParameters", "(", "ObjectOutputStream", "out", ",", "Class", "<", "?", ">", "[", "]", "parms", ")", "throws", "IOException", "{", "out", ".", "writeShort", "(", "parms", ".", "length", ")", ";", "outer", ":", "for", "(", "int", "i", "=", "0", ";", "i", "<", "parms", ".", "length", ";", "i", "++", ")", "{", "Class", "<", "?", ">", "parm", "=", "parms", "[", "i", "]", ";", "boolean", "primitive", "=", "parm", ".", "isPrimitive", "(", ")", ";", "out", ".", "writeBoolean", "(", "primitive", ")", ";", "if", "(", "!", "primitive", ")", "{", "out", ".", "writeObject", "(", "parm", ")", ";", "continue", ";", "}", "for", "(", "int", "j", "=", "0", ";", "j", "<", "primitives", ".", "length", ";", "j", "++", ")", "{", "if", "(", "parm", ".", "equals", "(", "primitives", "[", "j", "]", ")", ")", "{", "out", ".", "writeByte", "(", "j", ")", ";", "continue", "outer", ";", "}", "}", "throw", "new", "IllegalArgumentException", "(", "\"Primitive \"", "+", "parm", "+", "\" not found\"", ")", ";", "}", "}" ]
Writes an array of parameter types to the stream. Requires special handling because primitive types cannot be found upon deserialization by the default Java implementation.
[ "Writes", "an", "array", "of", "parameter", "types", "to", "the", "stream", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/MemberBox.java#L283-L305
21,520
mozilla/rhino
src/org/mozilla/javascript/MemberBox.java
MemberBox.readParameters
private static Class<?>[] readParameters(ObjectInputStream in) throws IOException, ClassNotFoundException { Class<?>[] result = new Class[in.readShort()]; for (int i=0; i < result.length; i++) { if (!in.readBoolean()) { result[i] = (Class<?>) in.readObject(); continue; } result[i] = primitives[in.readByte()]; } return result; }
java
private static Class<?>[] readParameters(ObjectInputStream in) throws IOException, ClassNotFoundException { Class<?>[] result = new Class[in.readShort()]; for (int i=0; i < result.length; i++) { if (!in.readBoolean()) { result[i] = (Class<?>) in.readObject(); continue; } result[i] = primitives[in.readByte()]; } return result; }
[ "private", "static", "Class", "<", "?", ">", "[", "]", "readParameters", "(", "ObjectInputStream", "in", ")", "throws", "IOException", ",", "ClassNotFoundException", "{", "Class", "<", "?", ">", "[", "]", "result", "=", "new", "Class", "[", "in", ".", "readShort", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "result", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "in", ".", "readBoolean", "(", ")", ")", "{", "result", "[", "i", "]", "=", "(", "Class", "<", "?", ">", ")", "in", ".", "readObject", "(", ")", ";", "continue", ";", "}", "result", "[", "i", "]", "=", "primitives", "[", "in", ".", "readByte", "(", ")", "]", ";", "}", "return", "result", ";", "}" ]
Reads an array of parameter types from the stream.
[ "Reads", "an", "array", "of", "parameter", "types", "from", "the", "stream", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/MemberBox.java#L310-L322
21,521
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.attachTo
public void attachTo(ContextFactory factory) { detach(); this.contextFactory = factory; this.listener = new DimIProxy(this, IPROXY_LISTEN); factory.addListener(this.listener); }
java
public void attachTo(ContextFactory factory) { detach(); this.contextFactory = factory; this.listener = new DimIProxy(this, IPROXY_LISTEN); factory.addListener(this.listener); }
[ "public", "void", "attachTo", "(", "ContextFactory", "factory", ")", "{", "detach", "(", ")", ";", "this", ".", "contextFactory", "=", "factory", ";", "this", ".", "listener", "=", "new", "DimIProxy", "(", "this", ",", "IPROXY_LISTEN", ")", ";", "factory", ".", "addListener", "(", "this", ".", "listener", ")", ";", "}" ]
Attaches the debugger to the given ContextFactory.
[ "Attaches", "the", "debugger", "to", "the", "given", "ContextFactory", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L232-L237
21,522
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.detach
public void detach() { if (listener != null) { contextFactory.removeListener(listener); contextFactory = null; listener = null; } }
java
public void detach() { if (listener != null) { contextFactory.removeListener(listener); contextFactory = null; listener = null; } }
[ "public", "void", "detach", "(", ")", "{", "if", "(", "listener", "!=", "null", ")", "{", "contextFactory", ".", "removeListener", "(", "listener", ")", ";", "contextFactory", "=", "null", ";", "listener", "=", "null", ";", "}", "}" ]
Detaches the debugger from the current ContextFactory.
[ "Detaches", "the", "debugger", "from", "the", "current", "ContextFactory", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L242-L248
21,523
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.getFunctionSource
private FunctionSource getFunctionSource(DebuggableScript fnOrScript) { FunctionSource fsource = functionSource(fnOrScript); if (fsource == null) { String url = getNormalizedUrl(fnOrScript); SourceInfo si = sourceInfo(url); if (si == null) { if (!fnOrScript.isGeneratedScript()) { // Not eval or Function, try to load it from URL String source = loadSource(url); if (source != null) { DebuggableScript top = fnOrScript; for (;;) { DebuggableScript parent = top.getParent(); if (parent == null) { break; } top = parent; } registerTopScript(top, source); fsource = functionSource(fnOrScript); } } } } return fsource; }
java
private FunctionSource getFunctionSource(DebuggableScript fnOrScript) { FunctionSource fsource = functionSource(fnOrScript); if (fsource == null) { String url = getNormalizedUrl(fnOrScript); SourceInfo si = sourceInfo(url); if (si == null) { if (!fnOrScript.isGeneratedScript()) { // Not eval or Function, try to load it from URL String source = loadSource(url); if (source != null) { DebuggableScript top = fnOrScript; for (;;) { DebuggableScript parent = top.getParent(); if (parent == null) { break; } top = parent; } registerTopScript(top, source); fsource = functionSource(fnOrScript); } } } } return fsource; }
[ "private", "FunctionSource", "getFunctionSource", "(", "DebuggableScript", "fnOrScript", ")", "{", "FunctionSource", "fsource", "=", "functionSource", "(", "fnOrScript", ")", ";", "if", "(", "fsource", "==", "null", ")", "{", "String", "url", "=", "getNormalizedUrl", "(", "fnOrScript", ")", ";", "SourceInfo", "si", "=", "sourceInfo", "(", "url", ")", ";", "if", "(", "si", "==", "null", ")", "{", "if", "(", "!", "fnOrScript", ".", "isGeneratedScript", "(", ")", ")", "{", "// Not eval or Function, try to load it from URL", "String", "source", "=", "loadSource", "(", "url", ")", ";", "if", "(", "source", "!=", "null", ")", "{", "DebuggableScript", "top", "=", "fnOrScript", ";", "for", "(", ";", ";", ")", "{", "DebuggableScript", "parent", "=", "top", ".", "getParent", "(", ")", ";", "if", "(", "parent", "==", "null", ")", "{", "break", ";", "}", "top", "=", "parent", ";", "}", "registerTopScript", "(", "top", ",", "source", ")", ";", "fsource", "=", "functionSource", "(", "fnOrScript", ")", ";", "}", "}", "}", "}", "return", "fsource", ";", "}" ]
Returns the FunctionSource object for the given script or function.
[ "Returns", "the", "FunctionSource", "object", "for", "the", "given", "script", "or", "function", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L260-L285
21,524
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.loadSource
private String loadSource(String sourceUrl) { String source = null; int hash = sourceUrl.indexOf('#'); if (hash >= 0) { sourceUrl = sourceUrl.substring(0, hash); } try { InputStream is; openStream: { if (sourceUrl.indexOf(':') < 0) { // Can be a file name try { if (sourceUrl.startsWith("~/")) { String home = SecurityUtilities.getSystemProperty("user.home"); if (home != null) { String pathFromHome = sourceUrl.substring(2); File f = new File(new File(home), pathFromHome); if (f.exists()) { is = new FileInputStream(f); break openStream; } } } File f = new File(sourceUrl); if (f.exists()) { is = new FileInputStream(f); break openStream; } } catch (SecurityException ex) { } // No existing file, assume missed http:// if (sourceUrl.startsWith("//")) { sourceUrl = "http:" + sourceUrl; } else if (sourceUrl.startsWith("/")) { sourceUrl = "http://127.0.0.1" + sourceUrl; } else { sourceUrl = "http://" + sourceUrl; } } is = (new URL(sourceUrl)).openStream(); } try { source = Kit.readReader(new InputStreamReader(is)); } finally { is.close(); } } catch (IOException ex) { System.err.println ("Failed to load source from "+sourceUrl+": "+ ex); } return source; }
java
private String loadSource(String sourceUrl) { String source = null; int hash = sourceUrl.indexOf('#'); if (hash >= 0) { sourceUrl = sourceUrl.substring(0, hash); } try { InputStream is; openStream: { if (sourceUrl.indexOf(':') < 0) { // Can be a file name try { if (sourceUrl.startsWith("~/")) { String home = SecurityUtilities.getSystemProperty("user.home"); if (home != null) { String pathFromHome = sourceUrl.substring(2); File f = new File(new File(home), pathFromHome); if (f.exists()) { is = new FileInputStream(f); break openStream; } } } File f = new File(sourceUrl); if (f.exists()) { is = new FileInputStream(f); break openStream; } } catch (SecurityException ex) { } // No existing file, assume missed http:// if (sourceUrl.startsWith("//")) { sourceUrl = "http:" + sourceUrl; } else if (sourceUrl.startsWith("/")) { sourceUrl = "http://127.0.0.1" + sourceUrl; } else { sourceUrl = "http://" + sourceUrl; } } is = (new URL(sourceUrl)).openStream(); } try { source = Kit.readReader(new InputStreamReader(is)); } finally { is.close(); } } catch (IOException ex) { System.err.println ("Failed to load source from "+sourceUrl+": "+ ex); } return source; }
[ "private", "String", "loadSource", "(", "String", "sourceUrl", ")", "{", "String", "source", "=", "null", ";", "int", "hash", "=", "sourceUrl", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "hash", ">=", "0", ")", "{", "sourceUrl", "=", "sourceUrl", ".", "substring", "(", "0", ",", "hash", ")", ";", "}", "try", "{", "InputStream", "is", ";", "openStream", ":", "{", "if", "(", "sourceUrl", ".", "indexOf", "(", "'", "'", ")", "<", "0", ")", "{", "// Can be a file name", "try", "{", "if", "(", "sourceUrl", ".", "startsWith", "(", "\"~/\"", ")", ")", "{", "String", "home", "=", "SecurityUtilities", ".", "getSystemProperty", "(", "\"user.home\"", ")", ";", "if", "(", "home", "!=", "null", ")", "{", "String", "pathFromHome", "=", "sourceUrl", ".", "substring", "(", "2", ")", ";", "File", "f", "=", "new", "File", "(", "new", "File", "(", "home", ")", ",", "pathFromHome", ")", ";", "if", "(", "f", ".", "exists", "(", ")", ")", "{", "is", "=", "new", "FileInputStream", "(", "f", ")", ";", "break", "openStream", ";", "}", "}", "}", "File", "f", "=", "new", "File", "(", "sourceUrl", ")", ";", "if", "(", "f", ".", "exists", "(", ")", ")", "{", "is", "=", "new", "FileInputStream", "(", "f", ")", ";", "break", "openStream", ";", "}", "}", "catch", "(", "SecurityException", "ex", ")", "{", "}", "// No existing file, assume missed http://", "if", "(", "sourceUrl", ".", "startsWith", "(", "\"//\"", ")", ")", "{", "sourceUrl", "=", "\"http:\"", "+", "sourceUrl", ";", "}", "else", "if", "(", "sourceUrl", ".", "startsWith", "(", "\"/\"", ")", ")", "{", "sourceUrl", "=", "\"http://127.0.0.1\"", "+", "sourceUrl", ";", "}", "else", "{", "sourceUrl", "=", "\"http://\"", "+", "sourceUrl", ";", "}", "}", "is", "=", "(", "new", "URL", "(", "sourceUrl", ")", ")", ".", "openStream", "(", ")", ";", "}", "try", "{", "source", "=", "Kit", ".", "readReader", "(", "new", "InputStreamReader", "(", "is", ")", ")", ";", "}", "finally", "{", "is", ".", "close", "(", ")", ";", "}", "}", "catch", "(", "IOException", "ex", ")", "{", "System", ".", "err", ".", "println", "(", "\"Failed to load source from \"", "+", "sourceUrl", "+", "\": \"", "+", "ex", ")", ";", "}", "return", "source", ";", "}" ]
Loads the script at the given URL.
[ "Loads", "the", "script", "at", "the", "given", "URL", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L290-L343
21,525
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.registerTopScript
private void registerTopScript(DebuggableScript topScript, String source) { if (!topScript.isTopLevel()) { throw new IllegalArgumentException(); } String url = getNormalizedUrl(topScript); DebuggableScript[] functions = getAllFunctions(topScript); if (sourceProvider != null) { final String providedSource = sourceProvider.getSource(topScript); if(providedSource != null) { source = providedSource; } } final SourceInfo sourceInfo = new SourceInfo(source, functions, url); synchronized (urlToSourceInfo) { SourceInfo old = urlToSourceInfo.get(url); if (old != null) { sourceInfo.copyBreakpointsFrom(old); } urlToSourceInfo.put(url, sourceInfo); for (int i = 0; i != sourceInfo.functionSourcesTop(); ++i) { FunctionSource fsource = sourceInfo.functionSource(i); String name = fsource.name(); if (name.length() != 0) { functionNames.put(name, fsource); } } } synchronized (functionToSource) { for (int i = 0; i != functions.length; ++i) { FunctionSource fsource = sourceInfo.functionSource(i); functionToSource.put(functions[i], fsource); } } callback.updateSourceText(sourceInfo); }
java
private void registerTopScript(DebuggableScript topScript, String source) { if (!topScript.isTopLevel()) { throw new IllegalArgumentException(); } String url = getNormalizedUrl(topScript); DebuggableScript[] functions = getAllFunctions(topScript); if (sourceProvider != null) { final String providedSource = sourceProvider.getSource(topScript); if(providedSource != null) { source = providedSource; } } final SourceInfo sourceInfo = new SourceInfo(source, functions, url); synchronized (urlToSourceInfo) { SourceInfo old = urlToSourceInfo.get(url); if (old != null) { sourceInfo.copyBreakpointsFrom(old); } urlToSourceInfo.put(url, sourceInfo); for (int i = 0; i != sourceInfo.functionSourcesTop(); ++i) { FunctionSource fsource = sourceInfo.functionSource(i); String name = fsource.name(); if (name.length() != 0) { functionNames.put(name, fsource); } } } synchronized (functionToSource) { for (int i = 0; i != functions.length; ++i) { FunctionSource fsource = sourceInfo.functionSource(i); functionToSource.put(functions[i], fsource); } } callback.updateSourceText(sourceInfo); }
[ "private", "void", "registerTopScript", "(", "DebuggableScript", "topScript", ",", "String", "source", ")", "{", "if", "(", "!", "topScript", ".", "isTopLevel", "(", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "String", "url", "=", "getNormalizedUrl", "(", "topScript", ")", ";", "DebuggableScript", "[", "]", "functions", "=", "getAllFunctions", "(", "topScript", ")", ";", "if", "(", "sourceProvider", "!=", "null", ")", "{", "final", "String", "providedSource", "=", "sourceProvider", ".", "getSource", "(", "topScript", ")", ";", "if", "(", "providedSource", "!=", "null", ")", "{", "source", "=", "providedSource", ";", "}", "}", "final", "SourceInfo", "sourceInfo", "=", "new", "SourceInfo", "(", "source", ",", "functions", ",", "url", ")", ";", "synchronized", "(", "urlToSourceInfo", ")", "{", "SourceInfo", "old", "=", "urlToSourceInfo", ".", "get", "(", "url", ")", ";", "if", "(", "old", "!=", "null", ")", "{", "sourceInfo", ".", "copyBreakpointsFrom", "(", "old", ")", ";", "}", "urlToSourceInfo", ".", "put", "(", "url", ",", "sourceInfo", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "!=", "sourceInfo", ".", "functionSourcesTop", "(", ")", ";", "++", "i", ")", "{", "FunctionSource", "fsource", "=", "sourceInfo", ".", "functionSource", "(", "i", ")", ";", "String", "name", "=", "fsource", ".", "name", "(", ")", ";", "if", "(", "name", ".", "length", "(", ")", "!=", "0", ")", "{", "functionNames", ".", "put", "(", "name", ",", "fsource", ")", ";", "}", "}", "}", "synchronized", "(", "functionToSource", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "!=", "functions", ".", "length", ";", "++", "i", ")", "{", "FunctionSource", "fsource", "=", "sourceInfo", ".", "functionSource", "(", "i", ")", ";", "functionToSource", ".", "put", "(", "functions", "[", "i", "]", ",", "fsource", ")", ";", "}", "}", "callback", ".", "updateSourceText", "(", "sourceInfo", ")", ";", "}" ]
Registers the given script as a top-level script in the debugger.
[ "Registers", "the", "given", "script", "as", "a", "top", "-", "level", "script", "in", "the", "debugger", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L348-L386
21,526
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.getNormalizedUrl
private String getNormalizedUrl(DebuggableScript fnOrScript) { String url = fnOrScript.getSourceName(); if (url == null) { url = "<stdin>"; } else { // Not to produce window for eval from different lines, // strip line numbers, i.e. replace all #[0-9]+\(eval\) by // (eval) // Option: similar teatment for Function? char evalSeparator = '#'; StringBuilder sb = null; int urlLength = url.length(); int cursor = 0; for (;;) { int searchStart = url.indexOf(evalSeparator, cursor); if (searchStart < 0) { break; } String replace = null; int i = searchStart + 1; while (i != urlLength) { int c = url.charAt(i); if (!('0' <= c && c <= '9')) { break; } ++i; } if (i != searchStart + 1) { // i points after #[0-9]+ if ("(eval)".regionMatches(0, url, i, 6)) { cursor = i + 6; replace = "(eval)"; } } if (replace == null) { break; } if (sb == null) { sb = new StringBuilder(); sb.append(url.substring(0, searchStart)); } sb.append(replace); } if (sb != null) { if (cursor != urlLength) { sb.append(url.substring(cursor)); } url = sb.toString(); } } return url; }
java
private String getNormalizedUrl(DebuggableScript fnOrScript) { String url = fnOrScript.getSourceName(); if (url == null) { url = "<stdin>"; } else { // Not to produce window for eval from different lines, // strip line numbers, i.e. replace all #[0-9]+\(eval\) by // (eval) // Option: similar teatment for Function? char evalSeparator = '#'; StringBuilder sb = null; int urlLength = url.length(); int cursor = 0; for (;;) { int searchStart = url.indexOf(evalSeparator, cursor); if (searchStart < 0) { break; } String replace = null; int i = searchStart + 1; while (i != urlLength) { int c = url.charAt(i); if (!('0' <= c && c <= '9')) { break; } ++i; } if (i != searchStart + 1) { // i points after #[0-9]+ if ("(eval)".regionMatches(0, url, i, 6)) { cursor = i + 6; replace = "(eval)"; } } if (replace == null) { break; } if (sb == null) { sb = new StringBuilder(); sb.append(url.substring(0, searchStart)); } sb.append(replace); } if (sb != null) { if (cursor != urlLength) { sb.append(url.substring(cursor)); } url = sb.toString(); } } return url; }
[ "private", "String", "getNormalizedUrl", "(", "DebuggableScript", "fnOrScript", ")", "{", "String", "url", "=", "fnOrScript", ".", "getSourceName", "(", ")", ";", "if", "(", "url", "==", "null", ")", "{", "url", "=", "\"<stdin>\"", ";", "}", "else", "{", "// Not to produce window for eval from different lines,", "// strip line numbers, i.e. replace all #[0-9]+\\(eval\\) by", "// (eval)", "// Option: similar teatment for Function?", "char", "evalSeparator", "=", "'", "'", ";", "StringBuilder", "sb", "=", "null", ";", "int", "urlLength", "=", "url", ".", "length", "(", ")", ";", "int", "cursor", "=", "0", ";", "for", "(", ";", ";", ")", "{", "int", "searchStart", "=", "url", ".", "indexOf", "(", "evalSeparator", ",", "cursor", ")", ";", "if", "(", "searchStart", "<", "0", ")", "{", "break", ";", "}", "String", "replace", "=", "null", ";", "int", "i", "=", "searchStart", "+", "1", ";", "while", "(", "i", "!=", "urlLength", ")", "{", "int", "c", "=", "url", ".", "charAt", "(", "i", ")", ";", "if", "(", "!", "(", "'", "'", "<=", "c", "&&", "c", "<=", "'", "'", ")", ")", "{", "break", ";", "}", "++", "i", ";", "}", "if", "(", "i", "!=", "searchStart", "+", "1", ")", "{", "// i points after #[0-9]+", "if", "(", "\"(eval)\"", ".", "regionMatches", "(", "0", ",", "url", ",", "i", ",", "6", ")", ")", "{", "cursor", "=", "i", "+", "6", ";", "replace", "=", "\"(eval)\"", ";", "}", "}", "if", "(", "replace", "==", "null", ")", "{", "break", ";", "}", "if", "(", "sb", "==", "null", ")", "{", "sb", "=", "new", "StringBuilder", "(", ")", ";", "sb", ".", "append", "(", "url", ".", "substring", "(", "0", ",", "searchStart", ")", ")", ";", "}", "sb", ".", "append", "(", "replace", ")", ";", "}", "if", "(", "sb", "!=", "null", ")", "{", "if", "(", "cursor", "!=", "urlLength", ")", "{", "sb", ".", "append", "(", "url", ".", "substring", "(", "cursor", ")", ")", ";", "}", "url", "=", "sb", ".", "toString", "(", ")", ";", "}", "}", "return", "url", ";", "}" ]
Returns the source URL for the given script or function.
[ "Returns", "the", "source", "URL", "for", "the", "given", "script", "or", "function", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L421-L471
21,527
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.getAllFunctions
private static DebuggableScript[] getAllFunctions (DebuggableScript function) { ObjArray functions = new ObjArray(); collectFunctions_r(function, functions); DebuggableScript[] result = new DebuggableScript[functions.size()]; functions.toArray(result); return result; }
java
private static DebuggableScript[] getAllFunctions (DebuggableScript function) { ObjArray functions = new ObjArray(); collectFunctions_r(function, functions); DebuggableScript[] result = new DebuggableScript[functions.size()]; functions.toArray(result); return result; }
[ "private", "static", "DebuggableScript", "[", "]", "getAllFunctions", "(", "DebuggableScript", "function", ")", "{", "ObjArray", "functions", "=", "new", "ObjArray", "(", ")", ";", "collectFunctions_r", "(", "function", ",", "functions", ")", ";", "DebuggableScript", "[", "]", "result", "=", "new", "DebuggableScript", "[", "functions", ".", "size", "(", ")", "]", ";", "functions", ".", "toArray", "(", "result", ")", ";", "return", "result", ";", "}" ]
Returns an array of all functions in the given script.
[ "Returns", "an", "array", "of", "all", "functions", "in", "the", "given", "script", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L476-L483
21,528
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.handleBreakpointHit
private void handleBreakpointHit(StackFrame frame, Context cx) { breakFlag = false; interrupted(cx, frame, null); }
java
private void handleBreakpointHit(StackFrame frame, Context cx) { breakFlag = false; interrupted(cx, frame, null); }
[ "private", "void", "handleBreakpointHit", "(", "StackFrame", "frame", ",", "Context", "cx", ")", "{", "breakFlag", "=", "false", ";", "interrupted", "(", "cx", ",", "frame", ",", "null", ")", ";", "}" ]
Called when a breakpoint has been hit.
[ "Called", "when", "a", "breakpoint", "has", "been", "hit", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L508-L511
21,529
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.handleExceptionThrown
private void handleExceptionThrown(Context cx, Throwable ex, StackFrame frame) { if (breakOnExceptions) { ContextData cd = frame.contextData(); if (cd.lastProcessedException != ex) { interrupted(cx, frame, ex); cd.lastProcessedException = ex; } } }
java
private void handleExceptionThrown(Context cx, Throwable ex, StackFrame frame) { if (breakOnExceptions) { ContextData cd = frame.contextData(); if (cd.lastProcessedException != ex) { interrupted(cx, frame, ex); cd.lastProcessedException = ex; } } }
[ "private", "void", "handleExceptionThrown", "(", "Context", "cx", ",", "Throwable", "ex", ",", "StackFrame", "frame", ")", "{", "if", "(", "breakOnExceptions", ")", "{", "ContextData", "cd", "=", "frame", ".", "contextData", "(", ")", ";", "if", "(", "cd", ".", "lastProcessedException", "!=", "ex", ")", "{", "interrupted", "(", "cx", ",", "frame", ",", "ex", ")", ";", "cd", ".", "lastProcessedException", "=", "ex", ";", "}", "}", "}" ]
Called when a script exception has been thrown.
[ "Called", "when", "a", "script", "exception", "has", "been", "thrown", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L516-L525
21,530
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.compileScript
public void compileScript(String url, String text) { DimIProxy action = new DimIProxy(this, IPROXY_COMPILE_SCRIPT); action.url = url; action.text = text; action.withContext(); }
java
public void compileScript(String url, String text) { DimIProxy action = new DimIProxy(this, IPROXY_COMPILE_SCRIPT); action.url = url; action.text = text; action.withContext(); }
[ "public", "void", "compileScript", "(", "String", "url", ",", "String", "text", ")", "{", "DimIProxy", "action", "=", "new", "DimIProxy", "(", "this", ",", "IPROXY_COMPILE_SCRIPT", ")", ";", "action", ".", "url", "=", "url", ";", "action", ".", "text", "=", "text", ";", "action", ".", "withContext", "(", ")", ";", "}" ]
Compiles the given script.
[ "Compiles", "the", "given", "script", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L594-L599
21,531
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.objectToString
public String objectToString(Object object) { DimIProxy action = new DimIProxy(this, IPROXY_OBJECT_TO_STRING); action.object = object; action.withContext(); return action.stringResult; }
java
public String objectToString(Object object) { DimIProxy action = new DimIProxy(this, IPROXY_OBJECT_TO_STRING); action.object = object; action.withContext(); return action.stringResult; }
[ "public", "String", "objectToString", "(", "Object", "object", ")", "{", "DimIProxy", "action", "=", "new", "DimIProxy", "(", "this", ",", "IPROXY_OBJECT_TO_STRING", ")", ";", "action", ".", "object", "=", "object", ";", "action", ".", "withContext", "(", ")", ";", "return", "action", ".", "stringResult", ";", "}" ]
Converts the given script object to a string.
[ "Converts", "the", "given", "script", "object", "to", "a", "string", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L614-L619
21,532
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.stringIsCompilableUnit
public boolean stringIsCompilableUnit(String str) { DimIProxy action = new DimIProxy(this, IPROXY_STRING_IS_COMPILABLE); action.text = str; action.withContext(); return action.booleanResult; }
java
public boolean stringIsCompilableUnit(String str) { DimIProxy action = new DimIProxy(this, IPROXY_STRING_IS_COMPILABLE); action.text = str; action.withContext(); return action.booleanResult; }
[ "public", "boolean", "stringIsCompilableUnit", "(", "String", "str", ")", "{", "DimIProxy", "action", "=", "new", "DimIProxy", "(", "this", ",", "IPROXY_STRING_IS_COMPILABLE", ")", ";", "action", ".", "text", "=", "str", ";", "action", ".", "withContext", "(", ")", ";", "return", "action", ".", "booleanResult", ";", "}" ]
Returns whether the given string is syntactically valid script.
[ "Returns", "whether", "the", "given", "string", "is", "syntactically", "valid", "script", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L624-L629
21,533
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
Dim.do_eval
private static String do_eval(Context cx, StackFrame frame, String expr) { String resultString; Debugger saved_debugger = cx.getDebugger(); Object saved_data = cx.getDebuggerContextData(); int saved_level = cx.getOptimizationLevel(); cx.setDebugger(null, null); cx.setOptimizationLevel(-1); cx.setGeneratingDebug(false); try { Callable script = (Callable)cx.compileString(expr, "", 0, null); Object result = script.call(cx, frame.scope, frame.thisObj, ScriptRuntime.emptyArgs); if (result == Undefined.instance) { resultString = ""; } else { resultString = ScriptRuntime.toString(result); } } catch (Exception exc) { resultString = exc.getMessage(); } finally { cx.setGeneratingDebug(true); cx.setOptimizationLevel(saved_level); cx.setDebugger(saved_debugger, saved_data); } if (resultString == null) { resultString = "null"; } return resultString; }
java
private static String do_eval(Context cx, StackFrame frame, String expr) { String resultString; Debugger saved_debugger = cx.getDebugger(); Object saved_data = cx.getDebuggerContextData(); int saved_level = cx.getOptimizationLevel(); cx.setDebugger(null, null); cx.setOptimizationLevel(-1); cx.setGeneratingDebug(false); try { Callable script = (Callable)cx.compileString(expr, "", 0, null); Object result = script.call(cx, frame.scope, frame.thisObj, ScriptRuntime.emptyArgs); if (result == Undefined.instance) { resultString = ""; } else { resultString = ScriptRuntime.toString(result); } } catch (Exception exc) { resultString = exc.getMessage(); } finally { cx.setGeneratingDebug(true); cx.setOptimizationLevel(saved_level); cx.setDebugger(saved_debugger, saved_data); } if (resultString == null) { resultString = "null"; } return resultString; }
[ "private", "static", "String", "do_eval", "(", "Context", "cx", ",", "StackFrame", "frame", ",", "String", "expr", ")", "{", "String", "resultString", ";", "Debugger", "saved_debugger", "=", "cx", ".", "getDebugger", "(", ")", ";", "Object", "saved_data", "=", "cx", ".", "getDebuggerContextData", "(", ")", ";", "int", "saved_level", "=", "cx", ".", "getOptimizationLevel", "(", ")", ";", "cx", ".", "setDebugger", "(", "null", ",", "null", ")", ";", "cx", ".", "setOptimizationLevel", "(", "-", "1", ")", ";", "cx", ".", "setGeneratingDebug", "(", "false", ")", ";", "try", "{", "Callable", "script", "=", "(", "Callable", ")", "cx", ".", "compileString", "(", "expr", ",", "\"\"", ",", "0", ",", "null", ")", ";", "Object", "result", "=", "script", ".", "call", "(", "cx", ",", "frame", ".", "scope", ",", "frame", ".", "thisObj", ",", "ScriptRuntime", ".", "emptyArgs", ")", ";", "if", "(", "result", "==", "Undefined", ".", "instance", ")", "{", "resultString", "=", "\"\"", ";", "}", "else", "{", "resultString", "=", "ScriptRuntime", ".", "toString", "(", "result", ")", ";", "}", "}", "catch", "(", "Exception", "exc", ")", "{", "resultString", "=", "exc", ".", "getMessage", "(", ")", ";", "}", "finally", "{", "cx", ".", "setGeneratingDebug", "(", "true", ")", ";", "cx", ".", "setOptimizationLevel", "(", "saved_level", ")", ";", "cx", ".", "setDebugger", "(", "saved_debugger", ",", "saved_data", ")", ";", "}", "if", "(", "resultString", "==", "null", ")", "{", "resultString", "=", "\"null\"", ";", "}", "return", "resultString", ";", "}" ]
Evaluates script in the given stack frame.
[ "Evaluates", "script", "in", "the", "given", "stack", "frame", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java#L866-L895
21,534
mozilla/rhino
src/org/mozilla/javascript/ast/Symbol.java
Symbol.setDeclType
public void setDeclType(int declType) { if (!(declType == Token.FUNCTION || declType == Token.LP || declType == Token.VAR || declType == Token.LET || declType == Token.CONST)) throw new IllegalArgumentException("Invalid declType: " + declType); this.declType = declType; }
java
public void setDeclType(int declType) { if (!(declType == Token.FUNCTION || declType == Token.LP || declType == Token.VAR || declType == Token.LET || declType == Token.CONST)) throw new IllegalArgumentException("Invalid declType: " + declType); this.declType = declType; }
[ "public", "void", "setDeclType", "(", "int", "declType", ")", "{", "if", "(", "!", "(", "declType", "==", "Token", ".", "FUNCTION", "||", "declType", "==", "Token", ".", "LP", "||", "declType", "==", "Token", ".", "VAR", "||", "declType", "==", "Token", ".", "LET", "||", "declType", "==", "Token", ".", "CONST", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"Invalid declType: \"", "+", "declType", ")", ";", "this", ".", "declType", "=", "declType", ";", "}" ]
Sets symbol declaration type
[ "Sets", "symbol", "declaration", "type" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/Symbol.java#L48-L56
21,535
mozilla/rhino
src/org/mozilla/javascript/ClassCache.java
ClassCache.associate
public boolean associate(ScriptableObject topScope) { if (topScope.getParentScope() != null) { // Can only associate cache with top level scope throw new IllegalArgumentException(); } if (this == topScope.associateValue(AKEY, this)) { associatedScope = topScope; return true; } return false; }
java
public boolean associate(ScriptableObject topScope) { if (topScope.getParentScope() != null) { // Can only associate cache with top level scope throw new IllegalArgumentException(); } if (this == topScope.associateValue(AKEY, this)) { associatedScope = topScope; return true; } return false; }
[ "public", "boolean", "associate", "(", "ScriptableObject", "topScope", ")", "{", "if", "(", "topScope", ".", "getParentScope", "(", ")", "!=", "null", ")", "{", "// Can only associate cache with top level scope", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "if", "(", "this", "==", "topScope", ".", "associateValue", "(", "AKEY", ",", "this", ")", ")", "{", "associatedScope", "=", "topScope", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Associate ClassCache object with the given top-level scope. The ClassCache object can only be associated with the given scope once. @param topScope scope to associate this ClassCache object with. @return true if no previous ClassCache objects were embedded into the scope and this ClassCache were successfully associated or false otherwise. @see #get(Scriptable scope)
[ "Associate", "ClassCache", "object", "with", "the", "given", "top", "-", "level", "scope", ".", "The", "ClassCache", "object", "can", "only", "be", "associated", "with", "the", "given", "scope", "once", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ClassCache.java#L67-L78
21,536
mozilla/rhino
examples/Foo.java
Foo.varargs
@JSFunction public static Object varargs(Context cx, Scriptable thisObj, Object[] args, Function funObj) { StringBuilder buf = new StringBuilder(); buf.append("this = "); buf.append(Context.toString(thisObj)); buf.append("; args = ["); for (int i=0; i < args.length; i++) { buf.append(Context.toString(args[i])); if (i+1 != args.length) buf.append(", "); } buf.append("]"); return buf.toString(); }
java
@JSFunction public static Object varargs(Context cx, Scriptable thisObj, Object[] args, Function funObj) { StringBuilder buf = new StringBuilder(); buf.append("this = "); buf.append(Context.toString(thisObj)); buf.append("; args = ["); for (int i=0; i < args.length; i++) { buf.append(Context.toString(args[i])); if (i+1 != args.length) buf.append(", "); } buf.append("]"); return buf.toString(); }
[ "@", "JSFunction", "public", "static", "Object", "varargs", "(", "Context", "cx", ",", "Scriptable", "thisObj", ",", "Object", "[", "]", "args", ",", "Function", "funObj", ")", "{", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "buf", ".", "append", "(", "\"this = \"", ")", ";", "buf", ".", "append", "(", "Context", ".", "toString", "(", "thisObj", ")", ")", ";", "buf", ".", "append", "(", "\"; args = [\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "args", ".", "length", ";", "i", "++", ")", "{", "buf", ".", "append", "(", "Context", ".", "toString", "(", "args", "[", "i", "]", ")", ")", ";", "if", "(", "i", "+", "1", "!=", "args", ".", "length", ")", "buf", ".", "append", "(", "\", \"", ")", ";", "}", "buf", ".", "append", "(", "\"]\"", ")", ";", "return", "buf", ".", "toString", "(", ")", ";", "}" ]
An example of a variable-arguments method. All variable arguments methods must have the same number and types of parameters, and must be static. <p> @param cx the Context of the current thread @param thisObj the JavaScript 'this' value. @param args the array of arguments for this call @param funObj the function object of the invoked JavaScript function This value is useful to compute a scope using Context.getTopLevelScope(). @return computes the string values and types of 'this' and of each of the supplied arguments and returns them in a string. @see org.mozilla.javascript.ScriptableObject#getTopLevelScope
[ "An", "example", "of", "a", "variable", "-", "arguments", "method", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/Foo.java#L126-L141
21,537
mozilla/rhino
src/org/mozilla/javascript/ES6Iterator.java
ES6Iterator.makeIteratorResult
private Scriptable makeIteratorResult(Context cx, Scriptable scope, boolean done, Object value) { Scriptable iteratorResult = cx.newObject(scope); ScriptableObject.putProperty(iteratorResult, VALUE_PROPERTY, value); ScriptableObject.putProperty(iteratorResult, DONE_PROPERTY, done); return iteratorResult; }
java
private Scriptable makeIteratorResult(Context cx, Scriptable scope, boolean done, Object value) { Scriptable iteratorResult = cx.newObject(scope); ScriptableObject.putProperty(iteratorResult, VALUE_PROPERTY, value); ScriptableObject.putProperty(iteratorResult, DONE_PROPERTY, done); return iteratorResult; }
[ "private", "Scriptable", "makeIteratorResult", "(", "Context", "cx", ",", "Scriptable", "scope", ",", "boolean", "done", ",", "Object", "value", ")", "{", "Scriptable", "iteratorResult", "=", "cx", ".", "newObject", "(", "scope", ")", ";", "ScriptableObject", ".", "putProperty", "(", "iteratorResult", ",", "VALUE_PROPERTY", ",", "value", ")", ";", "ScriptableObject", ".", "putProperty", "(", "iteratorResult", ",", "DONE_PROPERTY", ",", "done", ")", ";", "return", "iteratorResult", ";", "}" ]
25.1.1.3 The IteratorResult Interface
[ "25", ".", "1", ".", "1", ".", "3", "The", "IteratorResult", "Interface" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ES6Iterator.java#L126-L131
21,538
mozilla/rhino
src/org/mozilla/javascript/v8dtoa/DiyFp.java
DiyFp.subtract
void subtract(DiyFp other) { assert (e == other.e); assert uint64_gte(f, other.f); f -= other.f; }
java
void subtract(DiyFp other) { assert (e == other.e); assert uint64_gte(f, other.f); f -= other.f; }
[ "void", "subtract", "(", "DiyFp", "other", ")", "{", "assert", "(", "e", "==", "other", ".", "e", ")", ";", "assert", "uint64_gte", "(", "f", ",", "other", ".", "f", ")", ";", "f", "-=", "other", ".", "f", ";", "}" ]
The result will not be normalized.
[ "The", "result", "will", "not", "be", "normalized", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/v8dtoa/DiyFp.java#L66-L70
21,539
mozilla/rhino
src/org/mozilla/javascript/v8dtoa/DiyFp.java
DiyFp.minus
static DiyFp minus(DiyFp a, DiyFp b) { DiyFp result = new DiyFp(a.f, a.e); result.subtract(b); return result; }
java
static DiyFp minus(DiyFp a, DiyFp b) { DiyFp result = new DiyFp(a.f, a.e); result.subtract(b); return result; }
[ "static", "DiyFp", "minus", "(", "DiyFp", "a", ",", "DiyFp", "b", ")", "{", "DiyFp", "result", "=", "new", "DiyFp", "(", "a", ".", "f", ",", "a", ".", "e", ")", ";", "result", ".", "subtract", "(", "b", ")", ";", "return", "result", ";", "}" ]
than other. The result will not be normalized.
[ "than", "other", ".", "The", "result", "will", "not", "be", "normalized", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/v8dtoa/DiyFp.java#L75-L79
21,540
mozilla/rhino
src/org/mozilla/javascript/ast/SwitchStatement.java
SwitchStatement.setCases
public void setCases(List<SwitchCase> cases) { if (cases == null) { this.cases = null; } else { if (this.cases != null) this.cases.clear(); for (SwitchCase sc : cases) addCase(sc); } }
java
public void setCases(List<SwitchCase> cases) { if (cases == null) { this.cases = null; } else { if (this.cases != null) this.cases.clear(); for (SwitchCase sc : cases) addCase(sc); } }
[ "public", "void", "setCases", "(", "List", "<", "SwitchCase", ">", "cases", ")", "{", "if", "(", "cases", "==", "null", ")", "{", "this", ".", "cases", "=", "null", ";", "}", "else", "{", "if", "(", "this", ".", "cases", "!=", "null", ")", "this", ".", "cases", ".", "clear", "(", ")", ";", "for", "(", "SwitchCase", "sc", ":", "cases", ")", "addCase", "(", "sc", ")", ";", "}", "}" ]
Sets case statement list, and sets the parent of each child case to this node. @param cases list, which may be {@code null} to remove all the cases
[ "Sets", "case", "statement", "list", "and", "sets", "the", "parent", "of", "each", "child", "case", "to", "this", "node", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/SwitchStatement.java#L90-L99
21,541
mozilla/rhino
src/org/mozilla/javascript/ast/SwitchStatement.java
SwitchStatement.addCase
public void addCase(SwitchCase switchCase) { assertNotNull(switchCase); if (cases == null) { cases = new ArrayList<SwitchCase>(); } cases.add(switchCase); switchCase.setParent(this); }
java
public void addCase(SwitchCase switchCase) { assertNotNull(switchCase); if (cases == null) { cases = new ArrayList<SwitchCase>(); } cases.add(switchCase); switchCase.setParent(this); }
[ "public", "void", "addCase", "(", "SwitchCase", "switchCase", ")", "{", "assertNotNull", "(", "switchCase", ")", ";", "if", "(", "cases", "==", "null", ")", "{", "cases", "=", "new", "ArrayList", "<", "SwitchCase", ">", "(", ")", ";", "}", "cases", ".", "add", "(", "switchCase", ")", ";", "switchCase", ".", "setParent", "(", "this", ")", ";", "}" ]
Adds a switch case statement to the end of the list. @throws IllegalArgumentException} if switchCase is {@code null}
[ "Adds", "a", "switch", "case", "statement", "to", "the", "end", "of", "the", "list", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/SwitchStatement.java#L105-L112
21,542
mozilla/rhino
src/org/mozilla/javascript/ast/SwitchStatement.java
SwitchStatement.visit
@Override public void visit(NodeVisitor v) { if (v.visit(this)) { expression.visit(v); for (SwitchCase sc: getCases()) { sc.visit(v); } } }
java
@Override public void visit(NodeVisitor v) { if (v.visit(this)) { expression.visit(v); for (SwitchCase sc: getCases()) { sc.visit(v); } } }
[ "@", "Override", "public", "void", "visit", "(", "NodeVisitor", "v", ")", "{", "if", "(", "v", ".", "visit", "(", "this", ")", ")", "{", "expression", ".", "visit", "(", "v", ")", ";", "for", "(", "SwitchCase", "sc", ":", "getCases", "(", ")", ")", "{", "sc", ".", "visit", "(", "v", ")", ";", "}", "}", "}" ]
Visits this node, then the switch-expression, then the cases in lexical order.
[ "Visits", "this", "node", "then", "the", "switch", "-", "expression", "then", "the", "cases", "in", "lexical", "order", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/SwitchStatement.java#L172-L180
21,543
mozilla/rhino
src/org/mozilla/javascript/IRFactory.java
IRFactory.transformTree
public ScriptNode transformTree(AstRoot root) { currentScriptOrFn = root; this.inUseStrictDirective = root.isInStrictMode(); int sourceStartOffset = decompiler.getCurrentOffset(); if (Token.printTrees) { System.out.println("IRFactory.transformTree"); System.out.println(root.debugPrint()); } ScriptNode script = (ScriptNode)transform(root); int sourceEndOffset = decompiler.getCurrentOffset(); script.setEncodedSourceBounds(sourceStartOffset, sourceEndOffset); if (compilerEnv.isGeneratingSource()) { script.setEncodedSource(decompiler.getEncodedSource()); } decompiler = null; return script; }
java
public ScriptNode transformTree(AstRoot root) { currentScriptOrFn = root; this.inUseStrictDirective = root.isInStrictMode(); int sourceStartOffset = decompiler.getCurrentOffset(); if (Token.printTrees) { System.out.println("IRFactory.transformTree"); System.out.println(root.debugPrint()); } ScriptNode script = (ScriptNode)transform(root); int sourceEndOffset = decompiler.getCurrentOffset(); script.setEncodedSourceBounds(sourceStartOffset, sourceEndOffset); if (compilerEnv.isGeneratingSource()) { script.setEncodedSource(decompiler.getEncodedSource()); } decompiler = null; return script; }
[ "public", "ScriptNode", "transformTree", "(", "AstRoot", "root", ")", "{", "currentScriptOrFn", "=", "root", ";", "this", ".", "inUseStrictDirective", "=", "root", ".", "isInStrictMode", "(", ")", ";", "int", "sourceStartOffset", "=", "decompiler", ".", "getCurrentOffset", "(", ")", ";", "if", "(", "Token", ".", "printTrees", ")", "{", "System", ".", "out", ".", "println", "(", "\"IRFactory.transformTree\"", ")", ";", "System", ".", "out", ".", "println", "(", "root", ".", "debugPrint", "(", ")", ")", ";", "}", "ScriptNode", "script", "=", "(", "ScriptNode", ")", "transform", "(", "root", ")", ";", "int", "sourceEndOffset", "=", "decompiler", ".", "getCurrentOffset", "(", ")", ";", "script", ".", "setEncodedSourceBounds", "(", "sourceStartOffset", ",", "sourceEndOffset", ")", ";", "if", "(", "compilerEnv", ".", "isGeneratingSource", "(", ")", ")", "{", "script", ".", "setEncodedSource", "(", "decompiler", ".", "getEncodedSource", "(", ")", ")", ";", "}", "decompiler", "=", "null", ";", "return", "script", ";", "}" ]
Transforms the tree into a lower-level IR suitable for codegen. Optionally generates the encoded source.
[ "Transforms", "the", "tree", "into", "a", "lower", "-", "level", "IR", "suitable", "for", "codegen", ".", "Optionally", "generates", "the", "encoded", "source", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/IRFactory.java#L108-L129
21,544
mozilla/rhino
src/org/mozilla/javascript/IRFactory.java
IRFactory.transformXmlRef
private Node transformXmlRef(XmlRef node) { int memberTypeFlags = node.isAttributeAccess() ? Node.ATTRIBUTE_FLAG : 0; return transformXmlRef(null, node, memberTypeFlags); }
java
private Node transformXmlRef(XmlRef node) { int memberTypeFlags = node.isAttributeAccess() ? Node.ATTRIBUTE_FLAG : 0; return transformXmlRef(null, node, memberTypeFlags); }
[ "private", "Node", "transformXmlRef", "(", "XmlRef", "node", ")", "{", "int", "memberTypeFlags", "=", "node", ".", "isAttributeAccess", "(", ")", "?", "Node", ".", "ATTRIBUTE_FLAG", ":", "0", ";", "return", "transformXmlRef", "(", "null", ",", "node", ",", "memberTypeFlags", ")", ";", "}" ]
We get here if we weren't a child of a . or .. infix node
[ "We", "get", "here", "if", "we", "weren", "t", "a", "child", "of", "a", ".", "or", "..", "infix", "node" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/IRFactory.java#L1357-L1361
21,545
mozilla/rhino
src/org/mozilla/javascript/IRFactory.java
IRFactory.addSwitchCase
private void addSwitchCase(Node switchBlock, Node caseExpression, Node statements) { if (switchBlock.getType() != Token.BLOCK) throw Kit.codeBug(); Jump switchNode = (Jump)switchBlock.getFirstChild(); if (switchNode.getType() != Token.SWITCH) throw Kit.codeBug(); Node gotoTarget = Node.newTarget(); if (caseExpression != null) { Jump caseNode = new Jump(Token.CASE, caseExpression); caseNode.target = gotoTarget; switchNode.addChildToBack(caseNode); } else { switchNode.setDefault(gotoTarget); } switchBlock.addChildToBack(gotoTarget); switchBlock.addChildToBack(statements); }
java
private void addSwitchCase(Node switchBlock, Node caseExpression, Node statements) { if (switchBlock.getType() != Token.BLOCK) throw Kit.codeBug(); Jump switchNode = (Jump)switchBlock.getFirstChild(); if (switchNode.getType() != Token.SWITCH) throw Kit.codeBug(); Node gotoTarget = Node.newTarget(); if (caseExpression != null) { Jump caseNode = new Jump(Token.CASE, caseExpression); caseNode.target = gotoTarget; switchNode.addChildToBack(caseNode); } else { switchNode.setDefault(gotoTarget); } switchBlock.addChildToBack(gotoTarget); switchBlock.addChildToBack(statements); }
[ "private", "void", "addSwitchCase", "(", "Node", "switchBlock", ",", "Node", "caseExpression", ",", "Node", "statements", ")", "{", "if", "(", "switchBlock", ".", "getType", "(", ")", "!=", "Token", ".", "BLOCK", ")", "throw", "Kit", ".", "codeBug", "(", ")", ";", "Jump", "switchNode", "=", "(", "Jump", ")", "switchBlock", ".", "getFirstChild", "(", ")", ";", "if", "(", "switchNode", ".", "getType", "(", ")", "!=", "Token", ".", "SWITCH", ")", "throw", "Kit", ".", "codeBug", "(", ")", ";", "Node", "gotoTarget", "=", "Node", ".", "newTarget", "(", ")", ";", "if", "(", "caseExpression", "!=", "null", ")", "{", "Jump", "caseNode", "=", "new", "Jump", "(", "Token", ".", "CASE", ",", "caseExpression", ")", ";", "caseNode", ".", "target", "=", "gotoTarget", ";", "switchNode", ".", "addChildToBack", "(", "caseNode", ")", ";", "}", "else", "{", "switchNode", ".", "setDefault", "(", "gotoTarget", ")", ";", "}", "switchBlock", ".", "addChildToBack", "(", "gotoTarget", ")", ";", "switchBlock", ".", "addChildToBack", "(", "statements", ")", ";", "}" ]
If caseExpression argument is null it indicates a default label.
[ "If", "caseExpression", "argument", "is", "null", "it", "indicates", "a", "default", "label", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/IRFactory.java#L1395-L1412
21,546
mozilla/rhino
src/org/mozilla/javascript/IRFactory.java
IRFactory.createLoopNode
private Scope createLoopNode(Node loopLabel, int lineno) { Scope result = createScopeNode(Token.LOOP, lineno); if (loopLabel != null) { ((Jump)loopLabel).setLoop(result); } return result; }
java
private Scope createLoopNode(Node loopLabel, int lineno) { Scope result = createScopeNode(Token.LOOP, lineno); if (loopLabel != null) { ((Jump)loopLabel).setLoop(result); } return result; }
[ "private", "Scope", "createLoopNode", "(", "Node", "loopLabel", ",", "int", "lineno", ")", "{", "Scope", "result", "=", "createScopeNode", "(", "Token", ".", "LOOP", ",", "lineno", ")", ";", "if", "(", "loopLabel", "!=", "null", ")", "{", "(", "(", "Jump", ")", "loopLabel", ")", ".", "setLoop", "(", "result", ")", ";", "}", "return", "result", ";", "}" ]
Create loop node. The code generator will later call createWhile|createDoWhile|createFor|createForIn to finish loop generation.
[ "Create", "loop", "node", ".", "The", "code", "generator", "will", "later", "call", "createWhile|createDoWhile|createFor|createForIn", "to", "finish", "loop", "generation", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/IRFactory.java#L1508-L1514
21,547
mozilla/rhino
src/org/mozilla/javascript/IRFactory.java
IRFactory.createForIn
private Node createForIn(int declType, Node loop, Node lhs, Node obj, Node body, boolean isForEach, boolean isForOf) { int destructuring = -1; int destructuringLen = 0; Node lvalue; int type = lhs.getType(); if (type == Token.VAR || type == Token.LET) { Node kid = lhs.getLastChild(); int kidType = kid.getType(); if (kidType == Token.ARRAYLIT || kidType == Token.OBJECTLIT) { type = destructuring = kidType; lvalue = kid; destructuringLen = 0; if (kid instanceof ArrayLiteral) destructuringLen = ((ArrayLiteral) kid).getDestructuringLength(); } else if (kidType == Token.NAME) { lvalue = Node.newString(Token.NAME, kid.getString()); } else { reportError("msg.bad.for.in.lhs"); return null; } } else if (type == Token.ARRAYLIT || type == Token.OBJECTLIT) { destructuring = type; lvalue = lhs; destructuringLen = 0; if (lhs instanceof ArrayLiteral) destructuringLen = ((ArrayLiteral) lhs).getDestructuringLength(); } else { lvalue = makeReference(lhs); if (lvalue == null) { reportError("msg.bad.for.in.lhs"); return null; } } Node localBlock = new Node(Token.LOCAL_BLOCK); int initType = isForEach ? Token.ENUM_INIT_VALUES : isForOf ? Token.ENUM_INIT_VALUES_IN_ORDER : (destructuring != -1 ? Token.ENUM_INIT_ARRAY : Token.ENUM_INIT_KEYS); Node init = new Node(initType, obj); init.putProp(Node.LOCAL_BLOCK_PROP, localBlock); Node cond = new Node(Token.ENUM_NEXT); cond.putProp(Node.LOCAL_BLOCK_PROP, localBlock); Node id = new Node(Token.ENUM_ID); id.putProp(Node.LOCAL_BLOCK_PROP, localBlock); Node newBody = new Node(Token.BLOCK); Node assign; if (destructuring != -1) { assign = createDestructuringAssignment(declType, lvalue, id); if (!isForEach && !isForOf && (destructuring == Token.OBJECTLIT || destructuringLen != 2)) { // destructuring assignment is only allowed in for..each or // with an array type of length 2 (to hold key and value) reportError("msg.bad.for.in.destruct"); } } else { assign = simpleAssignment(lvalue, id); } newBody.addChildToBack(new Node(Token.EXPR_VOID, assign)); newBody.addChildToBack(body); loop = createLoop((Jump)loop, LOOP_WHILE, newBody, cond, null, null); loop.addChildToFront(init); if (type == Token.VAR || type == Token.LET) loop.addChildToFront(lhs); localBlock.addChildToBack(loop); return localBlock; }
java
private Node createForIn(int declType, Node loop, Node lhs, Node obj, Node body, boolean isForEach, boolean isForOf) { int destructuring = -1; int destructuringLen = 0; Node lvalue; int type = lhs.getType(); if (type == Token.VAR || type == Token.LET) { Node kid = lhs.getLastChild(); int kidType = kid.getType(); if (kidType == Token.ARRAYLIT || kidType == Token.OBJECTLIT) { type = destructuring = kidType; lvalue = kid; destructuringLen = 0; if (kid instanceof ArrayLiteral) destructuringLen = ((ArrayLiteral) kid).getDestructuringLength(); } else if (kidType == Token.NAME) { lvalue = Node.newString(Token.NAME, kid.getString()); } else { reportError("msg.bad.for.in.lhs"); return null; } } else if (type == Token.ARRAYLIT || type == Token.OBJECTLIT) { destructuring = type; lvalue = lhs; destructuringLen = 0; if (lhs instanceof ArrayLiteral) destructuringLen = ((ArrayLiteral) lhs).getDestructuringLength(); } else { lvalue = makeReference(lhs); if (lvalue == null) { reportError("msg.bad.for.in.lhs"); return null; } } Node localBlock = new Node(Token.LOCAL_BLOCK); int initType = isForEach ? Token.ENUM_INIT_VALUES : isForOf ? Token.ENUM_INIT_VALUES_IN_ORDER : (destructuring != -1 ? Token.ENUM_INIT_ARRAY : Token.ENUM_INIT_KEYS); Node init = new Node(initType, obj); init.putProp(Node.LOCAL_BLOCK_PROP, localBlock); Node cond = new Node(Token.ENUM_NEXT); cond.putProp(Node.LOCAL_BLOCK_PROP, localBlock); Node id = new Node(Token.ENUM_ID); id.putProp(Node.LOCAL_BLOCK_PROP, localBlock); Node newBody = new Node(Token.BLOCK); Node assign; if (destructuring != -1) { assign = createDestructuringAssignment(declType, lvalue, id); if (!isForEach && !isForOf && (destructuring == Token.OBJECTLIT || destructuringLen != 2)) { // destructuring assignment is only allowed in for..each or // with an array type of length 2 (to hold key and value) reportError("msg.bad.for.in.destruct"); } } else { assign = simpleAssignment(lvalue, id); } newBody.addChildToBack(new Node(Token.EXPR_VOID, assign)); newBody.addChildToBack(body); loop = createLoop((Jump)loop, LOOP_WHILE, newBody, cond, null, null); loop.addChildToFront(init); if (type == Token.VAR || type == Token.LET) loop.addChildToFront(lhs); localBlock.addChildToBack(loop); return localBlock; }
[ "private", "Node", "createForIn", "(", "int", "declType", ",", "Node", "loop", ",", "Node", "lhs", ",", "Node", "obj", ",", "Node", "body", ",", "boolean", "isForEach", ",", "boolean", "isForOf", ")", "{", "int", "destructuring", "=", "-", "1", ";", "int", "destructuringLen", "=", "0", ";", "Node", "lvalue", ";", "int", "type", "=", "lhs", ".", "getType", "(", ")", ";", "if", "(", "type", "==", "Token", ".", "VAR", "||", "type", "==", "Token", ".", "LET", ")", "{", "Node", "kid", "=", "lhs", ".", "getLastChild", "(", ")", ";", "int", "kidType", "=", "kid", ".", "getType", "(", ")", ";", "if", "(", "kidType", "==", "Token", ".", "ARRAYLIT", "||", "kidType", "==", "Token", ".", "OBJECTLIT", ")", "{", "type", "=", "destructuring", "=", "kidType", ";", "lvalue", "=", "kid", ";", "destructuringLen", "=", "0", ";", "if", "(", "kid", "instanceof", "ArrayLiteral", ")", "destructuringLen", "=", "(", "(", "ArrayLiteral", ")", "kid", ")", ".", "getDestructuringLength", "(", ")", ";", "}", "else", "if", "(", "kidType", "==", "Token", ".", "NAME", ")", "{", "lvalue", "=", "Node", ".", "newString", "(", "Token", ".", "NAME", ",", "kid", ".", "getString", "(", ")", ")", ";", "}", "else", "{", "reportError", "(", "\"msg.bad.for.in.lhs\"", ")", ";", "return", "null", ";", "}", "}", "else", "if", "(", "type", "==", "Token", ".", "ARRAYLIT", "||", "type", "==", "Token", ".", "OBJECTLIT", ")", "{", "destructuring", "=", "type", ";", "lvalue", "=", "lhs", ";", "destructuringLen", "=", "0", ";", "if", "(", "lhs", "instanceof", "ArrayLiteral", ")", "destructuringLen", "=", "(", "(", "ArrayLiteral", ")", "lhs", ")", ".", "getDestructuringLength", "(", ")", ";", "}", "else", "{", "lvalue", "=", "makeReference", "(", "lhs", ")", ";", "if", "(", "lvalue", "==", "null", ")", "{", "reportError", "(", "\"msg.bad.for.in.lhs\"", ")", ";", "return", "null", ";", "}", "}", "Node", "localBlock", "=", "new", "Node", "(", "Token", ".", "LOCAL_BLOCK", ")", ";", "int", "initType", "=", "isForEach", "?", "Token", ".", "ENUM_INIT_VALUES", ":", "isForOf", "?", "Token", ".", "ENUM_INIT_VALUES_IN_ORDER", ":", "(", "destructuring", "!=", "-", "1", "?", "Token", ".", "ENUM_INIT_ARRAY", ":", "Token", ".", "ENUM_INIT_KEYS", ")", ";", "Node", "init", "=", "new", "Node", "(", "initType", ",", "obj", ")", ";", "init", ".", "putProp", "(", "Node", ".", "LOCAL_BLOCK_PROP", ",", "localBlock", ")", ";", "Node", "cond", "=", "new", "Node", "(", "Token", ".", "ENUM_NEXT", ")", ";", "cond", ".", "putProp", "(", "Node", ".", "LOCAL_BLOCK_PROP", ",", "localBlock", ")", ";", "Node", "id", "=", "new", "Node", "(", "Token", ".", "ENUM_ID", ")", ";", "id", ".", "putProp", "(", "Node", ".", "LOCAL_BLOCK_PROP", ",", "localBlock", ")", ";", "Node", "newBody", "=", "new", "Node", "(", "Token", ".", "BLOCK", ")", ";", "Node", "assign", ";", "if", "(", "destructuring", "!=", "-", "1", ")", "{", "assign", "=", "createDestructuringAssignment", "(", "declType", ",", "lvalue", ",", "id", ")", ";", "if", "(", "!", "isForEach", "&&", "!", "isForOf", "&&", "(", "destructuring", "==", "Token", ".", "OBJECTLIT", "||", "destructuringLen", "!=", "2", ")", ")", "{", "// destructuring assignment is only allowed in for..each or", "// with an array type of length 2 (to hold key and value)", "reportError", "(", "\"msg.bad.for.in.destruct\"", ")", ";", "}", "}", "else", "{", "assign", "=", "simpleAssignment", "(", "lvalue", ",", "id", ")", ";", "}", "newBody", ".", "addChildToBack", "(", "new", "Node", "(", "Token", ".", "EXPR_VOID", ",", "assign", ")", ")", ";", "newBody", ".", "addChildToBack", "(", "body", ")", ";", "loop", "=", "createLoop", "(", "(", "Jump", ")", "loop", ",", "LOOP_WHILE", ",", "newBody", ",", "cond", ",", "null", ",", "null", ")", ";", "loop", ".", "addChildToFront", "(", "init", ")", ";", "if", "(", "type", "==", "Token", ".", "VAR", "||", "type", "==", "Token", ".", "LET", ")", "loop", ".", "addChildToFront", "(", "lhs", ")", ";", "localBlock", ".", "addChildToBack", "(", "loop", ")", ";", "return", "localBlock", ";", "}" ]
Generate IR for a for..in loop.
[ "Generate", "IR", "for", "a", "for", "..", "in", "loop", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/IRFactory.java#L1586-L1661
21,548
mozilla/rhino
src/org/mozilla/javascript/IRFactory.java
IRFactory.isAlwaysDefinedBoolean
private static int isAlwaysDefinedBoolean(Node node) { switch (node.getType()) { case Token.FALSE: case Token.NULL: return ALWAYS_FALSE_BOOLEAN; case Token.TRUE: return ALWAYS_TRUE_BOOLEAN; case Token.NUMBER: { double num = node.getDouble(); if (num == num && num != 0.0) { return ALWAYS_TRUE_BOOLEAN; } return ALWAYS_FALSE_BOOLEAN; } } return 0; }
java
private static int isAlwaysDefinedBoolean(Node node) { switch (node.getType()) { case Token.FALSE: case Token.NULL: return ALWAYS_FALSE_BOOLEAN; case Token.TRUE: return ALWAYS_TRUE_BOOLEAN; case Token.NUMBER: { double num = node.getDouble(); if (num == num && num != 0.0) { return ALWAYS_TRUE_BOOLEAN; } return ALWAYS_FALSE_BOOLEAN; } } return 0; }
[ "private", "static", "int", "isAlwaysDefinedBoolean", "(", "Node", "node", ")", "{", "switch", "(", "node", ".", "getType", "(", ")", ")", "{", "case", "Token", ".", "FALSE", ":", "case", "Token", ".", "NULL", ":", "return", "ALWAYS_FALSE_BOOLEAN", ";", "case", "Token", ".", "TRUE", ":", "return", "ALWAYS_TRUE_BOOLEAN", ";", "case", "Token", ".", "NUMBER", ":", "{", "double", "num", "=", "node", ".", "getDouble", "(", ")", ";", "if", "(", "num", "==", "num", "&&", "num", "!=", "0.0", ")", "{", "return", "ALWAYS_TRUE_BOOLEAN", ";", "}", "return", "ALWAYS_FALSE_BOOLEAN", ";", "}", "}", "return", "0", ";", "}" ]
Check if Node always mean true or false in boolean context
[ "Check", "if", "Node", "always", "mean", "true", "or", "false", "in", "boolean", "context" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/IRFactory.java#L2319-L2335
21,549
mozilla/rhino
src/org/mozilla/javascript/InterpretedFunction.java
InterpretedFunction.createScript
static InterpretedFunction createScript(InterpreterData idata, Object staticSecurityDomain) { InterpretedFunction f; f = new InterpretedFunction(idata, staticSecurityDomain); return f; }
java
static InterpretedFunction createScript(InterpreterData idata, Object staticSecurityDomain) { InterpretedFunction f; f = new InterpretedFunction(idata, staticSecurityDomain); return f; }
[ "static", "InterpretedFunction", "createScript", "(", "InterpreterData", "idata", ",", "Object", "staticSecurityDomain", ")", "{", "InterpretedFunction", "f", ";", "f", "=", "new", "InterpretedFunction", "(", "idata", ",", "staticSecurityDomain", ")", ";", "return", "f", ";", "}" ]
Create script from compiled bytecode.
[ "Create", "script", "from", "compiled", "bytecode", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/InterpretedFunction.java#L53-L59
21,550
mozilla/rhino
src/org/mozilla/javascript/InterpretedFunction.java
InterpretedFunction.createFunction
static InterpretedFunction createFunction(Context cx, Scriptable scope, InterpretedFunction parent, int index) { InterpretedFunction f = new InterpretedFunction(parent, index); f.initScriptFunction(cx, scope); return f; }
java
static InterpretedFunction createFunction(Context cx, Scriptable scope, InterpretedFunction parent, int index) { InterpretedFunction f = new InterpretedFunction(parent, index); f.initScriptFunction(cx, scope); return f; }
[ "static", "InterpretedFunction", "createFunction", "(", "Context", "cx", ",", "Scriptable", "scope", ",", "InterpretedFunction", "parent", ",", "int", "index", ")", "{", "InterpretedFunction", "f", "=", "new", "InterpretedFunction", "(", "parent", ",", "index", ")", ";", "f", ".", "initScriptFunction", "(", "cx", ",", "scope", ")", ";", "return", "f", ";", "}" ]
Create function embedded in script or another function.
[ "Create", "function", "embedded", "in", "script", "or", "another", "function", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/InterpretedFunction.java#L77-L84
21,551
mozilla/rhino
src/org/mozilla/javascript/InterpretedFunction.java
InterpretedFunction.call
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!ScriptRuntime.hasTopCall(cx)) { return ScriptRuntime.doTopCall(this, cx, scope, thisObj, args, idata.isStrict); } return Interpreter.interpret(this, cx, scope, thisObj, args); }
java
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (!ScriptRuntime.hasTopCall(cx)) { return ScriptRuntime.doTopCall(this, cx, scope, thisObj, args, idata.isStrict); } return Interpreter.interpret(this, cx, scope, thisObj, args); }
[ "@", "Override", "public", "Object", "call", "(", "Context", "cx", ",", "Scriptable", "scope", ",", "Scriptable", "thisObj", ",", "Object", "[", "]", "args", ")", "{", "if", "(", "!", "ScriptRuntime", ".", "hasTopCall", "(", "cx", ")", ")", "{", "return", "ScriptRuntime", ".", "doTopCall", "(", "this", ",", "cx", ",", "scope", ",", "thisObj", ",", "args", ",", "idata", ".", "isStrict", ")", ";", "}", "return", "Interpreter", ".", "interpret", "(", "this", ",", "cx", ",", "scope", ",", "thisObj", ",", "args", ")", ";", "}" ]
Calls the function. @param cx the current context @param scope the scope used for the call @param thisObj the value of "this" @param args function arguments. Must not be null. You can use {@link ScriptRuntime#emptyArgs} to pass empty arguments. @return the result of the function call.
[ "Calls", "the", "function", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/InterpretedFunction.java#L102-L110
21,552
mozilla/rhino
src/org/mozilla/javascript/ast/ObjectLiteral.java
ObjectLiteral.setElements
public void setElements(List<ObjectProperty> elements) { if (elements == null) { this.elements = null; } else { if (this.elements != null) this.elements.clear(); for (ObjectProperty o : elements) addElement(o); } }
java
public void setElements(List<ObjectProperty> elements) { if (elements == null) { this.elements = null; } else { if (this.elements != null) this.elements.clear(); for (ObjectProperty o : elements) addElement(o); } }
[ "public", "void", "setElements", "(", "List", "<", "ObjectProperty", ">", "elements", ")", "{", "if", "(", "elements", "==", "null", ")", "{", "this", ".", "elements", "=", "null", ";", "}", "else", "{", "if", "(", "this", ".", "elements", "!=", "null", ")", "this", ".", "elements", ".", "clear", "(", ")", ";", "for", "(", "ObjectProperty", "o", ":", "elements", ")", "addElement", "(", "o", ")", ";", "}", "}" ]
Sets the element list, and updates the parent of each element. Replaces any existing elements. @param elements the element list. Can be {@code null}.
[ "Sets", "the", "element", "list", "and", "updates", "the", "parent", "of", "each", "element", ".", "Replaces", "any", "existing", "elements", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/ObjectLiteral.java#L69-L78
21,553
mozilla/rhino
src/org/mozilla/javascript/ast/ObjectLiteral.java
ObjectLiteral.addElement
public void addElement(ObjectProperty element) { assertNotNull(element); if (elements == null) { elements = new ArrayList<ObjectProperty>(); } elements.add(element); element.setParent(this); }
java
public void addElement(ObjectProperty element) { assertNotNull(element); if (elements == null) { elements = new ArrayList<ObjectProperty>(); } elements.add(element); element.setParent(this); }
[ "public", "void", "addElement", "(", "ObjectProperty", "element", ")", "{", "assertNotNull", "(", "element", ")", ";", "if", "(", "elements", "==", "null", ")", "{", "elements", "=", "new", "ArrayList", "<", "ObjectProperty", ">", "(", ")", ";", "}", "elements", ".", "add", "(", "element", ")", ";", "element", ".", "setParent", "(", "this", ")", ";", "}" ]
Adds an element to the list, and sets its parent to this node. @param element the property node to append to the end of the list @throws IllegalArgumentException} if element is {@code null}
[ "Adds", "an", "element", "to", "the", "list", "and", "sets", "its", "parent", "to", "this", "node", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/ObjectLiteral.java#L85-L92
21,554
mozilla/rhino
src/org/mozilla/javascript/NativeIterator.java
NativeIterator.getStopIterationObject
public static Object getStopIterationObject(Scriptable scope) { Scriptable top = ScriptableObject.getTopLevelScope(scope); return ScriptableObject.getTopScopeValue(top, ITERATOR_TAG); }
java
public static Object getStopIterationObject(Scriptable scope) { Scriptable top = ScriptableObject.getTopLevelScope(scope); return ScriptableObject.getTopScopeValue(top, ITERATOR_TAG); }
[ "public", "static", "Object", "getStopIterationObject", "(", "Scriptable", "scope", ")", "{", "Scriptable", "top", "=", "ScriptableObject", ".", "getTopLevelScope", "(", "scope", ")", ";", "return", "ScriptableObject", ".", "getTopScopeValue", "(", "top", ",", "ITERATOR_TAG", ")", ";", "}" ]
Get the value of the "StopIteration" object. Note that this value is stored in the top-level scope using "associateValue" so the value can still be found even if a script overwrites or deletes the global "StopIteration" property. @param scope a scope whose parent chain reaches a top-level scope @return the StopIteration object
[ "Get", "the", "value", "of", "the", "StopIteration", "object", ".", "Note", "that", "this", "value", "is", "stored", "in", "the", "top", "-", "level", "scope", "using", "associateValue", "so", "the", "value", "can", "still", "be", "found", "even", "if", "a", "script", "overwrites", "or", "deletes", "the", "global", "StopIteration", "property", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/NativeIterator.java#L60-L63
21,555
mozilla/rhino
src/org/mozilla/javascript/ast/XmlPropRef.java
XmlPropRef.visit
@Override public void visit(NodeVisitor v) { if (v.visit(this)) { if (namespace != null) { namespace.visit(v); } propName.visit(v); } }
java
@Override public void visit(NodeVisitor v) { if (v.visit(this)) { if (namespace != null) { namespace.visit(v); } propName.visit(v); } }
[ "@", "Override", "public", "void", "visit", "(", "NodeVisitor", "v", ")", "{", "if", "(", "v", ".", "visit", "(", "this", ")", ")", "{", "if", "(", "namespace", "!=", "null", ")", "{", "namespace", ".", "visit", "(", "v", ")", ";", "}", "propName", ".", "visit", "(", "v", ")", ";", "}", "}" ]
Visits this node, then the namespace if present, then the property name.
[ "Visits", "this", "node", "then", "the", "namespace", "if", "present", "then", "the", "property", "name", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/XmlPropRef.java#L82-L90
21,556
mozilla/rhino
src/org/mozilla/javascript/SlotMapContainer.java
SlotMapContainer.checkMapSize
protected void checkMapSize() { if ((map instanceof EmbeddedSlotMap) && map.size() >= LARGE_HASH_SIZE) { SlotMap newMap = new HashSlotMap(); for (Slot s : map) { newMap.addSlot(s); } map = newMap; } }
java
protected void checkMapSize() { if ((map instanceof EmbeddedSlotMap) && map.size() >= LARGE_HASH_SIZE) { SlotMap newMap = new HashSlotMap(); for (Slot s : map) { newMap.addSlot(s); } map = newMap; } }
[ "protected", "void", "checkMapSize", "(", ")", "{", "if", "(", "(", "map", "instanceof", "EmbeddedSlotMap", ")", "&&", "map", ".", "size", "(", ")", ">=", "LARGE_HASH_SIZE", ")", "{", "SlotMap", "newMap", "=", "new", "HashSlotMap", "(", ")", ";", "for", "(", "Slot", "s", ":", "map", ")", "{", "newMap", ".", "addSlot", "(", "s", ")", ";", "}", "map", "=", "newMap", ";", "}", "}" ]
Before inserting a new item in the map, check and see if we need to expand from the embedded map to a HashMap that is more robust against large numbers of hash collisions.
[ "Before", "inserting", "a", "new", "item", "in", "the", "map", "check", "and", "see", "if", "we", "need", "to", "expand", "from", "the", "embedded", "map", "to", "a", "HashMap", "that", "is", "more", "robust", "against", "large", "numbers", "of", "hash", "collisions", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/SlotMapContainer.java#L100-L109
21,557
mozilla/rhino
src/org/mozilla/javascript/NativeObject.java
NativeObject.containsKey
@Override public boolean containsKey(Object key) { if (key instanceof String) { return has((String) key, this); } else if (key instanceof Number) { return has(((Number) key).intValue(), this); } return false; }
java
@Override public boolean containsKey(Object key) { if (key instanceof String) { return has((String) key, this); } else if (key instanceof Number) { return has(((Number) key).intValue(), this); } return false; }
[ "@", "Override", "public", "boolean", "containsKey", "(", "Object", "key", ")", "{", "if", "(", "key", "instanceof", "String", ")", "{", "return", "has", "(", "(", "String", ")", "key", ",", "this", ")", ";", "}", "else", "if", "(", "key", "instanceof", "Number", ")", "{", "return", "has", "(", "(", "(", "Number", ")", "key", ")", ".", "intValue", "(", ")", ",", "this", ")", ";", "}", "return", "false", ";", "}" ]
methods implementing java.util.Map
[ "methods", "implementing", "java", ".", "util", ".", "Map" ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/NativeObject.java#L549-L557
21,558
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.setVisible
@Override public void setVisible(boolean b) { super.setVisible(b); if (b) { // this needs to be done after the window is visible console.consoleTextArea.requestFocus(); context.split.setDividerLocation(0.5); try { console.setMaximum(true); console.setSelected(true); console.show(); console.consoleTextArea.requestFocus(); } catch (Exception exc) { } } }
java
@Override public void setVisible(boolean b) { super.setVisible(b); if (b) { // this needs to be done after the window is visible console.consoleTextArea.requestFocus(); context.split.setDividerLocation(0.5); try { console.setMaximum(true); console.setSelected(true); console.show(); console.consoleTextArea.requestFocus(); } catch (Exception exc) { } } }
[ "@", "Override", "public", "void", "setVisible", "(", "boolean", "b", ")", "{", "super", ".", "setVisible", "(", "b", ")", ";", "if", "(", "b", ")", "{", "// this needs to be done after the window is visible", "console", ".", "consoleTextArea", ".", "requestFocus", "(", ")", ";", "context", ".", "split", ".", "setDividerLocation", "(", "0.5", ")", ";", "try", "{", "console", ".", "setMaximum", "(", "true", ")", ";", "console", ".", "setSelected", "(", "true", ")", ";", "console", ".", "show", "(", ")", ";", "console", ".", "consoleTextArea", ".", "requestFocus", "(", ")", ";", "}", "catch", "(", "Exception", "exc", ")", "{", "}", "}", "}" ]
Sets the visibility of the debugger GUI.
[ "Sets", "the", "visibility", "of", "the", "debugger", "GUI", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L241-L256
21,559
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.addTopLevel
void addTopLevel(String key, JFrame frame) { if (frame != this) { toplevels.put(key, frame); } }
java
void addTopLevel(String key, JFrame frame) { if (frame != this) { toplevels.put(key, frame); } }
[ "void", "addTopLevel", "(", "String", "key", ",", "JFrame", "frame", ")", "{", "if", "(", "frame", "!=", "this", ")", "{", "toplevels", ".", "put", "(", "key", ",", "frame", ")", ";", "}", "}" ]
Records a new internal frame.
[ "Records", "a", "new", "internal", "frame", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L261-L265
21,560
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.getShortName
static String getShortName(String url) { int lastSlash = url.lastIndexOf('/'); if (lastSlash < 0) { lastSlash = url.lastIndexOf('\\'); } String shortName = url; if (lastSlash >= 0 && lastSlash + 1 < url.length()) { shortName = url.substring(lastSlash + 1); } return shortName; }
java
static String getShortName(String url) { int lastSlash = url.lastIndexOf('/'); if (lastSlash < 0) { lastSlash = url.lastIndexOf('\\'); } String shortName = url; if (lastSlash >= 0 && lastSlash + 1 < url.length()) { shortName = url.substring(lastSlash + 1); } return shortName; }
[ "static", "String", "getShortName", "(", "String", "url", ")", "{", "int", "lastSlash", "=", "url", ".", "lastIndexOf", "(", "'", "'", ")", ";", "if", "(", "lastSlash", "<", "0", ")", "{", "lastSlash", "=", "url", ".", "lastIndexOf", "(", "'", "'", ")", ";", "}", "String", "shortName", "=", "url", ";", "if", "(", "lastSlash", ">=", "0", "&&", "lastSlash", "+", "1", "<", "url", ".", "length", "(", ")", ")", "{", "shortName", "=", "url", ".", "substring", "(", "lastSlash", "+", "1", ")", ";", "}", "return", "shortName", ";", "}" ]
Returns a short version of the given URL.
[ "Returns", "a", "short", "version", "of", "the", "given", "URL", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L418-L428
21,561
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.showStopLine
void showStopLine(Dim.StackFrame frame) { String sourceName = frame.getUrl(); if (sourceName == null || sourceName.equals("<stdin>")) { if (console.isVisible()) { console.show(); } } else { showFileWindow(sourceName, -1); int lineNumber = frame.getLineNumber(); FileWindow w = getFileWindow(sourceName); if (w != null) { setFilePosition(w, lineNumber); } } }
java
void showStopLine(Dim.StackFrame frame) { String sourceName = frame.getUrl(); if (sourceName == null || sourceName.equals("<stdin>")) { if (console.isVisible()) { console.show(); } } else { showFileWindow(sourceName, -1); int lineNumber = frame.getLineNumber(); FileWindow w = getFileWindow(sourceName); if (w != null) { setFilePosition(w, lineNumber); } } }
[ "void", "showStopLine", "(", "Dim", ".", "StackFrame", "frame", ")", "{", "String", "sourceName", "=", "frame", ".", "getUrl", "(", ")", ";", "if", "(", "sourceName", "==", "null", "||", "sourceName", ".", "equals", "(", "\"<stdin>\"", ")", ")", "{", "if", "(", "console", ".", "isVisible", "(", ")", ")", "{", "console", ".", "show", "(", ")", ";", "}", "}", "else", "{", "showFileWindow", "(", "sourceName", ",", "-", "1", ")", ";", "int", "lineNumber", "=", "frame", ".", "getLineNumber", "(", ")", ";", "FileWindow", "w", "=", "getFileWindow", "(", "sourceName", ")", ";", "if", "(", "w", "!=", "null", ")", "{", "setFilePosition", "(", "w", ",", "lineNumber", ")", ";", "}", "}", "}" ]
Shows the line at which execution in the given stack frame just stopped.
[ "Shows", "the", "line", "at", "which", "execution", "in", "the", "given", "stack", "frame", "just", "stopped", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L489-L503
21,562
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.enterInterruptImpl
void enterInterruptImpl(Dim.StackFrame lastFrame, String threadTitle, String alertMessage) { statusBar.setText("Thread: " + threadTitle); showStopLine(lastFrame); if (alertMessage != null) { MessageDialogWrapper.showMessageDialog(this, alertMessage, "Exception in Script", JOptionPane.ERROR_MESSAGE); } updateEnabled(true); Dim.ContextData contextData = lastFrame.contextData(); JComboBox<String> ctx = context.context; List<String> toolTips = context.toolTips; context.disableUpdate(); int frameCount = contextData.frameCount(); ctx.removeAllItems(); // workaround for JDK 1.4 bug that caches selected value even after // removeAllItems() is called ctx.setSelectedItem(null); toolTips.clear(); for (int i = 0; i < frameCount; i++) { Dim.StackFrame frame = contextData.getFrame(i); String url = frame.getUrl(); int lineNumber = frame.getLineNumber(); String shortName = url; if (url.length() > 20) { shortName = "..." + url.substring(url.length() - 17); } String location = "\"" + shortName + "\", line " + lineNumber; ctx.insertItemAt(location, i); location = "\"" + url + "\", line " + lineNumber; toolTips.add(location); } context.enableUpdate(); ctx.setSelectedIndex(0); ctx.setMinimumSize(new Dimension(50, ctx.getMinimumSize().height)); }
java
void enterInterruptImpl(Dim.StackFrame lastFrame, String threadTitle, String alertMessage) { statusBar.setText("Thread: " + threadTitle); showStopLine(lastFrame); if (alertMessage != null) { MessageDialogWrapper.showMessageDialog(this, alertMessage, "Exception in Script", JOptionPane.ERROR_MESSAGE); } updateEnabled(true); Dim.ContextData contextData = lastFrame.contextData(); JComboBox<String> ctx = context.context; List<String> toolTips = context.toolTips; context.disableUpdate(); int frameCount = contextData.frameCount(); ctx.removeAllItems(); // workaround for JDK 1.4 bug that caches selected value even after // removeAllItems() is called ctx.setSelectedItem(null); toolTips.clear(); for (int i = 0; i < frameCount; i++) { Dim.StackFrame frame = contextData.getFrame(i); String url = frame.getUrl(); int lineNumber = frame.getLineNumber(); String shortName = url; if (url.length() > 20) { shortName = "..." + url.substring(url.length() - 17); } String location = "\"" + shortName + "\", line " + lineNumber; ctx.insertItemAt(location, i); location = "\"" + url + "\", line " + lineNumber; toolTips.add(location); } context.enableUpdate(); ctx.setSelectedIndex(0); ctx.setMinimumSize(new Dimension(50, ctx.getMinimumSize().height)); }
[ "void", "enterInterruptImpl", "(", "Dim", ".", "StackFrame", "lastFrame", ",", "String", "threadTitle", ",", "String", "alertMessage", ")", "{", "statusBar", ".", "setText", "(", "\"Thread: \"", "+", "threadTitle", ")", ";", "showStopLine", "(", "lastFrame", ")", ";", "if", "(", "alertMessage", "!=", "null", ")", "{", "MessageDialogWrapper", ".", "showMessageDialog", "(", "this", ",", "alertMessage", ",", "\"Exception in Script\"", ",", "JOptionPane", ".", "ERROR_MESSAGE", ")", ";", "}", "updateEnabled", "(", "true", ")", ";", "Dim", ".", "ContextData", "contextData", "=", "lastFrame", ".", "contextData", "(", ")", ";", "JComboBox", "<", "String", ">", "ctx", "=", "context", ".", "context", ";", "List", "<", "String", ">", "toolTips", "=", "context", ".", "toolTips", ";", "context", ".", "disableUpdate", "(", ")", ";", "int", "frameCount", "=", "contextData", ".", "frameCount", "(", ")", ";", "ctx", ".", "removeAllItems", "(", ")", ";", "// workaround for JDK 1.4 bug that caches selected value even after", "// removeAllItems() is called", "ctx", ".", "setSelectedItem", "(", "null", ")", ";", "toolTips", ".", "clear", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "frameCount", ";", "i", "++", ")", "{", "Dim", ".", "StackFrame", "frame", "=", "contextData", ".", "getFrame", "(", "i", ")", ";", "String", "url", "=", "frame", ".", "getUrl", "(", ")", ";", "int", "lineNumber", "=", "frame", ".", "getLineNumber", "(", ")", ";", "String", "shortName", "=", "url", ";", "if", "(", "url", ".", "length", "(", ")", ">", "20", ")", "{", "shortName", "=", "\"...\"", "+", "url", ".", "substring", "(", "url", ".", "length", "(", ")", "-", "17", ")", ";", "}", "String", "location", "=", "\"\\\"\"", "+", "shortName", "+", "\"\\\", line \"", "+", "lineNumber", ";", "ctx", ".", "insertItemAt", "(", "location", ",", "i", ")", ";", "location", "=", "\"\\\"\"", "+", "url", "+", "\"\\\", line \"", "+", "lineNumber", ";", "toolTips", ".", "add", "(", "location", ")", ";", "}", "context", ".", "enableUpdate", "(", ")", ";", "ctx", ".", "setSelectedIndex", "(", "0", ")", ";", "ctx", ".", "setMinimumSize", "(", "new", "Dimension", "(", "50", ",", "ctx", ".", "getMinimumSize", "(", ")", ".", "height", ")", ")", ";", "}" ]
Handles script interruption.
[ "Handles", "script", "interruption", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L658-L700
21,563
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.getSelectedFrame
private JInternalFrame getSelectedFrame() { JInternalFrame[] frames = desk.getAllFrames(); for (int i = 0; i < frames.length; i++) { if (frames[i].isShowing()) { return frames[i]; } } return frames[frames.length - 1]; }
java
private JInternalFrame getSelectedFrame() { JInternalFrame[] frames = desk.getAllFrames(); for (int i = 0; i < frames.length; i++) { if (frames[i].isShowing()) { return frames[i]; } } return frames[frames.length - 1]; }
[ "private", "JInternalFrame", "getSelectedFrame", "(", ")", "{", "JInternalFrame", "[", "]", "frames", "=", "desk", ".", "getAllFrames", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "frames", ".", "length", ";", "i", "++", ")", "{", "if", "(", "frames", "[", "i", "]", ".", "isShowing", "(", ")", ")", "{", "return", "frames", "[", "i", "]", ";", "}", "}", "return", "frames", "[", "frames", ".", "length", "-", "1", "]", ";", "}" ]
Returns the current selected internal frame.
[ "Returns", "the", "current", "selected", "internal", "frame", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L741-L749
21,564
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.updateEnabled
private void updateEnabled(boolean interrupted) { ((Menubar)getJMenuBar()).updateEnabled(interrupted); for (int ci = 0, cc = toolBar.getComponentCount(); ci < cc; ci++) { boolean enableButton; if (ci == 0) { // Break enableButton = !interrupted; } else { enableButton = interrupted; } toolBar.getComponent(ci).setEnabled(enableButton); } if (interrupted) { toolBar.setEnabled(true); // raise the debugger window int state = getExtendedState(); if (state == Frame.ICONIFIED) { setExtendedState(Frame.NORMAL); } toFront(); context.setEnabled(true); } else { if (currentWindow != null) currentWindow.setPosition(-1); context.setEnabled(false); } }
java
private void updateEnabled(boolean interrupted) { ((Menubar)getJMenuBar()).updateEnabled(interrupted); for (int ci = 0, cc = toolBar.getComponentCount(); ci < cc; ci++) { boolean enableButton; if (ci == 0) { // Break enableButton = !interrupted; } else { enableButton = interrupted; } toolBar.getComponent(ci).setEnabled(enableButton); } if (interrupted) { toolBar.setEnabled(true); // raise the debugger window int state = getExtendedState(); if (state == Frame.ICONIFIED) { setExtendedState(Frame.NORMAL); } toFront(); context.setEnabled(true); } else { if (currentWindow != null) currentWindow.setPosition(-1); context.setEnabled(false); } }
[ "private", "void", "updateEnabled", "(", "boolean", "interrupted", ")", "{", "(", "(", "Menubar", ")", "getJMenuBar", "(", ")", ")", ".", "updateEnabled", "(", "interrupted", ")", ";", "for", "(", "int", "ci", "=", "0", ",", "cc", "=", "toolBar", ".", "getComponentCount", "(", ")", ";", "ci", "<", "cc", ";", "ci", "++", ")", "{", "boolean", "enableButton", ";", "if", "(", "ci", "==", "0", ")", "{", "// Break", "enableButton", "=", "!", "interrupted", ";", "}", "else", "{", "enableButton", "=", "interrupted", ";", "}", "toolBar", ".", "getComponent", "(", "ci", ")", ".", "setEnabled", "(", "enableButton", ")", ";", "}", "if", "(", "interrupted", ")", "{", "toolBar", ".", "setEnabled", "(", "true", ")", ";", "// raise the debugger window", "int", "state", "=", "getExtendedState", "(", ")", ";", "if", "(", "state", "==", "Frame", ".", "ICONIFIED", ")", "{", "setExtendedState", "(", "Frame", ".", "NORMAL", ")", ";", "}", "toFront", "(", ")", ";", "context", ".", "setEnabled", "(", "true", ")", ";", "}", "else", "{", "if", "(", "currentWindow", "!=", "null", ")", "currentWindow", ".", "setPosition", "(", "-", "1", ")", ";", "context", ".", "setEnabled", "(", "false", ")", ";", "}", "}" ]
Enables or disables the menu and tool bars with respect to the state of script execution.
[ "Enables", "or", "disables", "the", "menu", "and", "tool", "bars", "with", "respect", "to", "the", "state", "of", "script", "execution", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L755-L780
21,565
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.readFile
private String readFile(String fileName) { String text; try { try (Reader r = new FileReader(fileName)) { text = Kit.readReader(r); } } catch (IOException ex) { MessageDialogWrapper.showMessageDialog(this, ex.getMessage(), "Error reading "+fileName, JOptionPane.ERROR_MESSAGE); text = null; } return text; }
java
private String readFile(String fileName) { String text; try { try (Reader r = new FileReader(fileName)) { text = Kit.readReader(r); } } catch (IOException ex) { MessageDialogWrapper.showMessageDialog(this, ex.getMessage(), "Error reading "+fileName, JOptionPane.ERROR_MESSAGE); text = null; } return text; }
[ "private", "String", "readFile", "(", "String", "fileName", ")", "{", "String", "text", ";", "try", "{", "try", "(", "Reader", "r", "=", "new", "FileReader", "(", "fileName", ")", ")", "{", "text", "=", "Kit", ".", "readReader", "(", "r", ")", ";", "}", "}", "catch", "(", "IOException", "ex", ")", "{", "MessageDialogWrapper", ".", "showMessageDialog", "(", "this", ",", "ex", ".", "getMessage", "(", ")", ",", "\"Error reading \"", "+", "fileName", ",", "JOptionPane", ".", "ERROR_MESSAGE", ")", ";", "text", "=", "null", ";", "}", "return", "text", ";", "}" ]
Reads the file with the given name and returns its contents as a String.
[ "Reads", "the", "file", "with", "the", "given", "name", "and", "returns", "its", "contents", "as", "a", "String", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L800-L814
21,566
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.updateSourceText
@Override public void updateSourceText(Dim.SourceInfo sourceInfo) { RunProxy proxy = new RunProxy(this, RunProxy.UPDATE_SOURCE_TEXT); proxy.sourceInfo = sourceInfo; SwingUtilities.invokeLater(proxy); }
java
@Override public void updateSourceText(Dim.SourceInfo sourceInfo) { RunProxy proxy = new RunProxy(this, RunProxy.UPDATE_SOURCE_TEXT); proxy.sourceInfo = sourceInfo; SwingUtilities.invokeLater(proxy); }
[ "@", "Override", "public", "void", "updateSourceText", "(", "Dim", ".", "SourceInfo", "sourceInfo", ")", "{", "RunProxy", "proxy", "=", "new", "RunProxy", "(", "this", ",", "RunProxy", ".", "UPDATE_SOURCE_TEXT", ")", ";", "proxy", ".", "sourceInfo", "=", "sourceInfo", ";", "SwingUtilities", ".", "invokeLater", "(", "proxy", ")", ";", "}" ]
Called when the source text for a script has been updated.
[ "Called", "when", "the", "source", "text", "for", "a", "script", "has", "been", "updated", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L821-L826
21,567
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.enterInterrupt
@Override public void enterInterrupt(Dim.StackFrame lastFrame, String threadTitle, String alertMessage) { if (SwingUtilities.isEventDispatchThread()) { enterInterruptImpl(lastFrame, threadTitle, alertMessage); } else { RunProxy proxy = new RunProxy(this, RunProxy.ENTER_INTERRUPT); proxy.lastFrame = lastFrame; proxy.threadTitle = threadTitle; proxy.alertMessage = alertMessage; SwingUtilities.invokeLater(proxy); } }
java
@Override public void enterInterrupt(Dim.StackFrame lastFrame, String threadTitle, String alertMessage) { if (SwingUtilities.isEventDispatchThread()) { enterInterruptImpl(lastFrame, threadTitle, alertMessage); } else { RunProxy proxy = new RunProxy(this, RunProxy.ENTER_INTERRUPT); proxy.lastFrame = lastFrame; proxy.threadTitle = threadTitle; proxy.alertMessage = alertMessage; SwingUtilities.invokeLater(proxy); } }
[ "@", "Override", "public", "void", "enterInterrupt", "(", "Dim", ".", "StackFrame", "lastFrame", ",", "String", "threadTitle", ",", "String", "alertMessage", ")", "{", "if", "(", "SwingUtilities", ".", "isEventDispatchThread", "(", ")", ")", "{", "enterInterruptImpl", "(", "lastFrame", ",", "threadTitle", ",", "alertMessage", ")", ";", "}", "else", "{", "RunProxy", "proxy", "=", "new", "RunProxy", "(", "this", ",", "RunProxy", ".", "ENTER_INTERRUPT", ")", ";", "proxy", ".", "lastFrame", "=", "lastFrame", ";", "proxy", ".", "threadTitle", "=", "threadTitle", ";", "proxy", ".", "alertMessage", "=", "alertMessage", ";", "SwingUtilities", ".", "invokeLater", "(", "proxy", ")", ";", "}", "}" ]
Called when the interrupt loop has been entered.
[ "Called", "when", "the", "interrupt", "loop", "has", "been", "entered", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L831-L844
21,568
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
SwingGui.dispatchNextGuiEvent
@Override public void dispatchNextGuiEvent() throws InterruptedException { EventQueue queue = awtEventQueue; if (queue == null) { queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); awtEventQueue = queue; } AWTEvent event = queue.getNextEvent(); if (event instanceof ActiveEvent) { ((ActiveEvent)event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component)source; comp.dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent)source).dispatchEvent(event); } } }
java
@Override public void dispatchNextGuiEvent() throws InterruptedException { EventQueue queue = awtEventQueue; if (queue == null) { queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); awtEventQueue = queue; } AWTEvent event = queue.getNextEvent(); if (event instanceof ActiveEvent) { ((ActiveEvent)event).dispatch(); } else { Object source = event.getSource(); if (source instanceof Component) { Component comp = (Component)source; comp.dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent)source).dispatchEvent(event); } } }
[ "@", "Override", "public", "void", "dispatchNextGuiEvent", "(", ")", "throws", "InterruptedException", "{", "EventQueue", "queue", "=", "awtEventQueue", ";", "if", "(", "queue", "==", "null", ")", "{", "queue", "=", "Toolkit", ".", "getDefaultToolkit", "(", ")", ".", "getSystemEventQueue", "(", ")", ";", "awtEventQueue", "=", "queue", ";", "}", "AWTEvent", "event", "=", "queue", ".", "getNextEvent", "(", ")", ";", "if", "(", "event", "instanceof", "ActiveEvent", ")", "{", "(", "(", "ActiveEvent", ")", "event", ")", ".", "dispatch", "(", ")", ";", "}", "else", "{", "Object", "source", "=", "event", ".", "getSource", "(", ")", ";", "if", "(", "source", "instanceof", "Component", ")", "{", "Component", "comp", "=", "(", "Component", ")", "source", ";", "comp", ".", "dispatchEvent", "(", "event", ")", ";", "}", "else", "if", "(", "source", "instanceof", "MenuComponent", ")", "{", "(", "(", "MenuComponent", ")", "source", ")", ".", "dispatchEvent", "(", "event", ")", ";", "}", "}", "}" ]
Processes the next GUI event.
[ "Processes", "the", "next", "GUI", "event", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L857-L876
21,569
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
EvalTextArea.returnPressed
private synchronized void returnPressed() { Document doc = getDocument(); int len = doc.getLength(); Segment segment = new Segment(); try { doc.getText(outputMark, len - outputMark, segment); } catch (javax.swing.text.BadLocationException ignored) { ignored.printStackTrace(); } String text = segment.toString(); if (debugGui.dim.stringIsCompilableUnit(text)) { if (text.trim().length() > 0) { history.add(text); historyIndex = history.size(); } append("\n"); String result = debugGui.dim.eval(text); if (result.length() > 0) { append(result); append("\n"); } append("% "); outputMark = doc.getLength(); } else { append("\n"); } }
java
private synchronized void returnPressed() { Document doc = getDocument(); int len = doc.getLength(); Segment segment = new Segment(); try { doc.getText(outputMark, len - outputMark, segment); } catch (javax.swing.text.BadLocationException ignored) { ignored.printStackTrace(); } String text = segment.toString(); if (debugGui.dim.stringIsCompilableUnit(text)) { if (text.trim().length() > 0) { history.add(text); historyIndex = history.size(); } append("\n"); String result = debugGui.dim.eval(text); if (result.length() > 0) { append(result); append("\n"); } append("% "); outputMark = doc.getLength(); } else { append("\n"); } }
[ "private", "synchronized", "void", "returnPressed", "(", ")", "{", "Document", "doc", "=", "getDocument", "(", ")", ";", "int", "len", "=", "doc", ".", "getLength", "(", ")", ";", "Segment", "segment", "=", "new", "Segment", "(", ")", ";", "try", "{", "doc", ".", "getText", "(", "outputMark", ",", "len", "-", "outputMark", ",", "segment", ")", ";", "}", "catch", "(", "javax", ".", "swing", ".", "text", ".", "BadLocationException", "ignored", ")", "{", "ignored", ".", "printStackTrace", "(", ")", ";", "}", "String", "text", "=", "segment", ".", "toString", "(", ")", ";", "if", "(", "debugGui", ".", "dim", ".", "stringIsCompilableUnit", "(", "text", ")", ")", "{", "if", "(", "text", ".", "trim", "(", ")", ".", "length", "(", ")", ">", "0", ")", "{", "history", ".", "add", "(", "text", ")", ";", "historyIndex", "=", "history", ".", "size", "(", ")", ";", "}", "append", "(", "\"\\n\"", ")", ";", "String", "result", "=", "debugGui", ".", "dim", ".", "eval", "(", "text", ")", ";", "if", "(", "result", ".", "length", "(", ")", ">", "0", ")", "{", "append", "(", "result", ")", ";", "append", "(", "\"\\n\"", ")", ";", "}", "append", "(", "\"% \"", ")", ";", "outputMark", "=", "doc", ".", "getLength", "(", ")", ";", "}", "else", "{", "append", "(", "\"\\n\"", ")", ";", "}", "}" ]
Called when Enter is pressed.
[ "Called", "when", "Enter", "is", "pressed", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1139-L1165
21,570
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
EvalTextArea.insertUpdate
@Override public synchronized void insertUpdate(DocumentEvent e) { int len = e.getLength(); int off = e.getOffset(); if (outputMark > off) { outputMark += len; } }
java
@Override public synchronized void insertUpdate(DocumentEvent e) { int len = e.getLength(); int off = e.getOffset(); if (outputMark > off) { outputMark += len; } }
[ "@", "Override", "public", "synchronized", "void", "insertUpdate", "(", "DocumentEvent", "e", ")", "{", "int", "len", "=", "e", ".", "getLength", "(", ")", ";", "int", "off", "=", "e", ".", "getOffset", "(", ")", ";", "if", "(", "outputMark", ">", "off", ")", "{", "outputMark", "+=", "len", ";", "}", "}" ]
Called when text was inserted into the text area.
[ "Called", "when", "text", "was", "inserted", "into", "the", "text", "area", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1272-L1279
21,571
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
EvalTextArea.removeUpdate
@Override public synchronized void removeUpdate(DocumentEvent e) { int len = e.getLength(); int off = e.getOffset(); if (outputMark > off) { if (outputMark >= off + len) { outputMark -= len; } else { outputMark = off; } } }
java
@Override public synchronized void removeUpdate(DocumentEvent e) { int len = e.getLength(); int off = e.getOffset(); if (outputMark > off) { if (outputMark >= off + len) { outputMark -= len; } else { outputMark = off; } } }
[ "@", "Override", "public", "synchronized", "void", "removeUpdate", "(", "DocumentEvent", "e", ")", "{", "int", "len", "=", "e", ".", "getLength", "(", ")", ";", "int", "off", "=", "e", ".", "getOffset", "(", ")", ";", "if", "(", "outputMark", ">", "off", ")", "{", "if", "(", "outputMark", ">=", "off", "+", "len", ")", "{", "outputMark", "-=", "len", ";", "}", "else", "{", "outputMark", "=", "off", ";", "}", "}", "}" ]
Called when text was removed from the text area.
[ "Called", "when", "text", "was", "removed", "from", "the", "text", "area", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1284-L1295
21,572
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
JSInternalConsole.actionPerformed
@Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Cut")) { consoleTextArea.cut(); } else if (cmd.equals("Copy")) { consoleTextArea.copy(); } else if (cmd.equals("Paste")) { consoleTextArea.paste(); } }
java
@Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Cut")) { consoleTextArea.cut(); } else if (cmd.equals("Copy")) { consoleTextArea.copy(); } else if (cmd.equals("Paste")) { consoleTextArea.paste(); } }
[ "@", "Override", "public", "void", "actionPerformed", "(", "ActionEvent", "e", ")", "{", "String", "cmd", "=", "e", ".", "getActionCommand", "(", ")", ";", "if", "(", "cmd", ".", "equals", "(", "\"Cut\"", ")", ")", "{", "consoleTextArea", ".", "cut", "(", ")", ";", "}", "else", "if", "(", "cmd", ".", "equals", "(", "\"Copy\"", ")", ")", "{", "consoleTextArea", ".", "copy", "(", ")", ";", "}", "else", "if", "(", "cmd", ".", "equals", "(", "\"Paste\"", ")", ")", "{", "consoleTextArea", ".", "paste", "(", ")", ";", "}", "}" ]
Performs an action on the text area.
[ "Performs", "an", "action", "on", "the", "text", "area", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1435-L1445
21,573
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FilePopupMenu.show
public void show(JComponent comp, int x, int y) { this.x = x; this.y = y; super.show(comp, x, y); }
java
public void show(JComponent comp, int x, int y) { this.x = x; this.y = y; super.show(comp, x, y); }
[ "public", "void", "show", "(", "JComponent", "comp", ",", "int", "x", ",", "int", "y", ")", "{", "this", ".", "x", "=", "x", ";", "this", ".", "y", "=", "y", ";", "super", ".", "show", "(", "comp", ",", "x", ",", "y", ")", ";", "}" ]
Displays the menu at the given coordinates.
[ "Displays", "the", "menu", "at", "the", "given", "coordinates", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1484-L1488
21,574
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileTextArea.select
public void select(int pos) { if (pos >= 0) { try { int line = getLineOfOffset(pos); Rectangle rect = modelToView(pos); if (rect == null) { select(pos, pos); } else { try { Rectangle nrect = modelToView(getLineStartOffset(line + 1)); if (nrect != null) { rect = nrect; } } catch (Exception exc) { } JViewport vp = (JViewport)getParent(); Rectangle viewRect = vp.getViewRect(); if (viewRect.y + viewRect.height > rect.y) { // need to scroll up select(pos, pos); } else { // need to scroll down rect.y += (viewRect.height - rect.height)/2; scrollRectToVisible(rect); select(pos, pos); } } } catch (BadLocationException exc) { select(pos, pos); //exc.printStackTrace(); } } }
java
public void select(int pos) { if (pos >= 0) { try { int line = getLineOfOffset(pos); Rectangle rect = modelToView(pos); if (rect == null) { select(pos, pos); } else { try { Rectangle nrect = modelToView(getLineStartOffset(line + 1)); if (nrect != null) { rect = nrect; } } catch (Exception exc) { } JViewport vp = (JViewport)getParent(); Rectangle viewRect = vp.getViewRect(); if (viewRect.y + viewRect.height > rect.y) { // need to scroll up select(pos, pos); } else { // need to scroll down rect.y += (viewRect.height - rect.height)/2; scrollRectToVisible(rect); select(pos, pos); } } } catch (BadLocationException exc) { select(pos, pos); //exc.printStackTrace(); } } }
[ "public", "void", "select", "(", "int", "pos", ")", "{", "if", "(", "pos", ">=", "0", ")", "{", "try", "{", "int", "line", "=", "getLineOfOffset", "(", "pos", ")", ";", "Rectangle", "rect", "=", "modelToView", "(", "pos", ")", ";", "if", "(", "rect", "==", "null", ")", "{", "select", "(", "pos", ",", "pos", ")", ";", "}", "else", "{", "try", "{", "Rectangle", "nrect", "=", "modelToView", "(", "getLineStartOffset", "(", "line", "+", "1", ")", ")", ";", "if", "(", "nrect", "!=", "null", ")", "{", "rect", "=", "nrect", ";", "}", "}", "catch", "(", "Exception", "exc", ")", "{", "}", "JViewport", "vp", "=", "(", "JViewport", ")", "getParent", "(", ")", ";", "Rectangle", "viewRect", "=", "vp", ".", "getViewRect", "(", ")", ";", "if", "(", "viewRect", ".", "y", "+", "viewRect", ".", "height", ">", "rect", ".", "y", ")", "{", "// need to scroll up", "select", "(", "pos", ",", "pos", ")", ";", "}", "else", "{", "// need to scroll down", "rect", ".", "y", "+=", "(", "viewRect", ".", "height", "-", "rect", ".", "height", ")", "/", "2", ";", "scrollRectToVisible", "(", "rect", ")", ";", "select", "(", "pos", ",", "pos", ")", ";", "}", "}", "}", "catch", "(", "BadLocationException", "exc", ")", "{", "select", "(", "pos", ",", "pos", ")", ";", "//exc.printStackTrace();", "}", "}", "}" ]
Moves the selection to the given offset.
[ "Moves", "the", "selection", "to", "the", "given", "offset", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1528-L1561
21,575
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileTextArea.checkPopup
private void checkPopup(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(this, e.getX(), e.getY()); } }
java
private void checkPopup(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(this, e.getX(), e.getY()); } }
[ "private", "void", "checkPopup", "(", "MouseEvent", "e", ")", "{", "if", "(", "e", ".", "isPopupTrigger", "(", ")", ")", "{", "popup", ".", "show", "(", "this", ",", "e", ".", "getX", "(", ")", ",", "e", ".", "getY", "(", ")", ")", ";", "}", "}" ]
Checks if the popup menu should be shown.
[ "Checks", "if", "the", "popup", "menu", "should", "be", "shown", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1566-L1570
21,576
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileTextArea.mouseClicked
@Override public void mouseClicked(MouseEvent e) { checkPopup(e); requestFocus(); getCaret().setVisible(true); }
java
@Override public void mouseClicked(MouseEvent e) { checkPopup(e); requestFocus(); getCaret().setVisible(true); }
[ "@", "Override", "public", "void", "mouseClicked", "(", "MouseEvent", "e", ")", "{", "checkPopup", "(", "e", ")", ";", "requestFocus", "(", ")", ";", "getCaret", "(", ")", ".", "setVisible", "(", "true", ")", ";", "}" ]
Called when the mouse is clicked.
[ "Called", "when", "the", "mouse", "is", "clicked", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1585-L1590
21,577
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileTextArea.keyPressed
@Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_ENTER: case KeyEvent.VK_DELETE: case KeyEvent.VK_TAB: e.consume(); break; } }
java
@Override public void keyPressed(KeyEvent e) { switch (e.getKeyCode()) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_ENTER: case KeyEvent.VK_DELETE: case KeyEvent.VK_TAB: e.consume(); break; } }
[ "@", "Override", "public", "void", "keyPressed", "(", "KeyEvent", "e", ")", "{", "switch", "(", "e", ".", "getKeyCode", "(", ")", ")", "{", "case", "KeyEvent", ".", "VK_BACK_SPACE", ":", "case", "KeyEvent", ".", "VK_ENTER", ":", "case", "KeyEvent", ".", "VK_DELETE", ":", "case", "KeyEvent", ".", "VK_TAB", ":", "e", ".", "consume", "(", ")", ";", "break", ";", "}", "}" ]
Called when a key is pressed.
[ "Called", "when", "a", "key", "is", "pressed", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1666-L1676
21,578
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
MoreWindows.showDialog
public String showDialog(Component comp) { value = null; setLocationRelativeTo(comp); setVisible(true); return value; }
java
public String showDialog(Component comp) { value = null; setLocationRelativeTo(comp); setVisible(true); return value; }
[ "public", "String", "showDialog", "(", "Component", "comp", ")", "{", "value", "=", "null", ";", "setLocationRelativeTo", "(", "comp", ")", ";", "setVisible", "(", "true", ")", ";", "return", "value", ";", "}" ]
Shows the dialog.
[ "Shows", "the", "dialog", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L1807-L1812
21,579
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileHeader.update
public void update() { FileTextArea textArea = fileWindow.textArea; Font font = textArea.getFont(); setFont(font); FontMetrics metrics = getFontMetrics(font); int h = metrics.getHeight(); int lineCount = textArea.getLineCount() + 1; String dummy = Integer.toString(lineCount); if (dummy.length() < 2) { dummy = "99"; } Dimension d = new Dimension(); d.width = metrics.stringWidth(dummy) + 16; d.height = lineCount * h + 100; setPreferredSize(d); setSize(d); }
java
public void update() { FileTextArea textArea = fileWindow.textArea; Font font = textArea.getFont(); setFont(font); FontMetrics metrics = getFontMetrics(font); int h = metrics.getHeight(); int lineCount = textArea.getLineCount() + 1; String dummy = Integer.toString(lineCount); if (dummy.length() < 2) { dummy = "99"; } Dimension d = new Dimension(); d.width = metrics.stringWidth(dummy) + 16; d.height = lineCount * h + 100; setPreferredSize(d); setSize(d); }
[ "public", "void", "update", "(", ")", "{", "FileTextArea", "textArea", "=", "fileWindow", ".", "textArea", ";", "Font", "font", "=", "textArea", ".", "getFont", "(", ")", ";", "setFont", "(", "font", ")", ";", "FontMetrics", "metrics", "=", "getFontMetrics", "(", "font", ")", ";", "int", "h", "=", "metrics", ".", "getHeight", "(", ")", ";", "int", "lineCount", "=", "textArea", ".", "getLineCount", "(", ")", "+", "1", ";", "String", "dummy", "=", "Integer", ".", "toString", "(", "lineCount", ")", ";", "if", "(", "dummy", ".", "length", "(", ")", "<", "2", ")", "{", "dummy", "=", "\"99\"", ";", "}", "Dimension", "d", "=", "new", "Dimension", "(", ")", ";", "d", ".", "width", "=", "metrics", ".", "stringWidth", "(", "dummy", ")", "+", "16", ";", "d", ".", "height", "=", "lineCount", "*", "h", "+", "100", ";", "setPreferredSize", "(", "d", ")", ";", "setSize", "(", "d", ")", ";", "}" ]
Updates the gutter.
[ "Updates", "the", "gutter", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2038-L2054
21,580
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileHeader.mousePressed
@Override public void mousePressed(MouseEvent e) { Font font = fileWindow.textArea.getFont(); FontMetrics metrics = getFontMetrics(font); int h = metrics.getHeight(); pressLine = e.getY() / h; }
java
@Override public void mousePressed(MouseEvent e) { Font font = fileWindow.textArea.getFont(); FontMetrics metrics = getFontMetrics(font); int h = metrics.getHeight(); pressLine = e.getY() / h; }
[ "@", "Override", "public", "void", "mousePressed", "(", "MouseEvent", "e", ")", "{", "Font", "font", "=", "fileWindow", ".", "textArea", ".", "getFont", "(", ")", ";", "FontMetrics", "metrics", "=", "getFontMetrics", "(", "font", ")", ";", "int", "h", "=", "metrics", ".", "getHeight", "(", ")", ";", "pressLine", "=", "e", ".", "getY", "(", ")", "/", "h", ";", "}" ]
Called when a mouse button is pressed.
[ "Called", "when", "a", "mouse", "button", "is", "pressed", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2135-L2141
21,581
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileWindow.load
void load() { String url = getUrl(); if (url != null) { RunProxy proxy = new RunProxy(debugGui, RunProxy.LOAD_FILE); proxy.fileName = url; proxy.text = sourceInfo.source(); new Thread(proxy).start(); } }
java
void load() { String url = getUrl(); if (url != null) { RunProxy proxy = new RunProxy(debugGui, RunProxy.LOAD_FILE); proxy.fileName = url; proxy.text = sourceInfo.source(); new Thread(proxy).start(); } }
[ "void", "load", "(", ")", "{", "String", "url", "=", "getUrl", "(", ")", ";", "if", "(", "url", "!=", "null", ")", "{", "RunProxy", "proxy", "=", "new", "RunProxy", "(", "debugGui", ",", "RunProxy", ".", "LOAD_FILE", ")", ";", "proxy", ".", "fileName", "=", "url", ";", "proxy", ".", "text", "=", "sourceInfo", ".", "source", "(", ")", ";", "new", "Thread", "(", "proxy", ")", ".", "start", "(", ")", ";", "}", "}" ]
Loads the file.
[ "Loads", "the", "file", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2221-L2229
21,582
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileWindow.getPosition
public int getPosition(int line) { int result = -1; try { result = textArea.getLineStartOffset(line); } catch (javax.swing.text.BadLocationException exc) { } return result; }
java
public int getPosition(int line) { int result = -1; try { result = textArea.getLineStartOffset(line); } catch (javax.swing.text.BadLocationException exc) { } return result; }
[ "public", "int", "getPosition", "(", "int", "line", ")", "{", "int", "result", "=", "-", "1", ";", "try", "{", "result", "=", "textArea", ".", "getLineStartOffset", "(", "line", ")", ";", "}", "catch", "(", "javax", ".", "swing", ".", "text", ".", "BadLocationException", "exc", ")", "{", "}", "return", "result", ";", "}" ]
Returns the offset position for the given line.
[ "Returns", "the", "offset", "position", "for", "the", "given", "line", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2234-L2241
21,583
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileWindow.setBreakPoint
public void setBreakPoint(int line) { if (sourceInfo.breakableLine(line)) { boolean changed = sourceInfo.breakpoint(line, true); if (changed) { fileHeader.repaint(); } } }
java
public void setBreakPoint(int line) { if (sourceInfo.breakableLine(line)) { boolean changed = sourceInfo.breakpoint(line, true); if (changed) { fileHeader.repaint(); } } }
[ "public", "void", "setBreakPoint", "(", "int", "line", ")", "{", "if", "(", "sourceInfo", ".", "breakableLine", "(", "line", ")", ")", "{", "boolean", "changed", "=", "sourceInfo", ".", "breakpoint", "(", "line", ",", "true", ")", ";", "if", "(", "changed", ")", "{", "fileHeader", ".", "repaint", "(", ")", ";", "}", "}", "}" ]
Sets a breakpoint on the given line.
[ "Sets", "a", "breakpoint", "on", "the", "given", "line", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2264-L2271
21,584
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileWindow.clearBreakPoint
public void clearBreakPoint(int line) { if (sourceInfo.breakableLine(line)) { boolean changed = sourceInfo.breakpoint(line, false); if (changed) { fileHeader.repaint(); } } }
java
public void clearBreakPoint(int line) { if (sourceInfo.breakableLine(line)) { boolean changed = sourceInfo.breakpoint(line, false); if (changed) { fileHeader.repaint(); } } }
[ "public", "void", "clearBreakPoint", "(", "int", "line", ")", "{", "if", "(", "sourceInfo", ".", "breakableLine", "(", "line", ")", ")", "{", "boolean", "changed", "=", "sourceInfo", ".", "breakpoint", "(", "line", ",", "false", ")", ";", "if", "(", "changed", ")", "{", "fileHeader", ".", "repaint", "(", ")", ";", "}", "}", "}" ]
Clears a breakpoint from the given line.
[ "Clears", "a", "breakpoint", "from", "the", "given", "line", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2276-L2283
21,585
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileWindow.updateToolTip
private void updateToolTip() { // Try to set tool tip on frame. On Mac OS X 10.5, // the number of components is different, so try to be safe. int n = getComponentCount() - 1; if (n > 1) { n = 1; } else if (n < 0) { return; } Component c = getComponent(n); // this will work at least for Metal L&F if (c != null && c instanceof JComponent) { ((JComponent)c).setToolTipText(getUrl()); } }
java
private void updateToolTip() { // Try to set tool tip on frame. On Mac OS X 10.5, // the number of components is different, so try to be safe. int n = getComponentCount() - 1; if (n > 1) { n = 1; } else if (n < 0) { return; } Component c = getComponent(n); // this will work at least for Metal L&F if (c != null && c instanceof JComponent) { ((JComponent)c).setToolTipText(getUrl()); } }
[ "private", "void", "updateToolTip", "(", ")", "{", "// Try to set tool tip on frame. On Mac OS X 10.5,", "// the number of components is different, so try to be safe.", "int", "n", "=", "getComponentCount", "(", ")", "-", "1", ";", "if", "(", "n", ">", "1", ")", "{", "n", "=", "1", ";", "}", "else", "if", "(", "n", "<", "0", ")", "{", "return", ";", "}", "Component", "c", "=", "getComponent", "(", "n", ")", ";", "// this will work at least for Metal L&F", "if", "(", "c", "!=", "null", "&&", "c", "instanceof", "JComponent", ")", "{", "(", "(", "JComponent", ")", "c", ")", ".", "setToolTipText", "(", "getUrl", "(", ")", ")", ";", "}", "}" ]
Updates the tool tip contents.
[ "Updates", "the", "tool", "tip", "contents", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2311-L2325
21,586
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileWindow.updateText
public void updateText(Dim.SourceInfo sourceInfo) { this.sourceInfo = sourceInfo; String newText = sourceInfo.source(); if (!textArea.getText().equals(newText)) { textArea.setText(newText); int pos = 0; if (currentPos != -1) { pos = currentPos; } textArea.select(pos); } fileHeader.update(); fileHeader.repaint(); }
java
public void updateText(Dim.SourceInfo sourceInfo) { this.sourceInfo = sourceInfo; String newText = sourceInfo.source(); if (!textArea.getText().equals(newText)) { textArea.setText(newText); int pos = 0; if (currentPos != -1) { pos = currentPos; } textArea.select(pos); } fileHeader.update(); fileHeader.repaint(); }
[ "public", "void", "updateText", "(", "Dim", ".", "SourceInfo", "sourceInfo", ")", "{", "this", ".", "sourceInfo", "=", "sourceInfo", ";", "String", "newText", "=", "sourceInfo", ".", "source", "(", ")", ";", "if", "(", "!", "textArea", ".", "getText", "(", ")", ".", "equals", "(", "newText", ")", ")", "{", "textArea", ".", "setText", "(", "newText", ")", ";", "int", "pos", "=", "0", ";", "if", "(", "currentPos", "!=", "-", "1", ")", "{", "pos", "=", "currentPos", ";", "}", "textArea", ".", "select", "(", "pos", ")", ";", "}", "fileHeader", ".", "update", "(", ")", ";", "fileHeader", ".", "repaint", "(", ")", ";", "}" ]
Called when the text of the script has changed.
[ "Called", "when", "the", "text", "of", "the", "script", "has", "changed", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2337-L2350
21,587
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
FileWindow.select
public void select(int start, int end) { int docEnd = textArea.getDocument().getLength(); textArea.select(docEnd, docEnd); textArea.select(start, end); }
java
public void select(int start, int end) { int docEnd = textArea.getDocument().getLength(); textArea.select(docEnd, docEnd); textArea.select(start, end); }
[ "public", "void", "select", "(", "int", "start", ",", "int", "end", ")", "{", "int", "docEnd", "=", "textArea", ".", "getDocument", "(", ")", ".", "getLength", "(", ")", ";", "textArea", ".", "select", "(", "docEnd", ",", "docEnd", ")", ";", "textArea", ".", "select", "(", "start", ",", "end", ")", ";", "}" ]
Selects a range of characters.
[ "Selects", "a", "range", "of", "characters", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2364-L2368
21,588
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
MyTableModel.getValueAt
@Override public Object getValueAt(int row, int column) { switch (column) { case 0: return expressions.get(row); case 1: return values.get(row); } return ""; }
java
@Override public Object getValueAt(int row, int column) { switch (column) { case 0: return expressions.get(row); case 1: return values.get(row); } return ""; }
[ "@", "Override", "public", "Object", "getValueAt", "(", "int", "row", ",", "int", "column", ")", "{", "switch", "(", "column", ")", "{", "case", "0", ":", "return", "expressions", ".", "get", "(", "row", ")", ";", "case", "1", ":", "return", "values", ".", "get", "(", "row", ")", ";", "}", "return", "\"\"", ";", "}" ]
Returns the value in the given cell.
[ "Returns", "the", "value", "in", "the", "given", "cell", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2474-L2483
21,589
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
MyTableModel.setValueAt
@Override public void setValueAt(Object value, int row, int column) { switch (column) { case 0: String expr = value.toString(); expressions.set(row, expr); String result = ""; if (expr.length() > 0) { result = debugGui.dim.eval(expr); if (result == null) result = ""; } values.set(row, result); updateModel(); if (row + 1 == expressions.size()) { expressions.add(""); values.add(""); fireTableRowsInserted(row + 1, row + 1); } break; case 1: // just reset column 2; ignore edits fireTableDataChanged(); } }
java
@Override public void setValueAt(Object value, int row, int column) { switch (column) { case 0: String expr = value.toString(); expressions.set(row, expr); String result = ""; if (expr.length() > 0) { result = debugGui.dim.eval(expr); if (result == null) result = ""; } values.set(row, result); updateModel(); if (row + 1 == expressions.size()) { expressions.add(""); values.add(""); fireTableRowsInserted(row + 1, row + 1); } break; case 1: // just reset column 2; ignore edits fireTableDataChanged(); } }
[ "@", "Override", "public", "void", "setValueAt", "(", "Object", "value", ",", "int", "row", ",", "int", "column", ")", "{", "switch", "(", "column", ")", "{", "case", "0", ":", "String", "expr", "=", "value", ".", "toString", "(", ")", ";", "expressions", ".", "set", "(", "row", ",", "expr", ")", ";", "String", "result", "=", "\"\"", ";", "if", "(", "expr", ".", "length", "(", ")", ">", "0", ")", "{", "result", "=", "debugGui", ".", "dim", ".", "eval", "(", "expr", ")", ";", "if", "(", "result", "==", "null", ")", "result", "=", "\"\"", ";", "}", "values", ".", "set", "(", "row", ",", "result", ")", ";", "updateModel", "(", ")", ";", "if", "(", "row", "+", "1", "==", "expressions", ".", "size", "(", ")", ")", "{", "expressions", ".", "add", "(", "\"\"", ")", ";", "values", ".", "add", "(", "\"\"", ")", ";", "fireTableRowsInserted", "(", "row", "+", "1", ",", "row", "+", "1", ")", ";", "}", "break", ";", "case", "1", ":", "// just reset column 2; ignore edits", "fireTableDataChanged", "(", ")", ";", "}", "}" ]
Sets the value in the given cell.
[ "Sets", "the", "value", "in", "the", "given", "cell", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2488-L2511
21,590
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
MyTableModel.updateModel
void updateModel() { for (int i = 0; i < expressions.size(); ++i) { String expr = expressions.get(i); String result = ""; if (expr.length() > 0) { result = debugGui.dim.eval(expr); if (result == null) result = ""; } else { result = ""; } result = result.replace('\n', ' '); values.set(i, result); } fireTableDataChanged(); }
java
void updateModel() { for (int i = 0; i < expressions.size(); ++i) { String expr = expressions.get(i); String result = ""; if (expr.length() > 0) { result = debugGui.dim.eval(expr); if (result == null) result = ""; } else { result = ""; } result = result.replace('\n', ' '); values.set(i, result); } fireTableDataChanged(); }
[ "void", "updateModel", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "expressions", ".", "size", "(", ")", ";", "++", "i", ")", "{", "String", "expr", "=", "expressions", ".", "get", "(", "i", ")", ";", "String", "result", "=", "\"\"", ";", "if", "(", "expr", ".", "length", "(", ")", ">", "0", ")", "{", "result", "=", "debugGui", ".", "dim", ".", "eval", "(", "expr", ")", ";", "if", "(", "result", "==", "null", ")", "result", "=", "\"\"", ";", "}", "else", "{", "result", "=", "\"\"", ";", "}", "result", "=", "result", ".", "replace", "(", "'", "'", ",", "'", "'", ")", ";", "values", ".", "set", "(", "i", ",", "result", ")", ";", "}", "fireTableDataChanged", "(", ")", ";", "}" ]
Re-evaluates the expressions in the table.
[ "Re", "-", "evaluates", "the", "expressions", "in", "the", "table", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2516-L2530
21,591
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
VariableModel.getChildCount
@Override public int getChildCount(Object nodeObj) { if (debugger == null) { return 0; } VariableNode node = (VariableNode) nodeObj; return children(node).length; }
java
@Override public int getChildCount(Object nodeObj) { if (debugger == null) { return 0; } VariableNode node = (VariableNode) nodeObj; return children(node).length; }
[ "@", "Override", "public", "int", "getChildCount", "(", "Object", "nodeObj", ")", "{", "if", "(", "debugger", "==", "null", ")", "{", "return", "0", ";", "}", "VariableNode", "node", "=", "(", "VariableNode", ")", "nodeObj", ";", "return", "children", "(", "node", ")", ".", "length", ";", "}" ]
Returns the number of children of the given node.
[ "Returns", "the", "number", "of", "children", "of", "the", "given", "node", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2618-L2625
21,592
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
VariableModel.getChild
@Override public Object getChild(Object nodeObj, int i) { if (debugger == null) { return null; } VariableNode node = (VariableNode) nodeObj; return children(node)[i]; }
java
@Override public Object getChild(Object nodeObj, int i) { if (debugger == null) { return null; } VariableNode node = (VariableNode) nodeObj; return children(node)[i]; }
[ "@", "Override", "public", "Object", "getChild", "(", "Object", "nodeObj", ",", "int", "i", ")", "{", "if", "(", "debugger", "==", "null", ")", "{", "return", "null", ";", "}", "VariableNode", "node", "=", "(", "VariableNode", ")", "nodeObj", ";", "return", "children", "(", "node", ")", "[", "i", "]", ";", "}" ]
Returns a child of the given node.
[ "Returns", "a", "child", "of", "the", "given", "node", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2630-L2637
21,593
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
VariableModel.isLeaf
@Override public boolean isLeaf(Object nodeObj) { if (debugger == null) { return true; } VariableNode node = (VariableNode) nodeObj; return children(node).length == 0; }
java
@Override public boolean isLeaf(Object nodeObj) { if (debugger == null) { return true; } VariableNode node = (VariableNode) nodeObj; return children(node).length == 0; }
[ "@", "Override", "public", "boolean", "isLeaf", "(", "Object", "nodeObj", ")", "{", "if", "(", "debugger", "==", "null", ")", "{", "return", "true", ";", "}", "VariableNode", "node", "=", "(", "VariableNode", ")", "nodeObj", ";", "return", "children", "(", "node", ")", ".", "length", "==", "0", ";", "}" ]
Returns whether the given node is a leaf node.
[ "Returns", "whether", "the", "given", "node", "is", "a", "leaf", "node", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2642-L2649
21,594
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
VariableModel.getIndexOfChild
@Override public int getIndexOfChild(Object parentObj, Object childObj) { if (debugger == null) { return -1; } VariableNode parent = (VariableNode) parentObj; VariableNode child = (VariableNode) childObj; VariableNode[] children = children(parent); for (int i = 0; i != children.length; i++) { if (children[i] == child) { return i; } } return -1; }
java
@Override public int getIndexOfChild(Object parentObj, Object childObj) { if (debugger == null) { return -1; } VariableNode parent = (VariableNode) parentObj; VariableNode child = (VariableNode) childObj; VariableNode[] children = children(parent); for (int i = 0; i != children.length; i++) { if (children[i] == child) { return i; } } return -1; }
[ "@", "Override", "public", "int", "getIndexOfChild", "(", "Object", "parentObj", ",", "Object", "childObj", ")", "{", "if", "(", "debugger", "==", "null", ")", "{", "return", "-", "1", ";", "}", "VariableNode", "parent", "=", "(", "VariableNode", ")", "parentObj", ";", "VariableNode", "child", "=", "(", "VariableNode", ")", "childObj", ";", "VariableNode", "[", "]", "children", "=", "children", "(", "parent", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "!=", "children", ".", "length", ";", "i", "++", ")", "{", "if", "(", "children", "[", "i", "]", "==", "child", ")", "{", "return", "i", ";", "}", "}", "return", "-", "1", ";", "}" ]
Returns the index of a node under its parent.
[ "Returns", "the", "index", "of", "a", "node", "under", "its", "parent", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2654-L2668
21,595
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
VariableModel.getValueAt
@Override public Object getValueAt(Object nodeObj, int column) { if (debugger == null) { return null; } VariableNode node = (VariableNode)nodeObj; switch (column) { case 0: // Name return node.toString(); case 1: // Value String result; try { result = debugger.objectToString(getValue(node)); } catch (RuntimeException exc) { result = exc.getMessage(); } StringBuilder buf = new StringBuilder(); int len = result.length(); for (int i = 0; i < len; i++) { char ch = result.charAt(i); if (Character.isISOControl(ch)) { ch = ' '; } buf.append(ch); } return buf.toString(); } return null; }
java
@Override public Object getValueAt(Object nodeObj, int column) { if (debugger == null) { return null; } VariableNode node = (VariableNode)nodeObj; switch (column) { case 0: // Name return node.toString(); case 1: // Value String result; try { result = debugger.objectToString(getValue(node)); } catch (RuntimeException exc) { result = exc.getMessage(); } StringBuilder buf = new StringBuilder(); int len = result.length(); for (int i = 0; i < len; i++) { char ch = result.charAt(i); if (Character.isISOControl(ch)) { ch = ' '; } buf.append(ch); } return buf.toString(); } return null; }
[ "@", "Override", "public", "Object", "getValueAt", "(", "Object", "nodeObj", ",", "int", "column", ")", "{", "if", "(", "debugger", "==", "null", ")", "{", "return", "null", ";", "}", "VariableNode", "node", "=", "(", "VariableNode", ")", "nodeObj", ";", "switch", "(", "column", ")", "{", "case", "0", ":", "// Name", "return", "node", ".", "toString", "(", ")", ";", "case", "1", ":", "// Value", "String", "result", ";", "try", "{", "result", "=", "debugger", ".", "objectToString", "(", "getValue", "(", "node", ")", ")", ";", "}", "catch", "(", "RuntimeException", "exc", ")", "{", "result", "=", "exc", ".", "getMessage", "(", ")", ";", "}", "StringBuilder", "buf", "=", "new", "StringBuilder", "(", ")", ";", "int", "len", "=", "result", ".", "length", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "len", ";", "i", "++", ")", "{", "char", "ch", "=", "result", ".", "charAt", "(", "i", ")", ";", "if", "(", "Character", ".", "isISOControl", "(", "ch", ")", ")", "{", "ch", "=", "'", "'", ";", "}", "buf", ".", "append", "(", "ch", ")", ";", "}", "return", "buf", ".", "toString", "(", ")", ";", "}", "return", "null", ";", "}" ]
Returns the value at the given cell.
[ "Returns", "the", "value", "at", "the", "given", "cell", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2728-L2754
21,596
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
VariableModel.children
private VariableNode[] children(VariableNode node) { if (node.children != null) { return node.children; } VariableNode[] children; Object value = getValue(node); Object[] ids = debugger.getObjectIds(value); if (ids == null || ids.length == 0) { children = CHILDLESS; } else { Arrays.sort(ids, new Comparator<Object>() { @Override public int compare(Object l, Object r) { if (l instanceof String) { if (r instanceof Integer) { return -1; } return ((String)l).compareToIgnoreCase((String)r); } if (r instanceof String) { return 1; } int lint = ((Integer)l).intValue(); int rint = ((Integer)r).intValue(); return lint - rint; } }); children = new VariableNode[ids.length]; for (int i = 0; i != ids.length; ++i) { children[i] = new VariableNode(value, ids[i]); } } node.children = children; return children; }
java
private VariableNode[] children(VariableNode node) { if (node.children != null) { return node.children; } VariableNode[] children; Object value = getValue(node); Object[] ids = debugger.getObjectIds(value); if (ids == null || ids.length == 0) { children = CHILDLESS; } else { Arrays.sort(ids, new Comparator<Object>() { @Override public int compare(Object l, Object r) { if (l instanceof String) { if (r instanceof Integer) { return -1; } return ((String)l).compareToIgnoreCase((String)r); } if (r instanceof String) { return 1; } int lint = ((Integer)l).intValue(); int rint = ((Integer)r).intValue(); return lint - rint; } }); children = new VariableNode[ids.length]; for (int i = 0; i != ids.length; ++i) { children[i] = new VariableNode(value, ids[i]); } } node.children = children; return children; }
[ "private", "VariableNode", "[", "]", "children", "(", "VariableNode", "node", ")", "{", "if", "(", "node", ".", "children", "!=", "null", ")", "{", "return", "node", ".", "children", ";", "}", "VariableNode", "[", "]", "children", ";", "Object", "value", "=", "getValue", "(", "node", ")", ";", "Object", "[", "]", "ids", "=", "debugger", ".", "getObjectIds", "(", "value", ")", ";", "if", "(", "ids", "==", "null", "||", "ids", ".", "length", "==", "0", ")", "{", "children", "=", "CHILDLESS", ";", "}", "else", "{", "Arrays", ".", "sort", "(", "ids", ",", "new", "Comparator", "<", "Object", ">", "(", ")", "{", "@", "Override", "public", "int", "compare", "(", "Object", "l", ",", "Object", "r", ")", "{", "if", "(", "l", "instanceof", "String", ")", "{", "if", "(", "r", "instanceof", "Integer", ")", "{", "return", "-", "1", ";", "}", "return", "(", "(", "String", ")", "l", ")", ".", "compareToIgnoreCase", "(", "(", "String", ")", "r", ")", ";", "}", "if", "(", "r", "instanceof", "String", ")", "{", "return", "1", ";", "}", "int", "lint", "=", "(", "(", "Integer", ")", "l", ")", ".", "intValue", "(", ")", ";", "int", "rint", "=", "(", "(", "Integer", ")", "r", ")", ".", "intValue", "(", ")", ";", "return", "lint", "-", "rint", ";", "}", "}", ")", ";", "children", "=", "new", "VariableNode", "[", "ids", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "!=", "ids", ".", "length", ";", "++", "i", ")", "{", "children", "[", "i", "]", "=", "new", "VariableNode", "(", "value", ",", "ids", "[", "i", "]", ")", ";", "}", "}", "node", ".", "children", "=", "children", ";", "return", "children", ";", "}" ]
Returns an array of the children of the given node.
[ "Returns", "an", "array", "of", "the", "children", "of", "the", "given", "node", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2759-L2796
21,597
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
VariableModel.getValue
public Object getValue(VariableNode node) { try { return debugger.getObjectProperty(node.object, node.id); } catch (Exception exc) { return "undefined"; } }
java
public Object getValue(VariableNode node) { try { return debugger.getObjectProperty(node.object, node.id); } catch (Exception exc) { return "undefined"; } }
[ "public", "Object", "getValue", "(", "VariableNode", "node", ")", "{", "try", "{", "return", "debugger", ".", "getObjectProperty", "(", "node", ".", "object", ",", "node", ".", "id", ")", ";", "}", "catch", "(", "Exception", "exc", ")", "{", "return", "\"undefined\"", ";", "}", "}" ]
Returns the value of the given node.
[ "Returns", "the", "value", "of", "the", "given", "node", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2801-L2807
21,598
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
MyTreeTable.resetTree
public JTree resetTree(TreeTableModel treeTableModel) { tree = new TreeTableCellRenderer(treeTableModel); // Install a tableModel representing the visible rows in the tree. super.setModel(new TreeTableModelAdapter(treeTableModel, tree)); // Force the JTable and JTree to share their row selection models. ListToTreeSelectionModelWrapper selectionWrapper = new ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); // Make the tree and table row heights the same. if (tree.getRowHeight() < 1) { // Metal looks better like this. setRowHeight(18); } // Install the tree editor renderer and editor. setDefaultRenderer(TreeTableModel.class, tree); setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor()); setShowGrid(true); setIntercellSpacing(new Dimension(1,1)); tree.setRootVisible(false); tree.setShowsRootHandles(true); DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)tree.getCellRenderer(); r.setOpenIcon(null); r.setClosedIcon(null); r.setLeafIcon(null); return tree; }
java
public JTree resetTree(TreeTableModel treeTableModel) { tree = new TreeTableCellRenderer(treeTableModel); // Install a tableModel representing the visible rows in the tree. super.setModel(new TreeTableModelAdapter(treeTableModel, tree)); // Force the JTable and JTree to share their row selection models. ListToTreeSelectionModelWrapper selectionWrapper = new ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); // Make the tree and table row heights the same. if (tree.getRowHeight() < 1) { // Metal looks better like this. setRowHeight(18); } // Install the tree editor renderer and editor. setDefaultRenderer(TreeTableModel.class, tree); setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor()); setShowGrid(true); setIntercellSpacing(new Dimension(1,1)); tree.setRootVisible(false); tree.setShowsRootHandles(true); DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)tree.getCellRenderer(); r.setOpenIcon(null); r.setClosedIcon(null); r.setLeafIcon(null); return tree; }
[ "public", "JTree", "resetTree", "(", "TreeTableModel", "treeTableModel", ")", "{", "tree", "=", "new", "TreeTableCellRenderer", "(", "treeTableModel", ")", ";", "// Install a tableModel representing the visible rows in the tree.", "super", ".", "setModel", "(", "new", "TreeTableModelAdapter", "(", "treeTableModel", ",", "tree", ")", ")", ";", "// Force the JTable and JTree to share their row selection models.", "ListToTreeSelectionModelWrapper", "selectionWrapper", "=", "new", "ListToTreeSelectionModelWrapper", "(", ")", ";", "tree", ".", "setSelectionModel", "(", "selectionWrapper", ")", ";", "setSelectionModel", "(", "selectionWrapper", ".", "getListSelectionModel", "(", ")", ")", ";", "// Make the tree and table row heights the same.", "if", "(", "tree", ".", "getRowHeight", "(", ")", "<", "1", ")", "{", "// Metal looks better like this.", "setRowHeight", "(", "18", ")", ";", "}", "// Install the tree editor renderer and editor.", "setDefaultRenderer", "(", "TreeTableModel", ".", "class", ",", "tree", ")", ";", "setDefaultEditor", "(", "TreeTableModel", ".", "class", ",", "new", "TreeTableCellEditor", "(", ")", ")", ";", "setShowGrid", "(", "true", ")", ";", "setIntercellSpacing", "(", "new", "Dimension", "(", "1", ",", "1", ")", ")", ";", "tree", ".", "setRootVisible", "(", "false", ")", ";", "tree", ".", "setShowsRootHandles", "(", "true", ")", ";", "DefaultTreeCellRenderer", "r", "=", "(", "DefaultTreeCellRenderer", ")", "tree", ".", "getCellRenderer", "(", ")", ";", "r", ".", "setOpenIcon", "(", "null", ")", ";", "r", ".", "setClosedIcon", "(", "null", ")", ";", "r", ".", "setLeafIcon", "(", "null", ")", ";", "return", "tree", ";", "}" ]
Initializes a tree for this tree table.
[ "Initializes", "a", "tree", "for", "this", "tree", "table", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L2869-L2899
21,599
mozilla/rhino
toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
ContextWindow.setEnabled
@Override public void setEnabled(boolean enabled) { context.setEnabled(enabled); thisTable.setEnabled(enabled); localsTable.setEnabled(enabled); evaluator.setEnabled(enabled); cmdLine.setEnabled(enabled); }
java
@Override public void setEnabled(boolean enabled) { context.setEnabled(enabled); thisTable.setEnabled(enabled); localsTable.setEnabled(enabled); evaluator.setEnabled(enabled); cmdLine.setEnabled(enabled); }
[ "@", "Override", "public", "void", "setEnabled", "(", "boolean", "enabled", ")", "{", "context", ".", "setEnabled", "(", "enabled", ")", ";", "thisTable", ".", "setEnabled", "(", "enabled", ")", ";", "localsTable", ".", "setEnabled", "(", "enabled", ")", ";", "evaluator", ".", "setEnabled", "(", "enabled", ")", ";", "cmdLine", ".", "setEnabled", "(", "enabled", ")", ";", "}" ]
Enables or disables the component.
[ "Enables", "or", "disables", "the", "component", "." ]
fa8a86df11d37623f5faa8d445a5876612bc47b0
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java#L3260-L3267