提交 12afc7e1 编写于 作者: J jlaskey

Merge

......@@ -21,7 +21,7 @@
or visit www.oracle.com if you need additional information or have any
questions.
-->
<project name="nashorn" default="all" basedir="..">
<project name="nashorn" default="test" basedir="..">
<import file="build-nasgen.xml"/>
<import file="build-benchmark.xml"/>
<import file="code_coverage.xml"/>
......
......@@ -24,7 +24,7 @@
application.title=nashorn
# location of JDK embedded ASM sources
jdk.asm.src.dir=../jdk/src/share/classes/jdk/internal
jdk.asm.src.dir=../jdk/src/share/classes/jdk/internal/org/objectweb/asm
# source and target levels
build.compiler=modern
......
......@@ -83,7 +83,6 @@
package jdk.internal.dynalink.beans;
import java.beans.Introspector;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
......@@ -136,16 +135,16 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
// Add the method as a property getter and/or setter
if(name.startsWith("get") && name.length() > 3 && method.getParameterTypes().length == 0) {
// Property getter
setPropertyGetter(Introspector.decapitalize(name.substring(3)), introspector.unreflect(
setPropertyGetter(decapitalize(name.substring(3)), introspector.unreflect(
getMostGenericGetter(method)), ValidationType.INSTANCE_OF);
} else if(name.startsWith("is") && name.length() > 2 && method.getParameterTypes().length == 0 &&
method.getReturnType() == boolean.class) {
// Boolean property getter
setPropertyGetter(Introspector.decapitalize(name.substring(2)), introspector.unreflect(
setPropertyGetter(decapitalize(name.substring(2)), introspector.unreflect(
getMostGenericGetter(method)), ValidationType.INSTANCE_OF);
} else if(name.startsWith("set") && name.length() > 3 && method.getParameterTypes().length == 1) {
// Property setter
addMember(Introspector.decapitalize(name.substring(3)), methodHandle, propertySetters);
addMember(decapitalize(name.substring(3)), methodHandle, propertySetters);
}
}
......@@ -170,6 +169,27 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
}
}
private static String decapitalize(String str) {
assert str != null;
if(str.isEmpty()) {
return str;
}
final char c0 = str.charAt(0);
if(Character.isLowerCase(c0)) {
return str;
}
// If it has two consecutive upper-case characters, i.e. "URL", don't decapitalize
if(str.length() > 1 && Character.isUpperCase(str.charAt(1))) {
return str;
}
final char c[] = str.toCharArray();
c[0] = Character.toLowerCase(c0);
return new String(c);
}
abstract FacetIntrospector createFacetIntrospector();
void setPropertyGetter(String name, MethodHandle handle, ValidationType validationType) {
......
......@@ -83,7 +83,6 @@
package jdk.internal.dynalink.beans;
import java.beans.BeanInfo;
import java.lang.invoke.MethodHandles;
import jdk.internal.dynalink.CallSiteDescriptor;
import jdk.internal.dynalink.DynamicLinkerFactory;
......@@ -99,11 +98,9 @@ import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
* <ul>
* <li>expose all public methods of form {@code setXxx()}, {@code getXxx()}, and {@code isXxx()} as property setters and
* getters for {@code dyn:setProp} and {@code dyn:getProp} operations;</li>
* <li>expose all property getters and setters declared by the class' {@link BeanInfo};</li>
* <li>expose all public methods and methods declared by the class' {@link BeanInfo} for invocation through
* {@code dyn:callMethod} operation;</li>
* <li>expose all public methods and methods declared by the class' {@link BeanInfo} for retrieval for
* {@code dyn:getMethod} operation; the methods thus retrieved can then be invoked using {@code dyn:call};</li>
* <li>expose all public methods for invocation through {@code dyn:callMethod} operation;</li>
* <li>expose all public methods for retrieval for {@code dyn:getMethod} operation; the methods thus retrieved can then
* be invoked using {@code dyn:call};</li>
* <li>expose all public fields as properties, unless there are getters or setters for the properties of the same name;</li>
* <li>expose {@code dyn:getLength}, {@code dyn:getElem} and {@code dyn:setElem} on native Java arrays, as well as
* {@link java.util.List} and {@link java.util.Map} objects; ({@code dyn:getLength} works on any
......
......@@ -95,7 +95,7 @@ import jdk.nashorn.internal.runtime.Source;
* <p>
* There is also a very nice debug interface that can emit formatted
* bytecodes that have been written. This is enabled by setting the
* environment "nashorn.codegen.debug" to true, or --log=codegen:<level>
* environment "nashorn.codegen.debug" to true, or --log=codegen:{@literal <level>}
* <p>
* A ClassEmitter implements an Emitter - i.e. it needs to have
* well defined start and end calls for whatever it is generating. Assertions
......
......@@ -46,7 +46,6 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor;
import static jdk.nashorn.internal.ir.Symbol.IS_INTERNAL;
import static jdk.nashorn.internal.ir.Symbol.IS_TEMP;
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_FAST_SCOPE;
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_FUNCTION_DECLARATION;
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_SCOPE;
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
......@@ -2052,9 +2051,6 @@ final class CodeGenerator extends NodeOperatorVisitor {
if (needsScope) {
int flags = CALLSITE_SCOPE | getCallSiteFlags();
if (varNode.isFunctionVarNode()) {
flags |= CALLSITE_FUNCTION_DECLARATION;
}
final IdentNode identNode = varNode.getName();
final Type type = identNode.getType();
if (varSymbol.isFastScope(getCurrentFunctionNode())) {
......
......@@ -112,7 +112,7 @@ public final class ObjectClassGenerator {
private final Context context;
/**
* The list of available accessor types in width order. This order is used for type guesses narrow->wide
* The list of available accessor types in width order. This order is used for type guesses narrow{@literal ->} wide
* in the dual--fields world
*/
public static final List<Type> ACCESSOR_TYPES = Collections.unmodifiableList(
......@@ -184,7 +184,7 @@ public final class ObjectClassGenerator {
/**
* Return the accessor type based on its index in [0..getNumberOfAccessorTypes())
* Indexes are ordered narrower->wider / optimistic->pessimistic. Invalidations always
* Indexes are ordered narrower{@literal ->}wider / optimistic{@literal ->}pessimistic. Invalidations always
* go to a type of higher index
*
* @param index accessor type index
......
......@@ -459,120 +459,120 @@ public final class RuntimeCallSite extends MutableCallSite {
}
/**
* Specialized version of < operator for two int arguments. Do not call directly.
* Specialized version of {@literal <} operator for two int arguments. Do not call directly.
* @param a int
* @param b int
* @return a < b
* @return a {@code <} b
*/
public static boolean LT(final int a, final int b) {
return a < b;
}
/**
* Specialized version of < operator for two double arguments. Do not call directly.
* Specialized version of {@literal <} operator for two double arguments. Do not call directly.
* @param a double
* @param b double
* @return a < b
* @return a {@literal <} b
*/
public static boolean LT(final double a, final double b) {
return a < b;
}
/**
* Specialized version of < operator for two long arguments. Do not call directly.
* Specialized version of {@literal <} operator for two long arguments. Do not call directly.
* @param a long
* @param b long
* @return a < b
* @return a {@literal <} b
*/
public static boolean LT(final long a, final long b) {
return a < b;
}
/**
* Specialized version of <= operator for two int arguments. Do not call directly.
* Specialized version of {@literal <=} operator for two int arguments. Do not call directly.
* @param a int
* @param b int
* @return a <= b
* @return a {@literal <=} b
*/
public static boolean LE(final int a, final int b) {
return a <= b;
}
/**
* Specialized version of <= operator for two double arguments. Do not call directly.
* Specialized version of {@literal <=} operator for two double arguments. Do not call directly.
* @param a double
* @param b double
* @return a <= b
* @return a {@literal <=} b
*/
public static boolean LE(final double a, final double b) {
return a <= b;
}
/**
* Specialized version of <= operator for two long arguments. Do not call directly.
* Specialized version of {@literal <=} operator for two long arguments. Do not call directly.
* @param a long
* @param b long
* @return a <= b
* @return a {@literal <=} b
*/
public static boolean LE(final long a, final long b) {
return a <= b;
}
/**
* Specialized version of > operator for two int arguments. Do not call directly.
* Specialized version of {@literal >} operator for two int arguments. Do not call directly.
* @param a int
* @param b int
* @return a > b
* @return a {@literal >} b
*/
public static boolean GT(final int a, final int b) {
return a > b;
}
/**
* Specialized version of > operator for two double arguments. Do not call directly.
* Specialized version of {@literal >} operator for two double arguments. Do not call directly.
* @param a double
* @param b double
* @return a > b
* @return a {@literal >} b
*/
public static boolean GT(final double a, final double b) {
return a > b;
}
/**
* Specialized version of > operator for two long arguments. Do not call directly.
* Specialized version of {@literal >} operator for two long arguments. Do not call directly.
* @param a long
* @param b long
* @return a > b
* @return a {@literal >} b
*/
public static boolean GT(final long a, final long b) {
return a > b;
}
/**
* Specialized version of >= operator for two int arguments. Do not call directly.
* Specialized version of {@literal >=} operator for two int arguments. Do not call directly.
* @param a int
* @param b int
* @return a >= b
* @return a {@literal >=} b
*/
public static boolean GE(final int a, final int b) {
return a >= b;
}
/**
* Specialized version of >= operator for two double arguments. Do not call directly.
* Specialized version of {@literal >=} operator for two double arguments. Do not call directly.
* @param a double
* @param b double
* @return a >= b
* @return a {@literal >=} b
*/
public static boolean GE(final double a, final double b) {
return a >= b;
}
/**
* Specialized version of >= operator for two long arguments. Do not call directly.
* Specialized version of {@literal >=} operator for two long arguments. Do not call directly.
* @param a long
* @param b long
* @return a >= b
* @return a {@code >=} b
*/
public static boolean GE(final long a, final long b) {
return a >= b;
......
......@@ -46,18 +46,4 @@ public interface Assignment<D extends Node> {
* @return get the assignment source node
*/
public Node getAssignmentSource();
/**
* Reset the assignment source
*
* @param newSource new source node
*/
public void setAssignmentSource(final Node newSource);
/**
* Reset the assignment destination
*
* @param newDest new destination node
*/
public void setAssignmentDest(final D newDest);
}
......@@ -139,21 +139,11 @@ public class BinaryNode extends UnaryNode {
return isAssignment() ? lhs() : null;
}
@Override
public void setAssignmentDest(final Node node) {
setLHS(node);
}
@Override
public Node getAssignmentSource() {
return rhs();
}
@Override
public void setAssignmentSource(final Node source) {
setRHS(source);
}
@Override
public boolean equals(final Object other) {
if (!super.equals(other)) {
......
......@@ -64,17 +64,17 @@ public class RuntimeNode extends Node implements TypeOverride {
EQ_STRICT(TokenType.EQ_STRICT, Type.BOOLEAN, 2, true),
/** == operator with at least one object */
EQ(TokenType.EQ, Type.BOOLEAN, 2, true),
/** >= operator with at least one object */
/** {@literal >=} operator with at least one object */
GE(TokenType.GE, Type.BOOLEAN, 2, true),
/** > operator with at least one object */
/** {@literal >} operator with at least one object */
GT(TokenType.GT, Type.BOOLEAN, 2, true),
/** in operator */
IN(TokenType.IN, Type.BOOLEAN, 2),
/** instanceof operator */
INSTANCEOF(TokenType.INSTANCEOF, Type.BOOLEAN, 2),
/** <= operator with at least one object */
/** {@literal <=} operator with at least one object */
LE(TokenType.LE, Type.BOOLEAN, 2, true),
/** < operator with at least one object */
/** {@literal <} operator with at least one object */
LT(TokenType.LT, Type.BOOLEAN, 2, true),
/** !== operator with at least one object */
NE_STRICT(TokenType.NE_STRICT, Type.BOOLEAN, 2, true),
......@@ -184,7 +184,7 @@ public class RuntimeNode extends Node implements TypeOverride {
/**
* If this request can be reversed, return the reverse request
* Eq EQ -> NE.
* Eq EQ {@literal ->} NE.
*
* @param request request to reverse
*
......
......@@ -108,16 +108,6 @@ public class UnaryNode extends Node implements Assignment<Node> {
return getAssignmentDest();
}
@Override
public void setAssignmentSource(final Node source) {
setAssignmentDest(source);
}
@Override
public void setAssignmentDest(final Node source) {
setRHS(source);
}
@Override
public boolean equals(final Object other) {
if (!super.equals(other)) {
......
......@@ -82,21 +82,11 @@ public class VarNode extends Node implements Assignment<IdentNode> {
return isAssignment() ? name : null;
}
@Override
public void setAssignmentDest(final IdentNode node) {
setName(name);
}
@Override
public Node getAssignmentSource() {
return isAssignment() ? getInit() : null;
}
@Override
public void setAssignmentSource(final Node source) {
setInit(source);
}
/**
* Does this variable declaration have an init value
* @return true if an init exists, false otherwise
......
......@@ -542,7 +542,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering && operator
* Binary enter - callback for entering {@literal &&} operator
*
* @param binaryNode the node
* @return processed node
......@@ -552,7 +552,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving a && operator
* Binary leave - callback for leaving a {@literal &&} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -602,7 +602,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering &= operator
* Binary enter - callback for entering {@literal &=} operator
*
* @param binaryNode the node
* @return processed node
......@@ -612,7 +612,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving a &= operator
* Binary leave - callback for leaving a {@literal &=} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -722,7 +722,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering >>= operator
* Binary enter - callback for entering {@literal >>=} operator
*
* @param binaryNode the node
* @return processed node
......@@ -732,7 +732,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving a >>= operator
* Binary leave - callback for leaving a {@literal >>=} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -742,7 +742,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering a <<= operator
* Binary enter - callback for entering a {@literal <<=} operator
*
* @param binaryNode the node
* @return processed node
......@@ -752,7 +752,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving a <<= operator
* Binary leave - callback for leaving a {@literal <<=} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -762,7 +762,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering >>>= operator
* Binary enter - callback for entering {@literal >>>=} operator
*
* @param binaryNode the node
* @return processed node
......@@ -772,7 +772,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving a >>>= operator
* Binary leave - callback for leaving a {@literal >>>=} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -822,7 +822,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering & operator
* Binary enter - callback for entering {@literal &} operator
*
* @param binaryNode the node
* @return processed node
......@@ -832,7 +832,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving a & operator
* Binary leave - callback for leaving a {@literal &} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -986,7 +986,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering >= operator
* Binary enter - callback for entering {@literal >=} operator
*
* @param binaryNode the node
* @return processed node
......@@ -996,7 +996,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving >= operator
* Binary leave - callback for leaving {@literal >=} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -1006,7 +1006,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering > operator
* Binary enter - callback for entering {@literal >} operator
*
* @param binaryNode the node
* @return processed node
......@@ -1016,7 +1016,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving > operator
* Binary leave - callback for leaving {@literal >} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -1066,7 +1066,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering <= operator
* Binary enter - callback for entering {@literal <=} operator
*
* @param binaryNode the node
* @return processed node
......@@ -1076,7 +1076,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving <= operator
* Binary leave - callback for leaving {@literal <=} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -1086,7 +1086,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering < operator
* Binary enter - callback for entering {@literal <} operator
*
* @param binaryNode the node
* @return processed node
......@@ -1096,7 +1096,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving < operator
* Binary leave - callback for leaving {@literal <} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -1205,7 +1205,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering >> operator
* Binary enter - callback for entering {@literal >>} operator
*
* @param binaryNode the node
* @return processed node
......@@ -1215,7 +1215,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving >> operator
* Binary leave - callback for leaving {@literal >>} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -1225,7 +1225,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary enter - callback for entering << operator
* Binary enter - callback for entering {@literal <<} operator
*
* @param binaryNode the node
* @return processed node
......@@ -1235,7 +1235,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving << operator
* Binary leave - callback for leaving {@literal <<} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......@@ -1244,7 +1244,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
return leaveDefault(binaryNode);
}
/**
* Binary enter - callback for entering >>> operator
* Binary enter - callback for entering {@literal >>>} operator
*
* @param binaryNode the node
* @return processed node
......@@ -1254,7 +1254,7 @@ public class NodeOperatorVisitor extends NodeVisitor {
}
/**
* Binary leave - callback for leaving >>> operator
* Binary leave - callback for leaving {@literal >>>} operator
*
* @param binaryNode the node
* @return processed node, which will replace the original one, or the original node
......
......@@ -221,7 +221,7 @@ public class DateParser {
*
* <p>English month names and selected time zone names as well as AM/PM markers are recognized
* and handled properly. Additionally, numeric time zone offsets such as <tt>(+|-)hh:mm</tt> or
* <tt></tt>(+|-)hhmm</tt> are recognized. If the string does not contain a time zone offset
* <tt>(+|-)hhmm</tt> are recognized. If the string does not contain a time zone offset
* the <tt>TIMEZONE</tt>field is left undefined, meaning the local time zone should be applied.</p>
*
* <p>English weekday names are recognized but ignored. All text in parentheses is ignored as well.
......
......@@ -74,13 +74,16 @@ import jdk.nashorn.internal.runtime.linker.MethodHandleFactory;
* delete x.p; // calls y.__delete__
* for (i in x) { print(i); } // calls y.__getIds__
* </pre>
* <p>
* JavaScript caller of adapter object is isolated from the fact that the property access/mutation/deletion are really
* calls to JavaScript methods on adaptee.
* </p><p>
* </p>
* <p>
* JSAdapter constructor can optionally receive an "overrides" object. Properties of overrides object is copied to
* JSAdapter instance. When user accessed property is one of these, then adaptee's methods like {@code __get__},
* {@code __put__} etc. are not called for those. This can be used to make certain "preferred" properties that can be
* accessed in the usual/faster way avoiding proxy mechanism. Example:
* </p>
* <pre>
* var x = new JSAdapter({ foo: 444, bar: 6546 }) {
* __get__: function(name) { return name; }
......
......@@ -65,6 +65,7 @@ public final class NativeJava {
}
/**
* <p>
* Given a name of a Java type, returns an object representing that type in Nashorn. The Java class of the objects
* used to represent Java types in Nashorn is not {@link java.lang.Class} but rather {@link StaticClass}. They are
* the objects that you can use with the {@code new} operator to create new instances of the class as well as to
......@@ -75,7 +76,8 @@ public final class NativeJava {
* different expression (e.g. {@code java.io.File}) as an argument in "new" and to address statics, and it is
* distinct from the {@code Class} object (e.g. {@code java.io.File.class}). Below we cover in details the
* properties of the type objects.
* <h2>Constructing Java objects</h2>
* </p>
* <p><b>Constructing Java objects</b></p>
* Examples:
* <pre>
* var arrayListType = Java.type("java.util.ArrayList")
......@@ -104,19 +106,24 @@ public final class NativeJava {
* var arctype = Java.type("java.awt.geom.Arc2D")
* var ftype = arctype.Float
* </pre>
* <p>
* You can access both static and non-static inner classes. If you want to create an instance of a non-static
* inner class, remember to pass an instance of its outer class as the first argument to the constructor.
* </p><p>
* </p>
* <p>
* If the type is abstract, you can instantiate an anonymous subclass of it using an argument list that is
* applicable to any of its public or protected constructors, but inserting a JavaScript object with functions
* properties that provide JavaScript implementations of the abstract methods. If method names are overloaded, the
* JavaScript function will provide implementation for all overloads. E.g.:
* </p>
* <pre>
* var TimerTask = Java.type("java.util.TimerTask")
* var task = new TimerTask({ run: function() { print("Hello World!") } })
* </pre>
* <p>
* Nashorn supports a syntactic extension where a "new" expression followed by an argument is identical to
* invoking the constructor and passing the argument to it, so you can write the above example also as:
* </p>
* <pre>
* var task = new TimerTask {
* run: function() {
......@@ -124,30 +131,38 @@ public final class NativeJava {
* }
* }
* </pre>
* <p>
* which is very similar to Java anonymous inner class definition. On the other hand, if the type is an abstract
* type with a single abstract method (commonly referred to as a "SAM type") or all abstract methods it has share
* the same overloaded name), then instead of an object, you can just pass a function, so the above example can
* become even more simplified to:
* </p>
* <pre>
* var task = new TimerTask(function() { print("Hello World!") })
* </pre>
* <p>
* Note that in every one of these cases if you are trying to instantiate an abstract class that has constructors
* that take some arguments, you can invoke those simply by specifying the arguments after the initial
* implementation object or function.
* </p><p>The use of functions can be taken even further; if you are invoking a Java method that takes a SAM type,
* </p>
* <p>The use of functions can be taken even further; if you are invoking a Java method that takes a SAM type,
* you can just pass in a function object, and Nashorn will know what you meant:
* </p>
* <pre>
* var timer = new Java.type("java.util.Timer")
* timer.schedule(function() { print("Hello World!") })
* </pre>
* <p>
* Here, {@code Timer.schedule()} expects a {@code TimerTask} as its argument, so Nashorn creates an instance of a
* {@code TimerTask} subclass and uses the passed function to implement its only abstract method, {@code run()}. In
* this usage though, you can't use non-default constructors; the type must be either an interface, or must have a
* protected or public no-arg constructor.
* </p><p>
* </p>
* <p>
* You can also subclass non-abstract classes; for that you will need to use the {@link #extend(Object, Object...)}
* method.
* <h2>Accessing static members</h2>
* </p>
* <p><b>Accessing static members</b></p>
* Examples:
* <pre>
* var File = Java.type("java.io.File")
......@@ -176,7 +191,7 @@ public final class NativeJava {
* var File = Java.type("java.io.File")
* print(File.class.static === File) // prints true
* </pre>
* <h2>{@code instanceof} operator</h2>
* <p><b>{@code instanceof} operator</b></p>
* The standard ECMAScript {@code instanceof} operator is extended to recognize Java objects and their type objects:
* <pre>
* var File = Java.type("java.io.File")
......@@ -368,6 +383,7 @@ public final class NativeJava {
* <li>If the Java method is overloaded (as in the above example {@code List.add()}), then your JavaScript adapter
* must be prepared to deal with all overloads.</li>
* <li>You can't invoke {@code super.*()} from adapters for now.</li>
* </ul>
* @param self not used
* @param types the original types. The caller must pass at least one Java type object of class {@link StaticClass}
* representing either a public interface or a non-final public class with at least one public or protected
......
......@@ -30,7 +30,7 @@ package jdk.nashorn.internal.runtime;
* As only the code generating package (i.e. Context) knows about
* the ScriptLoader and it would be a security hazard otherwise
* the Compiler is given an installation interface for its code.
* <p>>
* <p>
* The compiler still retains most of the state around code emission
* and management internally, so this is to avoid passing around any
* logic that isn't directly related to installing a class
......
......@@ -509,7 +509,7 @@ public final class Context {
*
* @param fullName full name of class, e.g. jdk.nashorn.internal.objects.JO$2P1 contains 2 fields and 1 parameter.
*
* @return the Class<?> for this structure
* @return the {@code Class<?>} for this structure
*
* @throws ClassNotFoundException if structure class cannot be resolved
*/
......@@ -523,7 +523,7 @@ public final class Context {
*
* @param fullName full name of class to load
*
* @return the Class<?> for the name
* @return the {@code Class<?>} for the name
*
* @throws ClassNotFoundException if class cannot be resolved
*/
......
......@@ -1463,7 +1463,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
}
/**
* Returns the set of <property, value> entries that make up this
* Returns the set of {@literal <property, value>} entries that make up this
* ScriptObject's properties
* (java.util.Map-like method to help ScriptObjectMirror implementation)
*
......@@ -1524,7 +1524,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
* of their keys to their values
* (java.util.Map-like method to help ScriptObjectMirror implementation)
*
* @param otherMap a <key,value> map of properties to add
* @param otherMap a {@literal <key,value>} map of properties to add
*/
public void putAll(final Map<?, ?> otherMap) {
final boolean strict = getContext()._strict;
......
......@@ -815,7 +815,7 @@ public final class ScriptRuntime {
}
/**
* ECMA 11.8.1 - The less than operator (<) - generic implementation
* ECMA 11.8.1 - The less than operator ({@literal <}) - generic implementation
*
* @param x first object to compare
* @param y second object to compare
......@@ -828,7 +828,7 @@ public final class ScriptRuntime {
}
/**
* ECMA 11.8.2 - The greater than operator (>) - generic implementation
* ECMA 11.8.2 - The greater than operator ({@literal >}) - generic implementation
*
* @param x first object to compare
* @param y second object to compare
......@@ -841,7 +841,7 @@ public final class ScriptRuntime {
}
/**
* ECMA 11.8.3 - The less than or equal operator (<=) - generic implementation
* ECMA 11.8.3 - The less than or equal operator ({@literal <=}) - generic implementation
*
* @param x first object to compare
* @param y second object to compare
......@@ -854,7 +854,7 @@ public final class ScriptRuntime {
}
/**
* ECMA 11.8.4 - The greater than or equal operator (>=) - generic implementation
* ECMA 11.8.4 - The greater than or equal operator ({@literal >=}) - generic implementation
*
* @param x first object to compare
* @param y second object to compare
......
......@@ -87,7 +87,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime;
import jdk.nashorn.internal.runtime.Undefined;
/**
* A factory class that generates adapter classes. Adapter classes allow implementation of Java interfaces and
* <p>A factory class that generates adapter classes. Adapter classes allow implementation of Java interfaces and
* extending of Java classes from JavaScript. For every combination of a superclass to extend and interfaces to
* implement (collectively: "original types"), exactly one adapter class is generated that extends the specified
* superclass and implements the specified interfaces.
......
......@@ -43,8 +43,6 @@ public class NashornCallSiteDescriptor extends AbstractCallSiteDescriptor {
public static final int CALLSITE_SCOPE = 0x01;
/** Flags that the call site is in code that uses ECMAScript strict mode. */
public static final int CALLSITE_STRICT = 0x02;
/** Flags that a property setter call site is part of a function declaration that assigns the function object to a name. */
public static final int CALLSITE_FUNCTION_DECLARATION = 0x04;
/** Flags that a property getter or setter call site references a scope variable that is not in the global scope
* (it is in a function lexical scope), and the function's scope object class is fixed and known in advance. Such
* getters and setters can often be linked more optimally using these assumptions. */
......@@ -182,7 +180,7 @@ public class NashornCallSiteDescriptor extends AbstractCallSiteDescriptor {
/**
* Returns the named operand in this descriptor's name. Equivalent to
* {@code getNameToken(CallSiteDescriptor.NAME_OPERAND)}. E.g. for operation {@code "dyn:getProp:color"}, returns
* {@code "color"}. For call sites without named operands (e.g. {@link "dyn:new"}) returns null.
* {@code "color"}. For call sites without named operands (e.g. {@code "dyn:new"}) returns null.
* @return the named operand in this descriptor's name.
*/
public String getOperand() {
......
......@@ -200,7 +200,7 @@ public final class Options {
/**
* Return an option given its resource key. If the key doesn't begin with
* <resource>.option it will be completed using the resource from this
* {@literal <resource>}.option it will be completed using the resource from this
* instance
*
* @param key key for option
......
......@@ -117,10 +117,6 @@ public class JoniRegExp extends RegExp {
return new JoniRegExp(pattern, flags);
}
@Override
protected String replaceToken(final String str) {
return str.equals("[^]") ? "[\\s\\S]" : str;
}
}
class JoniMatcher implements RegExpMatcher {
......
......@@ -67,25 +67,6 @@ public class RegExpFactory {
return new DefaultRegExp(pattern, flags);
}
/**
* Replace a regexp token as suitable for regexp instances created by this factory.
*
* @param str a regular expression token
* @return the replacement token
*/
protected String replaceToken(final String str) {
switch (str) {
case "\\s":
return "[" + Lexer.getWhitespaceRegExp() + "]";
case "\\S":
return "[^" + Lexer.getWhitespaceRegExp() + "]";
case "[^]":
return "[\\s\\S]";
default:
return str;
}
}
/**
* Compile a regexp with the given {@code source} and {@code flags}.
*
......@@ -98,16 +79,6 @@ public class RegExpFactory {
return instance.compile(pattern, flags);
}
/**
* Replace a regexp token as needed by the currently installed factory instance.
*
* @param token a regexp token
* @return the replacement token
*/
public static String replace(final String token) {
return instance.replaceToken(token);
}
/**
* Validate a regexp with the given {@code source} and {@code flags}.
*
......@@ -120,4 +91,13 @@ public class RegExpFactory {
public static void validate(final String pattern, final String flags) throws ParserException {
instance.compile(pattern, flags);
}
/**
* Returns true if the instance uses the JDK's {@code java.util.regex} package.
*
* @return true if instance uses JDK regex package
*/
public static boolean usesJavaUtilRegex() {
return instance != null && instance.getClass() == RegExpFactory.class;
}
}
......@@ -219,7 +219,7 @@ public class EncodingHelper {
}
/**
* @see [http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt]
* @see <a href="http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt">http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt</a>
*/
public static boolean isCodeCType(int code, int ctype) {
int type;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册