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,400
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/AstNode.java
|
AstNode.operatorToString
|
public static String operatorToString(int op) {
String result = operatorNames.get(op);
if (result == null)
throw new IllegalArgumentException("Invalid operator: " + op);
return result;
}
|
java
|
public static String operatorToString(int op) {
String result = operatorNames.get(op);
if (result == null)
throw new IllegalArgumentException("Invalid operator: " + op);
return result;
}
|
[
"public",
"static",
"String",
"operatorToString",
"(",
"int",
"op",
")",
"{",
"String",
"result",
"=",
"operatorNames",
".",
"get",
"(",
"op",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid operator: \"",
"+",
"op",
")",
";",
"return",
"result",
";",
"}"
] |
Returns the string name for this operator.
@param op the token type, e.g. {@link Token#ADD} or {@link Token#TYPEOF}
@return the source operator string, such as "+" or "typeof"
|
[
"Returns",
"the",
"string",
"name",
"for",
"this",
"operator",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/AstNode.java#L345-L350
|
21,401
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/AstNode.java
|
AstNode.debugPrint
|
public String debugPrint() {
DebugPrintVisitor dpv = new DebugPrintVisitor(new StringBuilder(1000));
visit(dpv);
return dpv.toString();
}
|
java
|
public String debugPrint() {
DebugPrintVisitor dpv = new DebugPrintVisitor(new StringBuilder(1000));
visit(dpv);
return dpv.toString();
}
|
[
"public",
"String",
"debugPrint",
"(",
")",
"{",
"DebugPrintVisitor",
"dpv",
"=",
"new",
"DebugPrintVisitor",
"(",
"new",
"StringBuilder",
"(",
"1000",
")",
")",
";",
"visit",
"(",
"dpv",
")",
";",
"return",
"dpv",
".",
"toString",
"(",
")",
";",
"}"
] |
Returns a debugging representation of the parse tree
starting at this node.
@return a very verbose indented printout of the tree.
The format of each line is: abs-pos name position length [identifier]
|
[
"Returns",
"a",
"debugging",
"representation",
"of",
"the",
"parse",
"tree",
"starting",
"at",
"this",
"node",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/AstNode.java#L619-L623
|
21,402
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/Label.java
|
Label.setName
|
public void setName(String name) {
name = name == null ? null : name.trim();
if (name == null || "".equals(name))
throw new IllegalArgumentException("invalid label name");
this.name = name;
}
|
java
|
public void setName(String name) {
name = name == null ? null : name.trim();
if (name == null || "".equals(name))
throw new IllegalArgumentException("invalid label name");
this.name = name;
}
|
[
"public",
"void",
"setName",
"(",
"String",
"name",
")",
"{",
"name",
"=",
"name",
"==",
"null",
"?",
"null",
":",
"name",
".",
"trim",
"(",
")",
";",
"if",
"(",
"name",
"==",
"null",
"||",
"\"\"",
".",
"equals",
"(",
"name",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid label name\"",
")",
";",
"this",
".",
"name",
"=",
"name",
";",
"}"
] |
Sets the label text
@throws IllegalArgumentException if name is {@code null} or the
empty string.
|
[
"Sets",
"the",
"label",
"text"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/Label.java#L54-L59
|
21,403
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/NewExpression.java
|
NewExpression.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
target.visit(v);
for (AstNode arg : getArguments()) {
arg.visit(v);
}
if (initializer != null) {
initializer.visit(v);
}
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
target.visit(v);
for (AstNode arg : getArguments()) {
arg.visit(v);
}
if (initializer != null) {
initializer.visit(v);
}
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"target",
".",
"visit",
"(",
"v",
")",
";",
"for",
"(",
"AstNode",
"arg",
":",
"getArguments",
"(",
")",
")",
"{",
"arg",
".",
"visit",
"(",
"v",
")",
";",
"}",
"if",
"(",
"initializer",
"!=",
"null",
")",
"{",
"initializer",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}",
"}"
] |
Visits this node, the target, and each argument. If there is
a trailing initializer node, visits that last.
|
[
"Visits",
"this",
"node",
"the",
"target",
"and",
"each",
"argument",
".",
"If",
"there",
"is",
"a",
"trailing",
"initializer",
"node",
"visits",
"that",
"last",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/NewExpression.java#L87-L98
|
21,404
|
mozilla/rhino
|
src/org/mozilla/javascript/optimizer/ClassCompiler.java
|
ClassCompiler.setTargetImplements
|
public void setTargetImplements(Class<?>[] implementsClasses)
{
targetImplements = implementsClasses == null ? null : (Class[])implementsClasses.clone();
}
|
java
|
public void setTargetImplements(Class<?>[] implementsClasses)
{
targetImplements = implementsClasses == null ? null : (Class[])implementsClasses.clone();
}
|
[
"public",
"void",
"setTargetImplements",
"(",
"Class",
"<",
"?",
">",
"[",
"]",
"implementsClasses",
")",
"{",
"targetImplements",
"=",
"implementsClasses",
"==",
"null",
"?",
"null",
":",
"(",
"Class",
"[",
"]",
")",
"implementsClasses",
".",
"clone",
"(",
")",
";",
"}"
] |
Set the interfaces that the generated target will implement.
@param implementsClasses an array of Class objects, one for each
interface the target will extend
|
[
"Set",
"the",
"interfaces",
"that",
"the",
"generated",
"target",
"will",
"implement",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/optimizer/ClassCompiler.java#L102-L105
|
21,405
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/VariableInitializer.java
|
VariableInitializer.setTarget
|
public void setTarget(AstNode target) {
// Don't throw exception if target is an "invalid" node type.
// See mozilla/js/tests/js1_7/block/regress-350279.js
if (target == null)
throw new IllegalArgumentException("invalid target arg");
this.target = target;
target.setParent(this);
}
|
java
|
public void setTarget(AstNode target) {
// Don't throw exception if target is an "invalid" node type.
// See mozilla/js/tests/js1_7/block/regress-350279.js
if (target == null)
throw new IllegalArgumentException("invalid target arg");
this.target = target;
target.setParent(this);
}
|
[
"public",
"void",
"setTarget",
"(",
"AstNode",
"target",
")",
"{",
"// Don't throw exception if target is an \"invalid\" node type.",
"// See mozilla/js/tests/js1_7/block/regress-350279.js",
"if",
"(",
"target",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid target arg\"",
")",
";",
"this",
".",
"target",
"=",
"target",
";",
"target",
".",
"setParent",
"(",
"this",
")",
";",
"}"
] |
Sets the variable name or destructuring form, and sets
its parent to this node.
@throws IllegalArgumentException if target is {@code null}
|
[
"Sets",
"the",
"variable",
"name",
"or",
"destructuring",
"form",
"and",
"sets",
"its",
"parent",
"to",
"this",
"node",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/VariableInitializer.java#L75-L82
|
21,406
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/VariableInitializer.java
|
VariableInitializer.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
target.visit(v);
if (initializer != null) {
initializer.visit(v);
}
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
target.visit(v);
if (initializer != null) {
initializer.visit(v);
}
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"target",
".",
"visit",
"(",
"v",
")",
";",
"if",
"(",
"initializer",
"!=",
"null",
")",
"{",
"initializer",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}",
"}"
] |
Visits this node, then the target expression, then the initializer
expression if present.
|
[
"Visits",
"this",
"node",
"then",
"the",
"target",
"expression",
"then",
"the",
"initializer",
"expression",
"if",
"present",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/VariableInitializer.java#L117-L125
|
21,407
|
mozilla/rhino
|
src/org/mozilla/javascript/FunctionObject.java
|
FunctionObject.getMethodList
|
static Method[] getMethodList(Class<?> clazz) {
Method[] methods = null;
try {
// getDeclaredMethods may be rejected by the security manager
// but getMethods is more expensive
if (!sawSecurityException)
methods = clazz.getDeclaredMethods();
} catch (SecurityException e) {
// If we get an exception once, give up on getDeclaredMethods
sawSecurityException = true;
}
if (methods == null) {
methods = clazz.getMethods();
}
int count = 0;
for (int i=0; i < methods.length; i++) {
if (sawSecurityException
? methods[i].getDeclaringClass() != clazz
: !Modifier.isPublic(methods[i].getModifiers()))
{
methods[i] = null;
} else {
count++;
}
}
Method[] result = new Method[count];
int j=0;
for (int i=0; i < methods.length; i++) {
if (methods[i] != null)
result[j++] = methods[i];
}
return result;
}
|
java
|
static Method[] getMethodList(Class<?> clazz) {
Method[] methods = null;
try {
// getDeclaredMethods may be rejected by the security manager
// but getMethods is more expensive
if (!sawSecurityException)
methods = clazz.getDeclaredMethods();
} catch (SecurityException e) {
// If we get an exception once, give up on getDeclaredMethods
sawSecurityException = true;
}
if (methods == null) {
methods = clazz.getMethods();
}
int count = 0;
for (int i=0; i < methods.length; i++) {
if (sawSecurityException
? methods[i].getDeclaringClass() != clazz
: !Modifier.isPublic(methods[i].getModifiers()))
{
methods[i] = null;
} else {
count++;
}
}
Method[] result = new Method[count];
int j=0;
for (int i=0; i < methods.length; i++) {
if (methods[i] != null)
result[j++] = methods[i];
}
return result;
}
|
[
"static",
"Method",
"[",
"]",
"getMethodList",
"(",
"Class",
"<",
"?",
">",
"clazz",
")",
"{",
"Method",
"[",
"]",
"methods",
"=",
"null",
";",
"try",
"{",
"// getDeclaredMethods may be rejected by the security manager",
"// but getMethods is more expensive",
"if",
"(",
"!",
"sawSecurityException",
")",
"methods",
"=",
"clazz",
".",
"getDeclaredMethods",
"(",
")",
";",
"}",
"catch",
"(",
"SecurityException",
"e",
")",
"{",
"// If we get an exception once, give up on getDeclaredMethods",
"sawSecurityException",
"=",
"true",
";",
"}",
"if",
"(",
"methods",
"==",
"null",
")",
"{",
"methods",
"=",
"clazz",
".",
"getMethods",
"(",
")",
";",
"}",
"int",
"count",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"methods",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"sawSecurityException",
"?",
"methods",
"[",
"i",
"]",
".",
"getDeclaringClass",
"(",
")",
"!=",
"clazz",
":",
"!",
"Modifier",
".",
"isPublic",
"(",
"methods",
"[",
"i",
"]",
".",
"getModifiers",
"(",
")",
")",
")",
"{",
"methods",
"[",
"i",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"count",
"++",
";",
"}",
"}",
"Method",
"[",
"]",
"result",
"=",
"new",
"Method",
"[",
"count",
"]",
";",
"int",
"j",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"methods",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"methods",
"[",
"i",
"]",
"!=",
"null",
")",
"result",
"[",
"j",
"++",
"]",
"=",
"methods",
"[",
"i",
"]",
";",
"}",
"return",
"result",
";",
"}"
] |
Returns all public methods declared by the specified class. This excludes
inherited methods.
@param clazz the class from which to pull public declared methods
@return the public methods declared in the specified class
@see Class#getDeclaredMethods()
|
[
"Returns",
"all",
"public",
"methods",
"declared",
"by",
"the",
"specified",
"class",
".",
"This",
"excludes",
"inherited",
"methods",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/FunctionObject.java#L272-L304
|
21,408
|
mozilla/rhino
|
toolsrc/org/mozilla/javascript/tools/debugger/treetable/JTreeTable.java
|
JTreeTable.setRowHeight
|
@Override
public void setRowHeight(int rowHeight) {
super.setRowHeight(rowHeight);
if (tree != null && tree.getRowHeight() != rowHeight) {
tree.setRowHeight(getRowHeight());
}
}
|
java
|
@Override
public void setRowHeight(int rowHeight) {
super.setRowHeight(rowHeight);
if (tree != null && tree.getRowHeight() != rowHeight) {
tree.setRowHeight(getRowHeight());
}
}
|
[
"@",
"Override",
"public",
"void",
"setRowHeight",
"(",
"int",
"rowHeight",
")",
"{",
"super",
".",
"setRowHeight",
"(",
"rowHeight",
")",
";",
"if",
"(",
"tree",
"!=",
"null",
"&&",
"tree",
".",
"getRowHeight",
"(",
")",
"!=",
"rowHeight",
")",
"{",
"tree",
".",
"setRowHeight",
"(",
"getRowHeight",
"(",
")",
")",
";",
"}",
"}"
] |
Overridden to pass the new rowHeight to the tree.
|
[
"Overridden",
"to",
"pass",
"the",
"new",
"rowHeight",
"to",
"the",
"tree",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/debugger/treetable/JTreeTable.java#L140-L146
|
21,409
|
mozilla/rhino
|
src/org/mozilla/javascript/NativeJavaObject.java
|
NativeJavaObject.coerceType
|
@Deprecated
public static Object coerceType(Class<?> type, Object value)
{
return coerceTypeImpl(type, value);
}
|
java
|
@Deprecated
public static Object coerceType(Class<?> type, Object value)
{
return coerceTypeImpl(type, value);
}
|
[
"@",
"Deprecated",
"public",
"static",
"Object",
"coerceType",
"(",
"Class",
"<",
"?",
">",
"type",
",",
"Object",
"value",
")",
"{",
"return",
"coerceTypeImpl",
"(",
"type",
",",
"value",
")",
";",
"}"
] |
Not intended for public use. Callers should use the
public API Context.toType.
@deprecated as of 1.5 Release 4
@see org.mozilla.javascript.Context#jsToJava(Object, Class)
|
[
"Not",
"intended",
"for",
"public",
"use",
".",
"Callers",
"should",
"use",
"the",
"public",
"API",
"Context",
".",
"toType",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/NativeJavaObject.java#L496-L500
|
21,410
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/XmlElemRef.java
|
XmlElemRef.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
if (namespace != null) {
namespace.visit(v);
}
indexExpr.visit(v);
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
if (namespace != null) {
namespace.visit(v);
}
indexExpr.visit(v);
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"if",
"(",
"namespace",
"!=",
"null",
")",
"{",
"namespace",
".",
"visit",
"(",
"v",
")",
";",
"}",
"indexExpr",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}"
] |
Visits this node, then the namespace if provided, then the
index expression.
|
[
"Visits",
"this",
"node",
"then",
"the",
"namespace",
"if",
"provided",
"then",
"the",
"index",
"expression",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/XmlElemRef.java#L129-L137
|
21,411
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/ElementGet.java
|
ElementGet.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
target.visit(v);
element.visit(v);
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
target.visit(v);
element.visit(v);
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"target",
".",
"visit",
"(",
"v",
")",
";",
"element",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}"
] |
Visits this node, the target, and the index expression.
|
[
"Visits",
"this",
"node",
"the",
"target",
"and",
"the",
"index",
"expression",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/ElementGet.java#L132-L138
|
21,412
|
mozilla/rhino
|
src/org/mozilla/javascript/RhinoSecurityManager.java
|
RhinoSecurityManager.getCurrentScriptClass
|
protected Class<?> getCurrentScriptClass() {
Class<?>[] context = getClassContext();
for (Class<?> c : context) {
if (c != InterpretedFunction.class && NativeFunction.class.isAssignableFrom(c) ||
PolicySecurityController.SecureCaller.class.isAssignableFrom(c)) {
return c;
}
}
return null;
}
|
java
|
protected Class<?> getCurrentScriptClass() {
Class<?>[] context = getClassContext();
for (Class<?> c : context) {
if (c != InterpretedFunction.class && NativeFunction.class.isAssignableFrom(c) ||
PolicySecurityController.SecureCaller.class.isAssignableFrom(c)) {
return c;
}
}
return null;
}
|
[
"protected",
"Class",
"<",
"?",
">",
"getCurrentScriptClass",
"(",
")",
"{",
"Class",
"<",
"?",
">",
"[",
"]",
"context",
"=",
"getClassContext",
"(",
")",
";",
"for",
"(",
"Class",
"<",
"?",
">",
"c",
":",
"context",
")",
"{",
"if",
"(",
"c",
"!=",
"InterpretedFunction",
".",
"class",
"&&",
"NativeFunction",
".",
"class",
".",
"isAssignableFrom",
"(",
"c",
")",
"||",
"PolicySecurityController",
".",
"SecureCaller",
".",
"class",
".",
"isAssignableFrom",
"(",
"c",
")",
")",
"{",
"return",
"c",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get the class of the top-most stack element representing a script.
@return The class of the top-most script in the current stack,
or null if no script is currently running
|
[
"Get",
"the",
"class",
"of",
"the",
"top",
"-",
"most",
"stack",
"element",
"representing",
"a",
"script",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/RhinoSecurityManager.java#L22-L31
|
21,413
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/ArrayLiteral.java
|
ArrayLiteral.setElements
|
public void setElements(List<AstNode> elements) {
if (elements == null) {
this.elements = null;
} else {
if (this.elements != null)
this.elements.clear();
for (AstNode e : elements)
addElement(e);
}
}
|
java
|
public void setElements(List<AstNode> elements) {
if (elements == null) {
this.elements = null;
} else {
if (this.elements != null)
this.elements.clear();
for (AstNode e : elements)
addElement(e);
}
}
|
[
"public",
"void",
"setElements",
"(",
"List",
"<",
"AstNode",
">",
"elements",
")",
"{",
"if",
"(",
"elements",
"==",
"null",
")",
"{",
"this",
".",
"elements",
"=",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"elements",
"!=",
"null",
")",
"this",
".",
"elements",
".",
"clear",
"(",
")",
";",
"for",
"(",
"AstNode",
"e",
":",
"elements",
")",
"addElement",
"(",
")",
";",
"}",
"}"
] |
Sets the element list, and sets each element's parent to this node.
@param elements the element list. Can be {@code null}.
|
[
"Sets",
"the",
"element",
"list",
"and",
"sets",
"each",
"element",
"s",
"parent",
"to",
"this",
"node",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/ArrayLiteral.java#L72-L81
|
21,414
|
mozilla/rhino
|
src/org/mozilla/javascript/regexp/RegExpImpl.java
|
RegExpImpl.matchOrReplace
|
private static Object matchOrReplace(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args,
RegExpImpl reImpl,
GlobData data, NativeRegExp re)
{
String str = data.str;
data.global = (re.getFlags() & NativeRegExp.JSREG_GLOB) != 0;
int[] indexp = { 0 };
Object result = null;
if (data.mode == RA_SEARCH) {
result = re.executeRegExp(cx, scope, reImpl,
str, indexp, NativeRegExp.TEST);
if (result != null && result.equals(Boolean.TRUE))
result = Integer.valueOf(reImpl.leftContext.length);
else
result = Integer.valueOf(-1);
} else if (data.global) {
re.lastIndex = 0d;
for (int count = 0; indexp[0] <= str.length(); count++) {
result = re.executeRegExp(cx, scope, reImpl,
str, indexp, NativeRegExp.TEST);
if (result == null || !result.equals(Boolean.TRUE))
break;
if (data.mode == RA_MATCH) {
match_glob(data, cx, scope, count, reImpl);
} else {
if (data.mode != RA_REPLACE) Kit.codeBug();
SubString lastMatch = reImpl.lastMatch;
int leftIndex = data.leftIndex;
int leftlen = lastMatch.index - leftIndex;
data.leftIndex = lastMatch.index + lastMatch.length;
replace_glob(data, cx, scope, reImpl, leftIndex, leftlen);
}
if (reImpl.lastMatch.length == 0) {
if (indexp[0] == str.length())
break;
indexp[0]++;
}
}
} else {
result = re.executeRegExp(cx, scope, reImpl, str, indexp,
((data.mode == RA_REPLACE)
? NativeRegExp.TEST
: NativeRegExp.MATCH));
}
return result;
}
|
java
|
private static Object matchOrReplace(Context cx, Scriptable scope,
Scriptable thisObj, Object[] args,
RegExpImpl reImpl,
GlobData data, NativeRegExp re)
{
String str = data.str;
data.global = (re.getFlags() & NativeRegExp.JSREG_GLOB) != 0;
int[] indexp = { 0 };
Object result = null;
if (data.mode == RA_SEARCH) {
result = re.executeRegExp(cx, scope, reImpl,
str, indexp, NativeRegExp.TEST);
if (result != null && result.equals(Boolean.TRUE))
result = Integer.valueOf(reImpl.leftContext.length);
else
result = Integer.valueOf(-1);
} else if (data.global) {
re.lastIndex = 0d;
for (int count = 0; indexp[0] <= str.length(); count++) {
result = re.executeRegExp(cx, scope, reImpl,
str, indexp, NativeRegExp.TEST);
if (result == null || !result.equals(Boolean.TRUE))
break;
if (data.mode == RA_MATCH) {
match_glob(data, cx, scope, count, reImpl);
} else {
if (data.mode != RA_REPLACE) Kit.codeBug();
SubString lastMatch = reImpl.lastMatch;
int leftIndex = data.leftIndex;
int leftlen = lastMatch.index - leftIndex;
data.leftIndex = lastMatch.index + lastMatch.length;
replace_glob(data, cx, scope, reImpl, leftIndex, leftlen);
}
if (reImpl.lastMatch.length == 0) {
if (indexp[0] == str.length())
break;
indexp[0]++;
}
}
} else {
result = re.executeRegExp(cx, scope, reImpl, str, indexp,
((data.mode == RA_REPLACE)
? NativeRegExp.TEST
: NativeRegExp.MATCH));
}
return result;
}
|
[
"private",
"static",
"Object",
"matchOrReplace",
"(",
"Context",
"cx",
",",
"Scriptable",
"scope",
",",
"Scriptable",
"thisObj",
",",
"Object",
"[",
"]",
"args",
",",
"RegExpImpl",
"reImpl",
",",
"GlobData",
"data",
",",
"NativeRegExp",
"re",
")",
"{",
"String",
"str",
"=",
"data",
".",
"str",
";",
"data",
".",
"global",
"=",
"(",
"re",
".",
"getFlags",
"(",
")",
"&",
"NativeRegExp",
".",
"JSREG_GLOB",
")",
"!=",
"0",
";",
"int",
"[",
"]",
"indexp",
"=",
"{",
"0",
"}",
";",
"Object",
"result",
"=",
"null",
";",
"if",
"(",
"data",
".",
"mode",
"==",
"RA_SEARCH",
")",
"{",
"result",
"=",
"re",
".",
"executeRegExp",
"(",
"cx",
",",
"scope",
",",
"reImpl",
",",
"str",
",",
"indexp",
",",
"NativeRegExp",
".",
"TEST",
")",
";",
"if",
"(",
"result",
"!=",
"null",
"&&",
"result",
".",
"equals",
"(",
"Boolean",
".",
"TRUE",
")",
")",
"result",
"=",
"Integer",
".",
"valueOf",
"(",
"reImpl",
".",
"leftContext",
".",
"length",
")",
";",
"else",
"result",
"=",
"Integer",
".",
"valueOf",
"(",
"-",
"1",
")",
";",
"}",
"else",
"if",
"(",
"data",
".",
"global",
")",
"{",
"re",
".",
"lastIndex",
"=",
"0d",
";",
"for",
"(",
"int",
"count",
"=",
"0",
";",
"indexp",
"[",
"0",
"]",
"<=",
"str",
".",
"length",
"(",
")",
";",
"count",
"++",
")",
"{",
"result",
"=",
"re",
".",
"executeRegExp",
"(",
"cx",
",",
"scope",
",",
"reImpl",
",",
"str",
",",
"indexp",
",",
"NativeRegExp",
".",
"TEST",
")",
";",
"if",
"(",
"result",
"==",
"null",
"||",
"!",
"result",
".",
"equals",
"(",
"Boolean",
".",
"TRUE",
")",
")",
"break",
";",
"if",
"(",
"data",
".",
"mode",
"==",
"RA_MATCH",
")",
"{",
"match_glob",
"(",
"data",
",",
"cx",
",",
"scope",
",",
"count",
",",
"reImpl",
")",
";",
"}",
"else",
"{",
"if",
"(",
"data",
".",
"mode",
"!=",
"RA_REPLACE",
")",
"Kit",
".",
"codeBug",
"(",
")",
";",
"SubString",
"lastMatch",
"=",
"reImpl",
".",
"lastMatch",
";",
"int",
"leftIndex",
"=",
"data",
".",
"leftIndex",
";",
"int",
"leftlen",
"=",
"lastMatch",
".",
"index",
"-",
"leftIndex",
";",
"data",
".",
"leftIndex",
"=",
"lastMatch",
".",
"index",
"+",
"lastMatch",
".",
"length",
";",
"replace_glob",
"(",
"data",
",",
"cx",
",",
"scope",
",",
"reImpl",
",",
"leftIndex",
",",
"leftlen",
")",
";",
"}",
"if",
"(",
"reImpl",
".",
"lastMatch",
".",
"length",
"==",
"0",
")",
"{",
"if",
"(",
"indexp",
"[",
"0",
"]",
"==",
"str",
".",
"length",
"(",
")",
")",
"break",
";",
"indexp",
"[",
"0",
"]",
"++",
";",
"}",
"}",
"}",
"else",
"{",
"result",
"=",
"re",
".",
"executeRegExp",
"(",
"cx",
",",
"scope",
",",
"reImpl",
",",
"str",
",",
"indexp",
",",
"(",
"(",
"data",
".",
"mode",
"==",
"RA_REPLACE",
")",
"?",
"NativeRegExp",
".",
"TEST",
":",
"NativeRegExp",
".",
"MATCH",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Analog of C match_or_replace.
|
[
"Analog",
"of",
"C",
"match_or_replace",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/regexp/RegExpImpl.java#L162-L209
|
21,415
|
mozilla/rhino
|
src/org/mozilla/javascript/regexp/RegExpImpl.java
|
RegExpImpl.do_replace
|
private static void do_replace(GlobData rdata, Context cx,
RegExpImpl regExpImpl)
{
StringBuilder charBuf = rdata.charBuf;
int cp = 0;
String da = rdata.repstr;
int dp = rdata.dollar;
if (dp != -1) {
int[] skip = new int[1];
do {
int len = dp - cp;
charBuf.append(da.substring(cp, dp));
cp = dp;
SubString sub = interpretDollar(cx, regExpImpl, da,
dp, skip);
if (sub != null) {
len = sub.length;
if (len > 0) {
charBuf.append(sub.str, sub.index, sub.index + len);
}
cp += skip[0];
dp += skip[0];
} else {
++dp;
}
dp = da.indexOf('$', dp);
} while (dp >= 0);
}
int daL = da.length();
if (daL > cp) {
charBuf.append(da.substring(cp, daL));
}
}
|
java
|
private static void do_replace(GlobData rdata, Context cx,
RegExpImpl regExpImpl)
{
StringBuilder charBuf = rdata.charBuf;
int cp = 0;
String da = rdata.repstr;
int dp = rdata.dollar;
if (dp != -1) {
int[] skip = new int[1];
do {
int len = dp - cp;
charBuf.append(da.substring(cp, dp));
cp = dp;
SubString sub = interpretDollar(cx, regExpImpl, da,
dp, skip);
if (sub != null) {
len = sub.length;
if (len > 0) {
charBuf.append(sub.str, sub.index, sub.index + len);
}
cp += skip[0];
dp += skip[0];
} else {
++dp;
}
dp = da.indexOf('$', dp);
} while (dp >= 0);
}
int daL = da.length();
if (daL > cp) {
charBuf.append(da.substring(cp, daL));
}
}
|
[
"private",
"static",
"void",
"do_replace",
"(",
"GlobData",
"rdata",
",",
"Context",
"cx",
",",
"RegExpImpl",
"regExpImpl",
")",
"{",
"StringBuilder",
"charBuf",
"=",
"rdata",
".",
"charBuf",
";",
"int",
"cp",
"=",
"0",
";",
"String",
"da",
"=",
"rdata",
".",
"repstr",
";",
"int",
"dp",
"=",
"rdata",
".",
"dollar",
";",
"if",
"(",
"dp",
"!=",
"-",
"1",
")",
"{",
"int",
"[",
"]",
"skip",
"=",
"new",
"int",
"[",
"1",
"]",
";",
"do",
"{",
"int",
"len",
"=",
"dp",
"-",
"cp",
";",
"charBuf",
".",
"append",
"(",
"da",
".",
"substring",
"(",
"cp",
",",
"dp",
")",
")",
";",
"cp",
"=",
"dp",
";",
"SubString",
"sub",
"=",
"interpretDollar",
"(",
"cx",
",",
"regExpImpl",
",",
"da",
",",
"dp",
",",
"skip",
")",
";",
"if",
"(",
"sub",
"!=",
"null",
")",
"{",
"len",
"=",
"sub",
".",
"length",
";",
"if",
"(",
"len",
">",
"0",
")",
"{",
"charBuf",
".",
"append",
"(",
"sub",
".",
"str",
",",
"sub",
".",
"index",
",",
"sub",
".",
"index",
"+",
"len",
")",
";",
"}",
"cp",
"+=",
"skip",
"[",
"0",
"]",
";",
"dp",
"+=",
"skip",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"++",
"dp",
";",
"}",
"dp",
"=",
"da",
".",
"indexOf",
"(",
"'",
"'",
",",
"dp",
")",
";",
"}",
"while",
"(",
"dp",
">=",
"0",
")",
";",
"}",
"int",
"daL",
"=",
"da",
".",
"length",
"(",
")",
";",
"if",
"(",
"daL",
">",
"cp",
")",
"{",
"charBuf",
".",
"append",
"(",
"da",
".",
"substring",
"(",
"cp",
",",
"daL",
")",
")",
";",
"}",
"}"
] |
Analog of do_replace in jsstr.c
|
[
"Analog",
"of",
"do_replace",
"in",
"jsstr",
".",
"c"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/regexp/RegExpImpl.java#L488-L520
|
21,416
|
mozilla/rhino
|
src/org/mozilla/classfile/TypeInfo.java
|
TypeInfo.getPayloadAsType
|
static final String getPayloadAsType(int typeInfo, ConstantPool pool) {
if (getTag(typeInfo) == OBJECT_TAG) {
return (String) pool.getConstantData(getPayload(typeInfo));
}
throw new IllegalArgumentException("expecting object type");
}
|
java
|
static final String getPayloadAsType(int typeInfo, ConstantPool pool) {
if (getTag(typeInfo) == OBJECT_TAG) {
return (String) pool.getConstantData(getPayload(typeInfo));
}
throw new IllegalArgumentException("expecting object type");
}
|
[
"static",
"final",
"String",
"getPayloadAsType",
"(",
"int",
"typeInfo",
",",
"ConstantPool",
"pool",
")",
"{",
"if",
"(",
"getTag",
"(",
"typeInfo",
")",
"==",
"OBJECT_TAG",
")",
"{",
"return",
"(",
"String",
")",
"pool",
".",
"getConstantData",
"(",
"getPayload",
"(",
"typeInfo",
")",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"expecting object type\"",
")",
";",
"}"
] |
Treat the result of getPayload as a constant pool index and fetch the
corresponding String mapped to it.
Only works on OBJECT types.
|
[
"Treat",
"the",
"result",
"of",
"getPayload",
"as",
"a",
"constant",
"pool",
"index",
"and",
"fetch",
"the",
"corresponding",
"String",
"mapped",
"to",
"it",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/TypeInfo.java#L55-L60
|
21,417
|
mozilla/rhino
|
src/org/mozilla/classfile/TypeInfo.java
|
TypeInfo.fromType
|
static final int fromType(String type, ConstantPool pool) {
if (type.length() == 1) {
switch (type.charAt(0)) {
case 'B': // sbyte
case 'C': // unicode char
case 'S': // short
case 'Z': // boolean
case 'I': // all of the above are verified as integers
return INTEGER;
case 'D':
return DOUBLE;
case 'F':
return FLOAT;
case 'J':
return LONG;
default:
throw new IllegalArgumentException("bad type");
}
}
return TypeInfo.OBJECT(type, pool);
}
|
java
|
static final int fromType(String type, ConstantPool pool) {
if (type.length() == 1) {
switch (type.charAt(0)) {
case 'B': // sbyte
case 'C': // unicode char
case 'S': // short
case 'Z': // boolean
case 'I': // all of the above are verified as integers
return INTEGER;
case 'D':
return DOUBLE;
case 'F':
return FLOAT;
case 'J':
return LONG;
default:
throw new IllegalArgumentException("bad type");
}
}
return TypeInfo.OBJECT(type, pool);
}
|
[
"static",
"final",
"int",
"fromType",
"(",
"String",
"type",
",",
"ConstantPool",
"pool",
")",
"{",
"if",
"(",
"type",
".",
"length",
"(",
")",
"==",
"1",
")",
"{",
"switch",
"(",
"type",
".",
"charAt",
"(",
"0",
")",
")",
"{",
"case",
"'",
"'",
":",
"// sbyte",
"case",
"'",
"'",
":",
"// unicode char",
"case",
"'",
"'",
":",
"// short",
"case",
"'",
"'",
":",
"// boolean",
"case",
"'",
"'",
":",
"// all of the above are verified as integers",
"return",
"INTEGER",
";",
"case",
"'",
"'",
":",
"return",
"DOUBLE",
";",
"case",
"'",
"'",
":",
"return",
"FLOAT",
";",
"case",
"'",
"'",
":",
"return",
"LONG",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"bad type\"",
")",
";",
"}",
"}",
"return",
"TypeInfo",
".",
"OBJECT",
"(",
"type",
",",
"pool",
")",
";",
"}"
] |
Create type information from an internal type.
|
[
"Create",
"type",
"information",
"from",
"an",
"internal",
"type",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/TypeInfo.java#L65-L85
|
21,418
|
mozilla/rhino
|
src/org/mozilla/classfile/TypeInfo.java
|
TypeInfo.merge
|
static int merge(int current, int incoming, ConstantPool pool) {
int currentTag = getTag(current);
int incomingTag = getTag(incoming);
boolean currentIsObject = currentTag == TypeInfo.OBJECT_TAG;
boolean incomingIsObject = incomingTag == TypeInfo.OBJECT_TAG;
if (current == incoming || (currentIsObject && incoming == NULL)) {
return current;
} else if (currentTag == TypeInfo.TOP ||
incomingTag == TypeInfo.TOP) {
return TypeInfo.TOP;
} else if (current == NULL && incomingIsObject) {
return incoming;
} else if (currentIsObject && incomingIsObject) {
String currentName = getPayloadAsType(current, pool);
String incomingName = getPayloadAsType(incoming, pool);
// The class file always has the class and super names in the same
// spot. The constant order is: class_data, class_name, super_data,
// super_name.
String currentlyGeneratedName = (String) pool.getConstantData(2);
String currentlyGeneratedSuperName =
(String) pool.getConstantData(4);
// If any of the merged types are the class that's currently being
// generated, automatically start at the super class instead. At
// this point, we already know the classes are different, so we
// don't need to handle that case.
if (currentName.equals(currentlyGeneratedName)) {
currentName = currentlyGeneratedSuperName;
}
if (incomingName.equals(currentlyGeneratedName)) {
incomingName = currentlyGeneratedSuperName;
}
Class<?> currentClass = getClassFromInternalName(currentName);
Class<?> incomingClass = getClassFromInternalName(incomingName);
if (currentClass.isAssignableFrom(incomingClass)) {
return current;
} else if (incomingClass.isAssignableFrom(currentClass)) {
return incoming;
} else if (incomingClass.isInterface() ||
currentClass.isInterface()) {
// For verification purposes, Sun specifies that interfaces are
// subtypes of Object. Therefore, we know that the merge result
// involving interfaces where one is not assignable to the
// other results in Object.
return OBJECT("java/lang/Object", pool);
} else {
Class<?> commonClass = incomingClass.getSuperclass();
while (commonClass != null) {
if (commonClass.isAssignableFrom(currentClass)) {
String name = commonClass.getName();
name = ClassFileWriter.getSlashedForm(name);
return OBJECT(name, pool);
}
commonClass = commonClass.getSuperclass();
}
}
}
throw new IllegalArgumentException("bad merge attempt between " +
toString(current, pool) + " and " +
toString(incoming, pool));
}
|
java
|
static int merge(int current, int incoming, ConstantPool pool) {
int currentTag = getTag(current);
int incomingTag = getTag(incoming);
boolean currentIsObject = currentTag == TypeInfo.OBJECT_TAG;
boolean incomingIsObject = incomingTag == TypeInfo.OBJECT_TAG;
if (current == incoming || (currentIsObject && incoming == NULL)) {
return current;
} else if (currentTag == TypeInfo.TOP ||
incomingTag == TypeInfo.TOP) {
return TypeInfo.TOP;
} else if (current == NULL && incomingIsObject) {
return incoming;
} else if (currentIsObject && incomingIsObject) {
String currentName = getPayloadAsType(current, pool);
String incomingName = getPayloadAsType(incoming, pool);
// The class file always has the class and super names in the same
// spot. The constant order is: class_data, class_name, super_data,
// super_name.
String currentlyGeneratedName = (String) pool.getConstantData(2);
String currentlyGeneratedSuperName =
(String) pool.getConstantData(4);
// If any of the merged types are the class that's currently being
// generated, automatically start at the super class instead. At
// this point, we already know the classes are different, so we
// don't need to handle that case.
if (currentName.equals(currentlyGeneratedName)) {
currentName = currentlyGeneratedSuperName;
}
if (incomingName.equals(currentlyGeneratedName)) {
incomingName = currentlyGeneratedSuperName;
}
Class<?> currentClass = getClassFromInternalName(currentName);
Class<?> incomingClass = getClassFromInternalName(incomingName);
if (currentClass.isAssignableFrom(incomingClass)) {
return current;
} else if (incomingClass.isAssignableFrom(currentClass)) {
return incoming;
} else if (incomingClass.isInterface() ||
currentClass.isInterface()) {
// For verification purposes, Sun specifies that interfaces are
// subtypes of Object. Therefore, we know that the merge result
// involving interfaces where one is not assignable to the
// other results in Object.
return OBJECT("java/lang/Object", pool);
} else {
Class<?> commonClass = incomingClass.getSuperclass();
while (commonClass != null) {
if (commonClass.isAssignableFrom(currentClass)) {
String name = commonClass.getName();
name = ClassFileWriter.getSlashedForm(name);
return OBJECT(name, pool);
}
commonClass = commonClass.getSuperclass();
}
}
}
throw new IllegalArgumentException("bad merge attempt between " +
toString(current, pool) + " and " +
toString(incoming, pool));
}
|
[
"static",
"int",
"merge",
"(",
"int",
"current",
",",
"int",
"incoming",
",",
"ConstantPool",
"pool",
")",
"{",
"int",
"currentTag",
"=",
"getTag",
"(",
"current",
")",
";",
"int",
"incomingTag",
"=",
"getTag",
"(",
"incoming",
")",
";",
"boolean",
"currentIsObject",
"=",
"currentTag",
"==",
"TypeInfo",
".",
"OBJECT_TAG",
";",
"boolean",
"incomingIsObject",
"=",
"incomingTag",
"==",
"TypeInfo",
".",
"OBJECT_TAG",
";",
"if",
"(",
"current",
"==",
"incoming",
"||",
"(",
"currentIsObject",
"&&",
"incoming",
"==",
"NULL",
")",
")",
"{",
"return",
"current",
";",
"}",
"else",
"if",
"(",
"currentTag",
"==",
"TypeInfo",
".",
"TOP",
"||",
"incomingTag",
"==",
"TypeInfo",
".",
"TOP",
")",
"{",
"return",
"TypeInfo",
".",
"TOP",
";",
"}",
"else",
"if",
"(",
"current",
"==",
"NULL",
"&&",
"incomingIsObject",
")",
"{",
"return",
"incoming",
";",
"}",
"else",
"if",
"(",
"currentIsObject",
"&&",
"incomingIsObject",
")",
"{",
"String",
"currentName",
"=",
"getPayloadAsType",
"(",
"current",
",",
"pool",
")",
";",
"String",
"incomingName",
"=",
"getPayloadAsType",
"(",
"incoming",
",",
"pool",
")",
";",
"// The class file always has the class and super names in the same",
"// spot. The constant order is: class_data, class_name, super_data,",
"// super_name.",
"String",
"currentlyGeneratedName",
"=",
"(",
"String",
")",
"pool",
".",
"getConstantData",
"(",
"2",
")",
";",
"String",
"currentlyGeneratedSuperName",
"=",
"(",
"String",
")",
"pool",
".",
"getConstantData",
"(",
"4",
")",
";",
"// If any of the merged types are the class that's currently being",
"// generated, automatically start at the super class instead. At",
"// this point, we already know the classes are different, so we",
"// don't need to handle that case.",
"if",
"(",
"currentName",
".",
"equals",
"(",
"currentlyGeneratedName",
")",
")",
"{",
"currentName",
"=",
"currentlyGeneratedSuperName",
";",
"}",
"if",
"(",
"incomingName",
".",
"equals",
"(",
"currentlyGeneratedName",
")",
")",
"{",
"incomingName",
"=",
"currentlyGeneratedSuperName",
";",
"}",
"Class",
"<",
"?",
">",
"currentClass",
"=",
"getClassFromInternalName",
"(",
"currentName",
")",
";",
"Class",
"<",
"?",
">",
"incomingClass",
"=",
"getClassFromInternalName",
"(",
"incomingName",
")",
";",
"if",
"(",
"currentClass",
".",
"isAssignableFrom",
"(",
"incomingClass",
")",
")",
"{",
"return",
"current",
";",
"}",
"else",
"if",
"(",
"incomingClass",
".",
"isAssignableFrom",
"(",
"currentClass",
")",
")",
"{",
"return",
"incoming",
";",
"}",
"else",
"if",
"(",
"incomingClass",
".",
"isInterface",
"(",
")",
"||",
"currentClass",
".",
"isInterface",
"(",
")",
")",
"{",
"// For verification purposes, Sun specifies that interfaces are",
"// subtypes of Object. Therefore, we know that the merge result",
"// involving interfaces where one is not assignable to the",
"// other results in Object.",
"return",
"OBJECT",
"(",
"\"java/lang/Object\"",
",",
"pool",
")",
";",
"}",
"else",
"{",
"Class",
"<",
"?",
">",
"commonClass",
"=",
"incomingClass",
".",
"getSuperclass",
"(",
")",
";",
"while",
"(",
"commonClass",
"!=",
"null",
")",
"{",
"if",
"(",
"commonClass",
".",
"isAssignableFrom",
"(",
"currentClass",
")",
")",
"{",
"String",
"name",
"=",
"commonClass",
".",
"getName",
"(",
")",
";",
"name",
"=",
"ClassFileWriter",
".",
"getSlashedForm",
"(",
"name",
")",
";",
"return",
"OBJECT",
"(",
"name",
",",
"pool",
")",
";",
"}",
"commonClass",
"=",
"commonClass",
".",
"getSuperclass",
"(",
")",
";",
"}",
"}",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"bad merge attempt between \"",
"+",
"toString",
"(",
"current",
",",
"pool",
")",
"+",
"\" and \"",
"+",
"toString",
"(",
"incoming",
",",
"pool",
")",
")",
";",
"}"
] |
Merge two verification types.
In most cases, the verification types must be the same. For example,
INTEGER and DOUBLE cannot be merged and an exception will be thrown.
The basic rules are:
- If the types are equal, simply return one.
- If either type is TOP, return TOP.
- If either type is NULL, return the other type.
- If both types are objects, find the lowest common ancestor in the
class hierarchy.
This method uses reflection to traverse the class hierarchy. Therefore,
it is assumed that the current class being generated is never the target
of a full object-object merge, which would need to load the current
class reflectively.
|
[
"Merge",
"two",
"verification",
"types",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/TypeInfo.java#L109-L172
|
21,419
|
mozilla/rhino
|
src/org/mozilla/classfile/TypeInfo.java
|
TypeInfo.getClassFromInternalName
|
private static Class<?> getClassFromInternalName(String internalName) {
try {
return Class.forName(internalName.replace('/', '.'));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
|
java
|
private static Class<?> getClassFromInternalName(String internalName) {
try {
return Class.forName(internalName.replace('/', '.'));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
|
[
"private",
"static",
"Class",
"<",
"?",
">",
"getClassFromInternalName",
"(",
"String",
"internalName",
")",
"{",
"try",
"{",
"return",
"Class",
".",
"forName",
"(",
"internalName",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"e",
")",
";",
"}",
"}"
] |
Take an internal name and return a java.lang.Class instance that
represents it.
For example, given "java/lang/Object", returns the equivalent of
Class.forName("java.lang.Object"), but also handles exceptions.
|
[
"Take",
"an",
"internal",
"name",
"and",
"return",
"a",
"java",
".",
"lang",
".",
"Class",
"instance",
"that",
"represents",
"it",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/TypeInfo.java#L209-L215
|
21,420
|
mozilla/rhino
|
src/org/mozilla/javascript/RhinoException.java
|
RhinoException.initSourceName
|
public final void initSourceName(String sourceName)
{
if (sourceName == null) throw new IllegalArgumentException();
if (this.sourceName != null) throw new IllegalStateException();
this.sourceName = sourceName;
}
|
java
|
public final void initSourceName(String sourceName)
{
if (sourceName == null) throw new IllegalArgumentException();
if (this.sourceName != null) throw new IllegalStateException();
this.sourceName = sourceName;
}
|
[
"public",
"final",
"void",
"initSourceName",
"(",
"String",
"sourceName",
")",
"{",
"if",
"(",
"sourceName",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"if",
"(",
"this",
".",
"sourceName",
"!=",
"null",
")",
"throw",
"new",
"IllegalStateException",
"(",
")",
";",
"this",
".",
"sourceName",
"=",
"sourceName",
";",
"}"
] |
Initialize the uri of the script source containing the error.
@param sourceName the uri of the script source responsible for the error.
It should not be <tt>null</tt>.
@throws IllegalStateException if the method is called more then once.
|
[
"Initialize",
"the",
"uri",
"of",
"the",
"script",
"source",
"containing",
"the",
"error",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/RhinoException.java#L83-L88
|
21,421
|
mozilla/rhino
|
src/org/mozilla/javascript/RhinoException.java
|
RhinoException.initLineNumber
|
public final void initLineNumber(int lineNumber)
{
if (lineNumber <= 0) throw new IllegalArgumentException(String.valueOf(lineNumber));
if (this.lineNumber > 0) throw new IllegalStateException();
this.lineNumber = lineNumber;
}
|
java
|
public final void initLineNumber(int lineNumber)
{
if (lineNumber <= 0) throw new IllegalArgumentException(String.valueOf(lineNumber));
if (this.lineNumber > 0) throw new IllegalStateException();
this.lineNumber = lineNumber;
}
|
[
"public",
"final",
"void",
"initLineNumber",
"(",
"int",
"lineNumber",
")",
"{",
"if",
"(",
"lineNumber",
"<=",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"valueOf",
"(",
"lineNumber",
")",
")",
";",
"if",
"(",
"this",
".",
"lineNumber",
">",
"0",
")",
"throw",
"new",
"IllegalStateException",
"(",
")",
";",
"this",
".",
"lineNumber",
"=",
"lineNumber",
";",
"}"
] |
Initialize the line number of the script statement causing the error.
@param lineNumber the line number in the script source.
It should be positive number.
@throws IllegalStateException if the method is called more then once.
|
[
"Initialize",
"the",
"line",
"number",
"of",
"the",
"script",
"statement",
"causing",
"the",
"error",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/RhinoException.java#L107-L112
|
21,422
|
mozilla/rhino
|
src/org/mozilla/javascript/RhinoException.java
|
RhinoException.initColumnNumber
|
public final void initColumnNumber(int columnNumber)
{
if (columnNumber <= 0) throw new IllegalArgumentException(String.valueOf(columnNumber));
if (this.columnNumber > 0) throw new IllegalStateException();
this.columnNumber = columnNumber;
}
|
java
|
public final void initColumnNumber(int columnNumber)
{
if (columnNumber <= 0) throw new IllegalArgumentException(String.valueOf(columnNumber));
if (this.columnNumber > 0) throw new IllegalStateException();
this.columnNumber = columnNumber;
}
|
[
"public",
"final",
"void",
"initColumnNumber",
"(",
"int",
"columnNumber",
")",
"{",
"if",
"(",
"columnNumber",
"<=",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"valueOf",
"(",
"columnNumber",
")",
")",
";",
"if",
"(",
"this",
".",
"columnNumber",
">",
"0",
")",
"throw",
"new",
"IllegalStateException",
"(",
")",
";",
"this",
".",
"columnNumber",
"=",
"columnNumber",
";",
"}"
] |
Initialize the column number of the script statement causing the error.
@param columnNumber the column number in the script source.
It should be positive number.
@throws IllegalStateException if the method is called more then once.
|
[
"Initialize",
"the",
"column",
"number",
"of",
"the",
"script",
"statement",
"causing",
"the",
"error",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/RhinoException.java#L130-L135
|
21,423
|
mozilla/rhino
|
src/org/mozilla/javascript/RhinoException.java
|
RhinoException.initLineSource
|
public final void initLineSource(String lineSource)
{
if (lineSource == null) throw new IllegalArgumentException();
if (this.lineSource != null) throw new IllegalStateException();
this.lineSource = lineSource;
}
|
java
|
public final void initLineSource(String lineSource)
{
if (lineSource == null) throw new IllegalArgumentException();
if (this.lineSource != null) throw new IllegalStateException();
this.lineSource = lineSource;
}
|
[
"public",
"final",
"void",
"initLineSource",
"(",
"String",
"lineSource",
")",
"{",
"if",
"(",
"lineSource",
"==",
"null",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"if",
"(",
"this",
".",
"lineSource",
"!=",
"null",
")",
"throw",
"new",
"IllegalStateException",
"(",
")",
";",
"this",
".",
"lineSource",
"=",
"lineSource",
";",
"}"
] |
Initialize the text of the source line containing the error.
@param lineSource the text of the source line responsible for the error.
It should not be <tt>null</tt>.
@throws IllegalStateException if the method is called more then once.
|
[
"Initialize",
"the",
"text",
"of",
"the",
"source",
"line",
"containing",
"the",
"error",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/RhinoException.java#L153-L158
|
21,424
|
mozilla/rhino
|
src/org/mozilla/javascript/RhinoException.java
|
RhinoException.getScriptStackTrace
|
public String getScriptStackTrace(int limit, String functionName)
{
ScriptStackElement[] stack = getScriptStack(limit, functionName);
return formatStackTrace(stack, details());
}
|
java
|
public String getScriptStackTrace(int limit, String functionName)
{
ScriptStackElement[] stack = getScriptStack(limit, functionName);
return formatStackTrace(stack, details());
}
|
[
"public",
"String",
"getScriptStackTrace",
"(",
"int",
"limit",
",",
"String",
"functionName",
")",
"{",
"ScriptStackElement",
"[",
"]",
"stack",
"=",
"getScriptStack",
"(",
"limit",
",",
"functionName",
")",
";",
"return",
"formatStackTrace",
"(",
"stack",
",",
"details",
"(",
")",
")",
";",
"}"
] |
Get a string representing the script stack of this exception.
If optimization is enabled, this includes java stack elements
whose source and method names suggest they have been generated
by the Rhino script compiler.
The optional "limit" parameter limits the number of stack frames returned.
The "functionName" parameter will exclude any stack frames "below" the
specified function on the stack.
@param limit the number of stack frames returned
@param functionName the name of a function on the stack -- frames below it will be ignored
@return a script stack dump
@since 1.8.0
|
[
"Get",
"a",
"string",
"representing",
"the",
"script",
"stack",
"of",
"this",
"exception",
".",
"If",
"optimization",
"is",
"enabled",
"this",
"includes",
"java",
"stack",
"elements",
"whose",
"source",
"and",
"method",
"names",
"suggest",
"they",
"have",
"been",
"generated",
"by",
"the",
"Rhino",
"script",
"compiler",
".",
"The",
"optional",
"limit",
"parameter",
"limits",
"the",
"number",
"of",
"stack",
"frames",
"returned",
".",
"The",
"functionName",
"parameter",
"will",
"exclude",
"any",
"stack",
"frames",
"below",
"the",
"specified",
"function",
"on",
"the",
"stack",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/RhinoException.java#L221-L225
|
21,425
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/SwitchCase.java
|
SwitchCase.addStatement
|
public void addStatement(AstNode statement) {
assertNotNull(statement);
if (statements == null) {
statements = new ArrayList<AstNode>();
}
int end = statement.getPosition() + statement.getLength();
this.setLength(end - this.getPosition());
statements.add(statement);
statement.setParent(this);
}
|
java
|
public void addStatement(AstNode statement) {
assertNotNull(statement);
if (statements == null) {
statements = new ArrayList<AstNode>();
}
int end = statement.getPosition() + statement.getLength();
this.setLength(end - this.getPosition());
statements.add(statement);
statement.setParent(this);
}
|
[
"public",
"void",
"addStatement",
"(",
"AstNode",
"statement",
")",
"{",
"assertNotNull",
"(",
"statement",
")",
";",
"if",
"(",
"statements",
"==",
"null",
")",
"{",
"statements",
"=",
"new",
"ArrayList",
"<",
"AstNode",
">",
"(",
")",
";",
"}",
"int",
"end",
"=",
"statement",
".",
"getPosition",
"(",
")",
"+",
"statement",
".",
"getLength",
"(",
")",
";",
"this",
".",
"setLength",
"(",
"end",
"-",
"this",
".",
"getPosition",
"(",
")",
")",
";",
"statements",
".",
"add",
"(",
"statement",
")",
";",
"statement",
".",
"setParent",
"(",
"this",
")",
";",
"}"
] |
Adds a statement to the end of the statement list.
Sets the parent of the new statement to this node, updates
its start offset to be relative to this node, and sets the
length of this node to include the new child.
@param statement a child statement
@throws IllegalArgumentException} if statement is {@code null}
|
[
"Adds",
"a",
"statement",
"to",
"the",
"end",
"of",
"the",
"statement",
"list",
".",
"Sets",
"the",
"parent",
"of",
"the",
"new",
"statement",
"to",
"this",
"node",
"updates",
"its",
"start",
"offset",
"to",
"be",
"relative",
"to",
"this",
"node",
"and",
"sets",
"the",
"length",
"of",
"this",
"node",
"to",
"include",
"the",
"new",
"child",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/SwitchCase.java#L107-L116
|
21,426
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/XmlString.java
|
XmlString.setXml
|
public void setXml(String s) {
assertNotNull(s);
xml = s;
setLength(s.length());
}
|
java
|
public void setXml(String s) {
assertNotNull(s);
xml = s;
setLength(s.length());
}
|
[
"public",
"void",
"setXml",
"(",
"String",
"s",
")",
"{",
"assertNotNull",
"(",
"s",
")",
";",
"xml",
"=",
"s",
";",
"setLength",
"(",
"s",
".",
"length",
"(",
")",
")",
";",
"}"
] |
Sets the string for this XML component. Sets the length of the
component to the length of the passed string.
@param s a string of xml text
@throws IllegalArgumentException} if {@code s} is {@code null}
|
[
"Sets",
"the",
"string",
"for",
"this",
"XML",
"component",
".",
"Sets",
"the",
"length",
"of",
"the",
"component",
"to",
"the",
"length",
"of",
"the",
"passed",
"string",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/XmlString.java#L36-L40
|
21,427
|
mozilla/rhino
|
src/org/mozilla/javascript/typedarrays/NativeArrayBuffer.java
|
NativeArrayBuffer.slice
|
public NativeArrayBuffer slice(double s, double e)
{
// Handle negative start as relative to start
// Clamp as per the spec to between 0 and length
int end = ScriptRuntime.toInt32(Math.max(0, Math.min(buffer.length, (e < 0 ? buffer.length + e : e))));
int start = ScriptRuntime.toInt32(Math.min(end, Math.max(0, (s < 0 ? buffer.length + s : s))));
int len = end - start;
NativeArrayBuffer newBuf = new NativeArrayBuffer(len);
System.arraycopy(buffer, start, newBuf.buffer, 0, len);
return newBuf;
}
|
java
|
public NativeArrayBuffer slice(double s, double e)
{
// Handle negative start as relative to start
// Clamp as per the spec to between 0 and length
int end = ScriptRuntime.toInt32(Math.max(0, Math.min(buffer.length, (e < 0 ? buffer.length + e : e))));
int start = ScriptRuntime.toInt32(Math.min(end, Math.max(0, (s < 0 ? buffer.length + s : s))));
int len = end - start;
NativeArrayBuffer newBuf = new NativeArrayBuffer(len);
System.arraycopy(buffer, start, newBuf.buffer, 0, len);
return newBuf;
}
|
[
"public",
"NativeArrayBuffer",
"slice",
"(",
"double",
"s",
",",
"double",
"e",
")",
"{",
"// Handle negative start as relative to start",
"// Clamp as per the spec to between 0 and length",
"int",
"end",
"=",
"ScriptRuntime",
".",
"toInt32",
"(",
"Math",
".",
"max",
"(",
"0",
",",
"Math",
".",
"min",
"(",
"buffer",
".",
"length",
",",
"(",
"e",
"<",
"0",
"?",
"buffer",
".",
"length",
"+",
"e",
":",
"e",
")",
")",
")",
")",
";",
"int",
"start",
"=",
"ScriptRuntime",
".",
"toInt32",
"(",
"Math",
".",
"min",
"(",
"end",
",",
"Math",
".",
"max",
"(",
"0",
",",
"(",
"s",
"<",
"0",
"?",
"buffer",
".",
"length",
"+",
"s",
":",
"s",
")",
")",
")",
")",
";",
"int",
"len",
"=",
"end",
"-",
"start",
";",
"NativeArrayBuffer",
"newBuf",
"=",
"new",
"NativeArrayBuffer",
"(",
"len",
")",
";",
"System",
".",
"arraycopy",
"(",
"buffer",
",",
"start",
",",
"newBuf",
".",
"buffer",
",",
"0",
",",
"len",
")",
";",
"return",
"newBuf",
";",
"}"
] |
Return a new buffer that represents a slice of this buffer's content, starting at position
"start" and ending at position "end". Both values will be "clamped" as per the JavaScript
spec so that invalid values may be passed and will be adjusted up or down accordingly.
This method will return a new buffer that contains a copy of the original buffer. Changes
there will not affect the content of the buffer.
@param s the position where the new buffer will start
@param e the position where it will end
|
[
"Return",
"a",
"new",
"buffer",
"that",
"represents",
"a",
"slice",
"of",
"this",
"buffer",
"s",
"content",
"starting",
"at",
"position",
"start",
"and",
"ending",
"at",
"position",
"end",
".",
"Both",
"values",
"will",
"be",
"clamped",
"as",
"per",
"the",
"JavaScript",
"spec",
"so",
"that",
"invalid",
"values",
"may",
"be",
"passed",
"and",
"will",
"be",
"adjusted",
"up",
"or",
"down",
"accordingly",
".",
"This",
"method",
"will",
"return",
"a",
"new",
"buffer",
"that",
"contains",
"a",
"copy",
"of",
"the",
"original",
"buffer",
".",
"Changes",
"there",
"will",
"not",
"affect",
"the",
"content",
"of",
"the",
"buffer",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/typedarrays/NativeArrayBuffer.java#L104-L115
|
21,428
|
mozilla/rhino
|
src/org/mozilla/javascript/typedarrays/NativeArrayBuffer.java
|
NativeArrayBuffer.execIdCall
|
@Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(CLASS_NAME)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case ConstructorId_isView:
return (isArg(args, 0) && (args[0] instanceof NativeArrayBufferView));
case Id_constructor:
double length = isArg(args, 0) ? ScriptRuntime.toNumber(args[0]) : 0;
return new NativeArrayBuffer(length);
case Id_slice:
NativeArrayBuffer self = realThis(thisObj, f);
double start = isArg(args, 0) ? ScriptRuntime.toNumber(args[0]) : 0;
double end = isArg(args, 1) ? ScriptRuntime.toNumber(args[1]) : self.buffer.length;
return self.slice(start, end);
}
throw new IllegalArgumentException(String.valueOf(id));
}
|
java
|
@Override
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
Scriptable thisObj, Object[] args)
{
if (!f.hasTag(CLASS_NAME)) {
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
switch (id) {
case ConstructorId_isView:
return (isArg(args, 0) && (args[0] instanceof NativeArrayBufferView));
case Id_constructor:
double length = isArg(args, 0) ? ScriptRuntime.toNumber(args[0]) : 0;
return new NativeArrayBuffer(length);
case Id_slice:
NativeArrayBuffer self = realThis(thisObj, f);
double start = isArg(args, 0) ? ScriptRuntime.toNumber(args[0]) : 0;
double end = isArg(args, 1) ? ScriptRuntime.toNumber(args[1]) : self.buffer.length;
return self.slice(start, end);
}
throw new IllegalArgumentException(String.valueOf(id));
}
|
[
"@",
"Override",
"public",
"Object",
"execIdCall",
"(",
"IdFunctionObject",
"f",
",",
"Context",
"cx",
",",
"Scriptable",
"scope",
",",
"Scriptable",
"thisObj",
",",
"Object",
"[",
"]",
"args",
")",
"{",
"if",
"(",
"!",
"f",
".",
"hasTag",
"(",
"CLASS_NAME",
")",
")",
"{",
"return",
"super",
".",
"execIdCall",
"(",
"f",
",",
"cx",
",",
"scope",
",",
"thisObj",
",",
"args",
")",
";",
"}",
"int",
"id",
"=",
"f",
".",
"methodId",
"(",
")",
";",
"switch",
"(",
"id",
")",
"{",
"case",
"ConstructorId_isView",
":",
"return",
"(",
"isArg",
"(",
"args",
",",
"0",
")",
"&&",
"(",
"args",
"[",
"0",
"]",
"instanceof",
"NativeArrayBufferView",
")",
")",
";",
"case",
"Id_constructor",
":",
"double",
"length",
"=",
"isArg",
"(",
"args",
",",
"0",
")",
"?",
"ScriptRuntime",
".",
"toNumber",
"(",
"args",
"[",
"0",
"]",
")",
":",
"0",
";",
"return",
"new",
"NativeArrayBuffer",
"(",
"length",
")",
";",
"case",
"Id_slice",
":",
"NativeArrayBuffer",
"self",
"=",
"realThis",
"(",
"thisObj",
",",
"f",
")",
";",
"double",
"start",
"=",
"isArg",
"(",
"args",
",",
"0",
")",
"?",
"ScriptRuntime",
".",
"toNumber",
"(",
"args",
"[",
"0",
"]",
")",
":",
"0",
";",
"double",
"end",
"=",
"isArg",
"(",
"args",
",",
"1",
")",
"?",
"ScriptRuntime",
".",
"toNumber",
"(",
"args",
"[",
"1",
"]",
")",
":",
"self",
".",
"buffer",
".",
"length",
";",
"return",
"self",
".",
"slice",
"(",
"start",
",",
"end",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"valueOf",
"(",
"id",
")",
")",
";",
"}"
] |
Function-calling dispatcher
|
[
"Function",
"-",
"calling",
"dispatcher"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/typedarrays/NativeArrayBuffer.java#L119-L142
|
21,429
|
mozilla/rhino
|
examples/Shell.java
|
Shell.version
|
public static double version(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
double result = cx.getLanguageVersion();
if (args.length > 0) {
double d = Context.toNumber(args[0]);
cx.setLanguageVersion((int) d);
}
return result;
}
|
java
|
public static double version(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
double result = cx.getLanguageVersion();
if (args.length > 0) {
double d = Context.toNumber(args[0]);
cx.setLanguageVersion((int) d);
}
return result;
}
|
[
"public",
"static",
"double",
"version",
"(",
"Context",
"cx",
",",
"Scriptable",
"thisObj",
",",
"Object",
"[",
"]",
"args",
",",
"Function",
"funObj",
")",
"{",
"double",
"result",
"=",
"cx",
".",
"getLanguageVersion",
"(",
")",
";",
"if",
"(",
"args",
".",
"length",
">",
"0",
")",
"{",
"double",
"d",
"=",
"Context",
".",
"toNumber",
"(",
"args",
"[",
"0",
"]",
")",
";",
"cx",
".",
"setLanguageVersion",
"(",
"(",
"int",
")",
"d",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Get and set the language version.
This method is defined as a JavaScript function.
|
[
"Get",
"and",
"set",
"the",
"language",
"version",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/Shell.java#L185-L194
|
21,430
|
mozilla/rhino
|
src/org/mozilla/javascript/Arguments.java
|
Arguments.putIntoActivation
|
private void putIntoActivation(int index, Object value) {
String argName = activation.function.getParamOrVarName(index);
activation.put(argName, activation, value);
}
|
java
|
private void putIntoActivation(int index, Object value) {
String argName = activation.function.getParamOrVarName(index);
activation.put(argName, activation, value);
}
|
[
"private",
"void",
"putIntoActivation",
"(",
"int",
"index",
",",
"Object",
"value",
")",
"{",
"String",
"argName",
"=",
"activation",
".",
"function",
".",
"getParamOrVarName",
"(",
"index",
")",
";",
"activation",
".",
"put",
"(",
"argName",
",",
"activation",
",",
"value",
")",
";",
"}"
] |
the following helper methods assume that 0 < index < args.length
|
[
"the",
"following",
"helper",
"methods",
"assume",
"that",
"0",
"<",
"index",
"<",
"args",
".",
"length"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Arguments.java#L64-L67
|
21,431
|
mozilla/rhino
|
examples/File.java
|
File.jsConstructor
|
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
Function ctorObj,
boolean inNewExpr)
{
File result = new File();
if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
result.name = "";
result.file = null;
} else {
result.name = Context.toString(args[0]);
result.file = new java.io.File(result.name);
}
return result;
}
|
java
|
@JSConstructor
public static Scriptable jsConstructor(Context cx, Object[] args,
Function ctorObj,
boolean inNewExpr)
{
File result = new File();
if (args.length == 0 || args[0] == Context.getUndefinedValue()) {
result.name = "";
result.file = null;
} else {
result.name = Context.toString(args[0]);
result.file = new java.io.File(result.name);
}
return result;
}
|
[
"@",
"JSConstructor",
"public",
"static",
"Scriptable",
"jsConstructor",
"(",
"Context",
"cx",
",",
"Object",
"[",
"]",
"args",
",",
"Function",
"ctorObj",
",",
"boolean",
"inNewExpr",
")",
"{",
"File",
"result",
"=",
"new",
"File",
"(",
")",
";",
"if",
"(",
"args",
".",
"length",
"==",
"0",
"||",
"args",
"[",
"0",
"]",
"==",
"Context",
".",
"getUndefinedValue",
"(",
")",
")",
"{",
"result",
".",
"name",
"=",
"\"\"",
";",
"result",
".",
"file",
"=",
"null",
";",
"}",
"else",
"{",
"result",
".",
"name",
"=",
"Context",
".",
"toString",
"(",
"args",
"[",
"0",
"]",
")",
";",
"result",
".",
"file",
"=",
"new",
"java",
".",
"io",
".",
"File",
"(",
"result",
".",
"name",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
The Java method defining the JavaScript File constructor.
If the constructor has one or more arguments, and the
first argument is not undefined, the argument is converted
to a string as used as the filename.<p>
Otherwise System.in or System.out is assumed as appropriate
to the use.
|
[
"The",
"Java",
"method",
"defining",
"the",
"JavaScript",
"File",
"constructor",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L80-L94
|
21,432
|
mozilla/rhino
|
examples/File.java
|
File.readLines
|
@JSFunction
public Object readLines()
throws IOException
{
List<String> list = new ArrayList<String>();
String s;
while ((s = readLine()) != null) {
list.add(s);
}
String[] lines = list.toArray(new String[list.size()]);
Scriptable scope = ScriptableObject.getTopLevelScope(this);
Context cx = Context.getCurrentContext();
return cx.newObject(scope, "Array", lines);
}
|
java
|
@JSFunction
public Object readLines()
throws IOException
{
List<String> list = new ArrayList<String>();
String s;
while ((s = readLine()) != null) {
list.add(s);
}
String[] lines = list.toArray(new String[list.size()]);
Scriptable scope = ScriptableObject.getTopLevelScope(this);
Context cx = Context.getCurrentContext();
return cx.newObject(scope, "Array", lines);
}
|
[
"@",
"JSFunction",
"public",
"Object",
"readLines",
"(",
")",
"throws",
"IOException",
"{",
"List",
"<",
"String",
">",
"list",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"String",
"s",
";",
"while",
"(",
"(",
"s",
"=",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"list",
".",
"add",
"(",
"s",
")",
";",
"}",
"String",
"[",
"]",
"lines",
"=",
"list",
".",
"toArray",
"(",
"new",
"String",
"[",
"list",
".",
"size",
"(",
")",
"]",
")",
";",
"Scriptable",
"scope",
"=",
"ScriptableObject",
".",
"getTopLevelScope",
"(",
"this",
")",
";",
"Context",
"cx",
"=",
"Context",
".",
"getCurrentContext",
"(",
")",
";",
"return",
"cx",
".",
"newObject",
"(",
"scope",
",",
"\"Array\"",
",",
"lines",
")",
";",
"}"
] |
Read the remaining lines in the file and return them in an array.
Implements a JavaScript function.<p>
This is a good example of creating a new array and setting
elements in that array.
@exception IOException if an error occurred while accessing the file
associated with this object
|
[
"Read",
"the",
"remaining",
"lines",
"in",
"the",
"file",
"and",
"return",
"them",
"in",
"an",
"array",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L125-L138
|
21,433
|
mozilla/rhino
|
examples/File.java
|
File.write
|
@JSFunction
public static void write(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
throws IOException
{
write0(thisObj, args, false);
}
|
java
|
@JSFunction
public static void write(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
throws IOException
{
write0(thisObj, args, false);
}
|
[
"@",
"JSFunction",
"public",
"static",
"void",
"write",
"(",
"Context",
"cx",
",",
"Scriptable",
"thisObj",
",",
"Object",
"[",
"]",
"args",
",",
"Function",
"funObj",
")",
"throws",
"IOException",
"{",
"write0",
"(",
"thisObj",
",",
"args",
",",
"false",
")",
";",
"}"
] |
Write strings.
Implements a JavaScript function. <p>
This function takes a variable number of arguments, converts
each argument to a string, and writes that string to the file.
@exception IOException if an error occurred while accessing the file
associated with this object
|
[
"Write",
"strings",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L179-L185
|
21,434
|
mozilla/rhino
|
examples/File.java
|
File.writeLine
|
@JSFunction
public static void writeLine(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
throws IOException
{
write0(thisObj, args, true);
}
|
java
|
@JSFunction
public static void writeLine(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
throws IOException
{
write0(thisObj, args, true);
}
|
[
"@",
"JSFunction",
"public",
"static",
"void",
"writeLine",
"(",
"Context",
"cx",
",",
"Scriptable",
"thisObj",
",",
"Object",
"[",
"]",
"args",
",",
"Function",
"funObj",
")",
"throws",
"IOException",
"{",
"write0",
"(",
"thisObj",
",",
"args",
",",
"true",
")",
";",
"}"
] |
Write strings and a newline.
Implements a JavaScript function.
@exception IOException if an error occurred while accessing the file
associated with this object
|
[
"Write",
"strings",
"and",
"a",
"newline",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L195-L201
|
21,435
|
mozilla/rhino
|
examples/File.java
|
File.close
|
@JSFunction
public void close() throws IOException {
if (reader != null) {
reader.close();
reader = null;
} else if (writer != null) {
writer.close();
writer = null;
}
}
|
java
|
@JSFunction
public void close() throws IOException {
if (reader != null) {
reader.close();
reader = null;
} else if (writer != null) {
writer.close();
writer = null;
}
}
|
[
"@",
"JSFunction",
"public",
"void",
"close",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"reader",
"!=",
"null",
")",
"{",
"reader",
".",
"close",
"(",
")",
";",
"reader",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"writer",
"!=",
"null",
")",
"{",
"writer",
".",
"close",
"(",
")",
";",
"writer",
"=",
"null",
";",
"}",
"}"
] |
Close the file. It may be reopened.
Implements a JavaScript function.
@exception IOException if an error occurred while accessing the file
associated with this object
|
[
"Close",
"the",
"file",
".",
"It",
"may",
"be",
"reopened",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L217-L226
|
21,436
|
mozilla/rhino
|
examples/File.java
|
File.getJSReader
|
@JSFunction("getReader")
public Object getJSReader() {
if (reader == null)
return null;
// Here we use toObject() to "wrap" the BufferedReader object
// in a Scriptable object so that it can be manipulated by
// JavaScript.
Scriptable parent = ScriptableObject.getTopLevelScope(this);
return Context.javaToJS(reader, parent);
}
|
java
|
@JSFunction("getReader")
public Object getJSReader() {
if (reader == null)
return null;
// Here we use toObject() to "wrap" the BufferedReader object
// in a Scriptable object so that it can be manipulated by
// JavaScript.
Scriptable parent = ScriptableObject.getTopLevelScope(this);
return Context.javaToJS(reader, parent);
}
|
[
"@",
"JSFunction",
"(",
"\"getReader\"",
")",
"public",
"Object",
"getJSReader",
"(",
")",
"{",
"if",
"(",
"reader",
"==",
"null",
")",
"return",
"null",
";",
"// Here we use toObject() to \"wrap\" the BufferedReader object",
"// in a Scriptable object so that it can be manipulated by",
"// JavaScript.",
"Scriptable",
"parent",
"=",
"ScriptableObject",
".",
"getTopLevelScope",
"(",
"this",
")",
";",
"return",
"Context",
".",
"javaToJS",
"(",
"reader",
",",
"parent",
")",
";",
"}"
] |
Get the Java reader.
|
[
"Get",
"the",
"Java",
"reader",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L245-L254
|
21,437
|
mozilla/rhino
|
examples/File.java
|
File.getWriter
|
@JSFunction
public Object getWriter() {
if (writer == null)
return null;
Scriptable parent = ScriptableObject.getTopLevelScope(this);
return Context.javaToJS(writer, parent);
}
|
java
|
@JSFunction
public Object getWriter() {
if (writer == null)
return null;
Scriptable parent = ScriptableObject.getTopLevelScope(this);
return Context.javaToJS(writer, parent);
}
|
[
"@",
"JSFunction",
"public",
"Object",
"getWriter",
"(",
")",
"{",
"if",
"(",
"writer",
"==",
"null",
")",
"return",
"null",
";",
"Scriptable",
"parent",
"=",
"ScriptableObject",
".",
"getTopLevelScope",
"(",
"this",
")",
";",
"return",
"Context",
".",
"javaToJS",
"(",
"writer",
",",
"parent",
")",
";",
"}"
] |
Get the Java writer.
@see File#getReader
|
[
"Get",
"the",
"Java",
"writer",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L262-L268
|
21,438
|
mozilla/rhino
|
examples/File.java
|
File.getReader
|
private LineNumberReader getReader() throws FileNotFoundException {
if (writer != null) {
throw Context.reportRuntimeError("already writing file \""
+ name
+ "\"");
}
if (reader == null)
reader = new LineNumberReader(file == null
? new InputStreamReader(System.in)
: new FileReader(file));
return reader;
}
|
java
|
private LineNumberReader getReader() throws FileNotFoundException {
if (writer != null) {
throw Context.reportRuntimeError("already writing file \""
+ name
+ "\"");
}
if (reader == null)
reader = new LineNumberReader(file == null
? new InputStreamReader(System.in)
: new FileReader(file));
return reader;
}
|
[
"private",
"LineNumberReader",
"getReader",
"(",
")",
"throws",
"FileNotFoundException",
"{",
"if",
"(",
"writer",
"!=",
"null",
")",
"{",
"throw",
"Context",
".",
"reportRuntimeError",
"(",
"\"already writing file \\\"\"",
"+",
"name",
"+",
"\"\\\"\"",
")",
";",
"}",
"if",
"(",
"reader",
"==",
"null",
")",
"reader",
"=",
"new",
"LineNumberReader",
"(",
"file",
"==",
"null",
"?",
"new",
"InputStreamReader",
"(",
"System",
".",
"in",
")",
":",
"new",
"FileReader",
"(",
"file",
")",
")",
";",
"return",
"reader",
";",
"}"
] |
Get the reader, checking that we're not already writing this file.
|
[
"Get",
"the",
"reader",
"checking",
"that",
"we",
"re",
"not",
"already",
"writing",
"this",
"file",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L273-L284
|
21,439
|
mozilla/rhino
|
examples/File.java
|
File.write0
|
private static void write0(Scriptable thisObj, Object[] args, boolean eol)
throws IOException
{
File thisFile = checkInstance(thisObj);
if (thisFile.reader != null) {
throw Context.reportRuntimeError("already writing file \""
+ thisFile.name
+ "\"");
}
if (thisFile.writer == null)
thisFile.writer = new BufferedWriter(
thisFile.file == null ? new OutputStreamWriter(System.out)
: new FileWriter(thisFile.file));
for (int i=0; i < args.length; i++) {
String s = Context.toString(args[i]);
thisFile.writer.write(s, 0, s.length());
}
if (eol)
thisFile.writer.newLine();
}
|
java
|
private static void write0(Scriptable thisObj, Object[] args, boolean eol)
throws IOException
{
File thisFile = checkInstance(thisObj);
if (thisFile.reader != null) {
throw Context.reportRuntimeError("already writing file \""
+ thisFile.name
+ "\"");
}
if (thisFile.writer == null)
thisFile.writer = new BufferedWriter(
thisFile.file == null ? new OutputStreamWriter(System.out)
: new FileWriter(thisFile.file));
for (int i=0; i < args.length; i++) {
String s = Context.toString(args[i]);
thisFile.writer.write(s, 0, s.length());
}
if (eol)
thisFile.writer.newLine();
}
|
[
"private",
"static",
"void",
"write0",
"(",
"Scriptable",
"thisObj",
",",
"Object",
"[",
"]",
"args",
",",
"boolean",
"eol",
")",
"throws",
"IOException",
"{",
"File",
"thisFile",
"=",
"checkInstance",
"(",
"thisObj",
")",
";",
"if",
"(",
"thisFile",
".",
"reader",
"!=",
"null",
")",
"{",
"throw",
"Context",
".",
"reportRuntimeError",
"(",
"\"already writing file \\\"\"",
"+",
"thisFile",
".",
"name",
"+",
"\"\\\"\"",
")",
";",
"}",
"if",
"(",
"thisFile",
".",
"writer",
"==",
"null",
")",
"thisFile",
".",
"writer",
"=",
"new",
"BufferedWriter",
"(",
"thisFile",
".",
"file",
"==",
"null",
"?",
"new",
"OutputStreamWriter",
"(",
"System",
".",
"out",
")",
":",
"new",
"FileWriter",
"(",
"thisFile",
".",
"file",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"String",
"s",
"=",
"Context",
".",
"toString",
"(",
"args",
"[",
"i",
"]",
")",
";",
"thisFile",
".",
"writer",
".",
"write",
"(",
"s",
",",
"0",
",",
"s",
".",
"length",
"(",
")",
")",
";",
"}",
"if",
"(",
"eol",
")",
"thisFile",
".",
"writer",
".",
"newLine",
"(",
")",
";",
"}"
] |
Perform the guts of write and writeLine.
Since the two functions differ only in whether they write a
newline character, move the code into a common subroutine.
|
[
"Perform",
"the",
"guts",
"of",
"write",
"and",
"writeLine",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L293-L312
|
21,440
|
mozilla/rhino
|
examples/File.java
|
File.checkInstance
|
private static File checkInstance(Scriptable obj) {
if (obj == null || !(obj instanceof File)) {
throw Context.reportRuntimeError("called on incompatible object");
}
return (File) obj;
}
|
java
|
private static File checkInstance(Scriptable obj) {
if (obj == null || !(obj instanceof File)) {
throw Context.reportRuntimeError("called on incompatible object");
}
return (File) obj;
}
|
[
"private",
"static",
"File",
"checkInstance",
"(",
"Scriptable",
"obj",
")",
"{",
"if",
"(",
"obj",
"==",
"null",
"||",
"!",
"(",
"obj",
"instanceof",
"File",
")",
")",
"{",
"throw",
"Context",
".",
"reportRuntimeError",
"(",
"\"called on incompatible object\"",
")",
";",
"}",
"return",
"(",
"File",
")",
"obj",
";",
"}"
] |
Perform the instanceof check and return the downcasted File object.
This is necessary since methods may reside in the File.prototype
object and scripts can dynamically alter prototype chains. For example:
<pre>
js> defineClass("File");
js> o = {};
[object Object]
js> o.__proto__ = File.prototype;
[object File]
js> o.write("hi");
js: called on incompatible object
</pre>
The runtime will take care of such checks when non-static Java methods
are defined as JavaScript functions.
|
[
"Perform",
"the",
"instanceof",
"check",
"and",
"return",
"the",
"downcasted",
"File",
"object",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/examples/File.java#L331-L336
|
21,441
|
mozilla/rhino
|
src/org/mozilla/javascript/serialize/ScriptableOutputStream.java
|
ScriptableOutputStream.addOptionalExcludedName
|
public void addOptionalExcludedName(String name) {
Object obj = lookupQualifiedName(scope, name);
if(obj != null && obj != UniqueTag.NOT_FOUND) {
if (!(obj instanceof Scriptable)) {
throw new IllegalArgumentException(
"Object for excluded name " + name +
" is not a Scriptable, it is " +
obj.getClass().getName());
}
table.put(obj, name);
}
}
|
java
|
public void addOptionalExcludedName(String name) {
Object obj = lookupQualifiedName(scope, name);
if(obj != null && obj != UniqueTag.NOT_FOUND) {
if (!(obj instanceof Scriptable)) {
throw new IllegalArgumentException(
"Object for excluded name " + name +
" is not a Scriptable, it is " +
obj.getClass().getName());
}
table.put(obj, name);
}
}
|
[
"public",
"void",
"addOptionalExcludedName",
"(",
"String",
"name",
")",
"{",
"Object",
"obj",
"=",
"lookupQualifiedName",
"(",
"scope",
",",
"name",
")",
";",
"if",
"(",
"obj",
"!=",
"null",
"&&",
"obj",
"!=",
"UniqueTag",
".",
"NOT_FOUND",
")",
"{",
"if",
"(",
"!",
"(",
"obj",
"instanceof",
"Scriptable",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Object for excluded name \"",
"+",
"name",
"+",
"\" is not a Scriptable, it is \"",
"+",
"obj",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
")",
";",
"}",
"table",
".",
"put",
"(",
"obj",
",",
"name",
")",
";",
"}",
"}"
] |
Adds a qualified name to the list of object to be excluded from
serialization. Names excluded from serialization are looked up
in the new scope and replaced upon deserialization.
@param name a fully qualified name (of the form "a.b.c", where
"a" must be a property of the top-level object). The object
need not exist, in which case the name is ignored.
@throws IllegalArgumentException if the object is not a
{@link Scriptable}.
|
[
"Adds",
"a",
"qualified",
"name",
"to",
"the",
"list",
"of",
"object",
"to",
"be",
"excluded",
"from",
"serialization",
".",
"Names",
"excluded",
"from",
"serialization",
"are",
"looked",
"up",
"in",
"the",
"new",
"scope",
"and",
"replaced",
"upon",
"deserialization",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java#L80-L91
|
21,442
|
mozilla/rhino
|
src/org/mozilla/javascript/serialize/ScriptableOutputStream.java
|
ScriptableOutputStream.addExcludedName
|
public void addExcludedName(String name) {
Object obj = lookupQualifiedName(scope, name);
if (!(obj instanceof Scriptable)) {
throw new IllegalArgumentException("Object for excluded name " +
name + " not found.");
}
table.put(obj, name);
}
|
java
|
public void addExcludedName(String name) {
Object obj = lookupQualifiedName(scope, name);
if (!(obj instanceof Scriptable)) {
throw new IllegalArgumentException("Object for excluded name " +
name + " not found.");
}
table.put(obj, name);
}
|
[
"public",
"void",
"addExcludedName",
"(",
"String",
"name",
")",
"{",
"Object",
"obj",
"=",
"lookupQualifiedName",
"(",
"scope",
",",
"name",
")",
";",
"if",
"(",
"!",
"(",
"obj",
"instanceof",
"Scriptable",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Object for excluded name \"",
"+",
"name",
"+",
"\" not found.\"",
")",
";",
"}",
"table",
".",
"put",
"(",
"obj",
",",
"name",
")",
";",
"}"
] |
Adds a qualified name to the list of objects to be excluded from
serialization. Names excluded from serialization are looked up
in the new scope and replaced upon deserialization.
@param name a fully qualified name (of the form "a.b.c", where
"a" must be a property of the top-level object)
@throws IllegalArgumentException if the object is not found or is not
a {@link Scriptable}.
|
[
"Adds",
"a",
"qualified",
"name",
"to",
"the",
"list",
"of",
"objects",
"to",
"be",
"excluded",
"from",
"serialization",
".",
"Names",
"excluded",
"from",
"serialization",
"are",
"looked",
"up",
"in",
"the",
"new",
"scope",
"and",
"replaced",
"upon",
"deserialization",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java#L102-L109
|
21,443
|
mozilla/rhino
|
src/org/mozilla/javascript/serialize/ScriptableOutputStream.java
|
ScriptableOutputStream.excludeStandardObjectNames
|
public void excludeStandardObjectNames() {
String[] names = { "Object", "Object.prototype",
"Function", "Function.prototype",
"String", "String.prototype",
"Math", // no Math.prototype
"Array", "Array.prototype",
"Error", "Error.prototype",
"Number", "Number.prototype",
"Date", "Date.prototype",
"RegExp", "RegExp.prototype",
"Script", "Script.prototype",
"Continuation", "Continuation.prototype",
};
for (int i=0; i < names.length; i++) {
addExcludedName(names[i]);
}
String[] optionalNames = {
"XML", "XML.prototype",
"XMLList", "XMLList.prototype",
};
for (int i=0; i < optionalNames.length; i++) {
addOptionalExcludedName(optionalNames[i]);
}
}
|
java
|
public void excludeStandardObjectNames() {
String[] names = { "Object", "Object.prototype",
"Function", "Function.prototype",
"String", "String.prototype",
"Math", // no Math.prototype
"Array", "Array.prototype",
"Error", "Error.prototype",
"Number", "Number.prototype",
"Date", "Date.prototype",
"RegExp", "RegExp.prototype",
"Script", "Script.prototype",
"Continuation", "Continuation.prototype",
};
for (int i=0; i < names.length; i++) {
addExcludedName(names[i]);
}
String[] optionalNames = {
"XML", "XML.prototype",
"XMLList", "XMLList.prototype",
};
for (int i=0; i < optionalNames.length; i++) {
addOptionalExcludedName(optionalNames[i]);
}
}
|
[
"public",
"void",
"excludeStandardObjectNames",
"(",
")",
"{",
"String",
"[",
"]",
"names",
"=",
"{",
"\"Object\"",
",",
"\"Object.prototype\"",
",",
"\"Function\"",
",",
"\"Function.prototype\"",
",",
"\"String\"",
",",
"\"String.prototype\"",
",",
"\"Math\"",
",",
"// no Math.prototype",
"\"Array\"",
",",
"\"Array.prototype\"",
",",
"\"Error\"",
",",
"\"Error.prototype\"",
",",
"\"Number\"",
",",
"\"Number.prototype\"",
",",
"\"Date\"",
",",
"\"Date.prototype\"",
",",
"\"RegExp\"",
",",
"\"RegExp.prototype\"",
",",
"\"Script\"",
",",
"\"Script.prototype\"",
",",
"\"Continuation\"",
",",
"\"Continuation.prototype\"",
",",
"}",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"names",
".",
"length",
";",
"i",
"++",
")",
"{",
"addExcludedName",
"(",
"names",
"[",
"i",
"]",
")",
";",
"}",
"String",
"[",
"]",
"optionalNames",
"=",
"{",
"\"XML\"",
",",
"\"XML.prototype\"",
",",
"\"XMLList\"",
",",
"\"XMLList.prototype\"",
",",
"}",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"optionalNames",
".",
"length",
";",
"i",
"++",
")",
"{",
"addOptionalExcludedName",
"(",
"optionalNames",
"[",
"i",
"]",
")",
";",
"}",
"}"
] |
Adds the names of the standard objects and their
prototypes to the list of excluded names.
|
[
"Adds",
"the",
"names",
"of",
"the",
"standard",
"objects",
"and",
"their",
"prototypes",
"to",
"the",
"list",
"of",
"excluded",
"names",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java#L129-L153
|
21,444
|
mozilla/rhino
|
src/org/mozilla/javascript/NativeMap.java
|
NativeMap.loadFromIterable
|
static void loadFromIterable(Context cx, Scriptable scope, ScriptableObject map, Object arg1)
{
if ((arg1 == null) || Undefined.instance.equals(arg1)) {
return;
}
// Call the "[Symbol.iterator]" property as a function.
final Object ito = ScriptRuntime.callIterator(arg1, cx, scope);
if (Undefined.instance.equals(ito)) {
// Per spec, ignore if the iterator is undefined
return;
}
// Find the "add" function of our own prototype, since it might have
// been replaced. Since we're not fully constructed yet, create a dummy instance
// so that we can get our own prototype.
ScriptableObject dummy = ensureScriptableObject(cx.newObject(scope, map.getClassName()));
final Callable set =
ScriptRuntime.getPropFunctionAndThis(dummy.getPrototype(), "set", cx, scope);
ScriptRuntime.lastStoredScriptable(cx);
// Finally, run through all the iterated values and add them!
try (IteratorLikeIterable it = new IteratorLikeIterable(cx, scope, ito)) {
for (Object val : it) {
Scriptable sVal = ScriptableObject.ensureScriptable(val);
if (sVal instanceof Symbol) {
throw ScriptRuntime.typeError1("msg.arg.not.object", ScriptRuntime.typeof(sVal));
}
Object finalKey = sVal.get(0, sVal);
if (finalKey == NOT_FOUND) {
finalKey = Undefined.instance;
}
Object finalVal = sVal.get(1, sVal);
if (finalVal == NOT_FOUND) {
finalVal = Undefined.instance;
}
set.call(cx, scope, map, new Object[] { finalKey, finalVal });
}
}
}
|
java
|
static void loadFromIterable(Context cx, Scriptable scope, ScriptableObject map, Object arg1)
{
if ((arg1 == null) || Undefined.instance.equals(arg1)) {
return;
}
// Call the "[Symbol.iterator]" property as a function.
final Object ito = ScriptRuntime.callIterator(arg1, cx, scope);
if (Undefined.instance.equals(ito)) {
// Per spec, ignore if the iterator is undefined
return;
}
// Find the "add" function of our own prototype, since it might have
// been replaced. Since we're not fully constructed yet, create a dummy instance
// so that we can get our own prototype.
ScriptableObject dummy = ensureScriptableObject(cx.newObject(scope, map.getClassName()));
final Callable set =
ScriptRuntime.getPropFunctionAndThis(dummy.getPrototype(), "set", cx, scope);
ScriptRuntime.lastStoredScriptable(cx);
// Finally, run through all the iterated values and add them!
try (IteratorLikeIterable it = new IteratorLikeIterable(cx, scope, ito)) {
for (Object val : it) {
Scriptable sVal = ScriptableObject.ensureScriptable(val);
if (sVal instanceof Symbol) {
throw ScriptRuntime.typeError1("msg.arg.not.object", ScriptRuntime.typeof(sVal));
}
Object finalKey = sVal.get(0, sVal);
if (finalKey == NOT_FOUND) {
finalKey = Undefined.instance;
}
Object finalVal = sVal.get(1, sVal);
if (finalVal == NOT_FOUND) {
finalVal = Undefined.instance;
}
set.call(cx, scope, map, new Object[] { finalKey, finalVal });
}
}
}
|
[
"static",
"void",
"loadFromIterable",
"(",
"Context",
"cx",
",",
"Scriptable",
"scope",
",",
"ScriptableObject",
"map",
",",
"Object",
"arg1",
")",
"{",
"if",
"(",
"(",
"arg1",
"==",
"null",
")",
"||",
"Undefined",
".",
"instance",
".",
"equals",
"(",
"arg1",
")",
")",
"{",
"return",
";",
"}",
"// Call the \"[Symbol.iterator]\" property as a function.",
"final",
"Object",
"ito",
"=",
"ScriptRuntime",
".",
"callIterator",
"(",
"arg1",
",",
"cx",
",",
"scope",
")",
";",
"if",
"(",
"Undefined",
".",
"instance",
".",
"equals",
"(",
"ito",
")",
")",
"{",
"// Per spec, ignore if the iterator is undefined",
"return",
";",
"}",
"// Find the \"add\" function of our own prototype, since it might have",
"// been replaced. Since we're not fully constructed yet, create a dummy instance",
"// so that we can get our own prototype.",
"ScriptableObject",
"dummy",
"=",
"ensureScriptableObject",
"(",
"cx",
".",
"newObject",
"(",
"scope",
",",
"map",
".",
"getClassName",
"(",
")",
")",
")",
";",
"final",
"Callable",
"set",
"=",
"ScriptRuntime",
".",
"getPropFunctionAndThis",
"(",
"dummy",
".",
"getPrototype",
"(",
")",
",",
"\"set\"",
",",
"cx",
",",
"scope",
")",
";",
"ScriptRuntime",
".",
"lastStoredScriptable",
"(",
"cx",
")",
";",
"// Finally, run through all the iterated values and add them!",
"try",
"(",
"IteratorLikeIterable",
"it",
"=",
"new",
"IteratorLikeIterable",
"(",
"cx",
",",
"scope",
",",
"ito",
")",
")",
"{",
"for",
"(",
"Object",
"val",
":",
"it",
")",
"{",
"Scriptable",
"sVal",
"=",
"ScriptableObject",
".",
"ensureScriptable",
"(",
"val",
")",
";",
"if",
"(",
"sVal",
"instanceof",
"Symbol",
")",
"{",
"throw",
"ScriptRuntime",
".",
"typeError1",
"(",
"\"msg.arg.not.object\"",
",",
"ScriptRuntime",
".",
"typeof",
"(",
"sVal",
")",
")",
";",
"}",
"Object",
"finalKey",
"=",
"sVal",
".",
"get",
"(",
"0",
",",
"sVal",
")",
";",
"if",
"(",
"finalKey",
"==",
"NOT_FOUND",
")",
"{",
"finalKey",
"=",
"Undefined",
".",
"instance",
";",
"}",
"Object",
"finalVal",
"=",
"sVal",
".",
"get",
"(",
"1",
",",
"sVal",
")",
";",
"if",
"(",
"finalVal",
"==",
"NOT_FOUND",
")",
"{",
"finalVal",
"=",
"Undefined",
".",
"instance",
";",
"}",
"set",
".",
"call",
"(",
"cx",
",",
"scope",
",",
"map",
",",
"new",
"Object",
"[",
"]",
"{",
"finalKey",
",",
"finalVal",
"}",
")",
";",
"}",
"}",
"}"
] |
If an "iterable" object was passed to the constructor, there are many many things
to do... Make this static because NativeWeakMap has the exact same requirement.
|
[
"If",
"an",
"iterable",
"object",
"was",
"passed",
"to",
"the",
"constructor",
"there",
"are",
"many",
"many",
"things",
"to",
"do",
"...",
"Make",
"this",
"static",
"because",
"NativeWeakMap",
"has",
"the",
"exact",
"same",
"requirement",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/NativeMap.java#L180-L219
|
21,445
|
mozilla/rhino
|
src/org/mozilla/javascript/NativeMath.java
|
NativeMath.js_pow
|
private static double js_pow(double x, double y) {
double result;
if (y != y) {
// y is NaN, result is always NaN
result = y;
} else if (y == 0) {
// Java's pow(NaN, 0) = NaN; we need 1
result = 1.0;
} else if (x == 0) {
// Many differences from Java's Math.pow
if (1 / x > 0) {
result = (y > 0) ? 0 : Double.POSITIVE_INFINITY;
} else {
// x is -0, need to check if y is an odd integer
long y_long = (long)y;
if (y_long == y && (y_long & 0x1) != 0) {
result = (y > 0) ? -0.0 : Double.NEGATIVE_INFINITY;
} else {
result = (y > 0) ? 0.0 : Double.POSITIVE_INFINITY;
}
}
} else {
result = Math.pow(x, y);
if (result != result) {
// Check for broken Java implementations that gives NaN
// when they should return something else
if (y == Double.POSITIVE_INFINITY) {
if (x < -1.0 || 1.0 < x) {
result = Double.POSITIVE_INFINITY;
} else if (-1.0 < x && x < 1.0) {
result = 0;
}
} else if (y == Double.NEGATIVE_INFINITY) {
if (x < -1.0 || 1.0 < x) {
result = 0;
} else if (-1.0 < x && x < 1.0) {
result = Double.POSITIVE_INFINITY;
}
} else if (x == Double.POSITIVE_INFINITY) {
result = (y > 0) ? Double.POSITIVE_INFINITY : 0.0;
} else if (x == Double.NEGATIVE_INFINITY) {
long y_long = (long)y;
if (y_long == y && (y_long & 0x1) != 0) {
// y is odd integer
result = (y > 0) ? Double.NEGATIVE_INFINITY : -0.0;
} else {
result = (y > 0) ? Double.POSITIVE_INFINITY : 0.0;
}
}
}
}
return result;
}
|
java
|
private static double js_pow(double x, double y) {
double result;
if (y != y) {
// y is NaN, result is always NaN
result = y;
} else if (y == 0) {
// Java's pow(NaN, 0) = NaN; we need 1
result = 1.0;
} else if (x == 0) {
// Many differences from Java's Math.pow
if (1 / x > 0) {
result = (y > 0) ? 0 : Double.POSITIVE_INFINITY;
} else {
// x is -0, need to check if y is an odd integer
long y_long = (long)y;
if (y_long == y && (y_long & 0x1) != 0) {
result = (y > 0) ? -0.0 : Double.NEGATIVE_INFINITY;
} else {
result = (y > 0) ? 0.0 : Double.POSITIVE_INFINITY;
}
}
} else {
result = Math.pow(x, y);
if (result != result) {
// Check for broken Java implementations that gives NaN
// when they should return something else
if (y == Double.POSITIVE_INFINITY) {
if (x < -1.0 || 1.0 < x) {
result = Double.POSITIVE_INFINITY;
} else if (-1.0 < x && x < 1.0) {
result = 0;
}
} else if (y == Double.NEGATIVE_INFINITY) {
if (x < -1.0 || 1.0 < x) {
result = 0;
} else if (-1.0 < x && x < 1.0) {
result = Double.POSITIVE_INFINITY;
}
} else if (x == Double.POSITIVE_INFINITY) {
result = (y > 0) ? Double.POSITIVE_INFINITY : 0.0;
} else if (x == Double.NEGATIVE_INFINITY) {
long y_long = (long)y;
if (y_long == y && (y_long & 0x1) != 0) {
// y is odd integer
result = (y > 0) ? Double.NEGATIVE_INFINITY : -0.0;
} else {
result = (y > 0) ? Double.POSITIVE_INFINITY : 0.0;
}
}
}
}
return result;
}
|
[
"private",
"static",
"double",
"js_pow",
"(",
"double",
"x",
",",
"double",
"y",
")",
"{",
"double",
"result",
";",
"if",
"(",
"y",
"!=",
"y",
")",
"{",
"// y is NaN, result is always NaN",
"result",
"=",
"y",
";",
"}",
"else",
"if",
"(",
"y",
"==",
"0",
")",
"{",
"// Java's pow(NaN, 0) = NaN; we need 1",
"result",
"=",
"1.0",
";",
"}",
"else",
"if",
"(",
"x",
"==",
"0",
")",
"{",
"// Many differences from Java's Math.pow",
"if",
"(",
"1",
"/",
"x",
">",
"0",
")",
"{",
"result",
"=",
"(",
"y",
">",
"0",
")",
"?",
"0",
":",
"Double",
".",
"POSITIVE_INFINITY",
";",
"}",
"else",
"{",
"// x is -0, need to check if y is an odd integer",
"long",
"y_long",
"=",
"(",
"long",
")",
"y",
";",
"if",
"(",
"y_long",
"==",
"y",
"&&",
"(",
"y_long",
"&",
"0x1",
")",
"!=",
"0",
")",
"{",
"result",
"=",
"(",
"y",
">",
"0",
")",
"?",
"-",
"0.0",
":",
"Double",
".",
"NEGATIVE_INFINITY",
";",
"}",
"else",
"{",
"result",
"=",
"(",
"y",
">",
"0",
")",
"?",
"0.0",
":",
"Double",
".",
"POSITIVE_INFINITY",
";",
"}",
"}",
"}",
"else",
"{",
"result",
"=",
"Math",
".",
"pow",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"result",
"!=",
"result",
")",
"{",
"// Check for broken Java implementations that gives NaN",
"// when they should return something else",
"if",
"(",
"y",
"==",
"Double",
".",
"POSITIVE_INFINITY",
")",
"{",
"if",
"(",
"x",
"<",
"-",
"1.0",
"||",
"1.0",
"<",
"x",
")",
"{",
"result",
"=",
"Double",
".",
"POSITIVE_INFINITY",
";",
"}",
"else",
"if",
"(",
"-",
"1.0",
"<",
"x",
"&&",
"x",
"<",
"1.0",
")",
"{",
"result",
"=",
"0",
";",
"}",
"}",
"else",
"if",
"(",
"y",
"==",
"Double",
".",
"NEGATIVE_INFINITY",
")",
"{",
"if",
"(",
"x",
"<",
"-",
"1.0",
"||",
"1.0",
"<",
"x",
")",
"{",
"result",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"-",
"1.0",
"<",
"x",
"&&",
"x",
"<",
"1.0",
")",
"{",
"result",
"=",
"Double",
".",
"POSITIVE_INFINITY",
";",
"}",
"}",
"else",
"if",
"(",
"x",
"==",
"Double",
".",
"POSITIVE_INFINITY",
")",
"{",
"result",
"=",
"(",
"y",
">",
"0",
")",
"?",
"Double",
".",
"POSITIVE_INFINITY",
":",
"0.0",
";",
"}",
"else",
"if",
"(",
"x",
"==",
"Double",
".",
"NEGATIVE_INFINITY",
")",
"{",
"long",
"y_long",
"=",
"(",
"long",
")",
"y",
";",
"if",
"(",
"y_long",
"==",
"y",
"&&",
"(",
"y_long",
"&",
"0x1",
")",
"!=",
"0",
")",
"{",
"// y is odd integer",
"result",
"=",
"(",
"y",
">",
"0",
")",
"?",
"Double",
".",
"NEGATIVE_INFINITY",
":",
"-",
"0.0",
";",
"}",
"else",
"{",
"result",
"=",
"(",
"y",
">",
"0",
")",
"?",
"Double",
".",
"POSITIVE_INFINITY",
":",
"0.0",
";",
"}",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] |
See Ecma 15.8.2.13
|
[
"See",
"Ecma",
"15",
".",
"8",
".",
"2",
".",
"13"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/NativeMath.java#L367-L419
|
21,446
|
mozilla/rhino
|
src/org/mozilla/javascript/NativeMath.java
|
NativeMath.js_imul
|
private static int js_imul(Object[] args)
{
if (args == null) {
return 0;
}
int x = ScriptRuntime.toInt32(args, 0);
int y = ScriptRuntime.toInt32(args, 1);
return x * y;
}
|
java
|
private static int js_imul(Object[] args)
{
if (args == null) {
return 0;
}
int x = ScriptRuntime.toInt32(args, 0);
int y = ScriptRuntime.toInt32(args, 1);
return x * y;
}
|
[
"private",
"static",
"int",
"js_imul",
"(",
"Object",
"[",
"]",
"args",
")",
"{",
"if",
"(",
"args",
"==",
"null",
")",
"{",
"return",
"0",
";",
"}",
"int",
"x",
"=",
"ScriptRuntime",
".",
"toInt32",
"(",
"args",
",",
"0",
")",
";",
"int",
"y",
"=",
"ScriptRuntime",
".",
"toInt32",
"(",
"args",
",",
"1",
")",
";",
"return",
"x",
"*",
"y",
";",
"}"
] |
From EcmaScript 6 section 20.2.2.19
|
[
"From",
"EcmaScript",
"6",
"section",
"20",
".",
"2",
".",
"2",
".",
"19"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/NativeMath.java#L448-L457
|
21,447
|
mozilla/rhino
|
toolsrc/org/mozilla/javascript/tools/jsc/Main.java
|
Main.badUsage
|
private static void badUsage(String s) {
System.err.println(ToolErrorReporter.getMessage(
"msg.jsc.bad.usage", Main.class.getName(), s));
}
|
java
|
private static void badUsage(String s) {
System.err.println(ToolErrorReporter.getMessage(
"msg.jsc.bad.usage", Main.class.getName(), s));
}
|
[
"private",
"static",
"void",
"badUsage",
"(",
"String",
"s",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"ToolErrorReporter",
".",
"getMessage",
"(",
"\"msg.jsc.bad.usage\"",
",",
"Main",
".",
"class",
".",
"getName",
"(",
")",
",",
"s",
")",
")",
";",
"}"
] |
Print a usage message.
|
[
"Print",
"a",
"usage",
"message",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/jsc/Main.java#L217-L220
|
21,448
|
mozilla/rhino
|
toolsrc/org/mozilla/javascript/tools/jsc/Main.java
|
Main.processSource
|
public void processSource(String[] filenames)
{
for (int i = 0; i != filenames.length; ++i) {
String filename = filenames[i];
if (!filename.endsWith(".js")) {
addError("msg.extension.not.js", filename);
return;
}
File f = new File(filename);
String source = readSource(f);
if (source == null) return;
String mainClassName = targetName;
if (mainClassName == null) {
String name = f.getName();
String nojs = name.substring(0, name.length() - 3);
mainClassName = getClassName(nojs);
}
if (targetPackage.length() != 0) {
mainClassName = targetPackage+"."+mainClassName;
}
Object[] compiled
= compiler.compileToClassFiles(source, filename, 1,
mainClassName);
if (compiled == null || compiled.length == 0) {
return;
}
File targetTopDir = null;
if (destinationDir != null) {
targetTopDir = new File(destinationDir);
} else {
String parent = f.getParent();
if (parent != null) {
targetTopDir = new File(parent);
}
}
for (int j = 0; j != compiled.length; j += 2) {
String className = (String)compiled[j];
byte[] bytes = (byte[])compiled[j + 1];
File outfile = getOutputFile(targetTopDir, className);
try {
FileOutputStream os = new FileOutputStream(outfile);
try {
os.write(bytes);
} finally {
os.close();
}
} catch (IOException ioe) {
addFormatedError(ioe.toString());
}
}
}
}
|
java
|
public void processSource(String[] filenames)
{
for (int i = 0; i != filenames.length; ++i) {
String filename = filenames[i];
if (!filename.endsWith(".js")) {
addError("msg.extension.not.js", filename);
return;
}
File f = new File(filename);
String source = readSource(f);
if (source == null) return;
String mainClassName = targetName;
if (mainClassName == null) {
String name = f.getName();
String nojs = name.substring(0, name.length() - 3);
mainClassName = getClassName(nojs);
}
if (targetPackage.length() != 0) {
mainClassName = targetPackage+"."+mainClassName;
}
Object[] compiled
= compiler.compileToClassFiles(source, filename, 1,
mainClassName);
if (compiled == null || compiled.length == 0) {
return;
}
File targetTopDir = null;
if (destinationDir != null) {
targetTopDir = new File(destinationDir);
} else {
String parent = f.getParent();
if (parent != null) {
targetTopDir = new File(parent);
}
}
for (int j = 0; j != compiled.length; j += 2) {
String className = (String)compiled[j];
byte[] bytes = (byte[])compiled[j + 1];
File outfile = getOutputFile(targetTopDir, className);
try {
FileOutputStream os = new FileOutputStream(outfile);
try {
os.write(bytes);
} finally {
os.close();
}
} catch (IOException ioe) {
addFormatedError(ioe.toString());
}
}
}
}
|
[
"public",
"void",
"processSource",
"(",
"String",
"[",
"]",
"filenames",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"!=",
"filenames",
".",
"length",
";",
"++",
"i",
")",
"{",
"String",
"filename",
"=",
"filenames",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"filename",
".",
"endsWith",
"(",
"\".js\"",
")",
")",
"{",
"addError",
"(",
"\"msg.extension.not.js\"",
",",
"filename",
")",
";",
"return",
";",
"}",
"File",
"f",
"=",
"new",
"File",
"(",
"filename",
")",
";",
"String",
"source",
"=",
"readSource",
"(",
"f",
")",
";",
"if",
"(",
"source",
"==",
"null",
")",
"return",
";",
"String",
"mainClassName",
"=",
"targetName",
";",
"if",
"(",
"mainClassName",
"==",
"null",
")",
"{",
"String",
"name",
"=",
"f",
".",
"getName",
"(",
")",
";",
"String",
"nojs",
"=",
"name",
".",
"substring",
"(",
"0",
",",
"name",
".",
"length",
"(",
")",
"-",
"3",
")",
";",
"mainClassName",
"=",
"getClassName",
"(",
"nojs",
")",
";",
"}",
"if",
"(",
"targetPackage",
".",
"length",
"(",
")",
"!=",
"0",
")",
"{",
"mainClassName",
"=",
"targetPackage",
"+",
"\".\"",
"+",
"mainClassName",
";",
"}",
"Object",
"[",
"]",
"compiled",
"=",
"compiler",
".",
"compileToClassFiles",
"(",
"source",
",",
"filename",
",",
"1",
",",
"mainClassName",
")",
";",
"if",
"(",
"compiled",
"==",
"null",
"||",
"compiled",
".",
"length",
"==",
"0",
")",
"{",
"return",
";",
"}",
"File",
"targetTopDir",
"=",
"null",
";",
"if",
"(",
"destinationDir",
"!=",
"null",
")",
"{",
"targetTopDir",
"=",
"new",
"File",
"(",
"destinationDir",
")",
";",
"}",
"else",
"{",
"String",
"parent",
"=",
"f",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"parent",
"!=",
"null",
")",
"{",
"targetTopDir",
"=",
"new",
"File",
"(",
"parent",
")",
";",
"}",
"}",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"!=",
"compiled",
".",
"length",
";",
"j",
"+=",
"2",
")",
"{",
"String",
"className",
"=",
"(",
"String",
")",
"compiled",
"[",
"j",
"]",
";",
"byte",
"[",
"]",
"bytes",
"=",
"(",
"byte",
"[",
"]",
")",
"compiled",
"[",
"j",
"+",
"1",
"]",
";",
"File",
"outfile",
"=",
"getOutputFile",
"(",
"targetTopDir",
",",
"className",
")",
";",
"try",
"{",
"FileOutputStream",
"os",
"=",
"new",
"FileOutputStream",
"(",
"outfile",
")",
";",
"try",
"{",
"os",
".",
"write",
"(",
"bytes",
")",
";",
"}",
"finally",
"{",
"os",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"ioe",
")",
"{",
"addFormatedError",
"(",
"ioe",
".",
"toString",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Compile JavaScript source.
|
[
"Compile",
"JavaScript",
"source",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/jsc/Main.java#L226-L280
|
21,449
|
mozilla/rhino
|
toolsrc/org/mozilla/javascript/tools/jsc/Main.java
|
Main.getClassName
|
String getClassName(String name) {
char[] s = new char[name.length()+1];
char c;
int j = 0;
if (!Character.isJavaIdentifierStart(name.charAt(0))) {
s[j++] = '_';
}
for (int i=0; i < name.length(); i++, j++) {
c = name.charAt(i);
if ( Character.isJavaIdentifierPart(c) ) {
s[j] = c;
} else {
s[j] = '_';
}
}
return (new String(s)).trim();
}
|
java
|
String getClassName(String name) {
char[] s = new char[name.length()+1];
char c;
int j = 0;
if (!Character.isJavaIdentifierStart(name.charAt(0))) {
s[j++] = '_';
}
for (int i=0; i < name.length(); i++, j++) {
c = name.charAt(i);
if ( Character.isJavaIdentifierPart(c) ) {
s[j] = c;
} else {
s[j] = '_';
}
}
return (new String(s)).trim();
}
|
[
"String",
"getClassName",
"(",
"String",
"name",
")",
"{",
"char",
"[",
"]",
"s",
"=",
"new",
"char",
"[",
"name",
".",
"length",
"(",
")",
"+",
"1",
"]",
";",
"char",
"c",
";",
"int",
"j",
"=",
"0",
";",
"if",
"(",
"!",
"Character",
".",
"isJavaIdentifierStart",
"(",
"name",
".",
"charAt",
"(",
"0",
")",
")",
")",
"{",
"s",
"[",
"j",
"++",
"]",
"=",
"'",
"'",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"name",
".",
"length",
"(",
")",
";",
"i",
"++",
",",
"j",
"++",
")",
"{",
"c",
"=",
"name",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"Character",
".",
"isJavaIdentifierPart",
"(",
"c",
")",
")",
"{",
"s",
"[",
"j",
"]",
"=",
"c",
";",
"}",
"else",
"{",
"s",
"[",
"j",
"]",
"=",
"'",
"'",
";",
"}",
"}",
"return",
"(",
"new",
"String",
"(",
"s",
")",
")",
".",
"trim",
"(",
")",
";",
"}"
] |
Verify that class file names are legal Java identifiers. Substitute
illegal characters with underscores, and prepend the name with an
underscore if the file name does not begin with a JavaLetter.
|
[
"Verify",
"that",
"class",
"file",
"names",
"are",
"legal",
"Java",
"identifiers",
".",
"Substitute",
"illegal",
"characters",
"with",
"underscores",
"and",
"prepend",
"the",
"name",
"with",
"an",
"underscore",
"if",
"the",
"file",
"name",
"does",
"not",
"begin",
"with",
"a",
"JavaLetter",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/toolsrc/org/mozilla/javascript/tools/jsc/Main.java#L321-L338
|
21,450
|
mozilla/rhino
|
src/org/mozilla/javascript/NativeFunction.java
|
NativeFunction.resumeGenerator
|
public Object resumeGenerator(Context cx, Scriptable scope,
int operation, Object state, Object value)
{
throw new EvaluatorException("resumeGenerator() not implemented");
}
|
java
|
public Object resumeGenerator(Context cx, Scriptable scope,
int operation, Object state, Object value)
{
throw new EvaluatorException("resumeGenerator() not implemented");
}
|
[
"public",
"Object",
"resumeGenerator",
"(",
"Context",
"cx",
",",
"Scriptable",
"scope",
",",
"int",
"operation",
",",
"Object",
"state",
",",
"Object",
"value",
")",
"{",
"throw",
"new",
"EvaluatorException",
"(",
"\"resumeGenerator() not implemented\"",
")",
";",
"}"
] |
Resume execution of a suspended generator.
@param cx The current context
@param scope Scope for the parent generator function
@param operation The resumption operation (next, send, etc.. )
@param state The generator state (has locals, stack, etc.)
@param value The return value of yield (if required).
@return The next yielded value (if any)
|
[
"Resume",
"execution",
"of",
"a",
"suspended",
"generator",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/NativeFunction.java#L97-L101
|
21,451
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/ConditionalExpression.java
|
ConditionalExpression.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
testExpression.visit(v);
trueExpression.visit(v);
falseExpression.visit(v);
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
testExpression.visit(v);
trueExpression.visit(v);
falseExpression.visit(v);
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"testExpression",
".",
"visit",
"(",
"v",
")",
";",
"trueExpression",
".",
"visit",
"(",
"v",
")",
";",
"falseExpression",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}"
] |
Visits this node, then the test-expression, the true-expression,
and the false-expression.
|
[
"Visits",
"this",
"node",
"then",
"the",
"test",
"-",
"expression",
"the",
"true",
"-",
"expression",
"and",
"the",
"false",
"-",
"expression",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/ConditionalExpression.java#L160-L167
|
21,452
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addInterface
|
public void addInterface(String interfaceName) {
short interfaceIndex = itsConstantPool.addClass(interfaceName);
itsInterfaces.add(Short.valueOf(interfaceIndex));
}
|
java
|
public void addInterface(String interfaceName) {
short interfaceIndex = itsConstantPool.addClass(interfaceName);
itsInterfaces.add(Short.valueOf(interfaceIndex));
}
|
[
"public",
"void",
"addInterface",
"(",
"String",
"interfaceName",
")",
"{",
"short",
"interfaceIndex",
"=",
"itsConstantPool",
".",
"addClass",
"(",
"interfaceName",
")",
";",
"itsInterfaces",
".",
"add",
"(",
"Short",
".",
"valueOf",
"(",
"interfaceIndex",
")",
")",
";",
"}"
] |
Add an interface implemented by this class.
This method may be called multiple times for classes that implement multiple interfaces.
@param interfaceName a name of an interface implemented by the class being written, including
full package qualification.
|
[
"Add",
"an",
"interface",
"implemented",
"by",
"this",
"class",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L75-L78
|
21,453
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.classNameToSignature
|
public static String classNameToSignature(String name) {
int nameLength = name.length();
int colonPos = 1 + nameLength;
char[] buf = new char[colonPos + 1];
buf[0] = 'L';
buf[colonPos] = ';';
name.getChars(0, nameLength, buf, 1);
for (int i = 1; i != colonPos; ++i) {
if (buf[i] == '.') {
buf[i] = '/';
}
}
return new String(buf, 0, colonPos + 1);
}
|
java
|
public static String classNameToSignature(String name) {
int nameLength = name.length();
int colonPos = 1 + nameLength;
char[] buf = new char[colonPos + 1];
buf[0] = 'L';
buf[colonPos] = ';';
name.getChars(0, nameLength, buf, 1);
for (int i = 1; i != colonPos; ++i) {
if (buf[i] == '.') {
buf[i] = '/';
}
}
return new String(buf, 0, colonPos + 1);
}
|
[
"public",
"static",
"String",
"classNameToSignature",
"(",
"String",
"name",
")",
"{",
"int",
"nameLength",
"=",
"name",
".",
"length",
"(",
")",
";",
"int",
"colonPos",
"=",
"1",
"+",
"nameLength",
";",
"char",
"[",
"]",
"buf",
"=",
"new",
"char",
"[",
"colonPos",
"+",
"1",
"]",
";",
"buf",
"[",
"0",
"]",
"=",
"'",
"'",
";",
"buf",
"[",
"colonPos",
"]",
"=",
"'",
"'",
";",
"name",
".",
"getChars",
"(",
"0",
",",
"nameLength",
",",
"buf",
",",
"1",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"!=",
"colonPos",
";",
"++",
"i",
")",
"{",
"if",
"(",
"buf",
"[",
"i",
"]",
"==",
"'",
"'",
")",
"{",
"buf",
"[",
"i",
"]",
"=",
"'",
"'",
";",
"}",
"}",
"return",
"new",
"String",
"(",
"buf",
",",
"0",
",",
"colonPos",
"+",
"1",
")",
";",
"}"
] |
Convert Java class name in dot notation into "Lname-with-dots-replaced-by-slashes;" form
suitable for use as JVM type signatures.
|
[
"Convert",
"Java",
"class",
"name",
"in",
"dot",
"notation",
"into",
"Lname",
"-",
"with",
"-",
"dots",
"-",
"replaced",
"-",
"by",
"-",
"slashes",
";",
"form",
"suitable",
"for",
"use",
"as",
"JVM",
"type",
"signatures",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L113-L126
|
21,454
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addVariableDescriptor
|
public void addVariableDescriptor(String name, String type, int startPC, int register) {
int nameIndex = itsConstantPool.addUtf8(name);
int descriptorIndex = itsConstantPool.addUtf8(type);
int[] chunk = {nameIndex, descriptorIndex, startPC, register};
if (itsVarDescriptors == null) {
itsVarDescriptors = new ObjArray();
}
itsVarDescriptors.add(chunk);
}
|
java
|
public void addVariableDescriptor(String name, String type, int startPC, int register) {
int nameIndex = itsConstantPool.addUtf8(name);
int descriptorIndex = itsConstantPool.addUtf8(type);
int[] chunk = {nameIndex, descriptorIndex, startPC, register};
if (itsVarDescriptors == null) {
itsVarDescriptors = new ObjArray();
}
itsVarDescriptors.add(chunk);
}
|
[
"public",
"void",
"addVariableDescriptor",
"(",
"String",
"name",
",",
"String",
"type",
",",
"int",
"startPC",
",",
"int",
"register",
")",
"{",
"int",
"nameIndex",
"=",
"itsConstantPool",
".",
"addUtf8",
"(",
"name",
")",
";",
"int",
"descriptorIndex",
"=",
"itsConstantPool",
".",
"addUtf8",
"(",
"type",
")",
";",
"int",
"[",
"]",
"chunk",
"=",
"{",
"nameIndex",
",",
"descriptorIndex",
",",
"startPC",
",",
"register",
"}",
";",
"if",
"(",
"itsVarDescriptors",
"==",
"null",
")",
"{",
"itsVarDescriptors",
"=",
"new",
"ObjArray",
"(",
")",
";",
"}",
"itsVarDescriptors",
".",
"add",
"(",
"chunk",
")",
";",
"}"
] |
Add Information about java variable to use when generating the local variable table.
@param name variable name.
@param type variable type as bytecode descriptor string.
@param startPC the starting bytecode PC where this variable is live, or -1 if it does not have
a Java register.
@param register the Java register number of variable or -1 if it does not have a Java
register.
|
[
"Add",
"Information",
"about",
"java",
"variable",
"to",
"use",
"when",
"generating",
"the",
"local",
"variable",
"table",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L214-L222
|
21,455
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.startMethod
|
public void startMethod(String methodName, String type, short flags) {
short methodNameIndex = itsConstantPool.addUtf8(methodName);
short typeIndex = itsConstantPool.addUtf8(type);
itsCurrentMethod = new ClassFileMethod(methodName, methodNameIndex,
type, typeIndex, flags);
itsJumpFroms = new UintMap();
itsMethods.add(itsCurrentMethod);
addSuperBlockStart(0);
}
|
java
|
public void startMethod(String methodName, String type, short flags) {
short methodNameIndex = itsConstantPool.addUtf8(methodName);
short typeIndex = itsConstantPool.addUtf8(type);
itsCurrentMethod = new ClassFileMethod(methodName, methodNameIndex,
type, typeIndex, flags);
itsJumpFroms = new UintMap();
itsMethods.add(itsCurrentMethod);
addSuperBlockStart(0);
}
|
[
"public",
"void",
"startMethod",
"(",
"String",
"methodName",
",",
"String",
"type",
",",
"short",
"flags",
")",
"{",
"short",
"methodNameIndex",
"=",
"itsConstantPool",
".",
"addUtf8",
"(",
"methodName",
")",
";",
"short",
"typeIndex",
"=",
"itsConstantPool",
".",
"addUtf8",
"(",
"type",
")",
";",
"itsCurrentMethod",
"=",
"new",
"ClassFileMethod",
"(",
"methodName",
",",
"methodNameIndex",
",",
"type",
",",
"typeIndex",
",",
"flags",
")",
";",
"itsJumpFroms",
"=",
"new",
"UintMap",
"(",
")",
";",
"itsMethods",
".",
"add",
"(",
"itsCurrentMethod",
")",
";",
"addSuperBlockStart",
"(",
"0",
")",
";",
"}"
] |
Add a method and begin adding code.
This method must be called before other methods for adding code, exception tables, etc. can be
invoked.
@param methodName the name of the method
@param type a string representing the type
@param flags the attributes of the field, such as ACC_PUBLIC, etc. bitwise or'd together
|
[
"Add",
"a",
"method",
"and",
"begin",
"adding",
"code",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L234-L242
|
21,456
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.add
|
public void add(int theOpCode) {
if (opcodeCount(theOpCode) != 0)
throw new IllegalArgumentException("Unexpected operands");
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack)
badStack(newStack);
if (DEBUGCODE)
System.out.println("Add " + bytecodeStr(theOpCode));
addToCodeBuffer(theOpCode);
itsStackTop = (short) newStack;
if (newStack > itsMaxStack)
itsMaxStack = (short) newStack;
if (DEBUGSTACK) {
System.out.println("After " + bytecodeStr(theOpCode)
+ " stack = " + itsStackTop);
}
if (theOpCode == ByteCode.ATHROW) {
addSuperBlockStart(itsCodeBufferTop);
}
}
|
java
|
public void add(int theOpCode) {
if (opcodeCount(theOpCode) != 0)
throw new IllegalArgumentException("Unexpected operands");
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack)
badStack(newStack);
if (DEBUGCODE)
System.out.println("Add " + bytecodeStr(theOpCode));
addToCodeBuffer(theOpCode);
itsStackTop = (short) newStack;
if (newStack > itsMaxStack)
itsMaxStack = (short) newStack;
if (DEBUGSTACK) {
System.out.println("After " + bytecodeStr(theOpCode)
+ " stack = " + itsStackTop);
}
if (theOpCode == ByteCode.ATHROW) {
addSuperBlockStart(itsCodeBufferTop);
}
}
|
[
"public",
"void",
"add",
"(",
"int",
"theOpCode",
")",
"{",
"if",
"(",
"opcodeCount",
"(",
"theOpCode",
")",
"!=",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unexpected operands\"",
")",
";",
"int",
"newStack",
"=",
"itsStackTop",
"+",
"stackChange",
"(",
"theOpCode",
")",
";",
"if",
"(",
"newStack",
"<",
"0",
"||",
"Short",
".",
"MAX_VALUE",
"<",
"newStack",
")",
"badStack",
"(",
"newStack",
")",
";",
"if",
"(",
"DEBUGCODE",
")",
"System",
".",
"out",
".",
"println",
"(",
"\"Add \"",
"+",
"bytecodeStr",
"(",
"theOpCode",
")",
")",
";",
"addToCodeBuffer",
"(",
"theOpCode",
")",
";",
"itsStackTop",
"=",
"(",
"short",
")",
"newStack",
";",
"if",
"(",
"newStack",
">",
"itsMaxStack",
")",
"itsMaxStack",
"=",
"(",
"short",
")",
"newStack",
";",
"if",
"(",
"DEBUGSTACK",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"After \"",
"+",
"bytecodeStr",
"(",
"theOpCode",
")",
"+",
"\" stack = \"",
"+",
"itsStackTop",
")",
";",
"}",
"if",
"(",
"theOpCode",
"==",
"ByteCode",
".",
"ATHROW",
")",
"{",
"addSuperBlockStart",
"(",
"itsCodeBufferTop",
")",
";",
"}",
"}"
] |
Add the single-byte opcode to the current method.
@param theOpCode the opcode of the bytecode
|
[
"Add",
"the",
"single",
"-",
"byte",
"opcode",
"to",
"the",
"current",
"method",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L425-L444
|
21,457
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addLoadConstant
|
public void addLoadConstant(int k) {
switch (k) {
case 0:
add(ByteCode.ICONST_0);
break;
case 1:
add(ByteCode.ICONST_1);
break;
case 2:
add(ByteCode.ICONST_2);
break;
case 3:
add(ByteCode.ICONST_3);
break;
case 4:
add(ByteCode.ICONST_4);
break;
case 5:
add(ByteCode.ICONST_5);
break;
default:
add(ByteCode.LDC, itsConstantPool.addConstant(k));
break;
}
}
|
java
|
public void addLoadConstant(int k) {
switch (k) {
case 0:
add(ByteCode.ICONST_0);
break;
case 1:
add(ByteCode.ICONST_1);
break;
case 2:
add(ByteCode.ICONST_2);
break;
case 3:
add(ByteCode.ICONST_3);
break;
case 4:
add(ByteCode.ICONST_4);
break;
case 5:
add(ByteCode.ICONST_5);
break;
default:
add(ByteCode.LDC, itsConstantPool.addConstant(k));
break;
}
}
|
[
"public",
"void",
"addLoadConstant",
"(",
"int",
"k",
")",
"{",
"switch",
"(",
"k",
")",
"{",
"case",
"0",
":",
"add",
"(",
"ByteCode",
".",
"ICONST_0",
")",
";",
"break",
";",
"case",
"1",
":",
"add",
"(",
"ByteCode",
".",
"ICONST_1",
")",
";",
"break",
";",
"case",
"2",
":",
"add",
"(",
"ByteCode",
".",
"ICONST_2",
")",
";",
"break",
";",
"case",
"3",
":",
"add",
"(",
"ByteCode",
".",
"ICONST_3",
")",
";",
"break",
";",
"case",
"4",
":",
"add",
"(",
"ByteCode",
".",
"ICONST_4",
")",
";",
"break",
";",
"case",
"5",
":",
"add",
"(",
"ByteCode",
".",
"ICONST_5",
")",
";",
"break",
";",
"default",
":",
"add",
"(",
"ByteCode",
".",
"LDC",
",",
"itsConstantPool",
".",
"addConstant",
"(",
"k",
")",
")",
";",
"break",
";",
"}",
"}"
] |
Generate the load constant bytecode for the given integer.
@param k the constant
|
[
"Generate",
"the",
"load",
"constant",
"bytecode",
"for",
"the",
"given",
"integer",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L610-L634
|
21,458
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.add
|
public void add(int theOpCode, int theOperand1, int theOperand2) {
if (DEBUGCODE) {
System.out.println("Add " + bytecodeStr(theOpCode)
+ ", " + Integer.toHexString(theOperand1)
+ ", " + Integer.toHexString(theOperand2));
}
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack)
badStack(newStack);
if (theOpCode == ByteCode.IINC) {
if (theOperand1 < 0 || 65536 <= theOperand1)
throw new ClassFileFormatException("out of range variable");
if (theOperand2 < 0 || 65536 <= theOperand2)
throw new ClassFileFormatException("out of range increment");
if (theOperand1 > 255 || theOperand2 < -128 || theOperand2 > 127) {
addToCodeBuffer(ByteCode.WIDE);
addToCodeBuffer(ByteCode.IINC);
addToCodeInt16(theOperand1);
addToCodeInt16(theOperand2);
} else {
addToCodeBuffer(ByteCode.IINC);
addToCodeBuffer(theOperand1);
addToCodeBuffer(theOperand2);
}
} else if (theOpCode == ByteCode.MULTIANEWARRAY) {
if (!(0 <= theOperand1 && theOperand1 < 65536))
throw new IllegalArgumentException("out of range index");
if (!(0 <= theOperand2 && theOperand2 < 256))
throw new IllegalArgumentException("out of range dimensions");
addToCodeBuffer(ByteCode.MULTIANEWARRAY);
addToCodeInt16(theOperand1);
addToCodeBuffer(theOperand2);
} else {
throw new IllegalArgumentException(
"Unexpected opcode for 2 operands");
}
itsStackTop = (short) newStack;
if (newStack > itsMaxStack)
itsMaxStack = (short) newStack;
if (DEBUGSTACK) {
System.out.println("After " + bytecodeStr(theOpCode)
+ " stack = " + itsStackTop);
}
}
|
java
|
public void add(int theOpCode, int theOperand1, int theOperand2) {
if (DEBUGCODE) {
System.out.println("Add " + bytecodeStr(theOpCode)
+ ", " + Integer.toHexString(theOperand1)
+ ", " + Integer.toHexString(theOperand2));
}
int newStack = itsStackTop + stackChange(theOpCode);
if (newStack < 0 || Short.MAX_VALUE < newStack)
badStack(newStack);
if (theOpCode == ByteCode.IINC) {
if (theOperand1 < 0 || 65536 <= theOperand1)
throw new ClassFileFormatException("out of range variable");
if (theOperand2 < 0 || 65536 <= theOperand2)
throw new ClassFileFormatException("out of range increment");
if (theOperand1 > 255 || theOperand2 < -128 || theOperand2 > 127) {
addToCodeBuffer(ByteCode.WIDE);
addToCodeBuffer(ByteCode.IINC);
addToCodeInt16(theOperand1);
addToCodeInt16(theOperand2);
} else {
addToCodeBuffer(ByteCode.IINC);
addToCodeBuffer(theOperand1);
addToCodeBuffer(theOperand2);
}
} else if (theOpCode == ByteCode.MULTIANEWARRAY) {
if (!(0 <= theOperand1 && theOperand1 < 65536))
throw new IllegalArgumentException("out of range index");
if (!(0 <= theOperand2 && theOperand2 < 256))
throw new IllegalArgumentException("out of range dimensions");
addToCodeBuffer(ByteCode.MULTIANEWARRAY);
addToCodeInt16(theOperand1);
addToCodeBuffer(theOperand2);
} else {
throw new IllegalArgumentException(
"Unexpected opcode for 2 operands");
}
itsStackTop = (short) newStack;
if (newStack > itsMaxStack)
itsMaxStack = (short) newStack;
if (DEBUGSTACK) {
System.out.println("After " + bytecodeStr(theOpCode)
+ " stack = " + itsStackTop);
}
}
|
[
"public",
"void",
"add",
"(",
"int",
"theOpCode",
",",
"int",
"theOperand1",
",",
"int",
"theOperand2",
")",
"{",
"if",
"(",
"DEBUGCODE",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Add \"",
"+",
"bytecodeStr",
"(",
"theOpCode",
")",
"+",
"\", \"",
"+",
"Integer",
".",
"toHexString",
"(",
"theOperand1",
")",
"+",
"\", \"",
"+",
"Integer",
".",
"toHexString",
"(",
"theOperand2",
")",
")",
";",
"}",
"int",
"newStack",
"=",
"itsStackTop",
"+",
"stackChange",
"(",
"theOpCode",
")",
";",
"if",
"(",
"newStack",
"<",
"0",
"||",
"Short",
".",
"MAX_VALUE",
"<",
"newStack",
")",
"badStack",
"(",
"newStack",
")",
";",
"if",
"(",
"theOpCode",
"==",
"ByteCode",
".",
"IINC",
")",
"{",
"if",
"(",
"theOperand1",
"<",
"0",
"||",
"65536",
"<=",
"theOperand1",
")",
"throw",
"new",
"ClassFileFormatException",
"(",
"\"out of range variable\"",
")",
";",
"if",
"(",
"theOperand2",
"<",
"0",
"||",
"65536",
"<=",
"theOperand2",
")",
"throw",
"new",
"ClassFileFormatException",
"(",
"\"out of range increment\"",
")",
";",
"if",
"(",
"theOperand1",
">",
"255",
"||",
"theOperand2",
"<",
"-",
"128",
"||",
"theOperand2",
">",
"127",
")",
"{",
"addToCodeBuffer",
"(",
"ByteCode",
".",
"WIDE",
")",
";",
"addToCodeBuffer",
"(",
"ByteCode",
".",
"IINC",
")",
";",
"addToCodeInt16",
"(",
"theOperand1",
")",
";",
"addToCodeInt16",
"(",
"theOperand2",
")",
";",
"}",
"else",
"{",
"addToCodeBuffer",
"(",
"ByteCode",
".",
"IINC",
")",
";",
"addToCodeBuffer",
"(",
"theOperand1",
")",
";",
"addToCodeBuffer",
"(",
"theOperand2",
")",
";",
"}",
"}",
"else",
"if",
"(",
"theOpCode",
"==",
"ByteCode",
".",
"MULTIANEWARRAY",
")",
"{",
"if",
"(",
"!",
"(",
"0",
"<=",
"theOperand1",
"&&",
"theOperand1",
"<",
"65536",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"out of range index\"",
")",
";",
"if",
"(",
"!",
"(",
"0",
"<=",
"theOperand2",
"&&",
"theOperand2",
"<",
"256",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"out of range dimensions\"",
")",
";",
"addToCodeBuffer",
"(",
"ByteCode",
".",
"MULTIANEWARRAY",
")",
";",
"addToCodeInt16",
"(",
"theOperand1",
")",
";",
"addToCodeBuffer",
"(",
"theOperand2",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unexpected opcode for 2 operands\"",
")",
";",
"}",
"itsStackTop",
"=",
"(",
"short",
")",
"newStack",
";",
"if",
"(",
"newStack",
">",
"itsMaxStack",
")",
"itsMaxStack",
"=",
"(",
"short",
")",
"newStack",
";",
"if",
"(",
"DEBUGSTACK",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"After \"",
"+",
"bytecodeStr",
"(",
"theOpCode",
")",
"+",
"\" stack = \"",
"+",
"itsStackTop",
")",
";",
"}",
"}"
] |
Add the given two-operand bytecode to the current method.
@param theOpCode the opcode of the bytecode
@param theOperand1 the first operand of the bytecode
@param theOperand2 the second operand of the bytecode
|
[
"Add",
"the",
"given",
"two",
"-",
"operand",
"bytecode",
"to",
"the",
"current",
"method",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L679-L726
|
21,459
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addPush
|
public void addPush(int k) {
if ((byte) k == k) {
if (k == -1) {
add(ByteCode.ICONST_M1);
} else if (0 <= k && k <= 5) {
add((byte) (ByteCode.ICONST_0 + k));
} else {
add(ByteCode.BIPUSH, (byte) k);
}
} else if ((short) k == k) {
add(ByteCode.SIPUSH, (short) k);
} else {
addLoadConstant(k);
}
}
|
java
|
public void addPush(int k) {
if ((byte) k == k) {
if (k == -1) {
add(ByteCode.ICONST_M1);
} else if (0 <= k && k <= 5) {
add((byte) (ByteCode.ICONST_0 + k));
} else {
add(ByteCode.BIPUSH, (byte) k);
}
} else if ((short) k == k) {
add(ByteCode.SIPUSH, (short) k);
} else {
addLoadConstant(k);
}
}
|
[
"public",
"void",
"addPush",
"(",
"int",
"k",
")",
"{",
"if",
"(",
"(",
"byte",
")",
"k",
"==",
"k",
")",
"{",
"if",
"(",
"k",
"==",
"-",
"1",
")",
"{",
"add",
"(",
"ByteCode",
".",
"ICONST_M1",
")",
";",
"}",
"else",
"if",
"(",
"0",
"<=",
"k",
"&&",
"k",
"<=",
"5",
")",
"{",
"add",
"(",
"(",
"byte",
")",
"(",
"ByteCode",
".",
"ICONST_0",
"+",
"k",
")",
")",
";",
"}",
"else",
"{",
"add",
"(",
"ByteCode",
".",
"BIPUSH",
",",
"(",
"byte",
")",
"k",
")",
";",
"}",
"}",
"else",
"if",
"(",
"(",
"short",
")",
"k",
"==",
"k",
")",
"{",
"add",
"(",
"ByteCode",
".",
"SIPUSH",
",",
"(",
"short",
")",
"k",
")",
";",
"}",
"else",
"{",
"addLoadConstant",
"(",
"k",
")",
";",
"}",
"}"
] |
Generate code to load the given integer on stack.
@param k the constant
|
[
"Generate",
"code",
"to",
"load",
"the",
"given",
"integer",
"on",
"stack",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L904-L918
|
21,460
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addPush
|
public void addPush(long k) {
int ik = (int) k;
if (ik == k) {
addPush(ik);
add(ByteCode.I2L);
} else {
addLoadConstant(k);
}
}
|
java
|
public void addPush(long k) {
int ik = (int) k;
if (ik == k) {
addPush(ik);
add(ByteCode.I2L);
} else {
addLoadConstant(k);
}
}
|
[
"public",
"void",
"addPush",
"(",
"long",
"k",
")",
"{",
"int",
"ik",
"=",
"(",
"int",
")",
"k",
";",
"if",
"(",
"ik",
"==",
"k",
")",
"{",
"addPush",
"(",
"ik",
")",
";",
"add",
"(",
"ByteCode",
".",
"I2L",
")",
";",
"}",
"else",
"{",
"addLoadConstant",
"(",
"k",
")",
";",
"}",
"}"
] |
Generate code to load the given long on stack.
@param k the constant
|
[
"Generate",
"code",
"to",
"load",
"the",
"given",
"long",
"on",
"stack",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L929-L937
|
21,461
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addPush
|
public void addPush(double k) {
if (k == 0.0) {
// zero
add(ByteCode.DCONST_0);
if (1.0 / k < 0) {
// Negative zero
add(ByteCode.DNEG);
}
} else if (k == 1.0 || k == -1.0) {
add(ByteCode.DCONST_1);
if (k < 0) {
add(ByteCode.DNEG);
}
} else {
addLoadConstant(k);
}
}
|
java
|
public void addPush(double k) {
if (k == 0.0) {
// zero
add(ByteCode.DCONST_0);
if (1.0 / k < 0) {
// Negative zero
add(ByteCode.DNEG);
}
} else if (k == 1.0 || k == -1.0) {
add(ByteCode.DCONST_1);
if (k < 0) {
add(ByteCode.DNEG);
}
} else {
addLoadConstant(k);
}
}
|
[
"public",
"void",
"addPush",
"(",
"double",
"k",
")",
"{",
"if",
"(",
"k",
"==",
"0.0",
")",
"{",
"// zero",
"add",
"(",
"ByteCode",
".",
"DCONST_0",
")",
";",
"if",
"(",
"1.0",
"/",
"k",
"<",
"0",
")",
"{",
"// Negative zero",
"add",
"(",
"ByteCode",
".",
"DNEG",
")",
";",
"}",
"}",
"else",
"if",
"(",
"k",
"==",
"1.0",
"||",
"k",
"==",
"-",
"1.0",
")",
"{",
"add",
"(",
"ByteCode",
".",
"DCONST_1",
")",
";",
"if",
"(",
"k",
"<",
"0",
")",
"{",
"add",
"(",
"ByteCode",
".",
"DNEG",
")",
";",
"}",
"}",
"else",
"{",
"addLoadConstant",
"(",
"k",
")",
";",
"}",
"}"
] |
Generate code to load the given double on stack.
@param k the constant
|
[
"Generate",
"code",
"to",
"load",
"the",
"given",
"double",
"on",
"stack",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L944-L960
|
21,462
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addPush
|
public void addPush(String k) {
int length = k.length();
int limit = itsConstantPool.getUtfEncodingLimit(k, 0, length);
if (limit == length) {
addLoadConstant(k);
return;
}
// Split string into picies fitting the UTF limit and generate code for
// StringBuilder sb = new StringBuilder(length);
// sb.append(loadConstant(piece_1));
// ...
// sb.append(loadConstant(piece_N));
// sb.toString();
final String SB = "java/lang/StringBuilder";
add(ByteCode.NEW, SB);
add(ByteCode.DUP);
addPush(length);
addInvoke(ByteCode.INVOKESPECIAL, SB, "<init>", "(I)V");
int cursor = 0;
for (; ; ) {
add(ByteCode.DUP);
String s = k.substring(cursor, limit);
addLoadConstant(s);
addInvoke(ByteCode.INVOKEVIRTUAL, SB, "append",
"(Ljava/lang/String;)Ljava/lang/StringBuilder;");
add(ByteCode.POP);
if (limit == length) {
break;
}
cursor = limit;
limit = itsConstantPool.getUtfEncodingLimit(k, limit, length);
}
addInvoke(ByteCode.INVOKEVIRTUAL, SB, "toString",
"()Ljava/lang/String;");
}
|
java
|
public void addPush(String k) {
int length = k.length();
int limit = itsConstantPool.getUtfEncodingLimit(k, 0, length);
if (limit == length) {
addLoadConstant(k);
return;
}
// Split string into picies fitting the UTF limit and generate code for
// StringBuilder sb = new StringBuilder(length);
// sb.append(loadConstant(piece_1));
// ...
// sb.append(loadConstant(piece_N));
// sb.toString();
final String SB = "java/lang/StringBuilder";
add(ByteCode.NEW, SB);
add(ByteCode.DUP);
addPush(length);
addInvoke(ByteCode.INVOKESPECIAL, SB, "<init>", "(I)V");
int cursor = 0;
for (; ; ) {
add(ByteCode.DUP);
String s = k.substring(cursor, limit);
addLoadConstant(s);
addInvoke(ByteCode.INVOKEVIRTUAL, SB, "append",
"(Ljava/lang/String;)Ljava/lang/StringBuilder;");
add(ByteCode.POP);
if (limit == length) {
break;
}
cursor = limit;
limit = itsConstantPool.getUtfEncodingLimit(k, limit, length);
}
addInvoke(ByteCode.INVOKEVIRTUAL, SB, "toString",
"()Ljava/lang/String;");
}
|
[
"public",
"void",
"addPush",
"(",
"String",
"k",
")",
"{",
"int",
"length",
"=",
"k",
".",
"length",
"(",
")",
";",
"int",
"limit",
"=",
"itsConstantPool",
".",
"getUtfEncodingLimit",
"(",
"k",
",",
"0",
",",
"length",
")",
";",
"if",
"(",
"limit",
"==",
"length",
")",
"{",
"addLoadConstant",
"(",
"k",
")",
";",
"return",
";",
"}",
"// Split string into picies fitting the UTF limit and generate code for",
"// StringBuilder sb = new StringBuilder(length);",
"// sb.append(loadConstant(piece_1));",
"// ...",
"// sb.append(loadConstant(piece_N));",
"// sb.toString();",
"final",
"String",
"SB",
"=",
"\"java/lang/StringBuilder\"",
";",
"add",
"(",
"ByteCode",
".",
"NEW",
",",
"SB",
")",
";",
"add",
"(",
"ByteCode",
".",
"DUP",
")",
";",
"addPush",
"(",
"length",
")",
";",
"addInvoke",
"(",
"ByteCode",
".",
"INVOKESPECIAL",
",",
"SB",
",",
"\"<init>\"",
",",
"\"(I)V\"",
")",
";",
"int",
"cursor",
"=",
"0",
";",
"for",
"(",
";",
";",
")",
"{",
"add",
"(",
"ByteCode",
".",
"DUP",
")",
";",
"String",
"s",
"=",
"k",
".",
"substring",
"(",
"cursor",
",",
"limit",
")",
";",
"addLoadConstant",
"(",
"s",
")",
";",
"addInvoke",
"(",
"ByteCode",
".",
"INVOKEVIRTUAL",
",",
"SB",
",",
"\"append\"",
",",
"\"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"",
")",
";",
"add",
"(",
"ByteCode",
".",
"POP",
")",
";",
"if",
"(",
"limit",
"==",
"length",
")",
"{",
"break",
";",
"}",
"cursor",
"=",
"limit",
";",
"limit",
"=",
"itsConstantPool",
".",
"getUtfEncodingLimit",
"(",
"k",
",",
"limit",
",",
"length",
")",
";",
"}",
"addInvoke",
"(",
"ByteCode",
".",
"INVOKEVIRTUAL",
",",
"SB",
",",
"\"toString\"",
",",
"\"()Ljava/lang/String;\"",
")",
";",
"}"
] |
Generate the code to leave on stack the given string even if the string encoding exeeds the
class file limit for single string constant
@param k the constant
|
[
"Generate",
"the",
"code",
"to",
"leave",
"on",
"stack",
"the",
"given",
"string",
"even",
"if",
"the",
"string",
"encoding",
"exeeds",
"the",
"class",
"file",
"limit",
"for",
"single",
"string",
"constant"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L968-L1002
|
21,463
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.setTableSwitchJump
|
public void setTableSwitchJump(int switchStart, int caseIndex,
int jumpTarget) {
if (jumpTarget < 0 || itsCodeBufferTop < jumpTarget)
throw new IllegalArgumentException("Bad jump target: " + jumpTarget);
if (caseIndex < -1)
throw new IllegalArgumentException("Bad case index: " + caseIndex);
int padSize = 3 & ~switchStart; // == 3 - switchStart % 4
int caseOffset;
if (caseIndex < 0) {
// default label
caseOffset = switchStart + 1 + padSize;
} else {
caseOffset = switchStart + 1 + padSize + 4 * (3 + caseIndex);
}
if (switchStart < 0 || itsCodeBufferTop - 4 * 4 - padSize - 1 < switchStart) {
throw new IllegalArgumentException(
switchStart + " is outside a possible range of tableswitch"
+ " in already generated code");
}
if ((0xFF & itsCodeBuffer[switchStart]) != ByteCode.TABLESWITCH) {
throw new IllegalArgumentException(
switchStart + " is not offset of tableswitch statement");
}
if (caseOffset < 0 || itsCodeBufferTop < caseOffset + 4) {
// caseIndex >= -1 does not guarantee that caseOffset >= 0 due
// to a possible overflow.
throw new ClassFileFormatException("Too big case index: " + caseIndex);
}
// ALERT: perhaps check against case bounds?
putInt32(jumpTarget - switchStart, itsCodeBuffer, caseOffset);
}
|
java
|
public void setTableSwitchJump(int switchStart, int caseIndex,
int jumpTarget) {
if (jumpTarget < 0 || itsCodeBufferTop < jumpTarget)
throw new IllegalArgumentException("Bad jump target: " + jumpTarget);
if (caseIndex < -1)
throw new IllegalArgumentException("Bad case index: " + caseIndex);
int padSize = 3 & ~switchStart; // == 3 - switchStart % 4
int caseOffset;
if (caseIndex < 0) {
// default label
caseOffset = switchStart + 1 + padSize;
} else {
caseOffset = switchStart + 1 + padSize + 4 * (3 + caseIndex);
}
if (switchStart < 0 || itsCodeBufferTop - 4 * 4 - padSize - 1 < switchStart) {
throw new IllegalArgumentException(
switchStart + " is outside a possible range of tableswitch"
+ " in already generated code");
}
if ((0xFF & itsCodeBuffer[switchStart]) != ByteCode.TABLESWITCH) {
throw new IllegalArgumentException(
switchStart + " is not offset of tableswitch statement");
}
if (caseOffset < 0 || itsCodeBufferTop < caseOffset + 4) {
// caseIndex >= -1 does not guarantee that caseOffset >= 0 due
// to a possible overflow.
throw new ClassFileFormatException("Too big case index: " + caseIndex);
}
// ALERT: perhaps check against case bounds?
putInt32(jumpTarget - switchStart, itsCodeBuffer, caseOffset);
}
|
[
"public",
"void",
"setTableSwitchJump",
"(",
"int",
"switchStart",
",",
"int",
"caseIndex",
",",
"int",
"jumpTarget",
")",
"{",
"if",
"(",
"jumpTarget",
"<",
"0",
"||",
"itsCodeBufferTop",
"<",
"jumpTarget",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Bad jump target: \"",
"+",
"jumpTarget",
")",
";",
"if",
"(",
"caseIndex",
"<",
"-",
"1",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Bad case index: \"",
"+",
"caseIndex",
")",
";",
"int",
"padSize",
"=",
"3",
"&",
"~",
"switchStart",
";",
"// == 3 - switchStart % 4",
"int",
"caseOffset",
";",
"if",
"(",
"caseIndex",
"<",
"0",
")",
"{",
"// default label",
"caseOffset",
"=",
"switchStart",
"+",
"1",
"+",
"padSize",
";",
"}",
"else",
"{",
"caseOffset",
"=",
"switchStart",
"+",
"1",
"+",
"padSize",
"+",
"4",
"*",
"(",
"3",
"+",
"caseIndex",
")",
";",
"}",
"if",
"(",
"switchStart",
"<",
"0",
"||",
"itsCodeBufferTop",
"-",
"4",
"*",
"4",
"-",
"padSize",
"-",
"1",
"<",
"switchStart",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"switchStart",
"+",
"\" is outside a possible range of tableswitch\"",
"+",
"\" in already generated code\"",
")",
";",
"}",
"if",
"(",
"(",
"0xFF",
"&",
"itsCodeBuffer",
"[",
"switchStart",
"]",
")",
"!=",
"ByteCode",
".",
"TABLESWITCH",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"switchStart",
"+",
"\" is not offset of tableswitch statement\"",
")",
";",
"}",
"if",
"(",
"caseOffset",
"<",
"0",
"||",
"itsCodeBufferTop",
"<",
"caseOffset",
"+",
"4",
")",
"{",
"// caseIndex >= -1 does not guarantee that caseOffset >= 0 due",
"// to a possible overflow.",
"throw",
"new",
"ClassFileFormatException",
"(",
"\"Too big case index: \"",
"+",
"caseIndex",
")",
";",
"}",
"// ALERT: perhaps check against case bounds?",
"putInt32",
"(",
"jumpTarget",
"-",
"switchStart",
",",
"itsCodeBuffer",
",",
"caseOffset",
")",
";",
"}"
] |
Set a jump case for a tableswitch instruction. The jump target should be marked as a super
block start for stack map generation.
|
[
"Set",
"a",
"jump",
"case",
"for",
"a",
"tableswitch",
"instruction",
".",
"The",
"jump",
"target",
"should",
"be",
"marked",
"as",
"a",
"super",
"block",
"start",
"for",
"stack",
"map",
"generation",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L1192-L1223
|
21,464
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.arrayTypeToName
|
private static char arrayTypeToName(int type) {
switch (type) {
case ByteCode.T_BOOLEAN:
return 'Z';
case ByteCode.T_CHAR:
return 'C';
case ByteCode.T_FLOAT:
return 'F';
case ByteCode.T_DOUBLE:
return 'D';
case ByteCode.T_BYTE:
return 'B';
case ByteCode.T_SHORT:
return 'S';
case ByteCode.T_INT:
return 'I';
case ByteCode.T_LONG:
return 'J';
default:
throw new IllegalArgumentException("bad operand");
}
}
|
java
|
private static char arrayTypeToName(int type) {
switch (type) {
case ByteCode.T_BOOLEAN:
return 'Z';
case ByteCode.T_CHAR:
return 'C';
case ByteCode.T_FLOAT:
return 'F';
case ByteCode.T_DOUBLE:
return 'D';
case ByteCode.T_BYTE:
return 'B';
case ByteCode.T_SHORT:
return 'S';
case ByteCode.T_INT:
return 'I';
case ByteCode.T_LONG:
return 'J';
default:
throw new IllegalArgumentException("bad operand");
}
}
|
[
"private",
"static",
"char",
"arrayTypeToName",
"(",
"int",
"type",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"ByteCode",
".",
"T_BOOLEAN",
":",
"return",
"'",
"'",
";",
"case",
"ByteCode",
".",
"T_CHAR",
":",
"return",
"'",
"'",
";",
"case",
"ByteCode",
".",
"T_FLOAT",
":",
"return",
"'",
"'",
";",
"case",
"ByteCode",
".",
"T_DOUBLE",
":",
"return",
"'",
"'",
";",
"case",
"ByteCode",
".",
"T_BYTE",
":",
"return",
"'",
"'",
";",
"case",
"ByteCode",
".",
"T_SHORT",
":",
"return",
"'",
"'",
";",
"case",
"ByteCode",
".",
"T_INT",
":",
"return",
"'",
"'",
";",
"case",
"ByteCode",
".",
"T_LONG",
":",
"return",
"'",
"'",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"bad operand\"",
")",
";",
"}",
"}"
] |
Convert a newarray operand into an internal type.
|
[
"Convert",
"a",
"newarray",
"operand",
"into",
"an",
"internal",
"type",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L2611-L2632
|
21,465
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.descriptorToInternalName
|
private static String descriptorToInternalName(String descriptor) {
switch (descriptor.charAt(0)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
case 'V':
case '[':
return descriptor;
case 'L':
return classDescriptorToInternalName(descriptor);
default:
throw new IllegalArgumentException("bad descriptor:" +
descriptor);
}
}
|
java
|
private static String descriptorToInternalName(String descriptor) {
switch (descriptor.charAt(0)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
case 'V':
case '[':
return descriptor;
case 'L':
return classDescriptorToInternalName(descriptor);
default:
throw new IllegalArgumentException("bad descriptor:" +
descriptor);
}
}
|
[
"private",
"static",
"String",
"descriptorToInternalName",
"(",
"String",
"descriptor",
")",
"{",
"switch",
"(",
"descriptor",
".",
"charAt",
"(",
"0",
")",
")",
"{",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"return",
"descriptor",
";",
"case",
"'",
"'",
":",
"return",
"classDescriptorToInternalName",
"(",
"descriptor",
")",
";",
"default",
":",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"bad descriptor:\"",
"+",
"descriptor",
")",
";",
"}",
"}"
] |
Convert a non-method type descriptor into an internal type.
@param descriptor the simple type descriptor to convert
|
[
"Convert",
"a",
"non",
"-",
"method",
"type",
"descriptor",
"into",
"an",
"internal",
"type",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L2648-L2667
|
21,466
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.createInitialLocals
|
private int[] createInitialLocals() {
int[] initialLocals = new int[itsMaxLocals];
int localsTop = 0;
// Instance methods require the first local variable in the array
// to be "this". However, if the method being created is a
// constructor, aka the method is <init>, then the type of "this"
// should be StackMapTable.UNINITIALIZED_THIS
if ((itsCurrentMethod.getFlags() & ACC_STATIC) == 0) {
if ("<init>".equals(itsCurrentMethod.getName())) {
initialLocals[localsTop++] = TypeInfo.UNINITIALIZED_THIS;
} else {
initialLocals[localsTop++] = TypeInfo.OBJECT(itsThisClassIndex);
}
}
// No error checking should be necessary, sizeOfParameters does this
String type = itsCurrentMethod.getType();
int lParenIndex = type.indexOf('(');
int rParenIndex = type.indexOf(')');
if (lParenIndex != 0 || rParenIndex < 0) {
throw new IllegalArgumentException("bad method type");
}
int start = lParenIndex + 1;
StringBuilder paramType = new StringBuilder();
while (start < rParenIndex) {
switch (type.charAt(start)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
paramType.append(type.charAt(start));
++start;
break;
case 'L':
int end = type.indexOf(';', start) + 1;
String name = type.substring(start, end);
paramType.append(name);
start = end;
break;
case '[':
paramType.append('[');
++start;
continue;
}
String internalType =
descriptorToInternalName(paramType.toString());
int typeInfo = TypeInfo.fromType(internalType, itsConstantPool);
initialLocals[localsTop++] = typeInfo;
if (TypeInfo.isTwoWords(typeInfo)) {
localsTop++;
}
paramType.setLength(0);
}
return initialLocals;
}
|
java
|
private int[] createInitialLocals() {
int[] initialLocals = new int[itsMaxLocals];
int localsTop = 0;
// Instance methods require the first local variable in the array
// to be "this". However, if the method being created is a
// constructor, aka the method is <init>, then the type of "this"
// should be StackMapTable.UNINITIALIZED_THIS
if ((itsCurrentMethod.getFlags() & ACC_STATIC) == 0) {
if ("<init>".equals(itsCurrentMethod.getName())) {
initialLocals[localsTop++] = TypeInfo.UNINITIALIZED_THIS;
} else {
initialLocals[localsTop++] = TypeInfo.OBJECT(itsThisClassIndex);
}
}
// No error checking should be necessary, sizeOfParameters does this
String type = itsCurrentMethod.getType();
int lParenIndex = type.indexOf('(');
int rParenIndex = type.indexOf(')');
if (lParenIndex != 0 || rParenIndex < 0) {
throw new IllegalArgumentException("bad method type");
}
int start = lParenIndex + 1;
StringBuilder paramType = new StringBuilder();
while (start < rParenIndex) {
switch (type.charAt(start)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
paramType.append(type.charAt(start));
++start;
break;
case 'L':
int end = type.indexOf(';', start) + 1;
String name = type.substring(start, end);
paramType.append(name);
start = end;
break;
case '[':
paramType.append('[');
++start;
continue;
}
String internalType =
descriptorToInternalName(paramType.toString());
int typeInfo = TypeInfo.fromType(internalType, itsConstantPool);
initialLocals[localsTop++] = typeInfo;
if (TypeInfo.isTwoWords(typeInfo)) {
localsTop++;
}
paramType.setLength(0);
}
return initialLocals;
}
|
[
"private",
"int",
"[",
"]",
"createInitialLocals",
"(",
")",
"{",
"int",
"[",
"]",
"initialLocals",
"=",
"new",
"int",
"[",
"itsMaxLocals",
"]",
";",
"int",
"localsTop",
"=",
"0",
";",
"// Instance methods require the first local variable in the array",
"// to be \"this\". However, if the method being created is a",
"// constructor, aka the method is <init>, then the type of \"this\"",
"// should be StackMapTable.UNINITIALIZED_THIS",
"if",
"(",
"(",
"itsCurrentMethod",
".",
"getFlags",
"(",
")",
"&",
"ACC_STATIC",
")",
"==",
"0",
")",
"{",
"if",
"(",
"\"<init>\"",
".",
"equals",
"(",
"itsCurrentMethod",
".",
"getName",
"(",
")",
")",
")",
"{",
"initialLocals",
"[",
"localsTop",
"++",
"]",
"=",
"TypeInfo",
".",
"UNINITIALIZED_THIS",
";",
"}",
"else",
"{",
"initialLocals",
"[",
"localsTop",
"++",
"]",
"=",
"TypeInfo",
".",
"OBJECT",
"(",
"itsThisClassIndex",
")",
";",
"}",
"}",
"// No error checking should be necessary, sizeOfParameters does this",
"String",
"type",
"=",
"itsCurrentMethod",
".",
"getType",
"(",
")",
";",
"int",
"lParenIndex",
"=",
"type",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"int",
"rParenIndex",
"=",
"type",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"lParenIndex",
"!=",
"0",
"||",
"rParenIndex",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"bad method type\"",
")",
";",
"}",
"int",
"start",
"=",
"lParenIndex",
"+",
"1",
";",
"StringBuilder",
"paramType",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"while",
"(",
"start",
"<",
"rParenIndex",
")",
"{",
"switch",
"(",
"type",
".",
"charAt",
"(",
"start",
")",
")",
"{",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"paramType",
".",
"append",
"(",
"type",
".",
"charAt",
"(",
"start",
")",
")",
";",
"++",
"start",
";",
"break",
";",
"case",
"'",
"'",
":",
"int",
"end",
"=",
"type",
".",
"indexOf",
"(",
"'",
"'",
",",
"start",
")",
"+",
"1",
";",
"String",
"name",
"=",
"type",
".",
"substring",
"(",
"start",
",",
"end",
")",
";",
"paramType",
".",
"append",
"(",
"name",
")",
";",
"start",
"=",
"end",
";",
"break",
";",
"case",
"'",
"'",
":",
"paramType",
".",
"append",
"(",
"'",
"'",
")",
";",
"++",
"start",
";",
"continue",
";",
"}",
"String",
"internalType",
"=",
"descriptorToInternalName",
"(",
"paramType",
".",
"toString",
"(",
")",
")",
";",
"int",
"typeInfo",
"=",
"TypeInfo",
".",
"fromType",
"(",
"internalType",
",",
"itsConstantPool",
")",
";",
"initialLocals",
"[",
"localsTop",
"++",
"]",
"=",
"typeInfo",
";",
"if",
"(",
"TypeInfo",
".",
"isTwoWords",
"(",
"typeInfo",
")",
")",
"{",
"localsTop",
"++",
";",
"}",
"paramType",
".",
"setLength",
"(",
"0",
")",
";",
"}",
"return",
"initialLocals",
";",
"}"
] |
Compute the initial local variable array for the current method.
Creates an array of the size of the method's max locals, regardless of the number of parameters
in the method.
|
[
"Compute",
"the",
"initial",
"local",
"variable",
"array",
"for",
"the",
"current",
"method",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L2675-L2733
|
21,467
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.addSuperBlockStart
|
private void addSuperBlockStart(int pc) {
if (GenerateStackMap) {
if (itsSuperBlockStarts == null) {
itsSuperBlockStarts = new int[SuperBlockStartsSize];
} else if (itsSuperBlockStarts.length == itsSuperBlockStartsTop) {
int[] tmp = new int[itsSuperBlockStartsTop * 2];
System.arraycopy(itsSuperBlockStarts, 0, tmp, 0,
itsSuperBlockStartsTop);
itsSuperBlockStarts = tmp;
}
itsSuperBlockStarts[itsSuperBlockStartsTop++] = pc;
}
}
|
java
|
private void addSuperBlockStart(int pc) {
if (GenerateStackMap) {
if (itsSuperBlockStarts == null) {
itsSuperBlockStarts = new int[SuperBlockStartsSize];
} else if (itsSuperBlockStarts.length == itsSuperBlockStartsTop) {
int[] tmp = new int[itsSuperBlockStartsTop * 2];
System.arraycopy(itsSuperBlockStarts, 0, tmp, 0,
itsSuperBlockStartsTop);
itsSuperBlockStarts = tmp;
}
itsSuperBlockStarts[itsSuperBlockStartsTop++] = pc;
}
}
|
[
"private",
"void",
"addSuperBlockStart",
"(",
"int",
"pc",
")",
"{",
"if",
"(",
"GenerateStackMap",
")",
"{",
"if",
"(",
"itsSuperBlockStarts",
"==",
"null",
")",
"{",
"itsSuperBlockStarts",
"=",
"new",
"int",
"[",
"SuperBlockStartsSize",
"]",
";",
"}",
"else",
"if",
"(",
"itsSuperBlockStarts",
".",
"length",
"==",
"itsSuperBlockStartsTop",
")",
"{",
"int",
"[",
"]",
"tmp",
"=",
"new",
"int",
"[",
"itsSuperBlockStartsTop",
"*",
"2",
"]",
";",
"System",
".",
"arraycopy",
"(",
"itsSuperBlockStarts",
",",
"0",
",",
"tmp",
",",
"0",
",",
"itsSuperBlockStartsTop",
")",
";",
"itsSuperBlockStarts",
"=",
"tmp",
";",
"}",
"itsSuperBlockStarts",
"[",
"itsSuperBlockStartsTop",
"++",
"]",
"=",
"pc",
";",
"}",
"}"
] |
Add a pc as the start of super block.
A pc is the beginning of a super block if: - pc == 0 - it is the target of a branch instruction
- it is the beginning of an exception handler - it is directly after an unconditional jump
|
[
"Add",
"a",
"pc",
"as",
"the",
"start",
"of",
"super",
"block",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L4344-L4356
|
21,468
|
mozilla/rhino
|
src/org/mozilla/classfile/ClassFileWriter.java
|
ClassFileWriter.finalizeSuperBlockStarts
|
private void finalizeSuperBlockStarts() {
if (GenerateStackMap) {
for (int i = 0; i < itsExceptionTableTop; i++) {
ExceptionTableEntry ete = itsExceptionTable[i];
int handlerPC = getLabelPC(ete.itsHandlerLabel);
addSuperBlockStart(handlerPC);
}
Arrays.sort(itsSuperBlockStarts, 0, itsSuperBlockStartsTop);
int prev = itsSuperBlockStarts[0];
int copyTo = 1;
for (int i = 1; i < itsSuperBlockStartsTop; i++) {
int curr = itsSuperBlockStarts[i];
if (prev != curr) {
if (copyTo != i) {
itsSuperBlockStarts[copyTo] = curr;
}
copyTo++;
prev = curr;
}
}
itsSuperBlockStartsTop = copyTo;
if (itsSuperBlockStarts[copyTo - 1] == itsCodeBufferTop) {
itsSuperBlockStartsTop--;
}
}
}
|
java
|
private void finalizeSuperBlockStarts() {
if (GenerateStackMap) {
for (int i = 0; i < itsExceptionTableTop; i++) {
ExceptionTableEntry ete = itsExceptionTable[i];
int handlerPC = getLabelPC(ete.itsHandlerLabel);
addSuperBlockStart(handlerPC);
}
Arrays.sort(itsSuperBlockStarts, 0, itsSuperBlockStartsTop);
int prev = itsSuperBlockStarts[0];
int copyTo = 1;
for (int i = 1; i < itsSuperBlockStartsTop; i++) {
int curr = itsSuperBlockStarts[i];
if (prev != curr) {
if (copyTo != i) {
itsSuperBlockStarts[copyTo] = curr;
}
copyTo++;
prev = curr;
}
}
itsSuperBlockStartsTop = copyTo;
if (itsSuperBlockStarts[copyTo - 1] == itsCodeBufferTop) {
itsSuperBlockStartsTop--;
}
}
}
|
[
"private",
"void",
"finalizeSuperBlockStarts",
"(",
")",
"{",
"if",
"(",
"GenerateStackMap",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"itsExceptionTableTop",
";",
"i",
"++",
")",
"{",
"ExceptionTableEntry",
"ete",
"=",
"itsExceptionTable",
"[",
"i",
"]",
";",
"int",
"handlerPC",
"=",
"getLabelPC",
"(",
"ete",
".",
"itsHandlerLabel",
")",
";",
"addSuperBlockStart",
"(",
"handlerPC",
")",
";",
"}",
"Arrays",
".",
"sort",
"(",
"itsSuperBlockStarts",
",",
"0",
",",
"itsSuperBlockStartsTop",
")",
";",
"int",
"prev",
"=",
"itsSuperBlockStarts",
"[",
"0",
"]",
";",
"int",
"copyTo",
"=",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"itsSuperBlockStartsTop",
";",
"i",
"++",
")",
"{",
"int",
"curr",
"=",
"itsSuperBlockStarts",
"[",
"i",
"]",
";",
"if",
"(",
"prev",
"!=",
"curr",
")",
"{",
"if",
"(",
"copyTo",
"!=",
"i",
")",
"{",
"itsSuperBlockStarts",
"[",
"copyTo",
"]",
"=",
"curr",
";",
"}",
"copyTo",
"++",
";",
"prev",
"=",
"curr",
";",
"}",
"}",
"itsSuperBlockStartsTop",
"=",
"copyTo",
";",
"if",
"(",
"itsSuperBlockStarts",
"[",
"copyTo",
"-",
"1",
"]",
"==",
"itsCodeBufferTop",
")",
"{",
"itsSuperBlockStartsTop",
"--",
";",
"}",
"}",
"}"
] |
Sort the list of recorded super block starts and remove duplicates.
Also adds exception handling blocks as block starts, since there is no explicit control flow to
these. Used for stack map table generation.
|
[
"Sort",
"the",
"list",
"of",
"recorded",
"super",
"block",
"starts",
"and",
"remove",
"duplicates",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/classfile/ClassFileWriter.java#L4364-L4389
|
21,469
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/VariableDeclaration.java
|
VariableDeclaration.setVariables
|
public void setVariables(List<VariableInitializer> variables) {
assertNotNull(variables);
this.variables.clear();
for (VariableInitializer vi : variables) {
addVariable(vi);
}
}
|
java
|
public void setVariables(List<VariableInitializer> variables) {
assertNotNull(variables);
this.variables.clear();
for (VariableInitializer vi : variables) {
addVariable(vi);
}
}
|
[
"public",
"void",
"setVariables",
"(",
"List",
"<",
"VariableInitializer",
">",
"variables",
")",
"{",
"assertNotNull",
"(",
"variables",
")",
";",
"this",
".",
"variables",
".",
"clear",
"(",
")",
";",
"for",
"(",
"VariableInitializer",
"vi",
":",
"variables",
")",
"{",
"addVariable",
"(",
"vi",
")",
";",
"}",
"}"
] |
Sets variable list
@throws IllegalArgumentException if variables list is {@code null}
|
[
"Sets",
"variable",
"list"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/VariableDeclaration.java#L58-L64
|
21,470
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/VariableDeclaration.java
|
VariableDeclaration.addVariable
|
public void addVariable(VariableInitializer v) {
assertNotNull(v);
variables.add(v);
v.setParent(this);
}
|
java
|
public void addVariable(VariableInitializer v) {
assertNotNull(v);
variables.add(v);
v.setParent(this);
}
|
[
"public",
"void",
"addVariable",
"(",
"VariableInitializer",
"v",
")",
"{",
"assertNotNull",
"(",
"v",
")",
";",
"variables",
".",
"add",
"(",
"v",
")",
";",
"v",
".",
"setParent",
"(",
"this",
")",
";",
"}"
] |
Adds a variable initializer node to the child list.
Sets initializer node's parent to this node.
@throws IllegalArgumentException if v is {@code null}
|
[
"Adds",
"a",
"variable",
"initializer",
"node",
"to",
"the",
"child",
"list",
".",
"Sets",
"initializer",
"node",
"s",
"parent",
"to",
"this",
"node",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/VariableDeclaration.java#L71-L75
|
21,471
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/VariableDeclaration.java
|
VariableDeclaration.setType
|
@Override
public org.mozilla.javascript.Node setType(int type) {
if (type != Token.VAR
&& type != Token.CONST
&& type != Token.LET)
throw new IllegalArgumentException("invalid decl type: " + type);
return super.setType(type);
}
|
java
|
@Override
public org.mozilla.javascript.Node setType(int type) {
if (type != Token.VAR
&& type != Token.CONST
&& type != Token.LET)
throw new IllegalArgumentException("invalid decl type: " + type);
return super.setType(type);
}
|
[
"@",
"Override",
"public",
"org",
".",
"mozilla",
".",
"javascript",
".",
"Node",
"setType",
"(",
"int",
"type",
")",
"{",
"if",
"(",
"type",
"!=",
"Token",
".",
"VAR",
"&&",
"type",
"!=",
"Token",
".",
"CONST",
"&&",
"type",
"!=",
"Token",
".",
"LET",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid decl type: \"",
"+",
"type",
")",
";",
"return",
"super",
".",
"setType",
"(",
"type",
")",
";",
"}"
] |
Sets the node type and returns this node.
@throws IllegalArgumentException if {@code declType} is invalid
|
[
"Sets",
"the",
"node",
"type",
"and",
"returns",
"this",
"node",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/VariableDeclaration.java#L81-L88
|
21,472
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.addStrictWarning
|
void addStrictWarning(String messageId, String messageArg) {
int beg = -1, end = -1;
if (ts != null) {
beg = ts.tokenBeg;
end = ts.tokenEnd - ts.tokenBeg;
}
addStrictWarning(messageId, messageArg, beg, end);
}
|
java
|
void addStrictWarning(String messageId, String messageArg) {
int beg = -1, end = -1;
if (ts != null) {
beg = ts.tokenBeg;
end = ts.tokenEnd - ts.tokenBeg;
}
addStrictWarning(messageId, messageArg, beg, end);
}
|
[
"void",
"addStrictWarning",
"(",
"String",
"messageId",
",",
"String",
"messageArg",
")",
"{",
"int",
"beg",
"=",
"-",
"1",
",",
"end",
"=",
"-",
"1",
";",
"if",
"(",
"ts",
"!=",
"null",
")",
"{",
"beg",
"=",
"ts",
".",
"tokenBeg",
";",
"end",
"=",
"ts",
".",
"tokenEnd",
"-",
"ts",
".",
"tokenBeg",
";",
"}",
"addStrictWarning",
"(",
"messageId",
",",
"messageArg",
",",
"beg",
",",
"end",
")",
";",
"}"
] |
Add a strict warning on the last matched token.
|
[
"Add",
"a",
"strict",
"warning",
"on",
"the",
"last",
"matched",
"token",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L184-L191
|
21,473
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.peekToken
|
private int peekToken()
throws IOException
{
// By far the most common case: last token hasn't been consumed,
// so return already-peeked token.
if (currentFlaggedToken != Token.EOF) {
return currentToken;
}
int lineno = ts.getLineno();
int tt = ts.getToken();
boolean sawEOL = false;
// process comments and whitespace
while (tt == Token.EOL || tt == Token.COMMENT) {
if (tt == Token.EOL) {
lineno++;
sawEOL = true;
tt = ts.getToken();
} else {
if (compilerEnv.isRecordingComments()) {
String comment = ts.getAndResetCurrentComment();
recordComment(lineno, comment);
// Comments may contain multiple lines, get the number
// of EoLs and increase the lineno
lineno += getNumberOfEols(comment);
break;
}tt = ts.getToken();
}
}
currentToken = tt;
currentFlaggedToken = tt | (sawEOL ? TI_AFTER_EOL : 0);
return currentToken; // return unflagged token
}
|
java
|
private int peekToken()
throws IOException
{
// By far the most common case: last token hasn't been consumed,
// so return already-peeked token.
if (currentFlaggedToken != Token.EOF) {
return currentToken;
}
int lineno = ts.getLineno();
int tt = ts.getToken();
boolean sawEOL = false;
// process comments and whitespace
while (tt == Token.EOL || tt == Token.COMMENT) {
if (tt == Token.EOL) {
lineno++;
sawEOL = true;
tt = ts.getToken();
} else {
if (compilerEnv.isRecordingComments()) {
String comment = ts.getAndResetCurrentComment();
recordComment(lineno, comment);
// Comments may contain multiple lines, get the number
// of EoLs and increase the lineno
lineno += getNumberOfEols(comment);
break;
}tt = ts.getToken();
}
}
currentToken = tt;
currentFlaggedToken = tt | (sawEOL ? TI_AFTER_EOL : 0);
return currentToken; // return unflagged token
}
|
[
"private",
"int",
"peekToken",
"(",
")",
"throws",
"IOException",
"{",
"// By far the most common case: last token hasn't been consumed,",
"// so return already-peeked token.",
"if",
"(",
"currentFlaggedToken",
"!=",
"Token",
".",
"EOF",
")",
"{",
"return",
"currentToken",
";",
"}",
"int",
"lineno",
"=",
"ts",
".",
"getLineno",
"(",
")",
";",
"int",
"tt",
"=",
"ts",
".",
"getToken",
"(",
")",
";",
"boolean",
"sawEOL",
"=",
"false",
";",
"// process comments and whitespace",
"while",
"(",
"tt",
"==",
"Token",
".",
"EOL",
"||",
"tt",
"==",
"Token",
".",
"COMMENT",
")",
"{",
"if",
"(",
"tt",
"==",
"Token",
".",
"EOL",
")",
"{",
"lineno",
"++",
";",
"sawEOL",
"=",
"true",
";",
"tt",
"=",
"ts",
".",
"getToken",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"compilerEnv",
".",
"isRecordingComments",
"(",
")",
")",
"{",
"String",
"comment",
"=",
"ts",
".",
"getAndResetCurrentComment",
"(",
")",
";",
"recordComment",
"(",
"lineno",
",",
"comment",
")",
";",
"// Comments may contain multiple lines, get the number",
"// of EoLs and increase the lineno",
"lineno",
"+=",
"getNumberOfEols",
"(",
"comment",
")",
";",
"break",
";",
"}",
"tt",
"=",
"ts",
".",
"getToken",
"(",
")",
";",
"}",
"}",
"currentToken",
"=",
"tt",
";",
"currentFlaggedToken",
"=",
"tt",
"|",
"(",
"sawEOL",
"?",
"TI_AFTER_EOL",
":",
"0",
")",
";",
"return",
"currentToken",
";",
"// return unflagged token",
"}"
] |
The flags, if any, are saved in currentFlaggedToken.
|
[
"The",
"flags",
"if",
"any",
"are",
"saved",
"in",
"currentFlaggedToken",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L395-L429
|
21,474
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.parse
|
public AstRoot parse(String sourceString, String sourceURI, int lineno)
{
if (parseFinished) throw new IllegalStateException("parser reused");
this.sourceURI = sourceURI;
if (compilerEnv.isIdeMode()) {
this.sourceChars = sourceString.toCharArray();
}
this.ts = new TokenStream(this, null, sourceString, lineno);
try {
return parse();
} catch (IOException iox) {
// Should never happen
throw new IllegalStateException();
} finally {
parseFinished = true;
}
}
|
java
|
public AstRoot parse(String sourceString, String sourceURI, int lineno)
{
if (parseFinished) throw new IllegalStateException("parser reused");
this.sourceURI = sourceURI;
if (compilerEnv.isIdeMode()) {
this.sourceChars = sourceString.toCharArray();
}
this.ts = new TokenStream(this, null, sourceString, lineno);
try {
return parse();
} catch (IOException iox) {
// Should never happen
throw new IllegalStateException();
} finally {
parseFinished = true;
}
}
|
[
"public",
"AstRoot",
"parse",
"(",
"String",
"sourceString",
",",
"String",
"sourceURI",
",",
"int",
"lineno",
")",
"{",
"if",
"(",
"parseFinished",
")",
"throw",
"new",
"IllegalStateException",
"(",
"\"parser reused\"",
")",
";",
"this",
".",
"sourceURI",
"=",
"sourceURI",
";",
"if",
"(",
"compilerEnv",
".",
"isIdeMode",
"(",
")",
")",
"{",
"this",
".",
"sourceChars",
"=",
"sourceString",
".",
"toCharArray",
"(",
")",
";",
"}",
"this",
".",
"ts",
"=",
"new",
"TokenStream",
"(",
"this",
",",
"null",
",",
"sourceString",
",",
"lineno",
")",
";",
"try",
"{",
"return",
"parse",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"iox",
")",
"{",
"// Should never happen",
"throw",
"new",
"IllegalStateException",
"(",
")",
";",
"}",
"finally",
"{",
"parseFinished",
"=",
"true",
";",
"}",
"}"
] |
Builds a parse tree from the given source string.
@return an {@link AstRoot} object representing the parsed program. If
the parse fails, {@code null} will be returned. (The parse failure will
result in a call to the {@link ErrorReporter} from
{@link CompilerEnvirons}.)
|
[
"Builds",
"a",
"parse",
"tree",
"from",
"the",
"given",
"source",
"string",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L584-L600
|
21,475
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.parse
|
public AstRoot parse(Reader sourceReader, String sourceURI, int lineno)
throws IOException
{
if (parseFinished) throw new IllegalStateException("parser reused");
if (compilerEnv.isIdeMode()) {
return parse(readFully(sourceReader), sourceURI, lineno);
}
try {
this.sourceURI = sourceURI;
ts = new TokenStream(this, sourceReader, null, lineno);
return parse();
} finally {
parseFinished = true;
}
}
|
java
|
public AstRoot parse(Reader sourceReader, String sourceURI, int lineno)
throws IOException
{
if (parseFinished) throw new IllegalStateException("parser reused");
if (compilerEnv.isIdeMode()) {
return parse(readFully(sourceReader), sourceURI, lineno);
}
try {
this.sourceURI = sourceURI;
ts = new TokenStream(this, sourceReader, null, lineno);
return parse();
} finally {
parseFinished = true;
}
}
|
[
"public",
"AstRoot",
"parse",
"(",
"Reader",
"sourceReader",
",",
"String",
"sourceURI",
",",
"int",
"lineno",
")",
"throws",
"IOException",
"{",
"if",
"(",
"parseFinished",
")",
"throw",
"new",
"IllegalStateException",
"(",
"\"parser reused\"",
")",
";",
"if",
"(",
"compilerEnv",
".",
"isIdeMode",
"(",
")",
")",
"{",
"return",
"parse",
"(",
"readFully",
"(",
"sourceReader",
")",
",",
"sourceURI",
",",
"lineno",
")",
";",
"}",
"try",
"{",
"this",
".",
"sourceURI",
"=",
"sourceURI",
";",
"ts",
"=",
"new",
"TokenStream",
"(",
"this",
",",
"sourceReader",
",",
"null",
",",
"lineno",
")",
";",
"return",
"parse",
"(",
")",
";",
"}",
"finally",
"{",
"parseFinished",
"=",
"true",
";",
"}",
"}"
] |
Builds a parse tree from the given sourcereader.
@see #parse(String,String,int)
@throws IOException if the {@link Reader} encounters an error
|
[
"Builds",
"a",
"parse",
"tree",
"from",
"the",
"given",
"sourcereader",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L607-L621
|
21,476
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.statements
|
private AstNode statements(AstNode parent) throws IOException {
if (currentToken != Token.LC // assertion can be invalid in bad code
&& !compilerEnv.isIdeMode()) codeBug();
int pos = ts.tokenBeg;
AstNode block = parent != null ? parent : new Block(pos);
block.setLineno(ts.lineno);
int tt;
while ((tt = peekToken()) > Token.EOF && tt != Token.RC) {
block.addChild(statement());
}
block.setLength(ts.tokenBeg - pos);
return block;
}
|
java
|
private AstNode statements(AstNode parent) throws IOException {
if (currentToken != Token.LC // assertion can be invalid in bad code
&& !compilerEnv.isIdeMode()) codeBug();
int pos = ts.tokenBeg;
AstNode block = parent != null ? parent : new Block(pos);
block.setLineno(ts.lineno);
int tt;
while ((tt = peekToken()) > Token.EOF && tt != Token.RC) {
block.addChild(statement());
}
block.setLength(ts.tokenBeg - pos);
return block;
}
|
[
"private",
"AstNode",
"statements",
"(",
"AstNode",
"parent",
")",
"throws",
"IOException",
"{",
"if",
"(",
"currentToken",
"!=",
"Token",
".",
"LC",
"// assertion can be invalid in bad code",
"&&",
"!",
"compilerEnv",
".",
"isIdeMode",
"(",
")",
")",
"codeBug",
"(",
")",
";",
"int",
"pos",
"=",
"ts",
".",
"tokenBeg",
";",
"AstNode",
"block",
"=",
"parent",
"!=",
"null",
"?",
"parent",
":",
"new",
"Block",
"(",
"pos",
")",
";",
"block",
".",
"setLineno",
"(",
"ts",
".",
"lineno",
")",
";",
"int",
"tt",
";",
"while",
"(",
"(",
"tt",
"=",
"peekToken",
"(",
")",
")",
">",
"Token",
".",
"EOF",
"&&",
"tt",
"!=",
"Token",
".",
"RC",
")",
"{",
"block",
".",
"addChild",
"(",
"statement",
"(",
")",
")",
";",
"}",
"block",
".",
"setLength",
"(",
"ts",
".",
"tokenBeg",
"-",
"pos",
")",
";",
"return",
"block",
";",
"}"
] |
node are given relative start positions and correct lengths.
|
[
"node",
"are",
"given",
"relative",
"start",
"positions",
"and",
"correct",
"lengths",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L1070-L1083
|
21,477
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.condition
|
private ConditionData condition()
throws IOException
{
ConditionData data = new ConditionData();
if (mustMatchToken(Token.LP, "msg.no.paren.cond", true))
data.lp = ts.tokenBeg;
data.condition = expr();
if (mustMatchToken(Token.RP, "msg.no.paren.after.cond", true))
data.rp = ts.tokenBeg;
// Report strict warning on code like "if (a = 7) ...". Suppress the
// warning if the condition is parenthesized, like "if ((a = 7)) ...".
if (data.condition instanceof Assignment) {
addStrictWarning("msg.equal.as.assign", "",
data.condition.getPosition(),
data.condition.getLength());
}
return data;
}
|
java
|
private ConditionData condition()
throws IOException
{
ConditionData data = new ConditionData();
if (mustMatchToken(Token.LP, "msg.no.paren.cond", true))
data.lp = ts.tokenBeg;
data.condition = expr();
if (mustMatchToken(Token.RP, "msg.no.paren.after.cond", true))
data.rp = ts.tokenBeg;
// Report strict warning on code like "if (a = 7) ...". Suppress the
// warning if the condition is parenthesized, like "if ((a = 7)) ...".
if (data.condition instanceof Assignment) {
addStrictWarning("msg.equal.as.assign", "",
data.condition.getPosition(),
data.condition.getLength());
}
return data;
}
|
[
"private",
"ConditionData",
"condition",
"(",
")",
"throws",
"IOException",
"{",
"ConditionData",
"data",
"=",
"new",
"ConditionData",
"(",
")",
";",
"if",
"(",
"mustMatchToken",
"(",
"Token",
".",
"LP",
",",
"\"msg.no.paren.cond\"",
",",
"true",
")",
")",
"data",
".",
"lp",
"=",
"ts",
".",
"tokenBeg",
";",
"data",
".",
"condition",
"=",
"expr",
"(",
")",
";",
"if",
"(",
"mustMatchToken",
"(",
"Token",
".",
"RP",
",",
"\"msg.no.paren.after.cond\"",
",",
"true",
")",
")",
"data",
".",
"rp",
"=",
"ts",
".",
"tokenBeg",
";",
"// Report strict warning on code like \"if (a = 7) ...\". Suppress the",
"// warning if the condition is parenthesized, like \"if ((a = 7)) ...\".",
"if",
"(",
"data",
".",
"condition",
"instanceof",
"Assignment",
")",
"{",
"addStrictWarning",
"(",
"\"msg.equal.as.assign\"",
",",
"\"\"",
",",
"data",
".",
"condition",
".",
"getPosition",
"(",
")",
",",
"data",
".",
"condition",
".",
"getLength",
"(",
")",
")",
";",
"}",
"return",
"data",
";",
"}"
] |
parse and return a parenthesized expression
|
[
"parse",
"and",
"return",
"a",
"parenthesized",
"expression"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L1096-L1117
|
21,478
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.nowAllSet
|
private static final boolean nowAllSet(int before, int after, int mask) {
return ((before & mask) != mask) && ((after & mask) == mask);
}
|
java
|
private static final boolean nowAllSet(int before, int after, int mask) {
return ((before & mask) != mask) && ((after & mask) == mask);
}
|
[
"private",
"static",
"final",
"boolean",
"nowAllSet",
"(",
"int",
"before",
",",
"int",
"after",
",",
"int",
"mask",
")",
"{",
"return",
"(",
"(",
"before",
"&",
"mask",
")",
"!=",
"mask",
")",
"&&",
"(",
"(",
"after",
"&",
"mask",
")",
"==",
"mask",
")",
";",
"}"
] |
Returns whether or not the bits in the mask have changed to all set.
@param before bits before change
@param after bits after change
@param mask mask for bits
@return {@code true} if all the bits in the mask are set in "after"
but not in "before"
|
[
"Returns",
"whether",
"or",
"not",
"the",
"bits",
"in",
"the",
"mask",
"have",
"changed",
"to",
"all",
"set",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L1908-L1910
|
21,479
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.variables
|
private VariableDeclaration variables(int declType, int pos, boolean isStatement)
throws IOException
{
int end;
VariableDeclaration pn = new VariableDeclaration(pos);
pn.setType(declType);
pn.setLineno(ts.lineno);
Comment varjsdocNode = getAndResetJsDoc();
if (varjsdocNode != null) {
pn.setJsDocNode(varjsdocNode);
}
// Example:
// var foo = {a: 1, b: 2}, bar = [3, 4];
// var {b: s2, a: s1} = foo, x = 6, y, [s3, s4] = bar;
for (;;) {
AstNode destructuring = null;
Name name = null;
int tt = peekToken(), kidPos = ts.tokenBeg;
end = ts.tokenEnd;
if (tt == Token.LB || tt == Token.LC) {
// Destructuring assignment, e.g., var [a,b] = ...
destructuring = destructuringPrimaryExpr();
end = getNodeEnd(destructuring);
if (!(destructuring instanceof DestructuringForm))
reportError("msg.bad.assign.left", kidPos, end - kidPos);
markDestructuring(destructuring);
} else {
// Simple variable name
mustMatchToken(Token.NAME, "msg.bad.var", true);
name = createNameNode();
name.setLineno(ts.getLineno());
if (inUseStrictDirective) {
String id = ts.getString();
if ("eval".equals(id) || "arguments".equals(ts.getString()))
{
reportError("msg.bad.id.strict", id);
}
}
defineSymbol(declType, ts.getString(), inForInit);
}
int lineno = ts.lineno;
Comment jsdocNode = getAndResetJsDoc();
AstNode init = null;
if (matchToken(Token.ASSIGN, true)) {
init = assignExpr();
end = getNodeEnd(init);
}
VariableInitializer vi = new VariableInitializer(kidPos, end - kidPos);
if (destructuring != null) {
if (init == null && !inForInit) {
reportError("msg.destruct.assign.no.init");
}
vi.setTarget(destructuring);
} else {
vi.setTarget(name);
}
vi.setInitializer(init);
vi.setType(declType);
vi.setJsDocNode(jsdocNode);
vi.setLineno(lineno);
pn.addVariable(vi);
if (!matchToken(Token.COMMA, true))
break;
}
pn.setLength(end - pos);
pn.setIsStatement(isStatement);
return pn;
}
|
java
|
private VariableDeclaration variables(int declType, int pos, boolean isStatement)
throws IOException
{
int end;
VariableDeclaration pn = new VariableDeclaration(pos);
pn.setType(declType);
pn.setLineno(ts.lineno);
Comment varjsdocNode = getAndResetJsDoc();
if (varjsdocNode != null) {
pn.setJsDocNode(varjsdocNode);
}
// Example:
// var foo = {a: 1, b: 2}, bar = [3, 4];
// var {b: s2, a: s1} = foo, x = 6, y, [s3, s4] = bar;
for (;;) {
AstNode destructuring = null;
Name name = null;
int tt = peekToken(), kidPos = ts.tokenBeg;
end = ts.tokenEnd;
if (tt == Token.LB || tt == Token.LC) {
// Destructuring assignment, e.g., var [a,b] = ...
destructuring = destructuringPrimaryExpr();
end = getNodeEnd(destructuring);
if (!(destructuring instanceof DestructuringForm))
reportError("msg.bad.assign.left", kidPos, end - kidPos);
markDestructuring(destructuring);
} else {
// Simple variable name
mustMatchToken(Token.NAME, "msg.bad.var", true);
name = createNameNode();
name.setLineno(ts.getLineno());
if (inUseStrictDirective) {
String id = ts.getString();
if ("eval".equals(id) || "arguments".equals(ts.getString()))
{
reportError("msg.bad.id.strict", id);
}
}
defineSymbol(declType, ts.getString(), inForInit);
}
int lineno = ts.lineno;
Comment jsdocNode = getAndResetJsDoc();
AstNode init = null;
if (matchToken(Token.ASSIGN, true)) {
init = assignExpr();
end = getNodeEnd(init);
}
VariableInitializer vi = new VariableInitializer(kidPos, end - kidPos);
if (destructuring != null) {
if (init == null && !inForInit) {
reportError("msg.destruct.assign.no.init");
}
vi.setTarget(destructuring);
} else {
vi.setTarget(name);
}
vi.setInitializer(init);
vi.setType(declType);
vi.setJsDocNode(jsdocNode);
vi.setLineno(lineno);
pn.addVariable(vi);
if (!matchToken(Token.COMMA, true))
break;
}
pn.setLength(end - pos);
pn.setIsStatement(isStatement);
return pn;
}
|
[
"private",
"VariableDeclaration",
"variables",
"(",
"int",
"declType",
",",
"int",
"pos",
",",
"boolean",
"isStatement",
")",
"throws",
"IOException",
"{",
"int",
"end",
";",
"VariableDeclaration",
"pn",
"=",
"new",
"VariableDeclaration",
"(",
"pos",
")",
";",
"pn",
".",
"setType",
"(",
"declType",
")",
";",
"pn",
".",
"setLineno",
"(",
"ts",
".",
"lineno",
")",
";",
"Comment",
"varjsdocNode",
"=",
"getAndResetJsDoc",
"(",
")",
";",
"if",
"(",
"varjsdocNode",
"!=",
"null",
")",
"{",
"pn",
".",
"setJsDocNode",
"(",
"varjsdocNode",
")",
";",
"}",
"// Example:",
"// var foo = {a: 1, b: 2}, bar = [3, 4];",
"// var {b: s2, a: s1} = foo, x = 6, y, [s3, s4] = bar;",
"for",
"(",
";",
";",
")",
"{",
"AstNode",
"destructuring",
"=",
"null",
";",
"Name",
"name",
"=",
"null",
";",
"int",
"tt",
"=",
"peekToken",
"(",
")",
",",
"kidPos",
"=",
"ts",
".",
"tokenBeg",
";",
"end",
"=",
"ts",
".",
"tokenEnd",
";",
"if",
"(",
"tt",
"==",
"Token",
".",
"LB",
"||",
"tt",
"==",
"Token",
".",
"LC",
")",
"{",
"// Destructuring assignment, e.g., var [a,b] = ...",
"destructuring",
"=",
"destructuringPrimaryExpr",
"(",
")",
";",
"end",
"=",
"getNodeEnd",
"(",
"destructuring",
")",
";",
"if",
"(",
"!",
"(",
"destructuring",
"instanceof",
"DestructuringForm",
")",
")",
"reportError",
"(",
"\"msg.bad.assign.left\"",
",",
"kidPos",
",",
"end",
"-",
"kidPos",
")",
";",
"markDestructuring",
"(",
"destructuring",
")",
";",
"}",
"else",
"{",
"// Simple variable name",
"mustMatchToken",
"(",
"Token",
".",
"NAME",
",",
"\"msg.bad.var\"",
",",
"true",
")",
";",
"name",
"=",
"createNameNode",
"(",
")",
";",
"name",
".",
"setLineno",
"(",
"ts",
".",
"getLineno",
"(",
")",
")",
";",
"if",
"(",
"inUseStrictDirective",
")",
"{",
"String",
"id",
"=",
"ts",
".",
"getString",
"(",
")",
";",
"if",
"(",
"\"eval\"",
".",
"equals",
"(",
"id",
")",
"||",
"\"arguments\"",
".",
"equals",
"(",
"ts",
".",
"getString",
"(",
")",
")",
")",
"{",
"reportError",
"(",
"\"msg.bad.id.strict\"",
",",
"id",
")",
";",
"}",
"}",
"defineSymbol",
"(",
"declType",
",",
"ts",
".",
"getString",
"(",
")",
",",
"inForInit",
")",
";",
"}",
"int",
"lineno",
"=",
"ts",
".",
"lineno",
";",
"Comment",
"jsdocNode",
"=",
"getAndResetJsDoc",
"(",
")",
";",
"AstNode",
"init",
"=",
"null",
";",
"if",
"(",
"matchToken",
"(",
"Token",
".",
"ASSIGN",
",",
"true",
")",
")",
"{",
"init",
"=",
"assignExpr",
"(",
")",
";",
"end",
"=",
"getNodeEnd",
"(",
"init",
")",
";",
"}",
"VariableInitializer",
"vi",
"=",
"new",
"VariableInitializer",
"(",
"kidPos",
",",
"end",
"-",
"kidPos",
")",
";",
"if",
"(",
"destructuring",
"!=",
"null",
")",
"{",
"if",
"(",
"init",
"==",
"null",
"&&",
"!",
"inForInit",
")",
"{",
"reportError",
"(",
"\"msg.destruct.assign.no.init\"",
")",
";",
"}",
"vi",
".",
"setTarget",
"(",
"destructuring",
")",
";",
"}",
"else",
"{",
"vi",
".",
"setTarget",
"(",
"name",
")",
";",
"}",
"vi",
".",
"setInitializer",
"(",
"init",
")",
";",
"vi",
".",
"setType",
"(",
"declType",
")",
";",
"vi",
".",
"setJsDocNode",
"(",
"jsdocNode",
")",
";",
"vi",
".",
"setLineno",
"(",
"lineno",
")",
";",
"pn",
".",
"addVariable",
"(",
"vi",
")",
";",
"if",
"(",
"!",
"matchToken",
"(",
"Token",
".",
"COMMA",
",",
"true",
")",
")",
"break",
";",
"}",
"pn",
".",
"setLength",
"(",
"end",
"-",
"pos",
")",
";",
"pn",
".",
"setIsStatement",
"(",
"isStatement",
")",
";",
"return",
"pn",
";",
"}"
] |
Parse a 'var' or 'const' statement, or a 'var' init list in a for
statement.
@param declType A token value: either VAR, CONST, or LET depending on
context.
@param pos the position where the node should start. It's sometimes
the var/const/let keyword, and other times the beginning of the first
token in the first variable declaration.
@return the parsed variable list
|
[
"Parse",
"a",
"var",
"or",
"const",
"statement",
"or",
"a",
"var",
"init",
"list",
"in",
"a",
"for",
"statement",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L2120-L2193
|
21,480
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.let
|
private AstNode let(boolean isStatement, int pos)
throws IOException
{
LetNode pn = new LetNode(pos);
pn.setLineno(ts.lineno);
if (mustMatchToken(Token.LP, "msg.no.paren.after.let", true))
pn.setLp(ts.tokenBeg - pos);
pushScope(pn);
try {
VariableDeclaration vars = variables(Token.LET, ts.tokenBeg, isStatement);
pn.setVariables(vars);
if (mustMatchToken(Token.RP, "msg.no.paren.let", true)) {
pn.setRp(ts.tokenBeg - pos);
}
if (isStatement && peekToken() == Token.LC) {
// let statement
consumeToken();
int beg = ts.tokenBeg; // position stmt at LC
AstNode stmt = statements();
mustMatchToken(Token.RC, "msg.no.curly.let", true);
stmt.setLength(ts.tokenEnd - beg);
pn.setLength(ts.tokenEnd - pos);
pn.setBody(stmt);
pn.setType(Token.LET);
} else {
// let expression
AstNode expr = expr();
pn.setLength(getNodeEnd(expr) - pos);
pn.setBody(expr);
if (isStatement) {
// let expression in statement context
ExpressionStatement es =
new ExpressionStatement(pn, !insideFunction());
es.setLineno(pn.getLineno());
return es;
}
}
} finally {
popScope();
}
return pn;
}
|
java
|
private AstNode let(boolean isStatement, int pos)
throws IOException
{
LetNode pn = new LetNode(pos);
pn.setLineno(ts.lineno);
if (mustMatchToken(Token.LP, "msg.no.paren.after.let", true))
pn.setLp(ts.tokenBeg - pos);
pushScope(pn);
try {
VariableDeclaration vars = variables(Token.LET, ts.tokenBeg, isStatement);
pn.setVariables(vars);
if (mustMatchToken(Token.RP, "msg.no.paren.let", true)) {
pn.setRp(ts.tokenBeg - pos);
}
if (isStatement && peekToken() == Token.LC) {
// let statement
consumeToken();
int beg = ts.tokenBeg; // position stmt at LC
AstNode stmt = statements();
mustMatchToken(Token.RC, "msg.no.curly.let", true);
stmt.setLength(ts.tokenEnd - beg);
pn.setLength(ts.tokenEnd - pos);
pn.setBody(stmt);
pn.setType(Token.LET);
} else {
// let expression
AstNode expr = expr();
pn.setLength(getNodeEnd(expr) - pos);
pn.setBody(expr);
if (isStatement) {
// let expression in statement context
ExpressionStatement es =
new ExpressionStatement(pn, !insideFunction());
es.setLineno(pn.getLineno());
return es;
}
}
} finally {
popScope();
}
return pn;
}
|
[
"private",
"AstNode",
"let",
"(",
"boolean",
"isStatement",
",",
"int",
"pos",
")",
"throws",
"IOException",
"{",
"LetNode",
"pn",
"=",
"new",
"LetNode",
"(",
"pos",
")",
";",
"pn",
".",
"setLineno",
"(",
"ts",
".",
"lineno",
")",
";",
"if",
"(",
"mustMatchToken",
"(",
"Token",
".",
"LP",
",",
"\"msg.no.paren.after.let\"",
",",
"true",
")",
")",
"pn",
".",
"setLp",
"(",
"ts",
".",
"tokenBeg",
"-",
"pos",
")",
";",
"pushScope",
"(",
"pn",
")",
";",
"try",
"{",
"VariableDeclaration",
"vars",
"=",
"variables",
"(",
"Token",
".",
"LET",
",",
"ts",
".",
"tokenBeg",
",",
"isStatement",
")",
";",
"pn",
".",
"setVariables",
"(",
"vars",
")",
";",
"if",
"(",
"mustMatchToken",
"(",
"Token",
".",
"RP",
",",
"\"msg.no.paren.let\"",
",",
"true",
")",
")",
"{",
"pn",
".",
"setRp",
"(",
"ts",
".",
"tokenBeg",
"-",
"pos",
")",
";",
"}",
"if",
"(",
"isStatement",
"&&",
"peekToken",
"(",
")",
"==",
"Token",
".",
"LC",
")",
"{",
"// let statement",
"consumeToken",
"(",
")",
";",
"int",
"beg",
"=",
"ts",
".",
"tokenBeg",
";",
"// position stmt at LC",
"AstNode",
"stmt",
"=",
"statements",
"(",
")",
";",
"mustMatchToken",
"(",
"Token",
".",
"RC",
",",
"\"msg.no.curly.let\"",
",",
"true",
")",
";",
"stmt",
".",
"setLength",
"(",
"ts",
".",
"tokenEnd",
"-",
"beg",
")",
";",
"pn",
".",
"setLength",
"(",
"ts",
".",
"tokenEnd",
"-",
"pos",
")",
";",
"pn",
".",
"setBody",
"(",
"stmt",
")",
";",
"pn",
".",
"setType",
"(",
"Token",
".",
"LET",
")",
";",
"}",
"else",
"{",
"// let expression",
"AstNode",
"expr",
"=",
"expr",
"(",
")",
";",
"pn",
".",
"setLength",
"(",
"getNodeEnd",
"(",
"expr",
")",
"-",
"pos",
")",
";",
"pn",
".",
"setBody",
"(",
"expr",
")",
";",
"if",
"(",
"isStatement",
")",
"{",
"// let expression in statement context",
"ExpressionStatement",
"es",
"=",
"new",
"ExpressionStatement",
"(",
"pn",
",",
"!",
"insideFunction",
"(",
")",
")",
";",
"es",
".",
"setLineno",
"(",
"pn",
".",
"getLineno",
"(",
")",
")",
";",
"return",
"es",
";",
"}",
"}",
"}",
"finally",
"{",
"popScope",
"(",
")",
";",
"}",
"return",
"pn",
";",
"}"
] |
have to pass in 'let' kwd position to compute kid offsets properly
|
[
"have",
"to",
"pass",
"in",
"let",
"kwd",
"position",
"to",
"compute",
"kid",
"offsets",
"properly"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L2196-L2237
|
21,481
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.propertyAccess
|
private AstNode propertyAccess(int tt, AstNode pn)
throws IOException
{
if (pn == null) codeBug();
int memberTypeFlags = 0, lineno = ts.lineno, dotPos = ts.tokenBeg;
consumeToken();
if (tt == Token.DOTDOT) {
mustHaveXML();
memberTypeFlags = Node.DESCENDANTS_FLAG;
}
if (!compilerEnv.isXmlAvailable()) {
int maybeName = nextToken();
if (maybeName != Token.NAME
&& !(compilerEnv.isReservedKeywordAsIdentifier()
&& TokenStream.isKeyword(ts.getString(), compilerEnv.getLanguageVersion(), inUseStrictDirective))) {
reportError("msg.no.name.after.dot");
}
Name name = createNameNode(true, Token.GETPROP);
PropertyGet pg = new PropertyGet(pn, name, dotPos);
pg.setLineno(lineno);
return pg;
}
AstNode ref = null; // right side of . or .. operator
int token = nextToken();
switch (token) {
case Token.THROW:
// needed for generator.throw();
saveNameTokenData(ts.tokenBeg, "throw", ts.lineno);
ref = propertyName(-1, "throw", memberTypeFlags);
break;
case Token.NAME:
// handles: name, ns::name, ns::*, ns::[expr]
ref = propertyName(-1, ts.getString(), memberTypeFlags);
break;
case Token.MUL:
// handles: *, *::name, *::*, *::[expr]
saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
ref = propertyName(-1, "*", memberTypeFlags);
break;
case Token.XMLATTR:
// handles: '@attr', '@ns::attr', '@ns::*', '@ns::*',
// '@::attr', '@::*', '@*', '@*::attr', '@*::*'
ref = attributeAccess();
break;
case Token.RESERVED: {
String name = ts.getString();
saveNameTokenData(ts.tokenBeg, name, ts.lineno);
ref = propertyName(-1, name, memberTypeFlags);
break;
}
default:
if (compilerEnv.isReservedKeywordAsIdentifier()) {
// allow keywords as property names, e.g. ({if: 1})
String name = Token.keywordToName(token);
if (name != null) {
saveNameTokenData(ts.tokenBeg, name, ts.lineno);
ref = propertyName(-1, name, memberTypeFlags);
break;
}
}
reportError("msg.no.name.after.dot");
return makeErrorNode();
}
boolean xml = ref instanceof XmlRef;
InfixExpression result = xml ? new XmlMemberGet() : new PropertyGet();
if (xml && tt == Token.DOT)
result.setType(Token.DOT);
int pos = pn.getPosition();
result.setPosition(pos);
result.setLength(getNodeEnd(ref) - pos);
result.setOperatorPosition(dotPos - pos);
result.setLineno(pn.getLineno());
result.setLeft(pn); // do this after setting position
result.setRight(ref);
return result;
}
|
java
|
private AstNode propertyAccess(int tt, AstNode pn)
throws IOException
{
if (pn == null) codeBug();
int memberTypeFlags = 0, lineno = ts.lineno, dotPos = ts.tokenBeg;
consumeToken();
if (tt == Token.DOTDOT) {
mustHaveXML();
memberTypeFlags = Node.DESCENDANTS_FLAG;
}
if (!compilerEnv.isXmlAvailable()) {
int maybeName = nextToken();
if (maybeName != Token.NAME
&& !(compilerEnv.isReservedKeywordAsIdentifier()
&& TokenStream.isKeyword(ts.getString(), compilerEnv.getLanguageVersion(), inUseStrictDirective))) {
reportError("msg.no.name.after.dot");
}
Name name = createNameNode(true, Token.GETPROP);
PropertyGet pg = new PropertyGet(pn, name, dotPos);
pg.setLineno(lineno);
return pg;
}
AstNode ref = null; // right side of . or .. operator
int token = nextToken();
switch (token) {
case Token.THROW:
// needed for generator.throw();
saveNameTokenData(ts.tokenBeg, "throw", ts.lineno);
ref = propertyName(-1, "throw", memberTypeFlags);
break;
case Token.NAME:
// handles: name, ns::name, ns::*, ns::[expr]
ref = propertyName(-1, ts.getString(), memberTypeFlags);
break;
case Token.MUL:
// handles: *, *::name, *::*, *::[expr]
saveNameTokenData(ts.tokenBeg, "*", ts.lineno);
ref = propertyName(-1, "*", memberTypeFlags);
break;
case Token.XMLATTR:
// handles: '@attr', '@ns::attr', '@ns::*', '@ns::*',
// '@::attr', '@::*', '@*', '@*::attr', '@*::*'
ref = attributeAccess();
break;
case Token.RESERVED: {
String name = ts.getString();
saveNameTokenData(ts.tokenBeg, name, ts.lineno);
ref = propertyName(-1, name, memberTypeFlags);
break;
}
default:
if (compilerEnv.isReservedKeywordAsIdentifier()) {
// allow keywords as property names, e.g. ({if: 1})
String name = Token.keywordToName(token);
if (name != null) {
saveNameTokenData(ts.tokenBeg, name, ts.lineno);
ref = propertyName(-1, name, memberTypeFlags);
break;
}
}
reportError("msg.no.name.after.dot");
return makeErrorNode();
}
boolean xml = ref instanceof XmlRef;
InfixExpression result = xml ? new XmlMemberGet() : new PropertyGet();
if (xml && tt == Token.DOT)
result.setType(Token.DOT);
int pos = pn.getPosition();
result.setPosition(pos);
result.setLength(getNodeEnd(ref) - pos);
result.setOperatorPosition(dotPos - pos);
result.setLineno(pn.getLineno());
result.setLeft(pn); // do this after setting position
result.setRight(ref);
return result;
}
|
[
"private",
"AstNode",
"propertyAccess",
"(",
"int",
"tt",
",",
"AstNode",
"pn",
")",
"throws",
"IOException",
"{",
"if",
"(",
"pn",
"==",
"null",
")",
"codeBug",
"(",
")",
";",
"int",
"memberTypeFlags",
"=",
"0",
",",
"lineno",
"=",
"ts",
".",
"lineno",
",",
"dotPos",
"=",
"ts",
".",
"tokenBeg",
";",
"consumeToken",
"(",
")",
";",
"if",
"(",
"tt",
"==",
"Token",
".",
"DOTDOT",
")",
"{",
"mustHaveXML",
"(",
")",
";",
"memberTypeFlags",
"=",
"Node",
".",
"DESCENDANTS_FLAG",
";",
"}",
"if",
"(",
"!",
"compilerEnv",
".",
"isXmlAvailable",
"(",
")",
")",
"{",
"int",
"maybeName",
"=",
"nextToken",
"(",
")",
";",
"if",
"(",
"maybeName",
"!=",
"Token",
".",
"NAME",
"&&",
"!",
"(",
"compilerEnv",
".",
"isReservedKeywordAsIdentifier",
"(",
")",
"&&",
"TokenStream",
".",
"isKeyword",
"(",
"ts",
".",
"getString",
"(",
")",
",",
"compilerEnv",
".",
"getLanguageVersion",
"(",
")",
",",
"inUseStrictDirective",
")",
")",
")",
"{",
"reportError",
"(",
"\"msg.no.name.after.dot\"",
")",
";",
"}",
"Name",
"name",
"=",
"createNameNode",
"(",
"true",
",",
"Token",
".",
"GETPROP",
")",
";",
"PropertyGet",
"pg",
"=",
"new",
"PropertyGet",
"(",
"pn",
",",
"name",
",",
"dotPos",
")",
";",
"pg",
".",
"setLineno",
"(",
"lineno",
")",
";",
"return",
"pg",
";",
"}",
"AstNode",
"ref",
"=",
"null",
";",
"// right side of . or .. operator",
"int",
"token",
"=",
"nextToken",
"(",
")",
";",
"switch",
"(",
"token",
")",
"{",
"case",
"Token",
".",
"THROW",
":",
"// needed for generator.throw();",
"saveNameTokenData",
"(",
"ts",
".",
"tokenBeg",
",",
"\"throw\"",
",",
"ts",
".",
"lineno",
")",
";",
"ref",
"=",
"propertyName",
"(",
"-",
"1",
",",
"\"throw\"",
",",
"memberTypeFlags",
")",
";",
"break",
";",
"case",
"Token",
".",
"NAME",
":",
"// handles: name, ns::name, ns::*, ns::[expr]",
"ref",
"=",
"propertyName",
"(",
"-",
"1",
",",
"ts",
".",
"getString",
"(",
")",
",",
"memberTypeFlags",
")",
";",
"break",
";",
"case",
"Token",
".",
"MUL",
":",
"// handles: *, *::name, *::*, *::[expr]",
"saveNameTokenData",
"(",
"ts",
".",
"tokenBeg",
",",
"\"*\"",
",",
"ts",
".",
"lineno",
")",
";",
"ref",
"=",
"propertyName",
"(",
"-",
"1",
",",
"\"*\"",
",",
"memberTypeFlags",
")",
";",
"break",
";",
"case",
"Token",
".",
"XMLATTR",
":",
"// handles: '@attr', '@ns::attr', '@ns::*', '@ns::*',",
"// '@::attr', '@::*', '@*', '@*::attr', '@*::*'",
"ref",
"=",
"attributeAccess",
"(",
")",
";",
"break",
";",
"case",
"Token",
".",
"RESERVED",
":",
"{",
"String",
"name",
"=",
"ts",
".",
"getString",
"(",
")",
";",
"saveNameTokenData",
"(",
"ts",
".",
"tokenBeg",
",",
"name",
",",
"ts",
".",
"lineno",
")",
";",
"ref",
"=",
"propertyName",
"(",
"-",
"1",
",",
"name",
",",
"memberTypeFlags",
")",
";",
"break",
";",
"}",
"default",
":",
"if",
"(",
"compilerEnv",
".",
"isReservedKeywordAsIdentifier",
"(",
")",
")",
"{",
"// allow keywords as property names, e.g. ({if: 1})",
"String",
"name",
"=",
"Token",
".",
"keywordToName",
"(",
"token",
")",
";",
"if",
"(",
"name",
"!=",
"null",
")",
"{",
"saveNameTokenData",
"(",
"ts",
".",
"tokenBeg",
",",
"name",
",",
"ts",
".",
"lineno",
")",
";",
"ref",
"=",
"propertyName",
"(",
"-",
"1",
",",
"name",
",",
"memberTypeFlags",
")",
";",
"break",
";",
"}",
"}",
"reportError",
"(",
"\"msg.no.name.after.dot\"",
")",
";",
"return",
"makeErrorNode",
"(",
")",
";",
"}",
"boolean",
"xml",
"=",
"ref",
"instanceof",
"XmlRef",
";",
"InfixExpression",
"result",
"=",
"xml",
"?",
"new",
"XmlMemberGet",
"(",
")",
":",
"new",
"PropertyGet",
"(",
")",
";",
"if",
"(",
"xml",
"&&",
"tt",
"==",
"Token",
".",
"DOT",
")",
"result",
".",
"setType",
"(",
"Token",
".",
"DOT",
")",
";",
"int",
"pos",
"=",
"pn",
".",
"getPosition",
"(",
")",
";",
"result",
".",
"setPosition",
"(",
"pos",
")",
";",
"result",
".",
"setLength",
"(",
"getNodeEnd",
"(",
"ref",
")",
"-",
"pos",
")",
";",
"result",
".",
"setOperatorPosition",
"(",
"dotPos",
"-",
"pos",
")",
";",
"result",
".",
"setLineno",
"(",
"pn",
".",
"getLineno",
"(",
")",
")",
";",
"result",
".",
"setLeft",
"(",
"pn",
")",
";",
"// do this after setting position",
"result",
".",
"setRight",
"(",
"ref",
")",
";",
"return",
"result",
";",
"}"
] |
Handles any construct following a "." or ".." operator.
@param pn the left-hand side (target) of the operator. Never null.
@return a PropertyGet, XmlMemberGet, or ErrorNode
|
[
"Handles",
"any",
"construct",
"following",
"a",
".",
"or",
"..",
"operator",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L2881-L2967
|
21,482
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.arrayComprehension
|
private AstNode arrayComprehension(AstNode result, int pos)
throws IOException
{
List<ArrayComprehensionLoop> loops =
new ArrayList<ArrayComprehensionLoop>();
while (peekToken() == Token.FOR) {
loops.add(arrayComprehensionLoop());
}
int ifPos = -1;
ConditionData data = null;
if (peekToken() == Token.IF) {
consumeToken();
ifPos = ts.tokenBeg - pos;
data = condition();
}
mustMatchToken(Token.RB, "msg.no.bracket.arg", true);
ArrayComprehension pn = new ArrayComprehension(pos, ts.tokenEnd - pos);
pn.setResult(result);
pn.setLoops(loops);
if (data != null) {
pn.setIfPosition(ifPos);
pn.setFilter(data.condition);
pn.setFilterLp(data.lp - pos);
pn.setFilterRp(data.rp - pos);
}
return pn;
}
|
java
|
private AstNode arrayComprehension(AstNode result, int pos)
throws IOException
{
List<ArrayComprehensionLoop> loops =
new ArrayList<ArrayComprehensionLoop>();
while (peekToken() == Token.FOR) {
loops.add(arrayComprehensionLoop());
}
int ifPos = -1;
ConditionData data = null;
if (peekToken() == Token.IF) {
consumeToken();
ifPos = ts.tokenBeg - pos;
data = condition();
}
mustMatchToken(Token.RB, "msg.no.bracket.arg", true);
ArrayComprehension pn = new ArrayComprehension(pos, ts.tokenEnd - pos);
pn.setResult(result);
pn.setLoops(loops);
if (data != null) {
pn.setIfPosition(ifPos);
pn.setFilter(data.condition);
pn.setFilterLp(data.lp - pos);
pn.setFilterRp(data.rp - pos);
}
return pn;
}
|
[
"private",
"AstNode",
"arrayComprehension",
"(",
"AstNode",
"result",
",",
"int",
"pos",
")",
"throws",
"IOException",
"{",
"List",
"<",
"ArrayComprehensionLoop",
">",
"loops",
"=",
"new",
"ArrayList",
"<",
"ArrayComprehensionLoop",
">",
"(",
")",
";",
"while",
"(",
"peekToken",
"(",
")",
"==",
"Token",
".",
"FOR",
")",
"{",
"loops",
".",
"add",
"(",
"arrayComprehensionLoop",
"(",
")",
")",
";",
"}",
"int",
"ifPos",
"=",
"-",
"1",
";",
"ConditionData",
"data",
"=",
"null",
";",
"if",
"(",
"peekToken",
"(",
")",
"==",
"Token",
".",
"IF",
")",
"{",
"consumeToken",
"(",
")",
";",
"ifPos",
"=",
"ts",
".",
"tokenBeg",
"-",
"pos",
";",
"data",
"=",
"condition",
"(",
")",
";",
"}",
"mustMatchToken",
"(",
"Token",
".",
"RB",
",",
"\"msg.no.bracket.arg\"",
",",
"true",
")",
";",
"ArrayComprehension",
"pn",
"=",
"new",
"ArrayComprehension",
"(",
"pos",
",",
"ts",
".",
"tokenEnd",
"-",
"pos",
")",
";",
"pn",
".",
"setResult",
"(",
"result",
")",
";",
"pn",
".",
"setLoops",
"(",
"loops",
")",
";",
"if",
"(",
"data",
"!=",
"null",
")",
"{",
"pn",
".",
"setIfPosition",
"(",
"ifPos",
")",
";",
"pn",
".",
"setFilter",
"(",
"data",
".",
"condition",
")",
";",
"pn",
".",
"setFilterLp",
"(",
"data",
".",
"lp",
"-",
"pos",
")",
";",
"pn",
".",
"setFilterRp",
"(",
"data",
".",
"rp",
"-",
"pos",
")",
";",
"}",
"return",
"pn",
";",
"}"
] |
Parse a JavaScript 1.7 Array comprehension.
@param result the first expression after the opening left-bracket
@param pos start of LB token that begins the array comprehension
@return the array comprehension or an error node
|
[
"Parse",
"a",
"JavaScript",
"1",
".",
"7",
"Array",
"comprehension",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L3323-L3349
|
21,483
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.lineBeginningFor
|
private int lineBeginningFor(int pos) {
if (sourceChars == null) {
return -1;
}
if (pos <= 0) {
return 0;
}
char[] buf = sourceChars;
if (pos >= buf.length) {
pos = buf.length - 1;
}
while (--pos >= 0) {
char c = buf[pos];
if (ScriptRuntime.isJSLineTerminator(c)) {
return pos + 1; // want position after the newline
}
}
return 0;
}
|
java
|
private int lineBeginningFor(int pos) {
if (sourceChars == null) {
return -1;
}
if (pos <= 0) {
return 0;
}
char[] buf = sourceChars;
if (pos >= buf.length) {
pos = buf.length - 1;
}
while (--pos >= 0) {
char c = buf[pos];
if (ScriptRuntime.isJSLineTerminator(c)) {
return pos + 1; // want position after the newline
}
}
return 0;
}
|
[
"private",
"int",
"lineBeginningFor",
"(",
"int",
"pos",
")",
"{",
"if",
"(",
"sourceChars",
"==",
"null",
")",
"{",
"return",
"-",
"1",
";",
"}",
"if",
"(",
"pos",
"<=",
"0",
")",
"{",
"return",
"0",
";",
"}",
"char",
"[",
"]",
"buf",
"=",
"sourceChars",
";",
"if",
"(",
"pos",
">=",
"buf",
".",
"length",
")",
"{",
"pos",
"=",
"buf",
".",
"length",
"-",
"1",
";",
"}",
"while",
"(",
"--",
"pos",
">=",
"0",
")",
"{",
"char",
"c",
"=",
"buf",
"[",
"pos",
"]",
";",
"if",
"(",
"ScriptRuntime",
".",
"isJSLineTerminator",
"(",
"c",
")",
")",
"{",
"return",
"pos",
"+",
"1",
";",
"// want position after the newline",
"}",
"}",
"return",
"0",
";",
"}"
] |
Return the file offset of the beginning of the input source line
containing the passed position.
@param pos an offset into the input source stream. If the offset
is negative, it's converted to 0, and if it's beyond the end of
the source buffer, the last source position is used.
@return the offset of the beginning of the line containing pos
(i.e. 1+ the offset of the first preceding newline). Returns -1
if the {@link CompilerEnvirons} is not set to ide-mode,
and {@link #parse(java.io.Reader,String,int)} was used.
|
[
"Return",
"the",
"file",
"offset",
"of",
"the",
"beginning",
"of",
"the",
"input",
"source",
"line",
"containing",
"the",
"passed",
"position",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L3872-L3890
|
21,484
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.createDestructuringAssignment
|
Node createDestructuringAssignment(int type, Node left, Node right)
{
String tempName = currentScriptOrFn.getNextTempName();
Node result = destructuringAssignmentHelper(type, left, right,
tempName);
Node comma = result.getLastChild();
comma.addChildToBack(createName(tempName));
return result;
}
|
java
|
Node createDestructuringAssignment(int type, Node left, Node right)
{
String tempName = currentScriptOrFn.getNextTempName();
Node result = destructuringAssignmentHelper(type, left, right,
tempName);
Node comma = result.getLastChild();
comma.addChildToBack(createName(tempName));
return result;
}
|
[
"Node",
"createDestructuringAssignment",
"(",
"int",
"type",
",",
"Node",
"left",
",",
"Node",
"right",
")",
"{",
"String",
"tempName",
"=",
"currentScriptOrFn",
".",
"getNextTempName",
"(",
")",
";",
"Node",
"result",
"=",
"destructuringAssignmentHelper",
"(",
"type",
",",
"left",
",",
"right",
",",
"tempName",
")",
";",
"Node",
"comma",
"=",
"result",
".",
"getLastChild",
"(",
")",
";",
"comma",
".",
"addChildToBack",
"(",
"createName",
"(",
"tempName",
")",
")",
";",
"return",
"result",
";",
"}"
] |
Given a destructuring assignment with a left hand side parsed
as an array or object literal and a right hand side expression,
rewrite as a series of assignments to the variables defined in
left from property accesses to the expression on the right.
@param type declaration type: Token.VAR or Token.LET or -1
@param left array or object literal containing NAME nodes for
variables to assign
@param right expression to assign from
@return expression that performs a series of assignments to
the variables defined in left
|
[
"Given",
"a",
"destructuring",
"assignment",
"with",
"a",
"left",
"hand",
"side",
"parsed",
"as",
"an",
"array",
"or",
"object",
"literal",
"and",
"a",
"right",
"hand",
"side",
"expression",
"rewrite",
"as",
"a",
"series",
"of",
"assignments",
"to",
"the",
"variables",
"defined",
"in",
"left",
"from",
"property",
"accesses",
"to",
"the",
"expression",
"on",
"the",
"right",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L3996-L4004
|
21,485
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.simpleAssignment
|
protected Node simpleAssignment(Node left, Node right) {
int nodeType = left.getType();
switch (nodeType) {
case Token.NAME:
String name = ((Name) left).getIdentifier();
if (inUseStrictDirective &&
("eval".equals(name) || "arguments".equals(name)))
{
reportError("msg.bad.id.strict", name);
}
left.setType(Token.BINDNAME);
return new Node(Token.SETNAME, left, right);
case Token.GETPROP:
case Token.GETELEM: {
Node obj, id;
// If it's a PropertyGet or ElementGet, we're in the parse pass.
// We could alternately have PropertyGet and ElementGet
// override getFirstChild/getLastChild and return the appropriate
// field, but that seems just as ugly as this casting.
if (left instanceof PropertyGet) {
obj = ((PropertyGet)left).getTarget();
id = ((PropertyGet)left).getProperty();
} else if (left instanceof ElementGet) {
obj = ((ElementGet)left).getTarget();
id = ((ElementGet)left).getElement();
} else {
// This branch is called during IRFactory transform pass.
obj = left.getFirstChild();
id = left.getLastChild();
}
int type;
if (nodeType == Token.GETPROP) {
type = Token.SETPROP;
// TODO(stevey) - see https://bugzilla.mozilla.org/show_bug.cgi?id=492036
// The new AST code generates NAME tokens for GETPROP ids where the old parser
// generated STRING nodes. If we don't set the type to STRING below, this will
// cause java.lang.VerifyError in codegen for code like
// "var obj={p:3};[obj.p]=[9];"
id.setType(Token.STRING);
} else {
type = Token.SETELEM;
}
return new Node(type, obj, id, right);
}
case Token.GET_REF: {
Node ref = left.getFirstChild();
checkMutableReference(ref);
return new Node(Token.SET_REF, ref, right);
}
}
throw codeBug();
}
|
java
|
protected Node simpleAssignment(Node left, Node right) {
int nodeType = left.getType();
switch (nodeType) {
case Token.NAME:
String name = ((Name) left).getIdentifier();
if (inUseStrictDirective &&
("eval".equals(name) || "arguments".equals(name)))
{
reportError("msg.bad.id.strict", name);
}
left.setType(Token.BINDNAME);
return new Node(Token.SETNAME, left, right);
case Token.GETPROP:
case Token.GETELEM: {
Node obj, id;
// If it's a PropertyGet or ElementGet, we're in the parse pass.
// We could alternately have PropertyGet and ElementGet
// override getFirstChild/getLastChild and return the appropriate
// field, but that seems just as ugly as this casting.
if (left instanceof PropertyGet) {
obj = ((PropertyGet)left).getTarget();
id = ((PropertyGet)left).getProperty();
} else if (left instanceof ElementGet) {
obj = ((ElementGet)left).getTarget();
id = ((ElementGet)left).getElement();
} else {
// This branch is called during IRFactory transform pass.
obj = left.getFirstChild();
id = left.getLastChild();
}
int type;
if (nodeType == Token.GETPROP) {
type = Token.SETPROP;
// TODO(stevey) - see https://bugzilla.mozilla.org/show_bug.cgi?id=492036
// The new AST code generates NAME tokens for GETPROP ids where the old parser
// generated STRING nodes. If we don't set the type to STRING below, this will
// cause java.lang.VerifyError in codegen for code like
// "var obj={p:3};[obj.p]=[9];"
id.setType(Token.STRING);
} else {
type = Token.SETELEM;
}
return new Node(type, obj, id, right);
}
case Token.GET_REF: {
Node ref = left.getFirstChild();
checkMutableReference(ref);
return new Node(Token.SET_REF, ref, right);
}
}
throw codeBug();
}
|
[
"protected",
"Node",
"simpleAssignment",
"(",
"Node",
"left",
",",
"Node",
"right",
")",
"{",
"int",
"nodeType",
"=",
"left",
".",
"getType",
"(",
")",
";",
"switch",
"(",
"nodeType",
")",
"{",
"case",
"Token",
".",
"NAME",
":",
"String",
"name",
"=",
"(",
"(",
"Name",
")",
"left",
")",
".",
"getIdentifier",
"(",
")",
";",
"if",
"(",
"inUseStrictDirective",
"&&",
"(",
"\"eval\"",
".",
"equals",
"(",
"name",
")",
"||",
"\"arguments\"",
".",
"equals",
"(",
"name",
")",
")",
")",
"{",
"reportError",
"(",
"\"msg.bad.id.strict\"",
",",
"name",
")",
";",
"}",
"left",
".",
"setType",
"(",
"Token",
".",
"BINDNAME",
")",
";",
"return",
"new",
"Node",
"(",
"Token",
".",
"SETNAME",
",",
"left",
",",
"right",
")",
";",
"case",
"Token",
".",
"GETPROP",
":",
"case",
"Token",
".",
"GETELEM",
":",
"{",
"Node",
"obj",
",",
"id",
";",
"// If it's a PropertyGet or ElementGet, we're in the parse pass.",
"// We could alternately have PropertyGet and ElementGet",
"// override getFirstChild/getLastChild and return the appropriate",
"// field, but that seems just as ugly as this casting.",
"if",
"(",
"left",
"instanceof",
"PropertyGet",
")",
"{",
"obj",
"=",
"(",
"(",
"PropertyGet",
")",
"left",
")",
".",
"getTarget",
"(",
")",
";",
"id",
"=",
"(",
"(",
"PropertyGet",
")",
"left",
")",
".",
"getProperty",
"(",
")",
";",
"}",
"else",
"if",
"(",
"left",
"instanceof",
"ElementGet",
")",
"{",
"obj",
"=",
"(",
"(",
"ElementGet",
")",
"left",
")",
".",
"getTarget",
"(",
")",
";",
"id",
"=",
"(",
"(",
"ElementGet",
")",
"left",
")",
".",
"getElement",
"(",
")",
";",
"}",
"else",
"{",
"// This branch is called during IRFactory transform pass.",
"obj",
"=",
"left",
".",
"getFirstChild",
"(",
")",
";",
"id",
"=",
"left",
".",
"getLastChild",
"(",
")",
";",
"}",
"int",
"type",
";",
"if",
"(",
"nodeType",
"==",
"Token",
".",
"GETPROP",
")",
"{",
"type",
"=",
"Token",
".",
"SETPROP",
";",
"// TODO(stevey) - see https://bugzilla.mozilla.org/show_bug.cgi?id=492036",
"// The new AST code generates NAME tokens for GETPROP ids where the old parser",
"// generated STRING nodes. If we don't set the type to STRING below, this will",
"// cause java.lang.VerifyError in codegen for code like",
"// \"var obj={p:3};[obj.p]=[9];\"",
"id",
".",
"setType",
"(",
"Token",
".",
"STRING",
")",
";",
"}",
"else",
"{",
"type",
"=",
"Token",
".",
"SETELEM",
";",
"}",
"return",
"new",
"Node",
"(",
"type",
",",
"obj",
",",
"id",
",",
"right",
")",
";",
"}",
"case",
"Token",
".",
"GET_REF",
":",
"{",
"Node",
"ref",
"=",
"left",
".",
"getFirstChild",
"(",
")",
";",
"checkMutableReference",
"(",
"ref",
")",
";",
"return",
"new",
"Node",
"(",
"Token",
".",
"SET_REF",
",",
"ref",
",",
"right",
")",
";",
"}",
"}",
"throw",
"codeBug",
"(",
")",
";",
"}"
] |
side effects in the RHS.
|
[
"side",
"effects",
"in",
"the",
"RHS",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L4204-L4257
|
21,486
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.removeParens
|
protected AstNode removeParens(AstNode node) {
while (node instanceof ParenthesizedExpression) {
node = ((ParenthesizedExpression)node).getExpression();
}
return node;
}
|
java
|
protected AstNode removeParens(AstNode node) {
while (node instanceof ParenthesizedExpression) {
node = ((ParenthesizedExpression)node).getExpression();
}
return node;
}
|
[
"protected",
"AstNode",
"removeParens",
"(",
"AstNode",
"node",
")",
"{",
"while",
"(",
"node",
"instanceof",
"ParenthesizedExpression",
")",
"{",
"node",
"=",
"(",
"(",
"ParenthesizedExpression",
")",
"node",
")",
".",
"getExpression",
"(",
")",
";",
"}",
"return",
"node",
";",
"}"
] |
remove any ParenthesizedExpression wrappers
|
[
"remove",
"any",
"ParenthesizedExpression",
"wrappers"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L4267-L4272
|
21,487
|
mozilla/rhino
|
src/org/mozilla/javascript/Parser.java
|
Parser.codeBug
|
private RuntimeException codeBug()
throws RuntimeException
{
throw Kit.codeBug("ts.cursor=" + ts.cursor
+ ", ts.tokenBeg=" + ts.tokenBeg
+ ", currentToken=" + currentToken);
}
|
java
|
private RuntimeException codeBug()
throws RuntimeException
{
throw Kit.codeBug("ts.cursor=" + ts.cursor
+ ", ts.tokenBeg=" + ts.tokenBeg
+ ", currentToken=" + currentToken);
}
|
[
"private",
"RuntimeException",
"codeBug",
"(",
")",
"throws",
"RuntimeException",
"{",
"throw",
"Kit",
".",
"codeBug",
"(",
"\"ts.cursor=\"",
"+",
"ts",
".",
"cursor",
"+",
"\", ts.tokenBeg=\"",
"+",
"ts",
".",
"tokenBeg",
"+",
"\", currentToken=\"",
"+",
"currentToken",
")",
";",
"}"
] |
throw a failed-assertion with some helpful debugging info
|
[
"throw",
"a",
"failed",
"-",
"assertion",
"with",
"some",
"helpful",
"debugging",
"info"
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/Parser.java#L4283-L4289
|
21,488
|
mozilla/rhino
|
src/org/mozilla/javascript/jdk18/VMBridge_jdk18.java
|
VMBridge_jdk18.getJavaIterator
|
@Override
protected Iterator<?> getJavaIterator(Context cx, Scriptable scope, Object obj) {
if (obj instanceof Wrapper) {
Object unwrapped = ((Wrapper) obj).unwrap();
Iterator<?> iterator = null;
if (unwrapped instanceof Iterator)
iterator = (Iterator<?>) unwrapped;
if (unwrapped instanceof Iterable)
iterator = ((Iterable<?>)unwrapped).iterator();
return iterator;
}
return null;
}
|
java
|
@Override
protected Iterator<?> getJavaIterator(Context cx, Scriptable scope, Object obj) {
if (obj instanceof Wrapper) {
Object unwrapped = ((Wrapper) obj).unwrap();
Iterator<?> iterator = null;
if (unwrapped instanceof Iterator)
iterator = (Iterator<?>) unwrapped;
if (unwrapped instanceof Iterable)
iterator = ((Iterable<?>)unwrapped).iterator();
return iterator;
}
return null;
}
|
[
"@",
"Override",
"protected",
"Iterator",
"<",
"?",
">",
"getJavaIterator",
"(",
"Context",
"cx",
",",
"Scriptable",
"scope",
",",
"Object",
"obj",
")",
"{",
"if",
"(",
"obj",
"instanceof",
"Wrapper",
")",
"{",
"Object",
"unwrapped",
"=",
"(",
"(",
"Wrapper",
")",
"obj",
")",
".",
"unwrap",
"(",
")",
";",
"Iterator",
"<",
"?",
">",
"iterator",
"=",
"null",
";",
"if",
"(",
"unwrapped",
"instanceof",
"Iterator",
")",
"iterator",
"=",
"(",
"Iterator",
"<",
"?",
">",
")",
"unwrapped",
";",
"if",
"(",
"unwrapped",
"instanceof",
"Iterable",
")",
"iterator",
"=",
"(",
"(",
"Iterable",
"<",
"?",
">",
")",
"unwrapped",
")",
".",
"iterator",
"(",
")",
";",
"return",
"iterator",
";",
"}",
"return",
"null",
";",
"}"
] |
If "obj" is a java.util.Iterator or a java.lang.Iterable, return a
wrapping as a JavaScript Iterator. Otherwise, return null.
This method is in VMBridge since Iterable is a JDK 1.5 addition.
|
[
"If",
"obj",
"is",
"a",
"java",
".",
"util",
".",
"Iterator",
"or",
"a",
"java",
".",
"lang",
".",
"Iterable",
"return",
"a",
"wrapping",
"as",
"a",
"JavaScript",
"Iterator",
".",
"Otherwise",
"return",
"null",
".",
"This",
"method",
"is",
"in",
"VMBridge",
"since",
"Iterable",
"is",
"a",
"JDK",
"1",
".",
"5",
"addition",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/jdk18/VMBridge_jdk18.java#L152-L164
|
21,489
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/PropertyGet.java
|
PropertyGet.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
getTarget().visit(v);
getProperty().visit(v);
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
getTarget().visit(v);
getProperty().visit(v);
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"getTarget",
"(",
")",
".",
"visit",
"(",
"v",
")",
";",
"getProperty",
"(",
")",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}"
] |
Visits this node, the target expression, and the property name.
|
[
"Visits",
"this",
"node",
"the",
"target",
"expression",
"and",
"the",
"property",
"name",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/PropertyGet.java#L93-L99
|
21,490
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/DoLoop.java
|
DoLoop.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
body.visit(v);
condition.visit(v);
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
body.visit(v);
condition.visit(v);
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"body",
".",
"visit",
"(",
"v",
")",
";",
"condition",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}"
] |
Visits this node, the body, and then the while-expression.
|
[
"Visits",
"this",
"node",
"the",
"body",
"and",
"then",
"the",
"while",
"-",
"expression",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/DoLoop.java#L86-L92
|
21,491
|
mozilla/rhino
|
src/org/mozilla/javascript/InterfaceAdapter.java
|
InterfaceAdapter.create
|
static Object create(Context cx, Class<?> cl, ScriptableObject object)
{
if (!cl.isInterface()) throw new IllegalArgumentException();
Scriptable topScope = ScriptRuntime.getTopCallScope(cx);
ClassCache cache = ClassCache.get(topScope);
InterfaceAdapter adapter;
adapter = (InterfaceAdapter)cache.getInterfaceAdapter(cl);
ContextFactory cf = cx.getFactory();
if (adapter == null) {
Method[] methods = cl.getMethods();
if ( object instanceof Callable) {
// Check if interface can be implemented by a single function.
// We allow this if the interface has only one method or multiple
// methods with the same name (in which case they'd result in
// the same function to be invoked anyway).
int length = methods.length;
if (length == 0) {
throw Context.reportRuntimeError1(
"msg.no.empty.interface.conversion", cl.getName());
}
if (length > 1) {
String methodName = methods[0].getName();
for (int i = 1; i < length; i++) {
if (!methodName.equals(methods[i].getName())) {
throw Context.reportRuntimeError1(
"msg.no.function.interface.conversion",
cl.getName());
}
}
}
}
adapter = new InterfaceAdapter(cf, cl);
cache.cacheInterfaceAdapter(cl, adapter);
}
return VMBridge.instance.newInterfaceProxy(
adapter.proxyHelper, cf, adapter, object, topScope);
}
|
java
|
static Object create(Context cx, Class<?> cl, ScriptableObject object)
{
if (!cl.isInterface()) throw new IllegalArgumentException();
Scriptable topScope = ScriptRuntime.getTopCallScope(cx);
ClassCache cache = ClassCache.get(topScope);
InterfaceAdapter adapter;
adapter = (InterfaceAdapter)cache.getInterfaceAdapter(cl);
ContextFactory cf = cx.getFactory();
if (adapter == null) {
Method[] methods = cl.getMethods();
if ( object instanceof Callable) {
// Check if interface can be implemented by a single function.
// We allow this if the interface has only one method or multiple
// methods with the same name (in which case they'd result in
// the same function to be invoked anyway).
int length = methods.length;
if (length == 0) {
throw Context.reportRuntimeError1(
"msg.no.empty.interface.conversion", cl.getName());
}
if (length > 1) {
String methodName = methods[0].getName();
for (int i = 1; i < length; i++) {
if (!methodName.equals(methods[i].getName())) {
throw Context.reportRuntimeError1(
"msg.no.function.interface.conversion",
cl.getName());
}
}
}
}
adapter = new InterfaceAdapter(cf, cl);
cache.cacheInterfaceAdapter(cl, adapter);
}
return VMBridge.instance.newInterfaceProxy(
adapter.proxyHelper, cf, adapter, object, topScope);
}
|
[
"static",
"Object",
"create",
"(",
"Context",
"cx",
",",
"Class",
"<",
"?",
">",
"cl",
",",
"ScriptableObject",
"object",
")",
"{",
"if",
"(",
"!",
"cl",
".",
"isInterface",
"(",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
")",
";",
"Scriptable",
"topScope",
"=",
"ScriptRuntime",
".",
"getTopCallScope",
"(",
"cx",
")",
";",
"ClassCache",
"cache",
"=",
"ClassCache",
".",
"get",
"(",
"topScope",
")",
";",
"InterfaceAdapter",
"adapter",
";",
"adapter",
"=",
"(",
"InterfaceAdapter",
")",
"cache",
".",
"getInterfaceAdapter",
"(",
"cl",
")",
";",
"ContextFactory",
"cf",
"=",
"cx",
".",
"getFactory",
"(",
")",
";",
"if",
"(",
"adapter",
"==",
"null",
")",
"{",
"Method",
"[",
"]",
"methods",
"=",
"cl",
".",
"getMethods",
"(",
")",
";",
"if",
"(",
"object",
"instanceof",
"Callable",
")",
"{",
"// Check if interface can be implemented by a single function.",
"// We allow this if the interface has only one method or multiple ",
"// methods with the same name (in which case they'd result in ",
"// the same function to be invoked anyway).",
"int",
"length",
"=",
"methods",
".",
"length",
";",
"if",
"(",
"length",
"==",
"0",
")",
"{",
"throw",
"Context",
".",
"reportRuntimeError1",
"(",
"\"msg.no.empty.interface.conversion\"",
",",
"cl",
".",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"length",
">",
"1",
")",
"{",
"String",
"methodName",
"=",
"methods",
"[",
"0",
"]",
".",
"getName",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"methodName",
".",
"equals",
"(",
"methods",
"[",
"i",
"]",
".",
"getName",
"(",
")",
")",
")",
"{",
"throw",
"Context",
".",
"reportRuntimeError1",
"(",
"\"msg.no.function.interface.conversion\"",
",",
"cl",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"adapter",
"=",
"new",
"InterfaceAdapter",
"(",
"cf",
",",
"cl",
")",
";",
"cache",
".",
"cacheInterfaceAdapter",
"(",
"cl",
",",
"adapter",
")",
";",
"}",
"return",
"VMBridge",
".",
"instance",
".",
"newInterfaceProxy",
"(",
"adapter",
".",
"proxyHelper",
",",
"cf",
",",
"adapter",
",",
"object",
",",
"topScope",
")",
";",
"}"
] |
Make glue object implementing interface cl that will
call the supplied JS function when called.
Only interfaces were all methods have the same signature is supported.
@return The glue object or null if <tt>cl</tt> is not interface or
has methods with different signatures.
|
[
"Make",
"glue",
"object",
"implementing",
"interface",
"cl",
"that",
"will",
"call",
"the",
"supplied",
"JS",
"function",
"when",
"called",
".",
"Only",
"interfaces",
"were",
"all",
"methods",
"have",
"the",
"same",
"signature",
"is",
"supported",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/InterfaceAdapter.java#L27-L64
|
21,492
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/ArrayComprehension.java
|
ArrayComprehension.visit
|
@Override
public void visit(NodeVisitor v) {
if (!v.visit(this)) {
return;
}
result.visit(v);
for (ArrayComprehensionLoop loop : loops) {
loop.visit(v);
}
if (filter != null) {
filter.visit(v);
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (!v.visit(this)) {
return;
}
result.visit(v);
for (ArrayComprehensionLoop loop : loops) {
loop.visit(v);
}
if (filter != null) {
filter.visit(v);
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"!",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"return",
";",
"}",
"result",
".",
"visit",
"(",
"v",
")",
";",
"for",
"(",
"ArrayComprehensionLoop",
"loop",
":",
"loops",
")",
"{",
"loop",
".",
"visit",
"(",
"v",
")",
";",
"}",
"if",
"(",
"filter",
"!=",
"null",
")",
"{",
"filter",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}"
] |
Visits this node, the result expression, the loops, and the optional
filter.
|
[
"Visits",
"this",
"node",
"the",
"result",
"expression",
"the",
"loops",
"and",
"the",
"optional",
"filter",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/ArrayComprehension.java#L169-L181
|
21,493
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/ExpressionStatement.java
|
ExpressionStatement.setExpression
|
public void setExpression(AstNode expression) {
assertNotNull(expression);
expr = expression;
expression.setParent(this);
setLineno(expression.getLineno());
}
|
java
|
public void setExpression(AstNode expression) {
assertNotNull(expression);
expr = expression;
expression.setParent(this);
setLineno(expression.getLineno());
}
|
[
"public",
"void",
"setExpression",
"(",
"AstNode",
"expression",
")",
"{",
"assertNotNull",
"(",
"expression",
")",
";",
"expr",
"=",
"expression",
";",
"expression",
".",
"setParent",
"(",
"this",
")",
";",
"setLineno",
"(",
"expression",
".",
"getLineno",
"(",
")",
")",
";",
"}"
] |
Sets the wrapped expression, and sets its parent to this node.
@throws IllegalArgumentException} if expression is {@code null}
|
[
"Sets",
"the",
"wrapped",
"expression",
"and",
"sets",
"its",
"parent",
"to",
"this",
"node",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/ExpressionStatement.java#L89-L94
|
21,494
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/InfixExpression.java
|
InfixExpression.setLeft
|
public void setLeft(AstNode left) {
assertNotNull(left);
this.left = left;
// line number should agree with source position
setLineno(left.getLineno());
left.setParent(this);
}
|
java
|
public void setLeft(AstNode left) {
assertNotNull(left);
this.left = left;
// line number should agree with source position
setLineno(left.getLineno());
left.setParent(this);
}
|
[
"public",
"void",
"setLeft",
"(",
"AstNode",
"left",
")",
"{",
"assertNotNull",
"(",
"left",
")",
";",
"this",
".",
"left",
"=",
"left",
";",
"// line number should agree with source position",
"setLineno",
"(",
"left",
".",
"getLineno",
"(",
")",
")",
";",
"left",
".",
"setParent",
"(",
"this",
")",
";",
"}"
] |
Sets the left-hand side of the expression, and sets its
parent to this node.
@param left the left-hand side of the expression
@throws IllegalArgumentException} if left is {@code null}
|
[
"Sets",
"the",
"left",
"-",
"hand",
"side",
"of",
"the",
"expression",
"and",
"sets",
"its",
"parent",
"to",
"this",
"node",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/InfixExpression.java#L104-L110
|
21,495
|
mozilla/rhino
|
src/org/mozilla/javascript/ast/InfixExpression.java
|
InfixExpression.visit
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
left.visit(v);
right.visit(v);
}
}
|
java
|
@Override
public void visit(NodeVisitor v) {
if (v.visit(this)) {
left.visit(v);
right.visit(v);
}
}
|
[
"@",
"Override",
"public",
"void",
"visit",
"(",
"NodeVisitor",
"v",
")",
"{",
"if",
"(",
"v",
".",
"visit",
"(",
"this",
")",
")",
"{",
"left",
".",
"visit",
"(",
"v",
")",
";",
"right",
".",
"visit",
"(",
"v",
")",
";",
"}",
"}"
] |
Visits this node, the left operand, and the right operand.
|
[
"Visits",
"this",
"node",
"the",
"left",
"operand",
"and",
"the",
"right",
"operand",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ast/InfixExpression.java#L178-L184
|
21,496
|
mozilla/rhino
|
src/org/mozilla/javascript/ScriptRuntime.java
|
ScriptRuntime.toNumber
|
public static double toNumber(Object val)
{
for (;;) {
if (val instanceof Number)
return ((Number) val).doubleValue();
if (val == null)
return +0.0;
if (val == Undefined.instance)
return NaN;
if (val instanceof String)
return toNumber((String) val);
if (val instanceof CharSequence)
return toNumber(val.toString());
if (val instanceof Boolean)
return ((Boolean) val).booleanValue() ? 1 : +0.0;
if (val instanceof Symbol)
throw typeError0("msg.not.a.number");
if (val instanceof Scriptable) {
val = ((Scriptable) val).getDefaultValue(NumberClass);
if ((val instanceof Scriptable) && !isSymbol(val))
throw errorWithClassName("msg.primitive.expected", val);
continue;
}
warnAboutNonJSObject(val);
return NaN;
}
}
|
java
|
public static double toNumber(Object val)
{
for (;;) {
if (val instanceof Number)
return ((Number) val).doubleValue();
if (val == null)
return +0.0;
if (val == Undefined.instance)
return NaN;
if (val instanceof String)
return toNumber((String) val);
if (val instanceof CharSequence)
return toNumber(val.toString());
if (val instanceof Boolean)
return ((Boolean) val).booleanValue() ? 1 : +0.0;
if (val instanceof Symbol)
throw typeError0("msg.not.a.number");
if (val instanceof Scriptable) {
val = ((Scriptable) val).getDefaultValue(NumberClass);
if ((val instanceof Scriptable) && !isSymbol(val))
throw errorWithClassName("msg.primitive.expected", val);
continue;
}
warnAboutNonJSObject(val);
return NaN;
}
}
|
[
"public",
"static",
"double",
"toNumber",
"(",
"Object",
"val",
")",
"{",
"for",
"(",
";",
";",
")",
"{",
"if",
"(",
"val",
"instanceof",
"Number",
")",
"return",
"(",
"(",
"Number",
")",
"val",
")",
".",
"doubleValue",
"(",
")",
";",
"if",
"(",
"val",
"==",
"null",
")",
"return",
"+",
"0.0",
";",
"if",
"(",
"val",
"==",
"Undefined",
".",
"instance",
")",
"return",
"NaN",
";",
"if",
"(",
"val",
"instanceof",
"String",
")",
"return",
"toNumber",
"(",
"(",
"String",
")",
"val",
")",
";",
"if",
"(",
"val",
"instanceof",
"CharSequence",
")",
"return",
"toNumber",
"(",
"val",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"val",
"instanceof",
"Boolean",
")",
"return",
"(",
"(",
"Boolean",
")",
"val",
")",
".",
"booleanValue",
"(",
")",
"?",
"1",
":",
"+",
"0.0",
";",
"if",
"(",
"val",
"instanceof",
"Symbol",
")",
"throw",
"typeError0",
"(",
"\"msg.not.a.number\"",
")",
";",
"if",
"(",
"val",
"instanceof",
"Scriptable",
")",
"{",
"val",
"=",
"(",
"(",
"Scriptable",
")",
"val",
")",
".",
"getDefaultValue",
"(",
"NumberClass",
")",
";",
"if",
"(",
"(",
"val",
"instanceof",
"Scriptable",
")",
"&&",
"!",
"isSymbol",
"(",
"val",
")",
")",
"throw",
"errorWithClassName",
"(",
"\"msg.primitive.expected\"",
",",
"val",
")",
";",
"continue",
";",
"}",
"warnAboutNonJSObject",
"(",
"val",
")",
";",
"return",
"NaN",
";",
"}",
"}"
] |
Convert the value to a number.
See ECMA 9.3.
|
[
"Convert",
"the",
"value",
"to",
"a",
"number",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L426-L452
|
21,497
|
mozilla/rhino
|
src/org/mozilla/javascript/ScriptRuntime.java
|
ScriptRuntime.padArguments
|
public static Object[] padArguments(Object[] args, int count) {
if (count < args.length)
return args;
int i;
Object[] result = new Object[count];
for (i = 0; i < args.length; i++) {
result[i] = args[i];
}
for (; i < count; i++) {
result[i] = Undefined.instance;
}
return result;
}
|
java
|
public static Object[] padArguments(Object[] args, int count) {
if (count < args.length)
return args;
int i;
Object[] result = new Object[count];
for (i = 0; i < args.length; i++) {
result[i] = args[i];
}
for (; i < count; i++) {
result[i] = Undefined.instance;
}
return result;
}
|
[
"public",
"static",
"Object",
"[",
"]",
"padArguments",
"(",
"Object",
"[",
"]",
"args",
",",
"int",
"count",
")",
"{",
"if",
"(",
"count",
"<",
"args",
".",
"length",
")",
"return",
"args",
";",
"int",
"i",
";",
"Object",
"[",
"]",
"result",
"=",
"new",
"Object",
"[",
"count",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"result",
"[",
"i",
"]",
"=",
"args",
"[",
"i",
"]",
";",
"}",
"for",
"(",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"result",
"[",
"i",
"]",
"=",
"Undefined",
".",
"instance",
";",
"}",
"return",
"result",
";",
"}"
] |
Helper function for builtin objects that use the varargs form.
ECMA function formal arguments are undefined if not supplied;
this function pads the argument array out to the expected
length, if necessary.
|
[
"Helper",
"function",
"for",
"builtin",
"objects",
"that",
"use",
"the",
"varargs",
"form",
".",
"ECMA",
"function",
"formal",
"arguments",
"are",
"undefined",
"if",
"not",
"supplied",
";",
"this",
"function",
"pads",
"the",
"argument",
"array",
"out",
"to",
"the",
"expected",
"length",
"if",
"necessary",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L745-L760
|
21,498
|
mozilla/rhino
|
src/org/mozilla/javascript/ScriptRuntime.java
|
ScriptRuntime.escapeString
|
public static String escapeString(String s, char escapeQuote)
{
if (!(escapeQuote == '"' || escapeQuote == '\'' || escapeQuote == '`')) Kit.codeBug();
StringBuilder sb = null;
for(int i = 0, L = s.length(); i != L; ++i) {
int c = s.charAt(i);
if (' ' <= c && c <= '~' && c != escapeQuote && c != '\\') {
// an ordinary print character (like C isprint()) and not "
// or \ .
if (sb != null) {
sb.append((char)c);
}
continue;
}
if (sb == null) {
sb = new StringBuilder(L + 3);
sb.append(s);
sb.setLength(i);
}
int escape = -1;
switch (c) {
case '\b': escape = 'b'; break;
case '\f': escape = 'f'; break;
case '\n': escape = 'n'; break;
case '\r': escape = 'r'; break;
case '\t': escape = 't'; break;
case 0xb: escape = 'v'; break; // Java lacks \v.
case ' ': escape = ' '; break;
case '\\': escape = '\\'; break;
}
if (escape >= 0) {
// an \escaped sort of character
sb.append('\\');
sb.append((char)escape);
} else if (c == escapeQuote) {
sb.append('\\');
sb.append(escapeQuote);
} else {
int hexSize;
if (c < 256) {
// 2-digit hex
sb.append("\\x");
hexSize = 2;
} else {
// Unicode.
sb.append("\\u");
hexSize = 4;
}
// append hexadecimal form of c left-padded with 0
for (int shift = (hexSize - 1) * 4; shift >= 0; shift -= 4) {
int digit = 0xf & (c >> shift);
int hc = (digit < 10) ? '0' + digit : 'a' - 10 + digit;
sb.append((char)hc);
}
}
}
return (sb == null) ? s : sb.toString();
}
|
java
|
public static String escapeString(String s, char escapeQuote)
{
if (!(escapeQuote == '"' || escapeQuote == '\'' || escapeQuote == '`')) Kit.codeBug();
StringBuilder sb = null;
for(int i = 0, L = s.length(); i != L; ++i) {
int c = s.charAt(i);
if (' ' <= c && c <= '~' && c != escapeQuote && c != '\\') {
// an ordinary print character (like C isprint()) and not "
// or \ .
if (sb != null) {
sb.append((char)c);
}
continue;
}
if (sb == null) {
sb = new StringBuilder(L + 3);
sb.append(s);
sb.setLength(i);
}
int escape = -1;
switch (c) {
case '\b': escape = 'b'; break;
case '\f': escape = 'f'; break;
case '\n': escape = 'n'; break;
case '\r': escape = 'r'; break;
case '\t': escape = 't'; break;
case 0xb: escape = 'v'; break; // Java lacks \v.
case ' ': escape = ' '; break;
case '\\': escape = '\\'; break;
}
if (escape >= 0) {
// an \escaped sort of character
sb.append('\\');
sb.append((char)escape);
} else if (c == escapeQuote) {
sb.append('\\');
sb.append(escapeQuote);
} else {
int hexSize;
if (c < 256) {
// 2-digit hex
sb.append("\\x");
hexSize = 2;
} else {
// Unicode.
sb.append("\\u");
hexSize = 4;
}
// append hexadecimal form of c left-padded with 0
for (int shift = (hexSize - 1) * 4; shift >= 0; shift -= 4) {
int digit = 0xf & (c >> shift);
int hc = (digit < 10) ? '0' + digit : 'a' - 10 + digit;
sb.append((char)hc);
}
}
}
return (sb == null) ? s : sb.toString();
}
|
[
"public",
"static",
"String",
"escapeString",
"(",
"String",
"s",
",",
"char",
"escapeQuote",
")",
"{",
"if",
"(",
"!",
"(",
"escapeQuote",
"==",
"'",
"'",
"||",
"escapeQuote",
"==",
"'",
"'",
"||",
"escapeQuote",
"==",
"'",
"'",
")",
")",
"Kit",
".",
"codeBug",
"(",
")",
";",
"StringBuilder",
"sb",
"=",
"null",
";",
"for",
"(",
"int",
"i",
"=",
"0",
",",
"L",
"=",
"s",
".",
"length",
"(",
")",
";",
"i",
"!=",
"L",
";",
"++",
"i",
")",
"{",
"int",
"c",
"=",
"s",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"'",
"'",
"<=",
"c",
"&&",
"c",
"<=",
"'",
"'",
"&&",
"c",
"!=",
"escapeQuote",
"&&",
"c",
"!=",
"'",
"'",
")",
"{",
"// an ordinary print character (like C isprint()) and not \"",
"// or \\ .",
"if",
"(",
"sb",
"!=",
"null",
")",
"{",
"sb",
".",
"append",
"(",
"(",
"char",
")",
"c",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"sb",
"==",
"null",
")",
"{",
"sb",
"=",
"new",
"StringBuilder",
"(",
"L",
"+",
"3",
")",
";",
"sb",
".",
"append",
"(",
"s",
")",
";",
"sb",
".",
"setLength",
"(",
"i",
")",
";",
"}",
"int",
"escape",
"=",
"-",
"1",
";",
"switch",
"(",
"c",
")",
"{",
"case",
"'",
"'",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"case",
"'",
"'",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"case",
"'",
"'",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"case",
"'",
"'",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"case",
"'",
"'",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"case",
"0xb",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"// Java lacks \\v.",
"case",
"'",
"'",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"case",
"'",
"'",
":",
"escape",
"=",
"'",
"'",
";",
"break",
";",
"}",
"if",
"(",
"escape",
">=",
"0",
")",
"{",
"// an \\escaped sort of character",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"sb",
".",
"append",
"(",
"(",
"char",
")",
"escape",
")",
";",
"}",
"else",
"if",
"(",
"c",
"==",
"escapeQuote",
")",
"{",
"sb",
".",
"append",
"(",
"'",
"'",
")",
";",
"sb",
".",
"append",
"(",
"escapeQuote",
")",
";",
"}",
"else",
"{",
"int",
"hexSize",
";",
"if",
"(",
"c",
"<",
"256",
")",
"{",
"// 2-digit hex",
"sb",
".",
"append",
"(",
"\"\\\\x\"",
")",
";",
"hexSize",
"=",
"2",
";",
"}",
"else",
"{",
"// Unicode.",
"sb",
".",
"append",
"(",
"\"\\\\u\"",
")",
";",
"hexSize",
"=",
"4",
";",
"}",
"// append hexadecimal form of c left-padded with 0",
"for",
"(",
"int",
"shift",
"=",
"(",
"hexSize",
"-",
"1",
")",
"*",
"4",
";",
"shift",
">=",
"0",
";",
"shift",
"-=",
"4",
")",
"{",
"int",
"digit",
"=",
"0xf",
"&",
"(",
"c",
">>",
"shift",
")",
";",
"int",
"hc",
"=",
"(",
"digit",
"<",
"10",
")",
"?",
"'",
"'",
"+",
"digit",
":",
"'",
"'",
"-",
"10",
"+",
"digit",
";",
"sb",
".",
"append",
"(",
"(",
"char",
")",
"hc",
")",
";",
"}",
"}",
"}",
"return",
"(",
"sb",
"==",
"null",
")",
"?",
"s",
":",
"sb",
".",
"toString",
"(",
")",
";",
"}"
] |
For escaping strings printed by object and array literals; not quite
the same as 'escape.'
|
[
"For",
"escaping",
"strings",
"printed",
"by",
"object",
"and",
"array",
"literals",
";",
"not",
"quite",
"the",
"same",
"as",
"escape",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L771-L831
|
21,499
|
mozilla/rhino
|
src/org/mozilla/javascript/ScriptRuntime.java
|
ScriptRuntime.toObject
|
public static Scriptable toObject(Context cx, Scriptable scope, Object val)
{
if (val == null) {
throw typeError0("msg.null.to.object");
}
if (Undefined.isUndefined(val)) {
throw typeError0("msg.undef.to.object");
}
if (isSymbol(val)) {
NativeSymbol result = new NativeSymbol((NativeSymbol)val);
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Symbol);
return result;
}
if (val instanceof Scriptable) {
return (Scriptable) val;
}
if (val instanceof CharSequence) {
// FIXME we want to avoid toString() here, especially for concat()
NativeString result = new NativeString((CharSequence)val);
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.String);
return result;
}
if (val instanceof Number) {
NativeNumber result = new NativeNumber(((Number)val).doubleValue());
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Number);
return result;
}
if (val instanceof Boolean) {
NativeBoolean result = new NativeBoolean(((Boolean)val).booleanValue());
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Boolean);
return result;
}
// Extension: Wrap as a LiveConnect object.
Object wrapped = cx.getWrapFactory().wrap(cx, scope, val, null);
if (wrapped instanceof Scriptable)
return (Scriptable) wrapped;
throw errorWithClassName("msg.invalid.type", val);
}
|
java
|
public static Scriptable toObject(Context cx, Scriptable scope, Object val)
{
if (val == null) {
throw typeError0("msg.null.to.object");
}
if (Undefined.isUndefined(val)) {
throw typeError0("msg.undef.to.object");
}
if (isSymbol(val)) {
NativeSymbol result = new NativeSymbol((NativeSymbol)val);
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Symbol);
return result;
}
if (val instanceof Scriptable) {
return (Scriptable) val;
}
if (val instanceof CharSequence) {
// FIXME we want to avoid toString() here, especially for concat()
NativeString result = new NativeString((CharSequence)val);
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.String);
return result;
}
if (val instanceof Number) {
NativeNumber result = new NativeNumber(((Number)val).doubleValue());
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Number);
return result;
}
if (val instanceof Boolean) {
NativeBoolean result = new NativeBoolean(((Boolean)val).booleanValue());
setBuiltinProtoAndParent(result, scope, TopLevel.Builtins.Boolean);
return result;
}
// Extension: Wrap as a LiveConnect object.
Object wrapped = cx.getWrapFactory().wrap(cx, scope, val, null);
if (wrapped instanceof Scriptable)
return (Scriptable) wrapped;
throw errorWithClassName("msg.invalid.type", val);
}
|
[
"public",
"static",
"Scriptable",
"toObject",
"(",
"Context",
"cx",
",",
"Scriptable",
"scope",
",",
"Object",
"val",
")",
"{",
"if",
"(",
"val",
"==",
"null",
")",
"{",
"throw",
"typeError0",
"(",
"\"msg.null.to.object\"",
")",
";",
"}",
"if",
"(",
"Undefined",
".",
"isUndefined",
"(",
"val",
")",
")",
"{",
"throw",
"typeError0",
"(",
"\"msg.undef.to.object\"",
")",
";",
"}",
"if",
"(",
"isSymbol",
"(",
"val",
")",
")",
"{",
"NativeSymbol",
"result",
"=",
"new",
"NativeSymbol",
"(",
"(",
"NativeSymbol",
")",
"val",
")",
";",
"setBuiltinProtoAndParent",
"(",
"result",
",",
"scope",
",",
"TopLevel",
".",
"Builtins",
".",
"Symbol",
")",
";",
"return",
"result",
";",
"}",
"if",
"(",
"val",
"instanceof",
"Scriptable",
")",
"{",
"return",
"(",
"Scriptable",
")",
"val",
";",
"}",
"if",
"(",
"val",
"instanceof",
"CharSequence",
")",
"{",
"// FIXME we want to avoid toString() here, especially for concat()",
"NativeString",
"result",
"=",
"new",
"NativeString",
"(",
"(",
"CharSequence",
")",
"val",
")",
";",
"setBuiltinProtoAndParent",
"(",
"result",
",",
"scope",
",",
"TopLevel",
".",
"Builtins",
".",
"String",
")",
";",
"return",
"result",
";",
"}",
"if",
"(",
"val",
"instanceof",
"Number",
")",
"{",
"NativeNumber",
"result",
"=",
"new",
"NativeNumber",
"(",
"(",
"(",
"Number",
")",
"val",
")",
".",
"doubleValue",
"(",
")",
")",
";",
"setBuiltinProtoAndParent",
"(",
"result",
",",
"scope",
",",
"TopLevel",
".",
"Builtins",
".",
"Number",
")",
";",
"return",
"result",
";",
"}",
"if",
"(",
"val",
"instanceof",
"Boolean",
")",
"{",
"NativeBoolean",
"result",
"=",
"new",
"NativeBoolean",
"(",
"(",
"(",
"Boolean",
")",
"val",
")",
".",
"booleanValue",
"(",
")",
")",
";",
"setBuiltinProtoAndParent",
"(",
"result",
",",
"scope",
",",
"TopLevel",
".",
"Builtins",
".",
"Boolean",
")",
";",
"return",
"result",
";",
"}",
"// Extension: Wrap as a LiveConnect object.",
"Object",
"wrapped",
"=",
"cx",
".",
"getWrapFactory",
"(",
")",
".",
"wrap",
"(",
"cx",
",",
"scope",
",",
"val",
",",
"null",
")",
";",
"if",
"(",
"wrapped",
"instanceof",
"Scriptable",
")",
"return",
"(",
"Scriptable",
")",
"wrapped",
";",
"throw",
"errorWithClassName",
"(",
"\"msg.invalid.type\"",
",",
"val",
")",
";",
"}"
] |
Convert the value to an object.
See ECMA 9.9.
|
[
"Convert",
"the",
"value",
"to",
"an",
"object",
"."
] |
fa8a86df11d37623f5faa8d445a5876612bc47b0
|
https://github.com/mozilla/rhino/blob/fa8a86df11d37623f5faa8d445a5876612bc47b0/src/org/mozilla/javascript/ScriptRuntime.java#L1111-L1150
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.