From 01f4856d53d38038f8f45523a6b1eb810d485b0c Mon Sep 17 00:00:00 2001 From: sundar Date: Fri, 30 May 2014 17:22:38 +0530 Subject: 8044415: ant makefile should have a target to generate javadoc only for jdk.nashorn.api and sub-packages Reviewed-by: jlaskey --- make/build.xml | 21 ++++- samples/filebrowser.js | 100 +++++++++++++++++++++ samples/word_histogram.js | 53 +++++++++++ .../nashorn/api/scripting/ScriptObjectMirror.java | 1 + src/jdk/nashorn/api/scripting/package-info.java | 3 +- .../nashorn/internal/ir/annotations/Reference.java | 2 - 6 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 samples/filebrowser.js create mode 100644 samples/word_histogram.js diff --git a/make/build.xml b/make/build.xml index 35877aef..f418ad1e 100644 --- a/make/build.xml +++ b/make/build.xml @@ -193,14 +193,16 @@ - - + + - + @@ -208,6 +210,19 @@ + + + + + + + + + + + + diff --git a/samples/filebrowser.js b/samples/filebrowser.js new file mode 100644 index 00000000..da00553a --- /dev/null +++ b/samples/filebrowser.js @@ -0,0 +1,100 @@ +#// Usage: jjs -fx filebrowser.js -- + +/* + * 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. + */ + +// Uses -fx and javafx TreeView to visualize directories +if (!$OPTIONS._fx) { + print("Usage: jjs -fx filebrowser.js -- "); + exit(1); +} + +// Java classes used +var File = Java.type("java.io.File"); +var Files = Java.type("java.nio.file.Files"); + +// check directory argument, if passed +var dir = arguments.length > 0? new File(arguments[0]) : new File("."); +if (! dir.isDirectory()) { + print(dir + " is not a directory!"); + exit(2); +} + +// JavaFX classes used +var FXCollections = Java.type("javafx.collections.FXCollections"); +var Scene = Java.type("javafx.scene.Scene"); +var TreeItem = Java.type("javafx.scene.control.TreeItem"); +var TreeView = Java.type("javafx.scene.control.TreeView"); + +// create a subclass of JavaFX TreeItem class +var LazyTreeItem = Java.extend(TreeItem); + +// lazily filling children of a directory LazyTreeItem +function buildChildren(dir) { + var children = FXCollections.observableArrayList(); + var stream = Files.list(dir.toPath()); + stream.forEach(function(path) { + var file = path.toFile(); + var item = file.isDirectory()? + makeLazyTreeItem(file) : new TreeItem(file.name); + children.add(item); + }); + stream.close(); + return children; +} + +// create an instance LazyTreeItem with override methods +function makeLazyTreeItem(dir) { + var item = new LazyTreeItem(dir.name) { + expanded: false, + isLeaf: function() false, + getChildren: function() { + if (! this.expanded) { + // call super class (TreeItem) method + Java.super(item).getChildren().setAll(buildChildren(dir)); + this.expanded = true; + } + // call super class (TreeItem) method + return Java.super(item).getChildren(); + } + } + return item; +} + +// JavaFX start method +function start(stage) { + stage.title = dir.absolutePath; + var rootItem = makeLazyTreeItem(dir); + rootItem.expanded = true; + var tree = new TreeView(rootItem); + stage.scene = new Scene(tree, 300, 450); + stage.show(); +} diff --git a/samples/word_histogram.js b/samples/word_histogram.js new file mode 100644 index 00000000..9c739ea0 --- /dev/null +++ b/samples/word_histogram.js @@ -0,0 +1,53 @@ +#nashorn word histogram of a file + +/* + * 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 example demonstrates how to print word histogram + * of a given text file using regex, array and JSON + * functions. + */ + +if (arguments.length < 1) { + print("Usage: jjs -scripting word_histogram.js -- "); + exit(1); +} + +var obj = {}; + +readFully(arguments[0]). + split(/[^\w+]/). + forEach(function(x) + (x in obj? obj[x]++ : obj[x] = 1)); + +print(JSON.stringify(obj)); + diff --git a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java index b1255336..07f4e8a6 100644 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java @@ -621,6 +621,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin /** * Utilitity to convert this script object to the given type. * + * @param destination type to convert to * @param type destination type to convert to * @return converted object */ diff --git a/src/jdk/nashorn/api/scripting/package-info.java b/src/jdk/nashorn/api/scripting/package-info.java index 6876151e..f017ba9e 100644 --- a/src/jdk/nashorn/api/scripting/package-info.java +++ b/src/jdk/nashorn/api/scripting/package-info.java @@ -32,7 +32,8 @@ * ScriptEngine nashornEngine = new ScriptEngineManager().getEngineByName("Nashorn"); * *

Nashorn script engines implement the optional {@link javax.script.Invocable} and {@link javax.script.Compilable} - * interfaces, allowing for efficient pre-compilation and repeated execution of scripts. See + * interfaces, allowing for efficient pre-compilation and repeated execution of scripts. In addition, + * this package provides nashorn specific extension classes, interfaces and methods. See * {@link jdk.nashorn.api.scripting.NashornScriptEngineFactory} for further details. */ package jdk.nashorn.api.scripting; diff --git a/src/jdk/nashorn/internal/ir/annotations/Reference.java b/src/jdk/nashorn/internal/ir/annotations/Reference.java index 20c8ffca..27f6a697 100644 --- a/src/jdk/nashorn/internal/ir/annotations/Reference.java +++ b/src/jdk/nashorn/internal/ir/annotations/Reference.java @@ -32,9 +32,7 @@ import java.lang.annotation.RetentionPolicy; * Reference node in AST, i.e. anything not a copy. Important for * AST traversal and cloning. Cloning currently as a rule uses * existingOrSame for references and otherwise existingOrCopy - *

*/ - @Retention(value=RetentionPolicy.RUNTIME) public @interface Reference { // EMPTY -- cgit v1.2.3 From 9632c562f98fcde891baffe603dd8f85a10e2e13 Mon Sep 17 00:00:00 2001 From: sundar Date: Tue, 3 Jun 2014 13:57:52 +0530 Subject: 8044612: StringIndexOutOfBoundException in NativeRegExp.appendReplacement Reviewed-by: hannesw, lagergren --- src/jdk/nashorn/internal/objects/NativeRegExp.java | 6 ++++ test/script/basic/JDK-8044612.js | 37 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test/script/basic/JDK-8044612.js diff --git a/src/jdk/nashorn/internal/objects/NativeRegExp.java b/src/jdk/nashorn/internal/objects/NativeRegExp.java index 89a9a828..34657d25 100644 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java @@ -731,6 +731,12 @@ public final class NativeRegExp extends ScriptObject { if (nextChar == '$') { // Skip past $ cursor++; + if (cursor == replacement.length()) { + // nothing after "$" + sb.append('$'); + break; + } + nextChar = replacement.charAt(cursor); final int firstDigit = nextChar - '0'; diff --git a/test/script/basic/JDK-8044612.js b/test/script/basic/JDK-8044612.js new file mode 100644 index 00000000..6980cd1b --- /dev/null +++ b/test/script/basic/JDK-8044612.js @@ -0,0 +1,37 @@ +/* + * 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. + * + * 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. + */ + +/** + * JDK-8044612: StringIndexOutOfBoundException in NativeRegExp.appendReplacement + * + * @test + * @run + */ + +if ("hello".replace("h", "$") != "$ello") { + fail("String.prototype.replace failed to handle '$' as replacement"); +} + +if ("hello".replace("o", "$x") != "hell$x") { + fail("String.prototype.replace failed to handle '$x' as replacement"); +} -- cgit v1.2.3 From 66e95be4970fa8efb1dec62d03f9af775f2a8b9d Mon Sep 17 00:00:00 2001 From: sundar Date: Tue, 3 Jun 2014 17:04:23 +0530 Subject: 8044520: Nashorn cannot execute node.js's express module Reviewed-by: hannesw, lagergren --- .../nashorn/api/scripting/ScriptObjectMirror.java | 2 +- .../nashorn/internal/codegen/CodeGenerator.java | 4 +- src/jdk/nashorn/internal/objects/Global.java | 4 +- src/jdk/nashorn/internal/objects/NativeObject.java | 39 +++++- .../nashorn/internal/runtime/GlobalFunctions.java | 1 - src/jdk/nashorn/internal/runtime/ScriptObject.java | 48 ++++--- test/script/basic/JDK-8044520.js | 145 +++++++++++++++++++++ 7 files changed, 222 insertions(+), 21 deletions(-) create mode 100644 test/script/basic/JDK-8044520.js diff --git a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java index 07f4e8a6..b8035d2e 100644 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java @@ -496,7 +496,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin public void setProto(final Object proto) { inGlobal(new Callable() { @Override public Void call() { - sobj.setProtoCheck(unwrap(proto, global)); + sobj.setPrototypeOf(unwrap(proto, global)); return null; } }); diff --git a/src/jdk/nashorn/internal/codegen/CodeGenerator.java b/src/jdk/nashorn/internal/codegen/CodeGenerator.java index 882846c6..52bdc7cb 100644 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java @@ -1500,7 +1500,9 @@ final class CodeGenerator extends NodeOperatorVisitor rtype, final Class... types) { + return MH.findStatic(MethodHandles.lookup(), NativeObject.class, name, MH.type(rtype, types)); + } } diff --git a/src/jdk/nashorn/internal/runtime/GlobalFunctions.java b/src/jdk/nashorn/internal/runtime/GlobalFunctions.java index c750d80e..10747a1b 100644 --- a/src/jdk/nashorn/internal/runtime/GlobalFunctions.java +++ b/src/jdk/nashorn/internal/runtime/GlobalFunctions.java @@ -459,5 +459,4 @@ loop: private static MethodHandle findOwnMH(final String name, final Class rtype, final Class... types) { return MH.findStatic(MethodHandles.lookup(), GlobalFunctions.class, name, MH.type(rtype, types)); } - } diff --git a/src/jdk/nashorn/internal/runtime/ScriptObject.java b/src/jdk/nashorn/internal/runtime/ScriptObject.java index d4556d89..a9e1e90c 100644 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java @@ -132,8 +132,6 @@ public abstract class ScriptObject implements PropertyAccess { /** Method handle to retrive prototype of this object */ public static final MethodHandle GETPROTO = findOwnMH("getProto", ScriptObject.class); - /** Method handle to set prototype of this object */ - public static final MethodHandle SETPROTOCHECK = findOwnMH("setProtoCheck", void.class, Object.class); static final MethodHandle MEGAMORPHIC_GET = findOwnMH("megamorphicGet", Object.class, String.class, boolean.class, boolean.class); static final MethodHandle GLOBALFILTER = findOwnMH("globalFilter", Object.class, Object.class); @@ -160,7 +158,7 @@ public abstract class ScriptObject implements PropertyAccess { public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setInitialProto", void.class, ScriptObject.class); /** Method handle for setting the proto of a ScriptObject after checking argument */ - public static final Call SET_PROTO_CHECK = virtualCallNoLookup(ScriptObject.class, "setProtoCheck", void.class, Object.class); + public static final Call SET_PROTO_FROM_LITERAL = virtualCallNoLookup(ScriptObject.class, "setProtoFromLiteral", void.class, Object.class); /** Method handle for setting the user accessors of a ScriptObject */ public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); @@ -1127,14 +1125,21 @@ public abstract class ScriptObject implements PropertyAccess { /** * Set the __proto__ of an object with checks. + * This is the built-in operation [[SetPrototypeOf]] + * See ES6 draft spec: 9.1.2 [[SetPrototypeOf]] (V) + * * @param newProto Prototype to set. */ - public final void setProtoCheck(final Object newProto) { - if (!isExtensible()) { - throw typeError("__proto__.set.non.extensible", ScriptRuntime.safeToString(this)); - } - + public final void setPrototypeOf(final Object newProto) { if (newProto == null || newProto instanceof ScriptObject) { + if (!isExtensible()) { + // okay to set same proto again - even if non-extensible + if (newProto == getProto()) { + return; + } + throw typeError("__proto__.set.non.extensible", ScriptRuntime.safeToString(this)); + } + // check for circularity ScriptObject p = (ScriptObject)newProto; while (p != null) { @@ -1145,14 +1150,27 @@ public abstract class ScriptObject implements PropertyAccess { } setProto((ScriptObject)newProto); } else { - final Global global = Context.getGlobal(); - final Object newProtoObject = JSType.toScriptObject(global, newProto); + throw typeError("cant.set.proto.to.non.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(newProto)); + } + } - if (newProtoObject instanceof ScriptObject) { - setProto((ScriptObject)newProtoObject); - } else { - throw typeError(global, "cant.set.proto.to.non.object", ScriptRuntime.safeToString(this), ScriptRuntime.safeToString(newProto)); - } + /** + * Set the __proto__ of an object from an object literal. + * See ES6 draft spec: B.3.1 __proto__ Property Names in + * Object Initializers. Step 6 handling of "__proto__". + * + * @param newProto Prototype to set. + */ + public final void setProtoFromLiteral(final Object newProto) { + if (newProto == null || newProto instanceof ScriptObject) { + setPrototypeOf(newProto); + } else { + // Some non-object, non-null. Then, we need to set + // Object.prototype as the new __proto__ + // + // var obj = { __proto__ : 34 }; + // print(obj.__proto__ === Object.prototype); // => true + setPrototypeOf(Global.objectPrototype()); } } diff --git a/test/script/basic/JDK-8044520.js b/test/script/basic/JDK-8044520.js new file mode 100644 index 00000000..edcaa116 --- /dev/null +++ b/test/script/basic/JDK-8044520.js @@ -0,0 +1,145 @@ +/* + * 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. + * + * 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. + */ + +/** + * JDK-8044520: Nashorn cannot execute node.js's express module + * + * @test + * @run + */ + +function checkNullProto() { + var obj = {}; + obj.__proto__ = null; + var proto = Object.getPrototypeOf(obj); + if (typeof proto != 'object' || proto !== null) { + fail("__proto__ can't be set to null!"); + } +} + +checkNullProto(); + +function checkSetProto(proto) { + var obj = {}; + obj.__proto__ = proto; + if (Object.getPrototypeOf(obj) !== Object.prototype) { + fail("obj.__proto__ set not ignored for " + proto); + } +} + +checkSetProto(undefined); +checkSetProto(42); +checkSetProto(false); +checkSetProto("hello"); + +function checkLiteralSetProto(proto) { + var obj = { __proto__: proto }; + if (obj.__proto__ !== Object.prototype) { + fail("object literal _proto__ set not ignored for " + proto); + } +} + +checkLiteralSetProto(undefined); +checkLiteralSetProto(34); +checkLiteralSetProto(true); +checkLiteralSetProto("world"); + +function checkNullProtoFromLiteral() { + var obj = { __proto__: null }; + var proto = Object.getPrototypeOf(obj); + if (typeof proto != 'object' || proto !== null) { + fail("__proto__ can't be set to null!"); + } +} + +checkNullProtoFromLiteral(); + +function checkSetPrototypeOf(proto) { + try { + Object.setPrototypeOf({}, proto); + fail("should have thrown error for " + proto); + } catch (e) { + if (! (e instanceof TypeError)) { + fail("should have thrown TypeError, got " + e); + } + } +} + +checkSetPrototypeOf(undefined); +checkSetPrototypeOf(43); +checkSetPrototypeOf(false); +checkSetPrototypeOf("nashorn"); + +function checkNullSetPrototypeOf() { + var obj = { }; + Object.setPrototypeOf(obj, null); + var proto = Object.getPrototypeOf(obj); + if (typeof proto != 'object' || proto !== null) { + fail("__proto__ can't be set to null!"); + } +} + +checkNullSetPrototypeOf(); + +var desc = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__"); + +function checkProtoGetterOnPrimitive(value) { + // call __proto__ getter on primitive - check ToObject + // is called on 'this' value as per draft spec + if (desc.get.call(value) !== Object(value).__proto__) { + fail("can't call __proto__ getter on " + value); + } +} + +checkProtoGetterOnPrimitive(32); +checkProtoGetterOnPrimitive(false); +checkProtoGetterOnPrimitive("great!"); + +function checkProtoSetterOnNonObjectThis(self) { + try { + desc.set.call(self); + fail("should have thrown TypeError"); + } catch (e) { + if (! (e instanceof TypeError)) { + fail("should throw TypeError on non-object self, got " +e); + } + } +} + +checkProtoSetterOnNonObjectThis(undefined); +checkProtoSetterOnNonObjectThis(null); + +function checkProtoSetterReturnValue(obj, p) { + if (typeof desc.set.call(obj, p) != "undefined") { + fail("__proto__ setter does not return undefined: " + obj + " " + p); + } +} + +// try non-object 'this'. setter is expected to return undefined. +checkProtoSetterReturnValue(23); +checkProtoSetterReturnValue(false); +checkProtoSetterReturnValue("foo"); + +// set proper __proto__. Still return value is undefined. +checkProtoSetterReturnValue({}, {}); +checkProtoSetterReturnValue({}, null); -- cgit v1.2.3 From 4b0a69d09ea3c8c0ab75e1056d21fa493956c7e4 Mon Sep 17 00:00:00 2001 From: sundar Date: Wed, 4 Jun 2014 16:39:04 +0530 Subject: 8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook Reviewed-by: attila, lagergren, hannesw --- src/jdk/nashorn/internal/runtime/ScriptObject.java | 13 ++---- test/script/basic/JDK-8044750.js | 53 ++++++++++++++++++++++ test/src/jdk/nashorn/api/scripting/ScopeTest.java | 17 +++++++ 3 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 test/script/basic/JDK-8044750.js diff --git a/src/jdk/nashorn/internal/runtime/ScriptObject.java b/src/jdk/nashorn/internal/runtime/ScriptObject.java index a9e1e90c..deae803e 100644 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java @@ -132,7 +132,7 @@ public abstract class ScriptObject implements PropertyAccess { /** Method handle to retrive prototype of this object */ public static final MethodHandle GETPROTO = findOwnMH("getProto", ScriptObject.class); - static final MethodHandle MEGAMORPHIC_GET = findOwnMH("megamorphicGet", Object.class, String.class, boolean.class, boolean.class); + static final MethodHandle MEGAMORPHIC_GET = findOwnMH("megamorphicGet", Object.class, String.class, boolean.class); static final MethodHandle GLOBALFILTER = findOwnMH("globalFilter", Object.class, Object.class); static final MethodHandle SETFIELD = findOwnMH("setField", void.class, CallSiteDescriptor.class, PropertyMap.class, PropertyMap.class, MethodHandle.class, Object.class, Object.class); @@ -1745,7 +1745,7 @@ public abstract class ScriptObject implements PropertyAccess { protected GuardedInvocation findGetMethod(final CallSiteDescriptor desc, final LinkRequest request, final String operator) { final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND); if (request.isCallSiteUnstable() || hasWithScope()) { - return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator), isScope() && NashornCallSiteDescriptor.isScope(desc)); + return findMegaMorphicGetMethod(desc, name, "getMethod".equals(operator)); } final FindProperty find = findProperty(name, true); @@ -1788,22 +1788,19 @@ public abstract class ScriptObject implements PropertyAccess { } private static GuardedInvocation findMegaMorphicGetMethod(final CallSiteDescriptor desc, final String name, - final boolean isMethod, final boolean isScope) { - final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod, isScope); + final boolean isMethod) { + final MethodHandle invoker = MH.insertArguments(MEGAMORPHIC_GET, 1, name, isMethod); final MethodHandle guard = getScriptObjectGuard(desc.getMethodType()); return new GuardedInvocation(invoker, guard); } @SuppressWarnings("unused") - private Object megamorphicGet(final String key, final boolean isMethod, final boolean isScope) { + private Object megamorphicGet(final String key, final boolean isMethod) { final FindProperty find = findProperty(key, true); if (find != null) { return find.getObjectValue(); } - if (isScope) { - throw referenceError("not.defined", key); - } return isMethod ? getNoSuchMethod(key) : invokeNoSuchProperty(key); } diff --git a/test/script/basic/JDK-8044750.js b/test/script/basic/JDK-8044750.js new file mode 100644 index 00000000..ee6fa4d5 --- /dev/null +++ b/test/script/basic/JDK-8044750.js @@ -0,0 +1,53 @@ +/* + * 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. + * + * 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. + */ + +/** + * JDK-8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook + * + * @test + * @run + */ + +__noSuchProperty__ = function(name) { + return 1; +} + +function func(obj) { + with(obj) { + // this "foo" getter site becomes megamorphic + // due to different 'with' scope objects. + foo; + } +} + +for (var i = 0; i < 20; i++) { + var obj = {}; + obj.foo = i; + obj[i] = i; + func(obj); +} + +// pass a 'with' scope object that does not have 'foo'. +// callsite inside func should see __noSuchProperty__ +// hook on global scope object. +func({}); diff --git a/test/src/jdk/nashorn/api/scripting/ScopeTest.java b/test/src/jdk/nashorn/api/scripting/ScopeTest.java index dc27d826..e2aec242 100644 --- a/test/src/jdk/nashorn/api/scripting/ScopeTest.java +++ b/test/src/jdk/nashorn/api/scripting/ScopeTest.java @@ -510,6 +510,23 @@ public class ScopeTest { assertEquals(e.eval("x", newCtxt), 2); } + // @bug 8044750: megamorphic getter for scope objects does not call __noSuchProperty__ hook + @Test + public static void testMegamorphicGetInGlobal() throws Exception { + final ScriptEngineManager m = new ScriptEngineManager(); + final ScriptEngine engine = m.getEngineByName("nashorn"); + final String script = "foo"; + // "foo" is megamorphic because of different global scopes. + // Make sure ScriptContext variable search works even after + // it becomes megamorphic. + for (int index = 0; index < 25; index++) { + final Bindings bindings = new SimpleBindings(); + bindings.put("foo", index); + final Number value = (Number)engine.eval(script, bindings); + assertEquals(index, value.intValue()); + } + } + /** * Test "slow" scopes involving {@code with} and {@code eval} statements for shared script classes with multiple globals. */ -- cgit v1.2.3 From 3766722d463fcc909607d0d52e5500df9b28e7df Mon Sep 17 00:00:00 2001 From: sundar Date: Thu, 5 Jun 2014 18:31:11 +0530 Subject: 8044695: __stack__ becomes visible in Error properties Reviewed-by: jlaskey, attila, lagergren --- src/jdk/nashorn/internal/objects/NativeError.java | 14 +++++++-- test/script/basic/JDK-8044695.js | 37 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/script/basic/JDK-8044695.js diff --git a/src/jdk/nashorn/internal/objects/NativeError.java b/src/jdk/nashorn/internal/objects/NativeError.java index 1b6b8094..18aa11e5 100644 --- a/src/jdk/nashorn/internal/objects/NativeError.java +++ b/src/jdk/nashorn/internal/objects/NativeError.java @@ -327,7 +327,12 @@ public final class NativeError extends ScriptObject { final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { Object value = getScriptStackString(sobj, (Throwable)exception); - sobj.put(STACK, value, false); + if (sobj.hasOwnProperty(STACK)) { + sobj.put(STACK, value, false); + } else { + sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); + } + return value; } @@ -346,7 +351,12 @@ public final class NativeError extends ScriptObject { public static Object setStack(final Object self, final Object value) { Global.checkObject(self); final ScriptObject sobj = (ScriptObject)self; - sobj.set(STACK, value, false); + if (sobj.hasOwnProperty(STACK)) { + sobj.put(STACK, value, false); + } else { + sobj.addOwnProperty(STACK, Attribute.NOT_ENUMERABLE, value); + } + return value; } diff --git a/test/script/basic/JDK-8044695.js b/test/script/basic/JDK-8044695.js new file mode 100644 index 00000000..2e7b7742 --- /dev/null +++ b/test/script/basic/JDK-8044695.js @@ -0,0 +1,37 @@ +/* + * 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. + * + * 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. + */ + +/** + * JDK-8044695: __stack__ becomes visible in Error properties + * + * @test + * @run + */ + +var e = new Error(); +// access stack to force __stack__ +e.stack; +var jsonStr = JSON.stringify(e); +if (jsonStr != "{}") { + fail("JSON string is not {}, it is " + jsonStr); +} -- cgit v1.2.3 From fdd645c487a49b6d4757d89468f442daf2094c6a Mon Sep 17 00:00:00 2001 From: sundar Date: Wed, 11 Jun 2014 17:41:52 +0530 Subject: 8044798: API for debugging Nashorn Reviewed-by: jlaskey, hannesw --- .../nashorn/internal/runtime/DebuggerSupport.java | 65 ++++++++- .../internal/runtime/ScriptFunctionData.java | 4 + src/jdk/nashorn/internal/runtime/Source.java | 5 + test/script/nosecurity/JDK-8044798.js | 159 +++++++++++++++++++++ test/script/nosecurity/JDK-8044798.js.EXPECTED | 104 ++++++++++++++ test/script/nosecurity/debuggersupportapi.js | 94 ++++++++++++ .../nosecurity/debuggersupportapi.js.EXPECTED | 22 +++ 7 files changed, 451 insertions(+), 2 deletions(-) create mode 100644 test/script/nosecurity/JDK-8044798.js create mode 100644 test/script/nosecurity/JDK-8044798.js.EXPECTED create mode 100644 test/script/nosecurity/debuggersupportapi.js create mode 100644 test/script/nosecurity/debuggersupportapi.js.EXPECTED diff --git a/src/jdk/nashorn/internal/runtime/DebuggerSupport.java b/src/jdk/nashorn/internal/runtime/DebuggerSupport.java index 261bc020..38e5d858 100644 --- a/src/jdk/nashorn/internal/runtime/DebuggerSupport.java +++ b/src/jdk/nashorn/internal/runtime/DebuggerSupport.java @@ -25,12 +25,20 @@ package jdk.nashorn.internal.runtime; +import static jdk.nashorn.internal.codegen.CompilerConstants.SOURCE; + +import java.lang.invoke.MethodHandle; +import java.lang.reflect.Field; +import java.net.URL; import java.util.HashSet; import java.util.Set; +import jdk.nashorn.internal.scripts.JS; /** * This class provides support for external debuggers. Its primary purpose is * is to simplify the debugger tasks and provide better performance. + * Even though the methods are not public, there are still part of the + * external debugger interface. */ final class DebuggerSupport { /** @@ -46,6 +54,11 @@ final class DebuggerSupport { */ @SuppressWarnings("unused") DebuggerValueDesc forceLoad = new DebuggerValueDesc(null, false, null, null); + + // Hook to force the loading of the SourceInfo class + @SuppressWarnings("unused") + final + SourceInfo srcInfo = new SourceInfo(null, 0, null, null); } /** This class is used to send a bulk description of a value. */ @@ -70,6 +83,54 @@ final class DebuggerSupport { } } + static class SourceInfo { + final String name; + final URL url; + final int hash; + final char[] content; + + SourceInfo(final String name, final int hash, final URL url, final char[] content) { + this.name = name; + this.hash = hash; + this.url = url; + this.content = content; + } + } + + /** + * Hook that is called just before invoking method handle + * from ScriptFunctionData via invoke, constructor method calls. + * + * @param mh script class method about to be invoked. + */ + static void notifyInvoke(final MethodHandle mh) { + // Do nothing here. This is placeholder method on which a + // debugger can place a breakpoint so that it can access the + // (script class) method handle that is about to be invoked. + // See ScriptFunctionData.invoke and ScriptFunctionData.construct. + } + + /** + * Return the script source info for the given script class. + * + * @param clazz compiled script class + * @return SourceInfo + */ + static SourceInfo getSourceInfo(final Class clazz) { + if (JS.class.isAssignableFrom(clazz)) { + try { + final Field sourceField = clazz.getDeclaredField(SOURCE.symbolName()); + sourceField.setAccessible(true); + final Source src = (Source) sourceField.get(null); + return src.getSourceInfo(); + } catch (final IllegalAccessException | NoSuchFieldException ignored) { + return null; + } + } + + return null; + } + /** * Return the current context global. * @return context global. @@ -84,7 +145,7 @@ final class DebuggerSupport { * @param self Receiver to use. * @param string String to evaluate. * @param returnException true if exceptions are to be returned. - * @return Result of eval as string, or, an exception or null depending on returnException. + * @return Result of eval, or, an exception or null depending on returnException. */ static Object eval(final ScriptObject scope, final Object self, final String string, final boolean returnException) { final ScriptObject global = Context.getGlobal(); @@ -235,7 +296,7 @@ final class DebuggerSupport { * @param value Arbitrary value to be displayed by the debugger. * @return A string representation of the value or an array of DebuggerValueDesc. */ - private static String valueAsString(final Object value) { + static String valueAsString(final Object value) { final JSType type = JSType.of(value); switch (type) { diff --git a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java index ad40d622..001996b7 100644 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java @@ -519,6 +519,8 @@ public abstract class ScriptFunctionData implements Serializable { final Object selfObj = convertThisObject(self); final Object[] args = arguments == null ? ScriptRuntime.EMPTY_ARRAY : arguments; + DebuggerSupport.notifyInvoke(mh); + if (isVarArg(mh)) { if (needsCallee(mh)) { return mh.invokeExact(fn, selfObj, args); @@ -572,6 +574,8 @@ public abstract class ScriptFunctionData implements Serializable { final MethodHandle mh = getGenericConstructor(); final Object[] args = arguments == null ? ScriptRuntime.EMPTY_ARRAY : arguments; + DebuggerSupport.notifyInvoke(mh); + if (isVarArg(mh)) { if (needsCallee(mh)) { return mh.invokeExact(fn, args); diff --git a/src/jdk/nashorn/internal/runtime/Source.java b/src/jdk/nashorn/internal/runtime/Source.java index f7e890ff..1423c163 100644 --- a/src/jdk/nashorn/internal/runtime/Source.java +++ b/src/jdk/nashorn/internal/runtime/Source.java @@ -124,6 +124,11 @@ public final class Source { } } + /* package-private */ + DebuggerSupport.SourceInfo getSourceInfo() { + return new DebuggerSupport.SourceInfo(getName(), data.hashCode(), data.url(), data.array()); + } + // Wrapper to manage lazy loading private static interface Data { diff --git a/test/script/nosecurity/JDK-8044798.js b/test/script/nosecurity/JDK-8044798.js new file mode 100644 index 00000000..dc1a7478 --- /dev/null +++ b/test/script/nosecurity/JDK-8044798.js @@ -0,0 +1,159 @@ +/* + * 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. + * + * 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. + */ + +/** + * JDK-8044798: API for debugging Nashorn + * + * @test + * @run + */ + +// basic API exercise checks + +var Arrays = Java.type("java.util.Arrays"); +var CharArray = Java.type("char[]"); +var DebuggerSupport = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport"); +var DebuggerValueDesc = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.DebuggerValueDesc"); + +var valueDescFields = DebuggerValueDesc.class.declaredFields; +Arrays.sort(valueDescFields, function(f1, f2) f1.name.compareTo(f2.name)); +var keyField; +for each (var f in valueDescFields) { + if (f.name == "key") { + keyField = f; + } + f.accessible = true; +} + +var debuggerSupportMethods = DebuggerSupport.class.declaredMethods; + +// methods of DebuggerSupport that we use +var evalMethod, valueInfoMethod, valueInfosMethod; +var getSourceInfoMethod, valueAsStringMethod; + +for each (var m in debuggerSupportMethods) { + m.accessible = true; + switch (m.name) { + case "eval": + evalMethod = m; + break; + case "valueInfo": + if (m.parameterCount == 3) { + valueInfoMethod = m; + } + break; + case "valueInfos": + valueInfosMethod = m; + break; + case "valueAsString": + valueAsStringMethod = m; + break; + case "getSourceInfo": + getSourceInfoMethod = m; + break; + } +} + +// eval +var value = evalMethod.invoke(null, null, null, "33 + 55", false); +print(value); + +// valueInfo +var info = valueInfoMethod.invoke(null, "apply", Function, true); +for each (var f in valueDescFields) { + print(f.name, "=", f.get(info)); +} + +// valueInfo - user defined object +var info = valueInfoMethod.invoke(null, "foo", { foo: 343 }, true); +for each (var f in valueDescFields) { + print(f.name, "=", f.get(info)); +} + +// valueInfos +var infos = valueInfosMethod.invoke(null, Object, true); +Arrays.sort(infos, function (i1, i2) keyField.get(i1).compareTo(keyField.get(i2))); + +for each (var info in infos) { + for each (var f in valueDescFields) { + print(f.name, "=", f.get(info)); + } +} + +// valueInfos - user defined object +var infos = valueInfosMethod.invoke(null, { foo: 34, bar: "hello" }, true); +Arrays.sort(infos, function (i1, i2) keyField.get(i1).compareTo(keyField.get(i2))); + +for each (var info in infos) { + for each (var f in valueDescFields) { + print(f.name, "=", f.get(info)); + } +} + +// valueAsString +function printValue(value) { + print(valueAsStringMethod.invoke(null, value)); +} + +printValue(undefined); +printValue(null); +printValue("hello"); +printValue(Math.PI); +printValue(this); + +// The below are not part of DebuggerSupport. But we need these to +// test DebuggerSupport.getSourceInfo etc. which need compiled script class + +var Source = Java.type("jdk.nashorn.internal.runtime.Source"); +var Context = Java.type("jdk.nashorn.internal.runtime.Context"); +var sourceCls = Source.class; +var errorMgrCls = Java.type("jdk.nashorn.internal.runtime.ErrorManager").class; +var booleanCls = Java.type("java.lang.Boolean").TYPE; + +// private compile method of Context class +var compileMethod = Context.class.getDeclaredMethod("compile", + sourceCls, errorMgrCls, booleanCls); +compileMethod.accessible = true; + +var scriptCls = compileMethod.invoke(Context.context, + Source.sourceFor("test", "print('hello')"), + new Context.ThrowErrorManager(), false); + +var SCRIPT_CLASS_NAME_PREFIX = "jdk.nashorn.internal.scripts.Script$"; +print("script class name pattern satisfied? " + + scriptCls.name.startsWith(SCRIPT_CLASS_NAME_PREFIX)); + +var srcInfo = getSourceInfoMethod.invoke(null, scriptCls); +var srcInfoFields = srcInfo.class.declaredFields; +Arrays.sort(srcInfoFields, function(f1, f2) f1.name.compareTo(f2.name)); + +print("Source info"); +for each (var f in srcInfoFields) { + f.accessible = true; + var fieldValue = f.get(srcInfo); + if (fieldValue instanceof CharArray) { + fieldValue = new java.lang.String(fieldValue); + } + + print(f.name, "=", fieldValue); +} diff --git a/test/script/nosecurity/JDK-8044798.js.EXPECTED b/test/script/nosecurity/JDK-8044798.js.EXPECTED new file mode 100644 index 00000000..2a21328c --- /dev/null +++ b/test/script/nosecurity/JDK-8044798.js.EXPECTED @@ -0,0 +1,104 @@ +88 +expandable = false +key = apply +valueAsObject = function Function() { [native code] } +valueAsString = function Function() { [native code] } +expandable = true +key = foo +valueAsObject = [object Object] +valueAsString = {foo: 343} +expandable = false +key = bindProperties +valueAsObject = function bindProperties() { [native code] } +valueAsString = function bindProperties() { [native code] } +expandable = false +key = create +valueAsObject = function create() { [native code] } +valueAsString = function create() { [native code] } +expandable = false +key = defineProperties +valueAsObject = function defineProperties() { [native code] } +valueAsString = function defineProperties() { [native code] } +expandable = false +key = defineProperty +valueAsObject = function defineProperty() { [native code] } +valueAsString = function defineProperty() { [native code] } +expandable = false +key = freeze +valueAsObject = function freeze() { [native code] } +valueAsString = function freeze() { [native code] } +expandable = false +key = getOwnPropertyDescriptor +valueAsObject = function getOwnPropertyDescriptor() { [native code] } +valueAsString = function getOwnPropertyDescriptor() { [native code] } +expandable = false +key = getOwnPropertyNames +valueAsObject = function getOwnPropertyNames() { [native code] } +valueAsString = function getOwnPropertyNames() { [native code] } +expandable = false +key = getPrototypeOf +valueAsObject = function getPrototypeOf() { [native code] } +valueAsString = function getPrototypeOf() { [native code] } +expandable = false +key = isExtensible +valueAsObject = function isExtensible() { [native code] } +valueAsString = function isExtensible() { [native code] } +expandable = false +key = isFrozen +valueAsObject = function isFrozen() { [native code] } +valueAsString = function isFrozen() { [native code] } +expandable = false +key = isSealed +valueAsObject = function isSealed() { [native code] } +valueAsString = function isSealed() { [native code] } +expandable = false +key = keys +valueAsObject = function keys() { [native code] } +valueAsString = function keys() { [native code] } +expandable = false +key = length +valueAsObject = 1 +valueAsString = 1 +expandable = false +key = name +valueAsObject = Object +valueAsString = "Object" +expandable = false +key = preventExtensions +valueAsObject = function preventExtensions() { [native code] } +valueAsString = function preventExtensions() { [native code] } +expandable = false +key = prototype +valueAsObject = [object Object] +valueAsString = {toString: function toString() { [native code] }, toLocaleString: function toLocaleString() { [native code] }, valueOf: function valueOf() { [native code] }, hasOwnProperty: function hasOwnProperty() { [native code] }, isPrototypeOf: function isPrototypeOf() { [native code] }, propertyIsEnumerable: function propertyIsEnumerable() { [native code] }, constructor: function Object() { [native code] }, __proto__: null} +expandable = false +key = seal +valueAsObject = function seal() { [native code] } +valueAsString = function seal() { [native code] } +expandable = false +key = setIndexedPropertiesToExternalArrayData +valueAsObject = function setIndexedPropertiesToExternalArrayData() { [native code] } +valueAsString = function setIndexedPropertiesToExternalArrayData() { [native code] } +expandable = false +key = setPrototypeOf +valueAsObject = function setPrototypeOf() { [native code] } +valueAsString = function setPrototypeOf() { [native code] } +expandable = false +key = bar +valueAsObject = hello +valueAsString = "hello" +expandable = false +key = foo +valueAsObject = 34 +valueAsString = 34 +undefined +null +"hello" +3.141592653589793 +[object global] +script class name pattern satisfied? true +Source info +content = print('hello') +hash = 1655359881 +name = test +url = null diff --git a/test/script/nosecurity/debuggersupportapi.js b/test/script/nosecurity/debuggersupportapi.js new file mode 100644 index 00000000..f2fa1014 --- /dev/null +++ b/test/script/nosecurity/debuggersupportapi.js @@ -0,0 +1,94 @@ +/* + * 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. + * + * 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. + */ + +/** + * JDK-8044798: API for debugging Nashorn + * + * @test + * @run + */ + +// Basic API class, method, field existence checks. + +// The following classes and the associated methods and fields are used as +// private debugger interface. Though private/implementation defined, nashorn +// code should not be changed to remove these classes, fields and methods. +// The test takes signatures of debugger interface and stores in .EXPECTED file. +// If any incompatible change is made to nashorn to break any of these, this +// test will fail. + +var Arrays = Java.type("java.util.Arrays"); +var DebuggerSupport = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport"); + +print(DebuggerSupport.class); +print(); +var methods = DebuggerSupport.class.declaredMethods; +Arrays.sort(methods, function(m1, m2) m1.name.compareTo(m2.name)); +for each (var mth in methods) { + switch (mth.name) { + case "eval": + case "notifyInvoke": + case "getSourceInfo": + case "valueAsString": + case "valueInfos": + print(mth); + break; + case "valueInfo": + if (mth.parameterCount == 3) { + print(mth); + } + break; + } +} +print(); + +var DebuggerValueDesc = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.DebuggerValueDesc"); +print(DebuggerValueDesc.class); +print(); +var fields = DebuggerValueDesc.class.declaredFields; +Arrays.sort(fields, function(f1, f2) f1.name.compareTo(f2.name)); +for each (var fld in fields) { + switch (fld.name) { + case "key": + case "expandable": + case "valueAsObject": + case "valueAsString": + print(fld); + } +} +print(); + +var SourceInfo = Java.type("jdk.nashorn.internal.runtime.DebuggerSupport.SourceInfo"); +print(SourceInfo.class); +print(); +var fields = SourceInfo.class.declaredFields; +Arrays.sort(fields, function(f1, f2) f1.name.compareTo(f2.name)); +for each (var fld in fields) { + switch (fld.name) { + case "name": + case "hash": + case "url": + case "content": + print(fld); + } +} diff --git a/test/script/nosecurity/debuggersupportapi.js.EXPECTED b/test/script/nosecurity/debuggersupportapi.js.EXPECTED new file mode 100644 index 00000000..0db8b30c --- /dev/null +++ b/test/script/nosecurity/debuggersupportapi.js.EXPECTED @@ -0,0 +1,22 @@ +class jdk.nashorn.internal.runtime.DebuggerSupport + +static java.lang.Object jdk.nashorn.internal.runtime.DebuggerSupport.eval(jdk.nashorn.internal.runtime.ScriptObject,java.lang.Object,java.lang.String,boolean) +static jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo jdk.nashorn.internal.runtime.DebuggerSupport.getSourceInfo(java.lang.Class) +static void jdk.nashorn.internal.runtime.DebuggerSupport.notifyInvoke(java.lang.invoke.MethodHandle) +static java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport.valueAsString(java.lang.Object) +static jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc jdk.nashorn.internal.runtime.DebuggerSupport.valueInfo(java.lang.String,java.lang.Object,boolean) +static jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc[] jdk.nashorn.internal.runtime.DebuggerSupport.valueInfos(java.lang.Object,boolean) + +class jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc + +final boolean jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.expandable +final java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.key +final java.lang.Object jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.valueAsObject +final java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport$DebuggerValueDesc.valueAsString + +class jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo + +final char[] jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.content +final int jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.hash +final java.lang.String jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.name +final java.net.URL jdk.nashorn.internal.runtime.DebuggerSupport$SourceInfo.url -- cgit v1.2.3 From 551861415cebed7eb14f1ee644d2d5e8fdf075db Mon Sep 17 00:00:00 2001 From: sundar Date: Mon, 16 Jun 2014 08:55:58 +0530 Subject: 8044517: Run & debug single Nashorn test Reviewed-by: lagergren, attila Contributed-by: jaroslav.tulach@oracle.com --- make/build.xml | 69 +++++++++++++++++++++++-------------- make/nbproject/ide-file-targets.xml | 36 ++++--------------- make/nbproject/project.xml | 22 ++++++------ 3 files changed, 61 insertions(+), 66 deletions(-) diff --git a/make/build.xml b/make/build.xml index f418ad1e..3b30a089 100644 --- a/make/build.xml +++ b/make/build.xml @@ -351,52 +351,71 @@ grant codeBase "file:/${basedir}/test/script/basic/classloader.js" { - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + - - + + + + + - - + + + + + + - - - - + + - - + + + + + diff --git a/make/nbproject/ide-file-targets.xml b/make/nbproject/ide-file-targets.xml index cb017bb2..00a06351 100644 --- a/make/nbproject/ide-file-targets.xml +++ b/make/nbproject/ide-file-targets.xml @@ -22,38 +22,14 @@ questions. --> - - - - - - - - - Must set property 'debug.class' - + + Must set property 'debug.class' - - - - - - - - - - - - - Must set property 'run.class' - - - - - - - + + + + diff --git a/make/nbproject/project.xml b/make/nbproject/project.xml index 828dc29d..2fcc6442 100644 --- a/make/nbproject/project.xml +++ b/make/nbproject/project.xml @@ -98,27 +98,27 @@ debug-nb - - - debug-selected-file-in-src + + + test - debug.class - test/src + test.class + ../test/src \.java$ - java-name + relative-path-noext - + - run-selected-file-in-src + debug-selected-file-in-src - run.class - test/src + test.class + ../test/src \.java$ - java-name + relative-path-noext -- cgit v1.2.3