Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8337280: Include jdk.jsobject module with JavaFX #1529

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
32 changes: 28 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3580,6 +3580,30 @@ project(":media") {
addValidateSourceSets(project, sourceSets)
}

project(":jsobject") {
project.ext.buildModule = true
project.ext.includeSources = true
project.ext.moduleRuntime = true
project.ext.moduleName = "jdk.jsobject"

sourceSets {
main
}

project.ext.moduleSourcePath = defaultModuleSourcePath
project.ext.moduleSourcePathShim = defaultModuleSourcePathShim

commonModuleSetup(project, [ 'jsobject' ])


dependencies {
}

addMavenPublication(project, [])

addValidateSourceSets(project, sourceSets)
}

project(":web") {
configurations {
webkit
Expand Down Expand Up @@ -3610,7 +3634,7 @@ project(":web") {
project.ext.moduleSourcePath = defaultModuleSourcePath
project.ext.moduleSourcePathShim = defaultModuleSourcePathShim

commonModuleSetup(project, [ 'base', 'graphics', 'controls', 'media', 'web' ])
commonModuleSetup(project, [ 'base', 'graphics', 'controls', 'media', 'jsobject', 'web' ])

dependencies {
if (IS_COMPILE_WEBKIT) {
Expand Down Expand Up @@ -3860,7 +3884,7 @@ project(":web") {
assemble.dependsOn compileJavaDOMBinding, drtJar
}

addMavenPublication(project, [ 'controls', 'media' ])
addMavenPublication(project, [ 'controls', 'media', 'jsobject' ])

addValidateSourceSets(project, sourceSets)
}
Expand Down Expand Up @@ -3922,7 +3946,7 @@ project(":systemTests") {
testImplementation project(":swing").sourceSets.test.output
}

def dependentProjects = [ 'base', 'graphics', 'controls', 'media', 'web', 'swing', 'fxml' ]
def dependentProjects = [ 'base', 'graphics', 'controls', 'media', 'jsobject', 'web', 'swing', 'fxml' ]
commonModuleSetup(project, dependentProjects)

File testJavaPolicyFile = new File(rootProject.buildDir, TESTJAVAPOLICYFILE);
Expand Down Expand Up @@ -4363,7 +4387,7 @@ task javadoc(type: Javadoc, dependsOn: createMSPfile) {
executable = JAVADOC
def projectsToDocument = [
project(":base"), project(":graphics"), project(":controls"), project(":media"),
project(":swing"), /*project(":swt"),*/ project(":fxml"), project(":web")]
project(":swing"), /*project(":swt"),*/ project(":fxml"), project(":jsobject"), project(":web")]
source(projectsToDocument.collect({
[it.sourceSets.main.java]
}));
Expand Down
34 changes: 34 additions & 0 deletions modules/jdk.jsobject/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2016, 2024, 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.
*/

/**
* Defines the API for the JavaScript Object.
*
* @moduleGraph
* @since 9
*/
module jdk.jsobject {
exports netscape.javascript;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2006, 2024, 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 netscape.javascript;

/**
* Thrown when an exception is raised in the JavaScript engine. This is merely
* a marker class to indicate an exception relating to the JavaScript
* interface.
* @since 1.5
*/
public class JSException extends RuntimeException {
private static final long serialVersionUID = 2778103758223661489L;

/**
* Constructs a new JavaScript exception with null as it's detail message.
*/
public JSException() {
super();
}

/**
* Construct a new JavaScript exception with the specified detail message.
*
* @param s The detail message
*/
public JSException(String s) {
super(s);
}

/**
* Construct a new JavaScript exception with the specified cause.
*
* @param t Throwable cause
*/
public JSException(Throwable t) {
super(t);
}
}
139 changes: 139 additions & 0 deletions modules/jdk.jsobject/src/main/java/netscape/javascript/JSObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2006, 2024, 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 netscape.javascript;

/**
* <p>
* Allows Java code to manipulate JavaScript objects.
* </p>
*
* <p>
* When a JavaScript object is passed or returned to Java code, it
* is wrapped in an instance of {@code JSObject}. When a
* {@code JSObject} instance is passed to the JavaScript engine,
* it is unwrapped back to its original JavaScript object. The
* {@code JSObject} class provides a way to invoke JavaScript
* methods and examine JavaScript properties.
* </p>
*
* <p> Any data returned from the JavaScript engine to Java is
* converted to Java data types. Certain data passed to the JavaScript
* engine is converted to JavaScript data types.
* </p>
* @since 1.5
*/
public abstract class JSObject {

static {
System.err.println("KCR: JavaFX version of jdk.jsobject loaded");
}
Comment on lines +50 to +52
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This debug print statement is there to make it easy to see if the JavaFX version of this class is being loaded. I'll leave it during testing and review, but I'll remove it before the final review.


/**
* Constructs a new JSObject. Users should neither call this method nor
* subclass JSObject.
*/
protected JSObject() {
}

/**
* Calls a JavaScript method. Equivalent to
* "this.methodName(args[0], args[1], ...)" in JavaScript.
*
* @param methodName The name of the JavaScript method to be invoked.
* @param args the Java objects passed as arguments to the method.
* @return Result of the method.
* @throws JSException when an error is reported from the browser or
* JavaScript engine.
*/
public abstract Object call(String methodName, Object... args) throws JSException;

/**
* Evaluates a JavaScript expression. The expression is a string of
* JavaScript source code which will be evaluated in the context given by
* "this".
*
* @param s The JavaScript expression.
* @return Result of the JavaScript evaluation.
* @throws JSException when an error is reported from the browser or
* JavaScript engine.
*/
public abstract Object eval(String s) throws JSException;

/**
* Retrieves a named member of a JavaScript object. Equivalent to
* "this.name" in JavaScript.
*
* @param name The name of the JavaScript property to be accessed.
* @return The value of the property.
* @throws JSException when an error is reported from the browser or
* JavaScript engine.
*/
public abstract Object getMember(String name) throws JSException;

/**
* Sets a named member of a JavaScript object. Equivalent to
* "this.name = value" in JavaScript.
*
* @param name The name of the JavaScript property to be accessed.
* @param value The value of the property.
* @throws JSException when an error is reported from the browser or
* JavaScript engine.
*/
public abstract void setMember(String name, Object value) throws JSException;

/**
* Removes a named member of a JavaScript object. Equivalent
* to "delete this.name" in JavaScript.
*
* @param name The name of the JavaScript property to be removed.
* @throws JSException when an error is reported from the browser or
* JavaScript engine.
*/
public abstract void removeMember(String name) throws JSException;

/**
* Retrieves an indexed member of a JavaScript object. Equivalent to
* "this[index]" in JavaScript.
*
* @param index The index of the array to be accessed.
* @return The value of the indexed member.
* @throws JSException when an error is reported from the browser or
* JavaScript engine.
*/
public abstract Object getSlot(int index) throws JSException;

/**
* Sets an indexed member of a JavaScript object. Equivalent to
* "this[index] = value" in JavaScript.
*
* @param index The index of the array to be accessed.
* @param value The value to set
* @throws JSException when an error is reported from the browser or
* JavaScript engine.
*/
public abstract void setSlot(int index, Object value) throws JSException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2008, 2024, 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.
*/

/**
* <p>
* Provides Java code the ability to access the JavaScript engine and the
* HTML DOM in the web browser.
* </p>
*
* <p>
* The classes in this package were initially specified by Netscape, and are the
* de facto standard mechanism for calling JavaScript from the Java runtime.
* </p>
*
* @since 1.5
*/

package netscape.javascript;
3 changes: 2 additions & 1 deletion settings.gradle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update to copyright year has been reverted by commit 33355b4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why I did that, but I'll redo the change to 2024. Thanks.

Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
* questions.
*/

include "base", "graphics", "controls", "swing", "swt", "fxml", "web", "media", "systemTests"
include "base", "graphics", "controls", "swing", "swt", "fxml", "jsobject", "web", "media", "systemTests"

project(":base").projectDir = file("modules/javafx.base")
project(":graphics").projectDir = file("modules/javafx.graphics")
project(":controls").projectDir = file("modules/javafx.controls")
project(":swing").projectDir = file("modules/javafx.swing")
project(":swt").projectDir = file("modules/javafx.swt")
project(":fxml").projectDir = file("modules/javafx.fxml")
project(":jsobject").projectDir = file("modules/jdk.jsobject")
project(":web").projectDir = file("modules/javafx.web")
project(":media").projectDir = file("modules/javafx.media")
project(":systemTests").projectDir = file("tests/system")
Expand Down