Skip to content

Commit

Permalink
working on a more complete context setup for WebWorker (#816) - simpl…
Browse files Browse the repository at this point in the history
…ify setup code
  • Loading branch information
rbri committed Jul 27, 2024
1 parent 8b3f485 commit cf76635
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/main/java/org/htmlunit/javascript/JavaScriptEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ private void init(final WebWindow webWindow, final Page page, final Context cont

configureConstantsPropertiesAndFunctions(windowConfig, window);

final HtmlUnitScriptable windowPrototype = configureClass(windowConfig, window, browserVersion);
final HtmlUnitScriptable windowPrototype = configureClass(windowConfig, window);
window.setPrototype(windowPrototype);
prototypes.put(windowConfig.getHostClass(), windowPrototype);
prototypesPerJSName.put(windowConfig.getClassName(), windowPrototype);

// setup the prototypes
for (final ClassConfiguration config : jsConfig_.getAll()) {
if (windowConfig != config) {
final HtmlUnitScriptable prototype = configureClass(config, window, browserVersion);
final HtmlUnitScriptable prototype = configureClass(config, window);
if (config.isJsObject()) {
// Place object with prototype property in Window scope
final HtmlUnitScriptable obj = config.getHostClass().getDeclaredConstructor().newInstance();
Expand Down Expand Up @@ -520,7 +520,6 @@ private static void removePrototypeProperties(final Scriptable scope, final Stri
* Configures the specified class for access via JavaScript.
* @param config the configuration settings for the class to be configured
* @param window the scope within which to configure the class
* @param browserVersion the browser version
* @throws InstantiationException if the new class cannot be instantiated
* @throws IllegalAccessException if we don't have access to create the new instance
* @return the created prototype
Expand All @@ -529,8 +528,7 @@ private static void removePrototypeProperties(final Scriptable scope, final Stri
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public static HtmlUnitScriptable configureClass(final ClassConfiguration config, final Scriptable window,
final BrowserVersion browserVersion)
public static HtmlUnitScriptable configureClass(final ClassConfiguration config, final Scriptable window)
throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {

final HtmlUnitScriptable prototype = config.getHostClass().getDeclaredConstructor().newInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/htmlunit/javascript/host/intl/Intl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void defineProperties(final BrowserVersion browserVersion) {
private void define(final Class<? extends HtmlUnitScriptable> c, final BrowserVersion browserVersion) {
try {
final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(c, browserVersion);
final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, this, browserVersion);
final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, this);
final FunctionObject functionObject =
new RecursiveFunctionObject(config.getJsConstructor().getKey(),
config.getJsConstructor().getValue(), this, browserVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ public void jsConstructor() {
ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(
(Class<? extends HtmlUnitScriptable>) DedicatedWorkerGlobalScope.class.getSuperclass(),
browserVersion);
final HtmlUnitScriptable parentPrototype = JavaScriptEngine.configureClass(config, this, browserVersion);
final HtmlUnitScriptable parentPrototype = JavaScriptEngine.configureClass(config, this);

config = AbstractJavaScriptConfiguration.getClassConfiguration(
DedicatedWorkerGlobalScope.class, browserVersion);
final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, this, browserVersion);
final HtmlUnitScriptable prototype = JavaScriptEngine.configureClass(config, this);
prototype.setPrototype(parentPrototype);
setPrototype(prototype);

Expand Down

0 comments on commit cf76635

Please sign in to comment.