mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-07 04:05:17 +00:00
Merge
This commit is contained in:
commit
46a7de200b
@ -32,6 +32,7 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||
import jdk.internal.org.objectweb.asm.Opcodes;
|
||||
import jdk.internal.org.objectweb.asm.util.CheckClassAdapter;
|
||||
|
||||
/**
|
||||
@ -39,6 +40,11 @@ import jdk.internal.org.objectweb.asm.util.CheckClassAdapter;
|
||||
*
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* ASM version to be used by nasgen tool.
|
||||
*/
|
||||
public static final int ASM_VERSION = Opcodes.ASM5;
|
||||
|
||||
private static final boolean DEBUG = Boolean.getBoolean("nasgen.debug");
|
||||
|
||||
private interface ErrorReporter {
|
||||
|
||||
@ -32,7 +32,6 @@ import static jdk.internal.org.objectweb.asm.Opcodes.ACONST_NULL;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.ANEWARRAY;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.ARETURN;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.ASM4;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.ASTORE;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.BALOAD;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.BASTORE;
|
||||
@ -96,7 +95,7 @@ public class MethodGenerator extends MethodVisitor {
|
||||
private final Type[] argumentTypes;
|
||||
|
||||
MethodGenerator(final MethodVisitor mv, final int access, final String name, final String descriptor) {
|
||||
super(ASM4, mv);
|
||||
super(Main.ASM_VERSION, mv);
|
||||
this.access = access;
|
||||
this.name = name;
|
||||
this.descriptor = descriptor;
|
||||
|
||||
@ -29,7 +29,6 @@ import jdk.internal.org.objectweb.asm.AnnotationVisitor;
|
||||
import jdk.internal.org.objectweb.asm.ClassVisitor;
|
||||
import jdk.internal.org.objectweb.asm.FieldVisitor;
|
||||
import jdk.internal.org.objectweb.asm.MethodVisitor;
|
||||
import jdk.internal.org.objectweb.asm.Opcodes;
|
||||
|
||||
/**
|
||||
* A visitor that does nothing on visitXXX calls.
|
||||
@ -37,7 +36,7 @@ import jdk.internal.org.objectweb.asm.Opcodes;
|
||||
*/
|
||||
public class NullVisitor extends ClassVisitor {
|
||||
NullVisitor() {
|
||||
super(Opcodes.ASM4);
|
||||
super(Main.ASM_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,7 +46,7 @@ public class NullVisitor extends ClassVisitor {
|
||||
final String desc,
|
||||
final String signature,
|
||||
final String[] exceptions) {
|
||||
return new MethodVisitor(Opcodes.ASM4) {
|
||||
return new MethodVisitor(Main.ASM_VERSION) {
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotationDefault() {
|
||||
return new NullAnnotationVisitor();
|
||||
@ -67,7 +66,7 @@ public class NullVisitor extends ClassVisitor {
|
||||
final String desc,
|
||||
final String signature,
|
||||
final Object value) {
|
||||
return new FieldVisitor(Opcodes.ASM4) {
|
||||
return new FieldVisitor(Main.ASM_VERSION) {
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
|
||||
return new NullAnnotationVisitor();
|
||||
@ -82,7 +81,7 @@ public class NullVisitor extends ClassVisitor {
|
||||
|
||||
private static class NullAnnotationVisitor extends AnnotationVisitor {
|
||||
NullAnnotationVisitor() {
|
||||
super(Opcodes.ASM4);
|
||||
super(Main.ASM_VERSION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ public class ScriptClassInfoCollector extends ClassVisitor {
|
||||
private String javaClassName;
|
||||
|
||||
ScriptClassInfoCollector(final ClassVisitor visitor) {
|
||||
super(Opcodes.ASM4, visitor);
|
||||
super(Main.ASM_VERSION, visitor);
|
||||
}
|
||||
|
||||
ScriptClassInfoCollector() {
|
||||
@ -80,7 +80,7 @@ public class ScriptClassInfoCollector extends ClassVisitor {
|
||||
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
|
||||
final AnnotationVisitor delegateAV = super.visitAnnotation(desc, visible);
|
||||
if (SCRIPT_CLASS_ANNO_DESC.equals(desc)) {
|
||||
return new AnnotationVisitor(Opcodes.ASM4, delegateAV) {
|
||||
return new AnnotationVisitor(Main.ASM_VERSION, delegateAV) {
|
||||
@Override
|
||||
public void visit(final String name, final Object value) {
|
||||
if ("value".equals(name)) {
|
||||
@ -98,7 +98,7 @@ public class ScriptClassInfoCollector extends ClassVisitor {
|
||||
public FieldVisitor visitField(final int fieldAccess, final String fieldName, final String fieldDesc, final String signature, final Object value) {
|
||||
final FieldVisitor delegateFV = super.visitField(fieldAccess, fieldName, fieldDesc, signature, value);
|
||||
|
||||
return new FieldVisitor(Opcodes.ASM4, delegateFV) {
|
||||
return new FieldVisitor(Main.ASM_VERSION, delegateFV) {
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
|
||||
final AnnotationVisitor delegateAV = super.visitAnnotation(descriptor, visible);
|
||||
@ -117,7 +117,7 @@ public class ScriptClassInfoCollector extends ClassVisitor {
|
||||
|
||||
addScriptMember(memInfo);
|
||||
|
||||
return new AnnotationVisitor(Opcodes.ASM4, delegateAV) {
|
||||
return new AnnotationVisitor(Main.ASM_VERSION, delegateAV) {
|
||||
// These could be "null" if values are not suppiled,
|
||||
// in which case we have to use the default values.
|
||||
private String name;
|
||||
@ -180,7 +180,7 @@ public class ScriptClassInfoCollector extends ClassVisitor {
|
||||
final MethodVisitor delegateMV = super.visitMethod(methodAccess, methodName, methodDesc,
|
||||
signature, exceptions);
|
||||
|
||||
return new MethodVisitor(Opcodes.ASM4, delegateMV) {
|
||||
return new MethodVisitor(Main.ASM_VERSION, delegateMV) {
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible) {
|
||||
@ -201,7 +201,7 @@ public class ScriptClassInfoCollector extends ClassVisitor {
|
||||
|
||||
addScriptMember(memInfo);
|
||||
|
||||
return new AnnotationVisitor(Opcodes.ASM4, delegateAV) {
|
||||
return new AnnotationVisitor(Main.ASM_VERSION, delegateAV) {
|
||||
// These could be "null" if values are not suppiled,
|
||||
// in which case we have to use the default values.
|
||||
private String name;
|
||||
|
||||
@ -73,7 +73,7 @@ public class ScriptClassInstrumentor extends ClassVisitor {
|
||||
private boolean staticInitFound;
|
||||
|
||||
ScriptClassInstrumentor(final ClassVisitor visitor, final ScriptClassInfo sci) {
|
||||
super(Opcodes.ASM4, visitor);
|
||||
super(Main.ASM_VERSION, visitor);
|
||||
if (sci == null) {
|
||||
throw new IllegalArgumentException("Null ScriptClassInfo, is the class annotated?");
|
||||
}
|
||||
@ -103,7 +103,7 @@ public class ScriptClassInstrumentor extends ClassVisitor {
|
||||
|
||||
final FieldVisitor delegateFV = super.visitField(fieldAccess, fieldName, fieldDesc,
|
||||
signature, value);
|
||||
return new FieldVisitor(Opcodes.ASM4, delegateFV) {
|
||||
return new FieldVisitor(Main.ASM_VERSION, delegateFV) {
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
|
||||
if (ScriptClassInfo.annotations.containsKey(desc)) {
|
||||
@ -140,7 +140,7 @@ public class ScriptClassInstrumentor extends ClassVisitor {
|
||||
final MethodGenerator delegateMV = new MethodGenerator(super.visitMethod(methodAccess, methodName, methodDesc,
|
||||
signature, exceptions), methodAccess, methodName, methodDesc);
|
||||
|
||||
return new MethodVisitor(Opcodes.ASM4, delegateMV) {
|
||||
return new MethodVisitor(Main.ASM_VERSION, delegateMV) {
|
||||
@Override
|
||||
public void visitInsn(final int opcode) {
|
||||
// call $clinit$ just before return from <clinit>
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
@ -61,7 +61,7 @@ PREFIX);
|
||||
|
||||
for each (opt in Options.validOptions) {
|
||||
|
||||
var isTimezone = (opt.type == "timezone");
|
||||
var isTimezone = (opt.type == "timezone");
|
||||
var defValue = opt.defaultValue;
|
||||
if (defValue == null) {
|
||||
defValue = "<none>";
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -32,7 +32,7 @@
|
||||
// load compatibility script
|
||||
load("nashorn:mozilla_compat.js");
|
||||
|
||||
// Import Java packages and classes
|
||||
// Import Java packages and classes
|
||||
// like import package.*; in Java
|
||||
importPackage(java.awt);
|
||||
// like import java.awt.Frame in Java
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,6 +31,6 @@
|
||||
|
||||
var out = java.lang.System.out;
|
||||
|
||||
// select a particular print function
|
||||
// select a particular print function
|
||||
out["println(java.lang.Object)"]("hello");
|
||||
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -128,6 +128,7 @@
|
||||
<compilerarg value="-Xlint:all"/>
|
||||
<compilerarg value="-XDignore.symbol.file"/>
|
||||
<compilerarg value="-Xdiags:verbose"/>
|
||||
<compilerarg value="-parameters"/>
|
||||
</javac>
|
||||
<copy todir="${build.classes.dir}/META-INF/services">
|
||||
<fileset dir="${meta.inf.dir}/services/"/>
|
||||
@ -519,6 +520,8 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
|
||||
<java classname="${parallel.test.runner}" dir="${basedir}" fork="true">
|
||||
<jvmarg line="${ext.class.path}"/>
|
||||
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
|
||||
<!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
|
||||
<jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
|
||||
<classpath>
|
||||
<pathelement path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
@ -582,6 +585,8 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
|
||||
<!-- clone test262 git repo -->
|
||||
<exec executable="${git.executable}">
|
||||
<arg value="clone"/>
|
||||
<arg value="--branch"/>
|
||||
<arg value="es5-tests"/>
|
||||
<arg value="https://github.com/tc39/test262"/>
|
||||
<arg value="${test.external.dir}/test262"/>
|
||||
</exec>
|
||||
|
||||
@ -28,8 +28,8 @@ jdk.asm.src.dir=../jdk/src/share/classes/jdk/internal/org/objectweb/asm
|
||||
|
||||
# source and target levels
|
||||
build.compiler=modern
|
||||
javac.source=1.7
|
||||
javac.target=1.7
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
|
||||
# nashorn version information
|
||||
nashorn.version=0.1
|
||||
@ -202,7 +202,7 @@ test262-test-sys-prop.test.js.enable.strict.mode=true
|
||||
# list of test262 test dirs to be excluded
|
||||
test262-test-sys-prop.test.js.exclude.dir=\
|
||||
${test262.suite.dir}/intl402/ \
|
||||
${test262.suite.dir}/bestPractice/
|
||||
${test262.suite.dir}/bestPractice/
|
||||
|
||||
test262-test-sys-prop.test.failed.list.file=${build.dir}/test/failedTests
|
||||
|
||||
@ -217,7 +217,7 @@ test262-test-sys-prop.test.js.framework=\
|
||||
${test262.dir}/test/harness/sta.js
|
||||
|
||||
# testmarkdown test root
|
||||
testmarkdown-test-sys-prop.test.js.roots=${testmarkdown.dir}
|
||||
testmarkdown-test-sys-prop.test.js.roots=${testmarkdown.dir}
|
||||
|
||||
# execute testmarkdown tests in shared nashorn context or not?
|
||||
testmarkdown-test-sys-prop.test.js.shared.context=false
|
||||
@ -227,7 +227,7 @@ testmarkdown-test-sys-prop.test.js.framework=\
|
||||
${test.script.dir}${file.separator}markdown.js
|
||||
|
||||
# testjfx test root
|
||||
testjfx-test-sys-prop.test.js.roots=${testjfx.dir}
|
||||
testjfx-test-sys-prop.test.js.roots=${testjfx.dir}
|
||||
|
||||
# execute testjfx tests in shared nashorn context or not?
|
||||
testjfx-test-sys-prop.test.js.shared.context=false
|
||||
@ -257,7 +257,7 @@ run.test.classpath=\
|
||||
${nashorn.internal.tests.jar}:\
|
||||
${nashorn.api.tests.jar}
|
||||
|
||||
src.dir=src
|
||||
src.dir=src/jdk.scripting.nashorn/share/classes
|
||||
test.src.dir=test/src
|
||||
|
||||
# -Xmx is used for all tests, -Xms only for octane benchmark
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,9 +31,9 @@
|
||||
|
||||
// Usage: jjs array_mapreduce.js
|
||||
|
||||
// Many Array.prototype functions such as map,
|
||||
// Many Array.prototype functions such as map,
|
||||
// filter, reduce, reduceRight, every, some are generic.
|
||||
// These functions accept ECMAScript array as well as
|
||||
// These functions accept ECMAScript array as well as
|
||||
// many array-like objects including java arrays.
|
||||
// So, you can do map/filter/reduce with Java streams or
|
||||
// you can also use Array.prototype functions as below.
|
||||
@ -73,6 +73,6 @@ forEach.call(jarr, function(x) print(x));
|
||||
// print sum of squares of the random numbers
|
||||
print("Square sum:",
|
||||
reduce.call(
|
||||
map.call(jarr, function(x) x*x),
|
||||
map.call(jarr, function(x) x*x),
|
||||
function(x, y) x + y)
|
||||
);
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -82,7 +82,7 @@ var sourceName = arguments.length == 0? __FILE__ : arguments[0];
|
||||
// load parser.js from nashorn resources
|
||||
load("nashorn:parser.js");
|
||||
|
||||
// read the full content of the file and parse it
|
||||
// read the full content of the file and parse it
|
||||
// to get AST of the script specified
|
||||
var ast = parse(readFully(sourceName));
|
||||
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
// Simple .class disassembler that uses bundled ObjectWeb ASM
|
||||
// classes in jdk8. WARNING: Bundled ObjectWeb ASM classes are
|
||||
// not part of official jdk8 API. It can be changed/removed
|
||||
// not part of official jdk8 API. It can be changed/removed
|
||||
// without notice. So, this script is brittle by design!
|
||||
|
||||
// This example demonstrates passing arguments to script
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -29,7 +29,7 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// simple example showing how to call a global script
|
||||
// simple example showing how to call a global script
|
||||
// function from caller
|
||||
|
||||
var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager");
|
||||
@ -42,7 +42,7 @@ var engine = manager.getEngineByName("js");
|
||||
engine.eval("function func(name) { print('I am func, hello ' + name) }");
|
||||
|
||||
// invoke functions, methods of code evaluated by engine
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// calling code is JavaScript and don't worry about types :)
|
||||
|
||||
engine.invokeFunction("func", "Nashorn");
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -55,7 +55,7 @@ engine.eval(<<CODE
|
||||
CODE);
|
||||
|
||||
// invoke methods of an object in script world
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// from javax.script.Invocable interface. But, hey,
|
||||
// calling code is JavaScript and don't worry about types :)
|
||||
|
||||
// get that script object on which to call a method
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -54,7 +54,7 @@ CODE);
|
||||
// the class jdk.nashorn.api.scripting.ScriptObjectMirror
|
||||
// But nashorn's dynalink linker can treat these objects
|
||||
// specially to support natural script syntax to access..
|
||||
// In Java code, you need to use ScriptObjectMirror's
|
||||
// In Java code, you need to use ScriptObjectMirror's
|
||||
// methods though. Once again, script world is simpler :-)
|
||||
|
||||
var foreignObj = engine.get("obj");
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -50,7 +50,7 @@ CODE);
|
||||
|
||||
// create Java interface object whose methods are
|
||||
// implemented by script functions. This is from
|
||||
// javax.script.Invocable. But we are in JS world,
|
||||
// javax.script.Invocable. But we are in JS world,
|
||||
// don't worry about types :)
|
||||
|
||||
var Runnable = Java.type("java.lang.Runnable");
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,8 +31,8 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// In nashorn -scripting mode,
|
||||
// "$ENV" object exposes process
|
||||
// In nashorn -scripting mode,
|
||||
// "$ENV" object exposes process
|
||||
// environment variables
|
||||
|
||||
print($ENV.PATH);
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
87
nashorn/samples/find_nonfinals.js
Normal file
87
nashorn/samples/find_nonfinals.js
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Nashorn project uses "final" modifier for method parameters
|
||||
* (like 'val' of Scala). This tool finds method parameters that
|
||||
* miss final modifier.
|
||||
*/
|
||||
|
||||
// Usage: jjs -J-Djava.ext.dirs=<your_nashorn_jar_dir> find_nonfinals.js
|
||||
|
||||
var Class = Java.type("java.lang.Class");
|
||||
var System = Java.type("java.lang.System");
|
||||
var File = Java.type("java.io.File");
|
||||
var JarFile = Java.type("java.util.jar.JarFile");
|
||||
var Modifier = Java.type("java.lang.reflect.Modifier");
|
||||
|
||||
// locate nashorn.jar from java.ext.dirs
|
||||
function findNashorn() {
|
||||
var paths = System.getProperty("java.ext.dirs").split(':');
|
||||
for each (var p in paths) {
|
||||
var nashorn = p + File.separator + "nashorn.jar";
|
||||
if (new File(nashorn).exists()) {
|
||||
return nashorn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// analyze a single Class and print info on non-final parameters
|
||||
function analyzeClass(cls) {
|
||||
var methods = cls.getDeclaredMethods();
|
||||
for each (var method in methods) {
|
||||
// this requires -parameters option when compiling java sources
|
||||
var params = method.parameters;
|
||||
for each (var p in params) {
|
||||
var modifiers = p.modifiers;
|
||||
if (!Modifier.isFinal(modifiers)) {
|
||||
if (! method.name.startsWith("access$")) {
|
||||
print(method);
|
||||
print(" ->", p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var jarFile = findNashorn();
|
||||
// load each class and use reflection to analyze each Class
|
||||
new JarFile(jarFile).stream().forEach(
|
||||
function(entry) {
|
||||
var name = entry.name;
|
||||
if (name.endsWith(".class")) {
|
||||
var clsName = name.substring(0, name.lastIndexOf('.class'));
|
||||
clsName = clsName.replace(/\//g, '.');
|
||||
var cls = Class.forName(clsName);
|
||||
analyzeClass(cls);
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -42,7 +42,7 @@ var JArray = Java.type("int[]");
|
||||
var arr = new JArray(10);
|
||||
|
||||
// store squares as values
|
||||
for (i in arr)
|
||||
for (i in arr)
|
||||
arr[i] = i*i;
|
||||
|
||||
// for .. each on java arrays
|
||||
@ -57,7 +57,7 @@ var System = Java.type("java.lang.System");
|
||||
print("System properties");
|
||||
for each (p in System.properties.entrySet()) {
|
||||
print(p.key, "=", p.value);
|
||||
}
|
||||
}
|
||||
|
||||
// print process environment vars as name = value pairs
|
||||
print("Process environment");
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -37,7 +37,7 @@ var DoubleStream = Java.type("java.util.stream.DoubleStream");
|
||||
var r = new Random();
|
||||
|
||||
// expression closure (see expression_closure.js as well)
|
||||
// passed as lambda double generator. "print" passed as
|
||||
// passed as lambda double generator. "print" passed as
|
||||
// double consumer lambda to 'forEach' method.
|
||||
|
||||
DoubleStream
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -34,7 +34,7 @@
|
||||
var Random = Java.type("java.util.Random");
|
||||
var DoubleStream = Java.type("java.util.stream.DoubleStream");
|
||||
|
||||
// function as lambda double generator. "print" passed as
|
||||
// function as lambda double generator. "print" passed as
|
||||
// double consumer lambda to 'forEach' method.
|
||||
// Function.prototype.bind used to attach 'state' for the
|
||||
// generator function.
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -69,7 +69,7 @@ function readRssFeed(url) {
|
||||
// capture title, description now
|
||||
inItem = true;
|
||||
}
|
||||
|
||||
|
||||
if (inItem) {
|
||||
switch (local) {
|
||||
case 'title':
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -38,14 +38,14 @@
|
||||
|
||||
var sender = "Buffy the Vampire Slayer";
|
||||
var recipient = "Spike";
|
||||
|
||||
|
||||
print(<<END
|
||||
|
||||
|
||||
Dear ${recipient},
|
||||
|
||||
|
||||
I wish you to leave Sunnydale and never return.
|
||||
|
||||
|
||||
Not Quite Love,
|
||||
${sender}
|
||||
|
||||
|
||||
END);
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -56,8 +56,8 @@ function javaASTToScriptObject(args) {
|
||||
// may not be exhaustive - any getAbc would become "abc" property or
|
||||
// public field becomes a property of same name.
|
||||
var ignoredProps = new HashSet();
|
||||
for each (var word in
|
||||
['extending', 'implementing', 'init', 'mods', 'clazz', 'defs',
|
||||
for each (var word in
|
||||
['extending', 'implementing', 'init', 'mods', 'clazz', 'defs',
|
||||
'expr', 'tag', 'preferredPosition', 'qualid', 'recvparam',
|
||||
'restype', 'params', 'startPosition', 'thrown',
|
||||
'tree', 'typarams', 'typetag', 'vartype']) {
|
||||
@ -83,7 +83,7 @@ function javaASTToScriptObject(args) {
|
||||
|
||||
var visitor = new ConverterVisitor() {
|
||||
// convert java AST node to a friendly script object
|
||||
// which can be viewed. Every node ends up in defaultAction
|
||||
// which can be viewed. Every node ends up in defaultAction
|
||||
// method of SimpleTreeVisitor method.
|
||||
|
||||
defaultAction: function (node, p) {
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -83,7 +83,7 @@ var counter = new CastCounter() {
|
||||
this.lineMap = node.lineMap;
|
||||
this.fileName = node.sourceFile.name;
|
||||
|
||||
// Using Java.super API to call super class method here
|
||||
// Using Java.super API to call super class method here
|
||||
return Java.super(counter).visitCompilationUnit(node, p);
|
||||
},
|
||||
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -30,7 +30,7 @@
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
// This example demonstrates Java subclassing by Java.extend
|
||||
// and javac Compiler and Tree API. This example counts number
|
||||
// of variables called "foo" in the given java source files!
|
||||
@ -38,7 +38,7 @@ if (arguments.length == 0) {
|
||||
print("Usage: jjs javafoovars.js -- <directory>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
// Java types used
|
||||
var File = Java.type("java.io.File");
|
||||
var Files = Java.type("java.nio.file.Files");
|
||||
@ -48,7 +48,7 @@ var ToolProvider = Java.type("javax.tools.ToolProvider");
|
||||
var Tree = Java.type("com.sun.source.tree.Tree");
|
||||
var TreeScanner = Java.type("com.sun.source.util.TreeScanner");
|
||||
var VariableTree = Java.type("com.sun.source.tree.VariableTree");
|
||||
|
||||
|
||||
// count "foo"-s in the given .java files
|
||||
function countFoo() {
|
||||
// get the system compiler tool
|
||||
@ -63,7 +63,7 @@ function countFoo() {
|
||||
// subclass SimpleTreeVisitor - to count variables called "foo"
|
||||
var FooCounterVisitor = Java.extend(TreeScanner);
|
||||
var fooCount = 0;
|
||||
|
||||
|
||||
var visitor = new FooCounterVisitor() {
|
||||
visitVariable: function (node, p) {
|
||||
if (node.name.toString() == "foo") {
|
||||
@ -71,13 +71,13 @@ function countFoo() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for each (var cu in task.parse()) {
|
||||
cu.accept(visitor, null);
|
||||
}
|
||||
return fooCount;
|
||||
}
|
||||
|
||||
|
||||
// for each ".java" file in directory (recursively) count "foo".
|
||||
function main(dir) {
|
||||
var totalCount = 0;
|
||||
@ -99,5 +99,5 @@ function main(dir) {
|
||||
});
|
||||
print("Total foo count: " + totalCount);
|
||||
}
|
||||
|
||||
|
||||
main(new File(arguments[0]));
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -34,14 +34,14 @@
|
||||
|
||||
function readTextFromURL(url) {
|
||||
|
||||
// equivalent to
|
||||
//
|
||||
// equivalent to
|
||||
//
|
||||
// import java.io.*;
|
||||
// import java.net.*;
|
||||
// import java.lang.StringBuffer;
|
||||
//
|
||||
// only inside the 'with' statement
|
||||
with (new JavaImporter(java.io,
|
||||
with (new JavaImporter(java.io,
|
||||
java.net,
|
||||
java.lang.StringBuilder)) {
|
||||
var buf = new StringBuilder();
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -45,7 +45,7 @@ print(map.get('js'));
|
||||
print(map['js']);
|
||||
print(map.js);
|
||||
|
||||
// also assign new key-value pair
|
||||
// also assign new key-value pair
|
||||
// as 'property-value'
|
||||
map['language'] = 'java';
|
||||
print(map.get("language"));
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -130,7 +130,7 @@ function exec(args) {
|
||||
// generate unique name
|
||||
function uniqueName() {
|
||||
var now = LocalDateTime.now().toString();
|
||||
// replace unsafe chars with '_'
|
||||
// replace unsafe chars with '_'
|
||||
return "JavaShell" + now.replace(/-|:|\./g, '_');
|
||||
}
|
||||
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
// Simple example that demonstrates reading XML Rss feed
|
||||
// to generate a HTML file from script and show it by browser
|
||||
// Uses XML DOM parser and DOM element wrapped by script
|
||||
// Uses XML DOM parser and DOM element wrapped by script
|
||||
// "proxy" (JSAdapter constructor)
|
||||
|
||||
// Java classes used
|
||||
@ -78,7 +78,7 @@ function getElemText(elem) {
|
||||
var node = nodeList.item(i);
|
||||
if (node.nodeType == TEXT_NODE) {
|
||||
text += node.nodeValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
var AbstractJSObject = Java.type("jdk.nashorn.api.scripting.AbstractJSObject");
|
||||
|
||||
// JSObject example that uses a map for properties and
|
||||
// JSObject example that uses a map for properties and
|
||||
// falls back to with methods on a java object (for missing
|
||||
// properties
|
||||
|
||||
@ -49,7 +49,7 @@ function makeJSObj(map, fallback) {
|
||||
return function() {
|
||||
var a = arguments;
|
||||
switch (a.length) {
|
||||
case 0: return fallback[name]();
|
||||
case 0: return fallback[name]();
|
||||
case 1: return fallback[name](a[0]);
|
||||
case 2: return fallback[name](a[0], a[1]);
|
||||
case 3: return fallback[name](a[0], a[1], a[2]);
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,9 +31,9 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// Many Array.prototype functions such as map,
|
||||
// Many Array.prototype functions such as map,
|
||||
// filter, reduce, reduceRight, every, some are generic.
|
||||
// These functions accept ECMAScript array as well as
|
||||
// These functions accept ECMAScript array as well as
|
||||
// many array-like objects including JSObjects.
|
||||
// See also http://en.wikipedia.org/wiki/MapReduce
|
||||
|
||||
@ -57,6 +57,6 @@ forEach.call(buf, function(x) print(x));
|
||||
// print sum of squares of the random numbers
|
||||
print("Square sum:",
|
||||
reduce.call(
|
||||
map.call(buf, function(x) x*x),
|
||||
map.call(buf, function(x) x*x),
|
||||
function(x, y) x + y)
|
||||
);
|
||||
|
||||
@ -4,22 +4,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -52,8 +52,8 @@ var TreeView = Java.type("javafx.scene.control.TreeView");
|
||||
|
||||
// read text content of a URL
|
||||
function readTextFromURL(url) {
|
||||
// equivalent to
|
||||
//
|
||||
// equivalent to
|
||||
//
|
||||
// import java.io.*;
|
||||
// import java.net.*;
|
||||
// import java.lang.StringBuffer;
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -43,7 +43,7 @@ var obj = { sender: $ARG[0], recipient: $ARG[1] };
|
||||
// JavaScript style line comment is ok too.
|
||||
print(<<EOF);
|
||||
Dear ${obj.recipient},
|
||||
|
||||
|
||||
I wish you all the best.
|
||||
|
||||
Regards,
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,9 +31,9 @@
|
||||
|
||||
// Usage: jjs list_mapreduce.js
|
||||
|
||||
// Many Array.prototype functions such as map,
|
||||
// Many Array.prototype functions such as map,
|
||||
// filter, reduce, reduceRight, every, some are generic.
|
||||
// These functions accept ECMAScript array as well as
|
||||
// These functions accept ECMAScript array as well as
|
||||
// many array-like objects including java.util.ArrayLists.
|
||||
// So, you can do map/filter/reduce with Java streams or
|
||||
// you can also use Array.prototype functions as below.
|
||||
@ -81,6 +81,6 @@ forEach.call(list, function(x) print(x));
|
||||
// print sum of squares of the random numbers
|
||||
print("Square sum:",
|
||||
reduce.call(
|
||||
map.call(list, function(x) x*x),
|
||||
map.call(list, function(x) x*x),
|
||||
function(x, y) x + y)
|
||||
);
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -46,6 +46,6 @@ timer.schedule(function() {
|
||||
}, 1000);
|
||||
|
||||
// wait for timer thread to print by
|
||||
// reading from stdin.
|
||||
// reading from stdin.
|
||||
print("press any key to exit after message from timer...");
|
||||
System.in.read();
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -33,7 +33,7 @@
|
||||
// error objects. This property's value is a string
|
||||
// that shows script stack trace.
|
||||
|
||||
function g() {
|
||||
function g() {
|
||||
throw new Error("wrong");
|
||||
}
|
||||
|
||||
@ -44,9 +44,9 @@ function f() {
|
||||
// Output looks something like:
|
||||
//
|
||||
// Error: wrong
|
||||
// at g (stack.js:37)
|
||||
// at f (stack.js:41)
|
||||
// at <program> (stack.js:52)
|
||||
// at g (stack.js:37)
|
||||
// at f (stack.js:41)
|
||||
// at <program> (stack.js:52)
|
||||
|
||||
try {
|
||||
f();
|
||||
|
||||
65
nashorn/samples/try_with_resource.js
Normal file
65
nashorn/samples/try_with_resource.js
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* This sample implements Java-like try..with..resource construct for nashorn */
|
||||
|
||||
if (arguments.length == 0) {
|
||||
print("Usage: jjs try_with_resource.js -- <file name>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Object.create accepts prototype and properties object
|
||||
function With(res) {
|
||||
return Object.create(With.prototype,
|
||||
{ res: { value: res } });
|
||||
}
|
||||
|
||||
// reserved words can be used as property names - for example "try"
|
||||
With.prototype.try = function(callback) {
|
||||
try {
|
||||
callback();
|
||||
} finally {
|
||||
this.res.close();
|
||||
}
|
||||
}
|
||||
|
||||
var BufferedReader = Java.type("java.io.BufferedReader");
|
||||
var FileReader = Java.type("java.io.FileReader");
|
||||
|
||||
var r = new BufferedReader(new FileReader(arguments[0]));
|
||||
|
||||
// Java-like try..with..resource
|
||||
With(r).try(function() {
|
||||
var s;
|
||||
while ((s = r.readLine()) != null) {
|
||||
print(s);
|
||||
}
|
||||
})
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -31,7 +31,7 @@
|
||||
|
||||
// Usage: jjs uniqs.js -- <file>
|
||||
// omit repeated lines and print unique lines
|
||||
// But this version uses Stream API
|
||||
// But this version uses Stream API
|
||||
|
||||
if (arguments.length < 1) {
|
||||
print("Usage: jjs uniqs.js -- <file>");
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
|
||||
48
nashorn/samples/zipfs.js
Normal file
48
nashorn/samples/zipfs.js
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
if (arguments.length == 0) {
|
||||
print("Usage: jjs zipfs.js -- <.zip/.jar file>")
|
||||
exit(1)
|
||||
}
|
||||
|
||||
var Files = Java.type("java.nio.file.Files")
|
||||
var FileSystems = Java.type("java.nio.file.FileSystems")
|
||||
var FileVisitOption = Java.type("java.nio.file.FileVisitOption")
|
||||
var Paths = Java.type("java.nio.file.Paths")
|
||||
|
||||
var zipfile = Paths.get(arguments[0])
|
||||
var fs = FileSystems.newFileSystem(zipfile, null)
|
||||
var root = fs.rootDirectories[0]
|
||||
Files.walk(root, FileVisitOption.FOLLOW_LINKS).forEach(
|
||||
function(p) (print(p), print(Files.readAttributes(p, "zip:*")))
|
||||
)
|
||||
fs.close()
|
||||
@ -1,21 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
if (arguments.length == 0) {
|
||||
print("Usage: jjs ziplist <zip-file>");
|
||||
print("Usage: jjs ziplist -- <zip-file>");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package jdk.nashorn.api.scripting;
|
||||
|
||||
/**
|
||||
* Class filter (optional) to be used by nashorn script engine.
|
||||
* jsr-223 program embedding nashorn script can set ClassFilter instance
|
||||
* to be used when an engine instance is created.
|
||||
*/
|
||||
public interface ClassFilter {
|
||||
/**
|
||||
* Should the Java class of the specified name be exposed to scripts?
|
||||
* @param className is the fully qualified name of the java class being
|
||||
* checked. This will not be null. Only non-array class names will be
|
||||
* passed.
|
||||
* @return true if the java class can be exposed to scripts false otherwise
|
||||
*/
|
||||
public boolean exposeToScripts(String className);
|
||||
}
|
||||
@ -40,7 +40,6 @@ import java.security.ProtectionDomain;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.script.AbstractScriptEngine;
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
@ -51,7 +50,6 @@ import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptException;
|
||||
import javax.script.SimpleBindings;
|
||||
|
||||
import jdk.nashorn.internal.objects.Global;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.ErrorManager;
|
||||
@ -95,9 +93,6 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
// This is used as "shared" global if above option is true.
|
||||
private final Global global;
|
||||
|
||||
// default options passed to Nashorn Options object
|
||||
private static final String[] DEFAULT_OPTIONS = new String[] { "-doe" };
|
||||
|
||||
// Nashorn script engine error message management
|
||||
private static final String MESSAGES_RESOURCE = "jdk.nashorn.api.scripting.resources.Messages";
|
||||
|
||||
@ -115,11 +110,8 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
}
|
||||
}
|
||||
|
||||
NashornScriptEngine(final NashornScriptEngineFactory factory, final ClassLoader appLoader) {
|
||||
this(factory, DEFAULT_OPTIONS, appLoader);
|
||||
}
|
||||
|
||||
NashornScriptEngine(final NashornScriptEngineFactory factory, final String[] args, final ClassLoader appLoader) {
|
||||
NashornScriptEngine(final NashornScriptEngineFactory factory, final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) {
|
||||
assert args != null : "null argument array";
|
||||
this.factory = factory;
|
||||
final Options options = new Options("nashorn");
|
||||
options.process(args);
|
||||
@ -131,7 +123,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
||||
@Override
|
||||
public Context run() {
|
||||
try {
|
||||
return new Context(options, errMgr, appLoader);
|
||||
return new Context(options, errMgr, appLoader, classFilter);
|
||||
} catch (final RuntimeException e) {
|
||||
if (Context.DEBUG) {
|
||||
e.printStackTrace();
|
||||
|
||||
@ -135,10 +135,13 @@ public final class NashornScriptEngineFactory implements ScriptEngineFactory {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// default options passed to Nashorn script engine
|
||||
private static final String[] DEFAULT_OPTIONS = new String[] { "-doe" };
|
||||
|
||||
@Override
|
||||
public ScriptEngine getScriptEngine() {
|
||||
try {
|
||||
return new NashornScriptEngine(this, getAppClassLoader());
|
||||
return new NashornScriptEngine(this, DEFAULT_OPTIONS, getAppClassLoader(), null);
|
||||
} catch (final RuntimeException e) {
|
||||
if (Context.DEBUG) {
|
||||
e.printStackTrace();
|
||||
@ -152,10 +155,27 @@ public final class NashornScriptEngineFactory implements ScriptEngineFactory {
|
||||
*
|
||||
* @param appLoader class loader to be used as script "app" class loader.
|
||||
* @return newly created script engine.
|
||||
* @throws SecurityException
|
||||
* if the security manager's {@code checkPermission}
|
||||
* denies {@code RuntimePermission("nashorn.setConfig")}
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final ClassLoader appLoader) {
|
||||
checkConfigPermission();
|
||||
return new NashornScriptEngine(this, appLoader);
|
||||
return newEngine(DEFAULT_OPTIONS, appLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Script engine initialized by given class filter.
|
||||
*
|
||||
* @param classFilter class filter to use.
|
||||
* @return newly created script engine.
|
||||
* @throws NullPointerException if {@code classFilter} is {@code null}
|
||||
* @throws SecurityException
|
||||
* if the security manager's {@code checkPermission}
|
||||
* denies {@code RuntimePermission("nashorn.setConfig")}
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final ClassFilter classFilter) {
|
||||
classFilter.getClass(); // null check
|
||||
return newEngine(DEFAULT_OPTIONS, getAppClassLoader(), classFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,10 +183,14 @@ public final class NashornScriptEngineFactory implements ScriptEngineFactory {
|
||||
*
|
||||
* @param args arguments array passed to script engine.
|
||||
* @return newly created script engine.
|
||||
* @throws NullPointerException if {@code args} is {@code null}
|
||||
* @throws SecurityException
|
||||
* if the security manager's {@code checkPermission}
|
||||
* denies {@code RuntimePermission("nashorn.setConfig")}
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final String... args) {
|
||||
checkConfigPermission();
|
||||
return new NashornScriptEngine(this, args, getAppClassLoader());
|
||||
args.getClass(); // null check
|
||||
return newEngine(args, getAppClassLoader(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,10 +199,44 @@ public final class NashornScriptEngineFactory implements ScriptEngineFactory {
|
||||
* @param args arguments array passed to script engine.
|
||||
* @param appLoader class loader to be used as script "app" class loader.
|
||||
* @return newly created script engine.
|
||||
* @throws NullPointerException if {@code args} is {@code null}
|
||||
* @throws SecurityException
|
||||
* if the security manager's {@code checkPermission}
|
||||
* denies {@code RuntimePermission("nashorn.setConfig")}
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final String[] args, final ClassLoader appLoader) {
|
||||
args.getClass(); // null check
|
||||
return newEngine(args, appLoader, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Script engine initialized by given arguments.
|
||||
*
|
||||
* @param args arguments array passed to script engine.
|
||||
* @param appLoader class loader to be used as script "app" class loader.
|
||||
* @param classFilter class filter to use.
|
||||
* @return newly created script engine.
|
||||
* @throws NullPointerException if {@code args} or {@code classFilter} is {@code null}
|
||||
* @throws SecurityException
|
||||
* if the security manager's {@code checkPermission}
|
||||
* denies {@code RuntimePermission("nashorn.setConfig")}
|
||||
*/
|
||||
public ScriptEngine getScriptEngine(final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) {
|
||||
args.getClass(); // null check
|
||||
classFilter.getClass(); // null check
|
||||
return newEngine(args, appLoader, classFilter);
|
||||
}
|
||||
|
||||
private ScriptEngine newEngine(final String[] args, final ClassLoader appLoader, final ClassFilter classFilter) {
|
||||
checkConfigPermission();
|
||||
return new NashornScriptEngine(this, args, appLoader);
|
||||
try {
|
||||
return new NashornScriptEngine(this, args, appLoader, classFilter);
|
||||
} catch (final RuntimeException e) {
|
||||
if (Context.DEBUG) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// -- Internals only below this point
|
||||
|
||||
@ -715,6 +715,23 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
|
||||
return newArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are the given objects mirrors to same underlying object?
|
||||
*
|
||||
* @param obj1 first object
|
||||
* @param obj2 second object
|
||||
* @return true if obj1 and obj2 are identical script objects or mirrors of it.
|
||||
*/
|
||||
public static boolean identical(final Object obj1, final Object obj2) {
|
||||
final Object o1 = (obj1 instanceof ScriptObjectMirror)?
|
||||
((ScriptObjectMirror)obj1).sobj : obj1;
|
||||
|
||||
final Object o2 = (obj2 instanceof ScriptObjectMirror)?
|
||||
((ScriptObjectMirror)obj2).sobj : obj2;
|
||||
|
||||
return o1 == o2;
|
||||
}
|
||||
|
||||
// package-privates below this.
|
||||
|
||||
ScriptObjectMirror(final ScriptObject sobj, final Global global) {
|
||||
|
||||
@ -382,10 +382,6 @@ final class AssignSymbols extends NodeOperatorVisitor<LexicalContext> implements
|
||||
symbol.setFlags(flags);
|
||||
}
|
||||
|
||||
if((isVar || isParam) && compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
|
||||
compiler.declareLocalSymbol(name);
|
||||
}
|
||||
|
||||
return symbol;
|
||||
}
|
||||
|
||||
@ -687,6 +683,22 @@ final class AssignSymbols extends NodeOperatorVisitor<LexicalContext> implements
|
||||
return binaryNode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node leaveBlock(final Block block) {
|
||||
// It's not necessary to guard the marking of symbols as locals with this "if"condition for correctness, it's
|
||||
// just an optimization -- runtime type calculation is not used when the compilation is not an on-demand
|
||||
// optimistic compilation, so we can skip locals marking then.
|
||||
if (compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
|
||||
for (final Symbol symbol: block.getSymbols()) {
|
||||
if (!symbol.isScope()) {
|
||||
assert symbol.isVar() || symbol.isParam();
|
||||
compiler.declareLocalSymbol(symbol.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node leaveDELETE(final UnaryNode unaryNode) {
|
||||
final FunctionNode currentFunctionNode = lc.getCurrentFunction();
|
||||
|
||||
@ -56,7 +56,6 @@ import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALL
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_OPTIMISTIC;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROGRAM_POINT_SHIFT;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_SCOPE;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayDeque;
|
||||
@ -250,8 +249,6 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
|
||||
private final Deque<Label> scopeEntryLabels = new ArrayDeque<>();
|
||||
|
||||
private final Set<Integer> initializedFunctionIds = new HashSet<>();
|
||||
|
||||
private static final Label METHOD_BOUNDARY = new Label("");
|
||||
private final Deque<Label> catchLabels = new ArrayDeque<>();
|
||||
// Number of live locals on entry to (and thus also break from) labeled blocks.
|
||||
@ -291,7 +288,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
* @return the correct flags for a call site in the current function
|
||||
*/
|
||||
int getCallSiteFlags() {
|
||||
return lc.getCurrentFunction().isStrict() ? callSiteFlags | CALLSITE_STRICT : callSiteFlags;
|
||||
return lc.getCurrentFunction().getCallSiteFlags() | callSiteFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1766,7 +1763,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
}
|
||||
|
||||
// Debugging: print symbols? @see --print-symbols flag
|
||||
printSymbols(block, (isFunctionBody ? "Function " : "Block in ") + (function.getIdent() == null ? "<anonymous>" : function.getIdent().getName()));
|
||||
printSymbols(block, function, (isFunctionBody ? "Function " : "Block in ") + (function.getIdent() == null ? "<anonymous>" : function.getIdent().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1872,6 +1869,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
// lingers around. Also, currently loading previously persisted optimistic types information only works if
|
||||
// we're on-demand compiling a function, so with this strategy the :program method can also have the warmup
|
||||
// benefit of using previously persisted types.
|
||||
//
|
||||
// NOTE that this means the first compiled class will effectively just have a :createProgramFunction method, and
|
||||
// the RecompilableScriptFunctionData (RSFD) object in its constants array. It won't even have the :program
|
||||
// method. This is by design. It does mean that we're wasting one compiler execution (and we could minimize this
|
||||
@ -1879,11 +1877,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
// We could emit an initial separate compile unit with the initial version of :program in it to better utilize
|
||||
// the compilation pipeline, but that would need more invasive changes, as currently the assumption that
|
||||
// :program is emitted into the first compilation unit of the function lives in many places.
|
||||
if(!onDemand && lazy && env._optimistic_types && functionNode.isProgram()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return !onDemand && lazy && env._optimistic_types && functionNode.isProgram();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -4111,19 +4105,18 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
* Debug code used to print symbols
|
||||
*
|
||||
* @param block the block we are in
|
||||
* @param function the function we are in
|
||||
* @param ident identifier for block or function where applicable
|
||||
*/
|
||||
private void printSymbols(final Block block, final String ident) {
|
||||
if (!compiler.getScriptEnvironment()._print_symbols) {
|
||||
return;
|
||||
private void printSymbols(final Block block, final FunctionNode function, final String ident) {
|
||||
if (compiler.getScriptEnvironment()._print_symbols || function.getFlag(FunctionNode.IS_PRINT_SYMBOLS)) {
|
||||
final PrintWriter out = compiler.getScriptEnvironment().getErr();
|
||||
out.println("[BLOCK in '" + ident + "']");
|
||||
if (!block.printSymbols(out)) {
|
||||
out.println("<no symbols>");
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
final PrintWriter out = compiler.getScriptEnvironment().getErr();
|
||||
out.println("[BLOCK in '" + ident + "']");
|
||||
if (!block.printSymbols(out)) {
|
||||
out.println("<no symbols>");
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
|
||||
|
||||
@ -4383,9 +4376,8 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
createFunction.end();
|
||||
}
|
||||
|
||||
if (addInitializer && !initializedFunctionIds.contains(fnId) && !compiler.isOnDemandCompilation()) {
|
||||
functionNode.getCompileUnit().addFunctionInitializer(data, functionNode);
|
||||
initializedFunctionIds.add(fnId);
|
||||
if (addInitializer && !compiler.isOnDemandCompilation()) {
|
||||
compiler.addFunctionInitializer(data, functionNode);
|
||||
}
|
||||
|
||||
// We don't emit a ScriptFunction on stack for the outermost compiled function (as there's no code being
|
||||
|
||||
@ -61,6 +61,7 @@ import jdk.nashorn.internal.ir.debug.ASTWriter;
|
||||
import jdk.nashorn.internal.ir.debug.PrintVisitor;
|
||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||
import jdk.nashorn.internal.runtime.CodeInstaller;
|
||||
import jdk.nashorn.internal.runtime.FunctionInitializer;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
import jdk.nashorn.internal.runtime.ScriptEnvironment;
|
||||
import jdk.nashorn.internal.runtime.logging.DebugLogger;
|
||||
@ -279,12 +280,12 @@ enum CompilationPhase {
|
||||
final PrintWriter err = senv.getErr();
|
||||
|
||||
//TODO separate phase for the debug printouts for abstraction and clarity
|
||||
if (senv._print_lower_ast) {
|
||||
if (senv._print_lower_ast || fn.getFlag(FunctionNode.IS_PRINT_LOWER_AST)) {
|
||||
err.println("Lower AST for: " + quote(newFunctionNode.getName()));
|
||||
err.println(new ASTWriter(newFunctionNode));
|
||||
}
|
||||
|
||||
if (senv._print_lower_parse) {
|
||||
if (senv._print_lower_parse || fn.getFlag(FunctionNode.IS_PRINT_LOWER_PARSE)) {
|
||||
err.println("Lower AST for: " + quote(newFunctionNode.getName()));
|
||||
err.println(new PrintVisitor(newFunctionNode));
|
||||
}
|
||||
@ -324,15 +325,15 @@ enum CompilationPhase {
|
||||
final DebugLogger log = compiler.getLogger();
|
||||
|
||||
log.fine("Clearing bytecode cache");
|
||||
compiler.clearBytecode();
|
||||
|
||||
for (final CompileUnit oldUnit : compiler.getCompileUnits()) {
|
||||
CompileUnit newUnit = map.get(oldUnit);
|
||||
assert map.get(oldUnit) == null;
|
||||
final StringBuilder sb = new StringBuilder(compiler.nextCompileUnitName());
|
||||
if (phases.isRestOfCompilation()) {
|
||||
sb.append("$restOf");
|
||||
}
|
||||
newUnit = compiler.createCompileUnit(sb.toString(), oldUnit.getWeight());
|
||||
final CompileUnit newUnit = compiler.createCompileUnit(sb.toString(), oldUnit.getWeight());
|
||||
log.fine("Creating new compile unit ", oldUnit, " => ", newUnit);
|
||||
map.put(oldUnit, newUnit);
|
||||
assert newUnit != null;
|
||||
@ -502,8 +503,7 @@ enum CompilationPhase {
|
||||
long length = 0L;
|
||||
|
||||
final CodeInstaller<ScriptEnvironment> codeInstaller = compiler.getCodeInstaller();
|
||||
|
||||
final Map<String, byte[]> bytecode = compiler.getBytecode();
|
||||
final Map<String, byte[]> bytecode = compiler.getBytecode();
|
||||
|
||||
for (final Entry<String, byte[]> entry : bytecode.entrySet()) {
|
||||
final String className = entry.getKey();
|
||||
@ -536,17 +536,18 @@ enum CompilationPhase {
|
||||
// initialize function in the compile units
|
||||
for (final CompileUnit unit : compiler.getCompileUnits()) {
|
||||
unit.setCode(installedClasses.get(unit.getUnitClassName()));
|
||||
unit.initializeFunctionsCode();
|
||||
}
|
||||
|
||||
if (!compiler.isOnDemandCompilation()) {
|
||||
codeInstaller.storeCompiledScript(compiler.getSource(), compiler.getFirstCompileUnit().getUnitClassName(), bytecode, constants);
|
||||
}
|
||||
|
||||
// remove installed bytecode from table in case compiler is reused
|
||||
for (final String className : installedClasses.keySet()) {
|
||||
log.fine("Removing installed class ", quote(className), " from bytecode table...");
|
||||
compiler.removeClass(className);
|
||||
// Initialize functions
|
||||
final Map<Integer, FunctionInitializer> initializers = compiler.getFunctionInitializers();
|
||||
if (initializers != null) {
|
||||
for (final Entry<Integer, FunctionInitializer> entry : initializers.entrySet()) {
|
||||
final FunctionInitializer initializer = entry.getValue();
|
||||
initializer.setCode(installedClasses.get(initializer.getClassName()));
|
||||
compiler.getScriptFunctionData(entry.getKey()).initializeCode(initializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (log.isEnabled()) {
|
||||
|
||||
@ -25,12 +25,8 @@
|
||||
|
||||
package jdk.nashorn.internal.codegen;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
|
||||
/**
|
||||
* Used to track split class compilation.
|
||||
@ -46,36 +42,6 @@ public final class CompileUnit implements Comparable<CompileUnit> {
|
||||
|
||||
private Class<?> clazz;
|
||||
|
||||
private Set<FunctionInitializer> functionInitializers = new LinkedHashSet<>();
|
||||
|
||||
private static class FunctionInitializer {
|
||||
final RecompilableScriptFunctionData data;
|
||||
final FunctionNode functionNode;
|
||||
|
||||
FunctionInitializer(final RecompilableScriptFunctionData data, final FunctionNode functionNode) {
|
||||
this.data = data;
|
||||
this.functionNode = functionNode;
|
||||
}
|
||||
|
||||
void initializeCode() {
|
||||
data.initializeCode(functionNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return data.hashCode() + 31 * functionNode.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null || obj.getClass() != FunctionInitializer.class) {
|
||||
return false;
|
||||
}
|
||||
final FunctionInitializer other = (FunctionInitializer)obj;
|
||||
return data == other.data && functionNode == other.functionNode;
|
||||
}
|
||||
}
|
||||
|
||||
CompileUnit(final String className, final ClassEmitter classEmitter, final long initialWeight) {
|
||||
this.className = className;
|
||||
this.weight = initialWeight;
|
||||
@ -108,29 +74,6 @@ public final class CompileUnit implements Comparable<CompileUnit> {
|
||||
this.classEmitter = null;
|
||||
}
|
||||
|
||||
void addFunctionInitializer(final RecompilableScriptFunctionData data, final FunctionNode functionNode) {
|
||||
functionInitializers.add(new FunctionInitializer(data, functionNode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this compile unit is responsible for initializing the specified function data with specified
|
||||
* function node.
|
||||
* @param data the function data to check
|
||||
* @param functionNode the function node to check
|
||||
* @return true if this unit is responsible for initializing the function data with the function node, otherwise
|
||||
* false
|
||||
*/
|
||||
public boolean isInitializing(final RecompilableScriptFunctionData data, final FunctionNode functionNode) {
|
||||
return functionInitializers.contains(new FunctionInitializer(data, functionNode));
|
||||
}
|
||||
|
||||
void initializeFunctionsCode() {
|
||||
for(final FunctionInitializer init : functionInitializers) {
|
||||
init.initializeCode();
|
||||
}
|
||||
functionInitializers = Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add weight to this compile unit
|
||||
* @param w weight to add
|
||||
|
||||
@ -50,7 +50,6 @@ import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import jdk.internal.dynalink.support.NameCodec;
|
||||
import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
@ -60,6 +59,7 @@ import jdk.nashorn.internal.ir.debug.ClassHistogramElement;
|
||||
import jdk.nashorn.internal.ir.debug.ObjectSizeCalculator;
|
||||
import jdk.nashorn.internal.runtime.CodeInstaller;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.FunctionInitializer;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
import jdk.nashorn.internal.runtime.ScriptEnvironment;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
@ -89,8 +89,6 @@ public final class Compiler implements Loggable {
|
||||
|
||||
private final String sourceName;
|
||||
|
||||
private final String sourceURL;
|
||||
|
||||
private final boolean optimistic;
|
||||
|
||||
private final Map<String, byte[]> bytecode;
|
||||
@ -309,21 +307,19 @@ public final class Compiler implements Loggable {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param context context
|
||||
* @param env script environment
|
||||
* @param installer code installer
|
||||
* @param source source to compile
|
||||
* @param sourceURL source URL, or null if not present
|
||||
* @param isStrict is this a strict compilation
|
||||
* @param context context
|
||||
* @param env script environment
|
||||
* @param installer code installer
|
||||
* @param source source to compile
|
||||
* @param isStrict is this a strict compilation
|
||||
*/
|
||||
public Compiler(
|
||||
final Context context,
|
||||
final ScriptEnvironment env,
|
||||
final CodeInstaller<ScriptEnvironment> installer,
|
||||
final Source source,
|
||||
final String sourceURL,
|
||||
final boolean isStrict) {
|
||||
this(context, env, installer, source, sourceURL, isStrict, false, null, null, null, null, null, null);
|
||||
this(context, env, installer, source, isStrict, false, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -333,7 +329,6 @@ public final class Compiler implements Loggable {
|
||||
* @param env script environment
|
||||
* @param installer code installer
|
||||
* @param source source to compile
|
||||
* @param sourceURL source URL, or null if not present
|
||||
* @param isStrict is this a strict compilation
|
||||
* @param isOnDemand is this an on demand compilation
|
||||
* @param compiledFunction compiled function, if any
|
||||
@ -348,7 +343,6 @@ public final class Compiler implements Loggable {
|
||||
final ScriptEnvironment env,
|
||||
final CodeInstaller<ScriptEnvironment> installer,
|
||||
final Source source,
|
||||
final String sourceURL,
|
||||
final boolean isStrict,
|
||||
final boolean isOnDemand,
|
||||
final RecompilableScriptFunctionData compiledFunction,
|
||||
@ -365,8 +359,7 @@ public final class Compiler implements Loggable {
|
||||
this.bytecode = new LinkedHashMap<>();
|
||||
this.log = initLogger(context);
|
||||
this.source = source;
|
||||
this.sourceURL = sourceURL;
|
||||
this.sourceName = FunctionNode.getSourceName(source, sourceURL);
|
||||
this.sourceName = FunctionNode.getSourceName(source);
|
||||
this.onDemand = isOnDemand;
|
||||
this.compiledFunction = compiledFunction;
|
||||
this.types = types;
|
||||
@ -411,6 +404,15 @@ public final class Compiler implements Loggable {
|
||||
sb.append(compilationId).append('$');
|
||||
}
|
||||
|
||||
if (types != null && compiledFunction.getFunctionNodeId() > 0) {
|
||||
sb.append(compiledFunction.getFunctionNodeId());
|
||||
final Type[] paramTypes = types.getParameterTypes(compiledFunction.getFunctionNodeId());
|
||||
for (final Type t : paramTypes) {
|
||||
sb.append(Type.getShortSignatureDescriptor(t));
|
||||
}
|
||||
sb.append('$');
|
||||
}
|
||||
|
||||
sb.append(Compiler.safeSourceName(env, installer, source));
|
||||
|
||||
return sb.toString();
|
||||
@ -559,8 +561,11 @@ public final class Compiler implements Loggable {
|
||||
return Collections.unmodifiableMap(bytecode);
|
||||
}
|
||||
|
||||
byte[] getBytecode(final String className) {
|
||||
return bytecode.get(className);
|
||||
/**
|
||||
* Reset bytecode cache for compiler reuse.
|
||||
*/
|
||||
void clearBytecode() {
|
||||
bytecode.clear();
|
||||
}
|
||||
|
||||
CompileUnit getFirstCompileUnit() {
|
||||
@ -584,15 +589,6 @@ public final class Compiler implements Loggable {
|
||||
bytecode.put(name, code);
|
||||
}
|
||||
|
||||
void removeClass(final String name) {
|
||||
assert bytecode.get(name) != null;
|
||||
bytecode.remove(name);
|
||||
}
|
||||
|
||||
String getSourceURL() {
|
||||
return sourceURL;
|
||||
}
|
||||
|
||||
String nextCompileUnitName() {
|
||||
final StringBuilder sb = new StringBuilder(firstCompileUnitName);
|
||||
final int cuid = nextCompileUnitId.getAndIncrement();
|
||||
@ -603,8 +599,51 @@ public final class Compiler implements Loggable {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void clearCompileUnits() {
|
||||
compileUnits.clear();
|
||||
Map<Integer, FunctionInitializer> functionInitializers;
|
||||
|
||||
void addFunctionInitializer(final RecompilableScriptFunctionData functionData, final FunctionNode functionNode) {
|
||||
if (functionInitializers == null) {
|
||||
functionInitializers = new HashMap<>();
|
||||
}
|
||||
if (!functionInitializers.containsKey(functionData)) {
|
||||
functionInitializers.put(functionData.getFunctionNodeId(), new FunctionInitializer(functionNode));
|
||||
}
|
||||
}
|
||||
|
||||
Map<Integer, FunctionInitializer> getFunctionInitializers() {
|
||||
return functionInitializers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist current compilation with the given {@code cacheKey}.
|
||||
* @param cacheKey cache key
|
||||
* @param functionNode function node
|
||||
*/
|
||||
public void persistClassInfo(final String cacheKey, final FunctionNode functionNode) {
|
||||
if (cacheKey != null && env._persistent_cache) {
|
||||
Map<Integer, FunctionInitializer> initializers;
|
||||
// If this is an on-demand compilation create a function initializer for the function being compiled.
|
||||
// Otherwise use function initializer map generated by codegen.
|
||||
if (functionInitializers == null) {
|
||||
initializers = new HashMap<>();
|
||||
final FunctionInitializer initializer = new FunctionInitializer(functionNode, getInvalidatedProgramPoints());
|
||||
initializers.put(functionNode.getId(), initializer);
|
||||
} else {
|
||||
initializers = functionInitializers;
|
||||
}
|
||||
final String mainClassName = getFirstCompileUnit().getUnitClassName();
|
||||
installer.storeScript(cacheKey, source, mainClassName, bytecode, initializers, constantData.toArray(), compilationId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the next compilation id is greater than {@code value}.
|
||||
* @param value compilation id value
|
||||
*/
|
||||
public static void updateCompilationId(final int value) {
|
||||
if (value >= COMPILATION_ID.get()) {
|
||||
COMPILATION_ID.set(value + 1);
|
||||
}
|
||||
}
|
||||
|
||||
CompileUnit addCompileUnit(final long initialWeight) {
|
||||
|
||||
@ -30,7 +30,6 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.runtime.Property;
|
||||
import jdk.nashorn.internal.runtime.PropertyMap;
|
||||
|
||||
/**
|
||||
@ -121,12 +120,7 @@ final class ConstantData {
|
||||
private final int hashCode;
|
||||
|
||||
public PropertyMapWrapper(final PropertyMap map) {
|
||||
int hash = 0;
|
||||
for (final Property property : map.getProperties()) {
|
||||
hash = hash << 7 ^ hash >> 7;
|
||||
hash ^= property.hashCode();
|
||||
}
|
||||
this.hashCode = hash;
|
||||
this.hashCode = Arrays.hashCode(map.getProperties());
|
||||
this.propertyMap = map;
|
||||
}
|
||||
|
||||
@ -137,14 +131,8 @@ final class ConstantData {
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
if (!(other instanceof PropertyMapWrapper)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Property[] ownProperties = propertyMap.getProperties();
|
||||
final Property[] otherProperties = ((PropertyMapWrapper) other).propertyMap.getProperties();
|
||||
|
||||
return Arrays.equals(ownProperties, otherProperties);
|
||||
return other instanceof PropertyMapWrapper &&
|
||||
Arrays.equals(propertyMap.getProperties(), ((PropertyMapWrapper) other).propertyMap.getProperties());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -217,7 +217,6 @@ final class FindScopeDepths extends NodeVisitor<LexicalContext> implements Logga
|
||||
allocatorClassName,
|
||||
allocatorMap,
|
||||
nestedFunctions,
|
||||
compiler.getSourceURL(),
|
||||
externalSymbolDepths.get(fnId),
|
||||
internalSymbols.get(fnId)
|
||||
);
|
||||
|
||||
@ -34,7 +34,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import jdk.nashorn.internal.ir.BaseNode;
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
import jdk.nashorn.internal.ir.Block;
|
||||
|
||||
@ -40,8 +40,6 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
|
||||
@ -80,12 +78,11 @@ public final class OptimisticTypesPersistence {
|
||||
final StringBuilder b = new StringBuilder(48);
|
||||
// Base64-encode the digest of the source, and append the function id.
|
||||
b.append(source.getDigest()).append('-').append(functionId);
|
||||
// Finally, if this is a parameter-type specialized version of the function, add the parameter types to the file
|
||||
// name.
|
||||
// Finally, if this is a parameter-type specialized version of the function, add the parameter types to the file name.
|
||||
if(paramTypes != null && paramTypes.length > 0) {
|
||||
b.append('-');
|
||||
for(final Type t: paramTypes) {
|
||||
b.append(t.getBytecodeStackType());
|
||||
b.append(Type.getShortSignatureDescriptor(t));
|
||||
}
|
||||
}
|
||||
return new LocationDescriptor(new File(cacheDir, b.toString()));
|
||||
@ -108,7 +105,7 @@ public final class OptimisticTypesPersistence {
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public static void store(final Object locationDescriptor, final Map<Integer, Type> optimisticTypes) {
|
||||
if(locationDescriptor == null) {
|
||||
if(locationDescriptor == null || optimisticTypes.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final File file = ((LocationDescriptor)locationDescriptor).file;
|
||||
@ -117,25 +114,10 @@ public final class OptimisticTypesPersistence {
|
||||
@Override
|
||||
public Void run() {
|
||||
synchronized(getFileLock(file)) {
|
||||
try (final FileOutputStream out = new FileOutputStream(file);) {
|
||||
try (final FileOutputStream out = new FileOutputStream(file)) {
|
||||
out.getChannel().lock(); // lock exclusive
|
||||
final DataOutputStream dout = new DataOutputStream(new BufferedOutputStream(out));
|
||||
dout.writeInt(optimisticTypes.size());
|
||||
for(final Map.Entry<Integer, Type> e: optimisticTypes.entrySet()) {
|
||||
dout.writeInt(e.getKey());
|
||||
final byte typeChar;
|
||||
final Type type = e.getValue();
|
||||
if(type == Type.OBJECT) {
|
||||
typeChar = 'L';
|
||||
} else if(type == Type.NUMBER) {
|
||||
typeChar = 'D';
|
||||
} else if(type == Type.LONG) {
|
||||
typeChar = 'J';
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
dout.write(typeChar);
|
||||
}
|
||||
Type.writeTypeMap(optimisticTypes, dout);
|
||||
dout.flush();
|
||||
} catch(final Exception e) {
|
||||
reportError("write", file, e);
|
||||
@ -166,24 +148,10 @@ public final class OptimisticTypesPersistence {
|
||||
return null;
|
||||
}
|
||||
synchronized(getFileLock(file)) {
|
||||
try (final FileInputStream in = new FileInputStream(file);) {
|
||||
try (final FileInputStream in = new FileInputStream(file)) {
|
||||
in.getChannel().lock(0, Long.MAX_VALUE, true); // lock shared
|
||||
final DataInputStream din = new DataInputStream(new BufferedInputStream(in));
|
||||
final Map<Integer, Type> map = new TreeMap<>();
|
||||
final int size = din.readInt();
|
||||
for(int i = 0; i < size; ++i) {
|
||||
final int pp = din.readInt();
|
||||
final int typeChar = din.read();
|
||||
final Type type;
|
||||
switch(typeChar) {
|
||||
case 'L': type = Type.OBJECT; break;
|
||||
case 'D': type = Type.NUMBER; break;
|
||||
case 'J': type = Type.LONG; break;
|
||||
default: throw new AssertionError();
|
||||
}
|
||||
map.put(pp, type);
|
||||
}
|
||||
return map;
|
||||
return Type.readTypeMap(din);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
@ -276,7 +244,7 @@ public final class OptimisticTypesPersistence {
|
||||
private static String getVersionDirName() throws Exception {
|
||||
final URL url = OptimisticTypesPersistence.class.getResource("");
|
||||
final String protocol = url.getProtocol();
|
||||
if(protocol.equals("jar")) {
|
||||
if (protocol.equals("jar")) {
|
||||
// Normal deployment: nashorn.jar
|
||||
final String jarUrlFile = url.getFile();
|
||||
final String filePath = jarUrlFile.substring(0, jarUrlFile.indexOf('!'));
|
||||
@ -310,12 +278,12 @@ public final class OptimisticTypesPersistence {
|
||||
for(final File f: dir.listFiles()) {
|
||||
if(f.getName().endsWith(".class")) {
|
||||
final long lastModified = f.lastModified();
|
||||
if(lastModified > currentMax) {
|
||||
if (lastModified > currentMax) {
|
||||
currentMax = lastModified;
|
||||
}
|
||||
} else if(f.isDirectory()) {
|
||||
} else if (f.isDirectory()) {
|
||||
final long lastModified = getLastModifiedClassFile(f, currentMax);
|
||||
if(lastModified > currentMax) {
|
||||
if (lastModified > currentMax) {
|
||||
currentMax = lastModified;
|
||||
}
|
||||
}
|
||||
@ -325,7 +293,7 @@ public final class OptimisticTypesPersistence {
|
||||
|
||||
private static Object[] createLockArray() {
|
||||
final Object[] lockArray = new Object[Runtime.getRuntime().availableProcessors() * 2];
|
||||
for(int i = 0; i < lockArray.length; ++i) {
|
||||
for (int i = 0; i < lockArray.length; ++i) {
|
||||
lockArray[i] = new Object();
|
||||
}
|
||||
return lockArray;
|
||||
|
||||
@ -115,6 +115,14 @@ final class TypeEvaluator {
|
||||
return Type.typeFor(JSType.unboxedFieldType(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares a symbol name as belonging to a non-scoped local variable during an on-demand compilation of a single
|
||||
* function. This method will add an explicit Undefined binding for the local into the runtime scope if it's
|
||||
* otherwise implicitly undefined so that when an expression is evaluated for the name, it won't accidentally find
|
||||
* an unrelated value higher up the scope chain. It is only required to call this method when doing an optimistic
|
||||
* on-demand compilation.
|
||||
* @param symbolName the name of the symbol that is to be declared as being a non-scoped local variable.
|
||||
*/
|
||||
void declareLocalSymbol(final String symbolName) {
|
||||
assert
|
||||
compiler.useOptimisticTypes() &&
|
||||
|
||||
@ -48,10 +48,15 @@ import static jdk.internal.org.objectweb.asm.Opcodes.T_INT;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.T_LONG;
|
||||
import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.CallSite;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import jdk.internal.org.objectweb.asm.Handle;
|
||||
@ -203,6 +208,20 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
|
||||
return jdk.internal.org.objectweb.asm.Type.getMethodDescriptor(getInternalType(returnType), itypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a character representing {@code type} in a method signature.
|
||||
*
|
||||
* @param type parameter type
|
||||
* @return descriptor character
|
||||
*/
|
||||
public static char getShortSignatureDescriptor(final Type type) {
|
||||
// Use 'Z' for boolean parameters as we need to distinguish from int
|
||||
if (type instanceof BooleanType) {
|
||||
return 'Z';
|
||||
}
|
||||
return type.getBytecodeStackType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type for an internal type, package private - do not use
|
||||
* outside code gen
|
||||
@ -275,6 +294,64 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a map of {@code int} to {@code Type} to an output stream. This is used to store deoptimization state.
|
||||
*
|
||||
* @param typeMap the type map
|
||||
* @param output data output
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void writeTypeMap(final Map<Integer, Type> typeMap, final DataOutput output) throws IOException {
|
||||
if (typeMap == null) {
|
||||
output.writeInt(0);
|
||||
} else {
|
||||
output.writeInt(typeMap.size());
|
||||
for(final Map.Entry<Integer, Type> e: typeMap.entrySet()) {
|
||||
output.writeInt(e.getKey());
|
||||
final byte typeChar;
|
||||
final Type type = e.getValue();
|
||||
if(type == Type.OBJECT) {
|
||||
typeChar = 'L';
|
||||
} else if (type == Type.NUMBER) {
|
||||
typeChar = 'D';
|
||||
} else if (type == Type.LONG) {
|
||||
typeChar = 'J';
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
output.writeByte(typeChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a map of {@code int} to {@code Type} from an input stream. This is used to store deoptimization state.
|
||||
*
|
||||
* @param input data input
|
||||
* @return type map
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Map<Integer, Type> readTypeMap(final DataInput input) throws IOException {
|
||||
final int size = input.readInt();
|
||||
if (size == 0) {
|
||||
return null;
|
||||
}
|
||||
final Map<Integer, Type> map = new TreeMap<>();
|
||||
for(int i = 0; i < size; ++i) {
|
||||
final int pp = input.readInt();
|
||||
final int typeChar = input.readByte();
|
||||
final Type type;
|
||||
switch(typeChar) {
|
||||
case 'L': type = Type.OBJECT; break;
|
||||
case 'D': type = Type.NUMBER; break;
|
||||
case 'J': type = Type.LONG; break;
|
||||
default: throw new AssertionError();
|
||||
}
|
||||
map.put(pp, type);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
static jdk.internal.org.objectweb.asm.Type getInternalType(final String className) {
|
||||
return jdk.internal.org.objectweb.asm.Type.getType(className);
|
||||
}
|
||||
|
||||
@ -30,7 +30,6 @@ import static jdk.nashorn.internal.runtime.UnwarrantedOptimismException.INVALID_
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
import jdk.nashorn.internal.ir.annotations.Ignore;
|
||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||
|
||||
@ -25,12 +25,18 @@
|
||||
|
||||
package jdk.nashorn.internal.ir;
|
||||
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROFILE;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_ENTEREXIT;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES;
|
||||
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||
@ -81,7 +87,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
LOWERED,
|
||||
/** program points have been assigned to unique locations */
|
||||
PROGRAM_POINTS_ASSIGNED,
|
||||
/** any transformations of builtins have taken place, e.g. apply=>call */
|
||||
/** any transformations of builtins have taken place, e.g. apply=>call */
|
||||
BUILTINS_TRANSFORMED,
|
||||
/** method has been split */
|
||||
SPLIT,
|
||||
@ -150,9 +156,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
/** Function flags. */
|
||||
private final int flags;
|
||||
|
||||
/** //@ sourceURL or //# sourceURL for program function nodes */
|
||||
private final String sourceURL;
|
||||
|
||||
/** Line number of function start */
|
||||
private final int lineNumber;
|
||||
|
||||
@ -232,6 +235,37 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
/** Is this declared in a dynamic context */
|
||||
public static final int IN_DYNAMIC_CONTEXT = 1 << 17;
|
||||
|
||||
/**
|
||||
* The following flags are derived from directive comments within this function.
|
||||
* Note that even IS_STRICT is one such flag but that requires special handling.
|
||||
*/
|
||||
|
||||
// parser, lower debugging this function
|
||||
public static final int IS_PRINT_PARSE = 1 << 18;
|
||||
public static final int IS_PRINT_LOWER_PARSE = 1 << 19;
|
||||
public static final int IS_PRINT_AST = 1 << 20;
|
||||
public static final int IS_PRINT_LOWER_AST = 1 << 21;
|
||||
public static final int IS_PRINT_SYMBOLS = 1 << 22;
|
||||
|
||||
/** profile callsites in this function? */
|
||||
public static final int IS_PROFILE = 1 << 23;
|
||||
|
||||
// callsite tracing, profiling within this function
|
||||
/** trace callsite enterexit in this function? */
|
||||
public static final int IS_TRACE_ENTEREXIT = 1 << 24;
|
||||
|
||||
/** trace callsite misses in this function? */
|
||||
public static final int IS_TRACE_MISSES = 1 << 25;
|
||||
|
||||
/** trace callsite values in this function? */
|
||||
public static final int IS_TRACE_VALUES = 1 << 26;
|
||||
|
||||
/** extension callsite flags mask */
|
||||
public static final int EXTENSION_CALLSITE_FLAGS = IS_PRINT_PARSE |
|
||||
IS_PRINT_LOWER_PARSE | IS_PRINT_AST | IS_PRINT_LOWER_AST |
|
||||
IS_PRINT_SYMBOLS | IS_PROFILE | IS_TRACE_ENTEREXIT |
|
||||
IS_TRACE_MISSES | IS_TRACE_VALUES;
|
||||
|
||||
/** Does this function or any nested functions contain an eval? */
|
||||
private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
|
||||
|
||||
@ -269,7 +303,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
* @param parameters parameter list
|
||||
* @param kind kind of function as in {@link FunctionNode.Kind}
|
||||
* @param flags initial flags
|
||||
* @param sourceURL sourceURL specified in script (optional)
|
||||
*/
|
||||
public FunctionNode(
|
||||
final Source source,
|
||||
@ -283,8 +316,7 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
final String name,
|
||||
final List<IdentNode> parameters,
|
||||
final FunctionNode.Kind kind,
|
||||
final int flags,
|
||||
final String sourceURL) {
|
||||
final int flags) {
|
||||
super(token, finish);
|
||||
|
||||
this.source = source;
|
||||
@ -300,7 +332,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this.compilationState = EnumSet.of(CompilationState.INITIALIZED);
|
||||
this.declaredSymbols = new HashSet<>();
|
||||
this.flags = flags;
|
||||
this.sourceURL = sourceURL;
|
||||
this.compileUnit = null;
|
||||
this.body = null;
|
||||
this.thisProperties = 0;
|
||||
@ -311,7 +342,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
final FunctionNode functionNode,
|
||||
final long lastToken,
|
||||
final int flags,
|
||||
final String sourceURL,
|
||||
final String name,
|
||||
final Type returnType,
|
||||
final CompileUnit compileUnit,
|
||||
@ -324,7 +354,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
|
||||
this.lineNumber = functionNode.lineNumber;
|
||||
this.flags = flags;
|
||||
this.sourceURL = sourceURL;
|
||||
this.name = name;
|
||||
this.returnType = returnType;
|
||||
this.compileUnit = compileUnit;
|
||||
@ -362,6 +391,41 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
return Node.accept(visitor, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional callsite flags to be used specific to this function.
|
||||
*
|
||||
* @return callsite flags
|
||||
*/
|
||||
public int getCallSiteFlags() {
|
||||
int callsiteFlags = 0;
|
||||
if (getFlag(IS_STRICT)) {
|
||||
callsiteFlags |= CALLSITE_STRICT;
|
||||
}
|
||||
|
||||
// quick check for extension callsite flags turned on by directives.
|
||||
if ((flags & EXTENSION_CALLSITE_FLAGS) == 0) {
|
||||
return callsiteFlags;
|
||||
}
|
||||
|
||||
if (getFlag(IS_PROFILE)) {
|
||||
callsiteFlags |= CALLSITE_PROFILE;
|
||||
}
|
||||
|
||||
if (getFlag(IS_TRACE_MISSES)) {
|
||||
callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_MISSES;
|
||||
}
|
||||
|
||||
if (getFlag(IS_TRACE_VALUES)) {
|
||||
callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT | CALLSITE_TRACE_VALUES;
|
||||
}
|
||||
|
||||
if (getFlag(IS_TRACE_ENTEREXIT)) {
|
||||
callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT;
|
||||
}
|
||||
|
||||
return callsiteFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source for this function
|
||||
* @return the source
|
||||
@ -384,56 +448,50 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
* @return name for the script source
|
||||
*/
|
||||
public String getSourceName() {
|
||||
return getSourceName(source, sourceURL);
|
||||
return getSourceName(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static source name getter
|
||||
*
|
||||
* @param source
|
||||
* @param sourceURL
|
||||
* @param source the source
|
||||
* @return source name
|
||||
*/
|
||||
public static String getSourceName(final Source source, final String sourceURL) {
|
||||
return sourceURL != null ? sourceURL : source.getName();
|
||||
public static String getSourceName(final Source source) {
|
||||
final String explicitURL = source.getExplicitURL();
|
||||
return explicitURL != null ? explicitURL : source.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the sourceURL
|
||||
* @return the sourceURL
|
||||
*/
|
||||
public String getSourceURL() {
|
||||
return sourceURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sourceURL
|
||||
* Function to parse nashorn per-function extension directive comments.
|
||||
*
|
||||
* @param lc lexical context
|
||||
* @param newSourceURL source url string to set
|
||||
* @return function node or a new one if state was changed
|
||||
* @param directive nashorn extension directive string
|
||||
* @return integer flag for the given directive.
|
||||
*/
|
||||
public FunctionNode setSourceURL(final LexicalContext lc, final String newSourceURL) {
|
||||
if (Objects.equals(sourceURL, newSourceURL)) {
|
||||
return this;
|
||||
public static int getDirectiveFlag(final String directive) {
|
||||
switch (directive) {
|
||||
case "nashorn callsite trace enterexit":
|
||||
return IS_TRACE_ENTEREXIT;
|
||||
case "nashorn callsite trace misses":
|
||||
return IS_TRACE_MISSES;
|
||||
case "nashorn callsite trace objects":
|
||||
return IS_TRACE_VALUES;
|
||||
case "nashorn callsite profile":
|
||||
return IS_PROFILE;
|
||||
case "nashorn print parse":
|
||||
return IS_PRINT_PARSE;
|
||||
case "nashorn print lower parse":
|
||||
return IS_PRINT_LOWER_PARSE;
|
||||
case "nashorn print ast":
|
||||
return IS_PRINT_AST;
|
||||
case "nashorn print lower ast":
|
||||
return IS_PRINT_LOWER_AST;
|
||||
case "nashorn print symbols":
|
||||
return IS_PRINT_SYMBOLS;
|
||||
default:
|
||||
// unknown/unsupported directive
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Node.replaceInLexicalContext(
|
||||
lc,
|
||||
this,
|
||||
new FunctionNode(
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
newSourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
compilationState,
|
||||
body,
|
||||
parameters,
|
||||
thisProperties,
|
||||
rootClass));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -469,11 +527,11 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the state of this FunctionNode contains a given compilation<
|
||||
* Check whether the state of this FunctionNode contains a given compilation
|
||||
* state.
|
||||
*
|
||||
* A node can be in many states at once, e.g. both lowered and initialized.
|
||||
* To check for an exact state, use {FunctionNode{@link #hasState(EnumSet)}
|
||||
* To check for an exact state, use {@link #hasState(EnumSet)}
|
||||
*
|
||||
* @param state state to check for
|
||||
* @return true if state is present in the total compilation state of this FunctionNode
|
||||
@ -504,7 +562,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -576,7 +633,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -733,7 +789,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
(body.needsScope() ?
|
||||
FunctionNode.HAS_SCOPE_BLOCK :
|
||||
0),
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -829,7 +884,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -890,7 +944,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -926,7 +979,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -992,7 +1044,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -1071,7 +1122,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
type,
|
||||
compileUnit,
|
||||
@ -1118,7 +1168,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
@ -1174,7 +1223,6 @@ public final class FunctionNode extends LexicalContextExpression implements Flag
|
||||
this,
|
||||
lastToken,
|
||||
flags,
|
||||
sourceURL,
|
||||
name,
|
||||
returnType,
|
||||
compileUnit,
|
||||
|
||||
@ -27,7 +27,6 @@ package jdk.nashorn.internal.ir;
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import jdk.nashorn.internal.runtime.Debug;
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
|
||||
|
||||
@ -29,7 +29,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||
import jdk.nashorn.internal.codegen.types.ArrayType;
|
||||
import jdk.nashorn.internal.codegen.types.Type;
|
||||
|
||||
@ -27,7 +27,6 @@ package jdk.nashorn.internal.ir;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||
import jdk.nashorn.internal.parser.Token;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
@ -39,7 +39,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.Attribute;
|
||||
import jdk.internal.org.objectweb.asm.Handle;
|
||||
import jdk.internal.org.objectweb.asm.Label;
|
||||
|
||||
@ -46,12 +46,11 @@ import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
import jdk.internal.dynalink.linker.LinkRequest;
|
||||
import jdk.nashorn.api.scripting.ClassFilter;
|
||||
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
import jdk.nashorn.internal.codegen.ApplySpecialization;
|
||||
import jdk.nashorn.internal.codegen.CompilerConstants.Call;
|
||||
@ -396,19 +395,19 @@ public final class Global extends ScriptObject implements Scope {
|
||||
private ScriptObject builtinJavafx;
|
||||
private ScriptObject builtinJavax;
|
||||
private ScriptObject builtinOrg;
|
||||
private ScriptObject builtinJavaImporter;
|
||||
private ScriptFunction builtinJavaImporter;
|
||||
private ScriptObject builtinJavaApi;
|
||||
private ScriptObject builtinArrayBuffer;
|
||||
private ScriptObject builtinDataView;
|
||||
private ScriptObject builtinInt8Array;
|
||||
private ScriptObject builtinUint8Array;
|
||||
private ScriptObject builtinUint8ClampedArray;
|
||||
private ScriptObject builtinInt16Array;
|
||||
private ScriptObject builtinUint16Array;
|
||||
private ScriptObject builtinInt32Array;
|
||||
private ScriptObject builtinUint32Array;
|
||||
private ScriptObject builtinFloat32Array;
|
||||
private ScriptObject builtinFloat64Array;
|
||||
private ScriptFunction builtinArrayBuffer;
|
||||
private ScriptFunction builtinDataView;
|
||||
private ScriptFunction builtinInt8Array;
|
||||
private ScriptFunction builtinUint8Array;
|
||||
private ScriptFunction builtinUint8ClampedArray;
|
||||
private ScriptFunction builtinInt16Array;
|
||||
private ScriptFunction builtinUint16Array;
|
||||
private ScriptFunction builtinInt32Array;
|
||||
private ScriptFunction builtinUint32Array;
|
||||
private ScriptFunction builtinFloat32Array;
|
||||
private ScriptFunction builtinFloat64Array;
|
||||
|
||||
/*
|
||||
* ECMA section 13.2.3 The [[ThrowTypeError]] Function Object
|
||||
@ -544,6 +543,14 @@ public final class Global extends ScriptObject implements Scope {
|
||||
|
||||
// Runtime interface to Global
|
||||
|
||||
/**
|
||||
* Is there a class filter in the current Context?
|
||||
* @return class filter
|
||||
*/
|
||||
public ClassFilter getClassFilter() {
|
||||
return context.getClassFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this global of the given Context?
|
||||
* @param ctxt the context
|
||||
@ -1688,15 +1695,15 @@ public final class Global extends ScriptObject implements Scope {
|
||||
this.quit = ScriptFunctionImpl.makeFunction("quit", EXIT);
|
||||
|
||||
// built-in constructors
|
||||
this.builtinArray = (ScriptFunction)initConstructor("Array");
|
||||
this.builtinBoolean = (ScriptFunction)initConstructor("Boolean");
|
||||
this.builtinDate = (ScriptFunction)initConstructor("Date");
|
||||
this.builtinJSON = initConstructor("JSON");
|
||||
this.builtinJSAdapter = (ScriptFunction)initConstructor("JSAdapter");
|
||||
this.builtinMath = initConstructor("Math");
|
||||
this.builtinNumber = (ScriptFunction)initConstructor("Number");
|
||||
this.builtinRegExp = (ScriptFunction)initConstructor("RegExp");
|
||||
this.builtinString = (ScriptFunction)initConstructor("String");
|
||||
this.builtinArray = initConstructor("Array", ScriptFunction.class);
|
||||
this.builtinBoolean = initConstructor("Boolean", ScriptFunction.class);
|
||||
this.builtinDate = initConstructor("Date", ScriptFunction.class);
|
||||
this.builtinJSON = initConstructor("JSON", ScriptObject.class);
|
||||
this.builtinJSAdapter = initConstructor("JSAdapter", ScriptFunction.class);
|
||||
this.builtinMath = initConstructor("Math", ScriptObject.class);
|
||||
this.builtinNumber = initConstructor("Number", ScriptFunction.class);
|
||||
this.builtinRegExp = initConstructor("RegExp", ScriptFunction.class);
|
||||
this.builtinString = initConstructor("String", ScriptFunction.class);
|
||||
|
||||
// initialize String.prototype.length to 0
|
||||
// add String.prototype.length
|
||||
@ -1777,7 +1784,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
|
||||
private void initErrorObjects() {
|
||||
// Error objects
|
||||
this.builtinError = (ScriptFunction)initConstructor("Error");
|
||||
this.builtinError = initConstructor("Error", ScriptFunction.class);
|
||||
final ScriptObject errorProto = getErrorPrototype();
|
||||
|
||||
// Nashorn specific accessors on Error.prototype - stack, lineNumber, columnNumber and fileName
|
||||
@ -1810,12 +1817,12 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
private ScriptFunction initErrorSubtype(final String name, final ScriptObject errorProto) {
|
||||
final ScriptObject cons = initConstructor(name);
|
||||
final ScriptFunction cons = initConstructor(name, ScriptFunction.class);
|
||||
final ScriptObject prototype = ScriptFunction.getPrototype(cons);
|
||||
prototype.set(NativeError.NAME, name, false);
|
||||
prototype.set(NativeError.MESSAGE, "", false);
|
||||
prototype.setInitialProto(errorProto);
|
||||
return (ScriptFunction)cons;
|
||||
return cons;
|
||||
}
|
||||
|
||||
private void initJavaAccess() {
|
||||
@ -1827,8 +1834,8 @@ public final class Global extends ScriptObject implements Scope {
|
||||
this.builtinJavafx = new NativeJavaPackage("javafx", objectProto);
|
||||
this.builtinJavax = new NativeJavaPackage("javax", objectProto);
|
||||
this.builtinOrg = new NativeJavaPackage("org", objectProto);
|
||||
this.builtinJavaImporter = initConstructor("JavaImporter");
|
||||
this.builtinJavaApi = initConstructor("Java");
|
||||
this.builtinJavaImporter = initConstructor("JavaImporter", ScriptFunction.class);
|
||||
this.builtinJavaApi = initConstructor("Java", ScriptObject.class);
|
||||
}
|
||||
|
||||
private void initScripting(final ScriptEnvironment scriptEnv) {
|
||||
@ -1881,17 +1888,17 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
private void initTypedArray() {
|
||||
this.builtinArrayBuffer = initConstructor("ArrayBuffer");
|
||||
this.builtinDataView = initConstructor("DataView");
|
||||
this.builtinInt8Array = initConstructor("Int8Array");
|
||||
this.builtinUint8Array = initConstructor("Uint8Array");
|
||||
this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray");
|
||||
this.builtinInt16Array = initConstructor("Int16Array");
|
||||
this.builtinUint16Array = initConstructor("Uint16Array");
|
||||
this.builtinInt32Array = initConstructor("Int32Array");
|
||||
this.builtinUint32Array = initConstructor("Uint32Array");
|
||||
this.builtinFloat32Array = initConstructor("Float32Array");
|
||||
this.builtinFloat64Array = initConstructor("Float64Array");
|
||||
this.builtinArrayBuffer = initConstructor("ArrayBuffer", ScriptFunction.class);
|
||||
this.builtinDataView = initConstructor("DataView", ScriptFunction.class);
|
||||
this.builtinInt8Array = initConstructor("Int8Array", ScriptFunction.class);
|
||||
this.builtinUint8Array = initConstructor("Uint8Array", ScriptFunction.class);
|
||||
this.builtinUint8ClampedArray = initConstructor("Uint8ClampedArray", ScriptFunction.class);
|
||||
this.builtinInt16Array = initConstructor("Int16Array", ScriptFunction.class);
|
||||
this.builtinUint16Array = initConstructor("Uint16Array", ScriptFunction.class);
|
||||
this.builtinInt32Array = initConstructor("Int32Array", ScriptFunction.class);
|
||||
this.builtinUint32Array = initConstructor("Uint32Array", ScriptFunction.class);
|
||||
this.builtinFloat32Array = initConstructor("Float32Array", ScriptFunction.class);
|
||||
this.builtinFloat64Array = initConstructor("Float64Array", ScriptFunction.class);
|
||||
}
|
||||
|
||||
private void copyBuiltins() {
|
||||
@ -1936,7 +1943,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
private void initDebug() {
|
||||
this.addOwnProperty("Debug", Attribute.NOT_ENUMERABLE, initConstructor("Debug"));
|
||||
this.addOwnProperty("Debug", Attribute.NOT_ENUMERABLE, initConstructor("Debug", ScriptObject.class));
|
||||
}
|
||||
|
||||
private Object printImpl(final boolean newLine, final Object... objects) {
|
||||
@ -1968,7 +1975,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
* These classes are generated by nasgen tool and so we have to use
|
||||
* reflection to load and create new instance of these classes.
|
||||
*/
|
||||
private ScriptObject initConstructor(final String name) {
|
||||
private <T extends ScriptObject> T initConstructor(final String name, final Class<T> clazz) {
|
||||
try {
|
||||
// Assuming class name pattern for built-in JS constructors.
|
||||
final StringBuilder sb = new StringBuilder("jdk.nashorn.internal.objects.");
|
||||
@ -1977,8 +1984,8 @@ public final class Global extends ScriptObject implements Scope {
|
||||
sb.append(name);
|
||||
sb.append("$Constructor");
|
||||
|
||||
final Class<?> funcClass = Class.forName(sb.toString());
|
||||
final ScriptObject res = (ScriptObject)funcClass.newInstance();
|
||||
final Class<?> funcClass = Class.forName(sb.toString());
|
||||
final T res = clazz.cast(funcClass.newInstance());
|
||||
|
||||
if (res instanceof ScriptFunction) {
|
||||
// All global constructor prototypes are not-writable,
|
||||
@ -1992,9 +1999,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
}
|
||||
|
||||
res.setIsBuiltin();
|
||||
|
||||
return res;
|
||||
|
||||
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -2008,7 +2013,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
// to play with object references carefully!!
|
||||
private void initFunctionAndObject() {
|
||||
// First-n-foremost is Function
|
||||
this.builtinFunction = (ScriptFunction)initConstructor("Function");
|
||||
this.builtinFunction = initConstructor("Function", ScriptFunction.class);
|
||||
|
||||
// create global anonymous function
|
||||
final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction();
|
||||
@ -2030,7 +2035,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
typeErrorThrower.preventExtensions();
|
||||
|
||||
// now initialize Object
|
||||
this.builtinObject = (ScriptFunction)initConstructor("Object");
|
||||
this.builtinObject = initConstructor("Object", ScriptFunction.class);
|
||||
final ScriptObject ObjectPrototype = getObjectPrototype();
|
||||
// Object.getPrototypeOf(Function.prototype) === Object.prototype
|
||||
anon.setInitialProto(ObjectPrototype);
|
||||
@ -2154,7 +2159,7 @@ public final class Global extends ScriptObject implements Scope {
|
||||
/**
|
||||
* Tag a reserved name as invalidated - used when someone writes
|
||||
* to a property with this name - overly conservative, but link time
|
||||
* is too late to apply e.g. apply->call specialization
|
||||
* is too late to apply e.g. apply->call specialization
|
||||
* @param name property name
|
||||
*/
|
||||
public void invalidateReservedName(final String name) {
|
||||
|
||||
@ -45,8 +45,8 @@ import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.ListAdapter;
|
||||
import jdk.nashorn.internal.runtime.PropertyMap;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.ScriptFunction;
|
||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||
import jdk.nashorn.internal.runtime.linker.Bootstrap;
|
||||
import jdk.nashorn.internal.runtime.linker.JavaAdapterFactory;
|
||||
|
||||
@ -39,7 +39,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import jdk.internal.dynalink.beans.BeansLinker;
|
||||
import jdk.internal.dynalink.beans.StaticClass;
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
|
||||
@ -39,6 +39,7 @@ import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import jdk.internal.dynalink.CallSiteDescriptor;
|
||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||
import jdk.internal.dynalink.linker.LinkRequest;
|
||||
@ -391,10 +392,12 @@ public final class NativeString extends ScriptObject {
|
||||
/**
|
||||
* return a List of own keys associated with the object.
|
||||
* @param all True if to include non-enumerable keys.
|
||||
* @param nonEnumerable set of non-enumerable properties seen already.Used
|
||||
* to filter out shadowed, but enumerable properties from proto children.
|
||||
* @return Array of keys.
|
||||
*/
|
||||
@Override
|
||||
public String[] getOwnKeys(final boolean all) {
|
||||
protected String[] getOwnKeys(final boolean all, final Set<String> nonEnumerable) {
|
||||
final List<Object> keys = new ArrayList<>();
|
||||
|
||||
// add string index keys
|
||||
@ -403,7 +406,7 @@ public final class NativeString extends ScriptObject {
|
||||
}
|
||||
|
||||
// add super class properties
|
||||
keys.addAll(Arrays.asList(super.getOwnKeys(all)));
|
||||
keys.addAll(Arrays.asList(super.getOwnKeys(all, nonEnumerable)));
|
||||
return keys.toArray(new String[keys.size()]);
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user