Skip to content

Commit

Permalink
start working on reducing the core-js dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Oct 9, 2023
1 parent 78d7b37 commit ceaa531
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
import org.htmlunit.WebResponse;
import org.htmlunit.corejs.javascript.Context;
import org.htmlunit.corejs.javascript.ContextAction;
import org.htmlunit.corejs.javascript.ContextFactory;
import org.htmlunit.corejs.javascript.Function;
import org.htmlunit.corejs.javascript.ScriptRuntime;
import org.htmlunit.corejs.javascript.Scriptable;
import org.htmlunit.corejs.javascript.Undefined;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.httpclient.HtmlUnitUsernamePasswordCredentials;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.background.BackgroundJavaScriptFactory;
import org.htmlunit.javascript.background.JavaScriptJob;
Expand Down Expand Up @@ -473,7 +473,7 @@ public void send(final Object body) {
}
else {
// Create and start a thread in which to execute the request.
final ContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final HtmlUnitContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final ContextAction<Object> action = cx -> {
// KEY_STARTING_SCOPE maintains a stack of scopes
@SuppressWarnings("unchecked")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/htmlunit/html/HtmlDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.htmlunit.SgmlPage;
import org.htmlunit.WebClient;
import org.htmlunit.corejs.javascript.ContextFactory;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.PostponedAction;
import org.htmlunit.javascript.host.event.Event;
Expand Down Expand Up @@ -132,7 +132,7 @@ public void close(final String returnValue) {
final PostponedAction action = new PostponedAction(page, "Dialog.CloseEvent") {
@Override
public void execute() {
final ContextFactory cf = jsEngine.getContextFactory();
final HtmlUnitContextFactory cf = jsEngine.getContextFactory();
cf.call(cx -> dialogElement.dispatchEvent(event));
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/htmlunit/javascript/host/MessagePort.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.htmlunit.Page;
import org.htmlunit.WebWindow;
import org.htmlunit.corejs.javascript.ContextFactory;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.PostponedAction;
import org.htmlunit.javascript.configuration.JsxClass;
Expand Down Expand Up @@ -110,7 +110,7 @@ public void postMessage(final String message, final Object transfer) {
final PostponedAction action = new PostponedAction(page, "MessagePort.postMessage") {
@Override
public void execute() {
final ContextFactory cf = jsEngine.getContextFactory();
final HtmlUnitContextFactory cf = jsEngine.getContextFactory();
cf.call(cx -> port1_.dispatchEvent(event));
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/htmlunit/javascript/host/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
import org.htmlunit.corejs.javascript.AccessorSlot;
import org.htmlunit.corejs.javascript.Context;
import org.htmlunit.corejs.javascript.ContextAction;
import org.htmlunit.corejs.javascript.ContextFactory;
import org.htmlunit.corejs.javascript.EcmaError;
import org.htmlunit.corejs.javascript.Function;
import org.htmlunit.corejs.javascript.JavaScriptException;
Expand Down Expand Up @@ -93,6 +92,7 @@
import org.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlSelect;
import org.htmlunit.html.HtmlTextArea;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.HtmlUnitScriptable;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.PostponedAction;
Expand Down Expand Up @@ -2062,7 +2062,7 @@ public static void postMessage(final Context cx, final Scriptable scope,
public void execute() {
final ContextAction<Object> contextAction = cx -> receiver.dispatchEvent(event);

final ContextFactory cf = jsEngine.getContextFactory();
final HtmlUnitContextFactory cf = jsEngine.getContextFactory();
cf.call(contextAction);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.htmlunit.corejs.javascript.Scriptable;
import org.htmlunit.corejs.javascript.Undefined;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.HtmlUnitScriptable;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.background.BasicJavaScriptJob;
Expand Down Expand Up @@ -188,7 +189,7 @@ public void postMessage(final Object message) {
return null;
};

final ContextFactory cf = jsEngine.getContextFactory();
final HtmlUnitContextFactory cf = jsEngine.getContextFactory();

final JavaScriptJob job = new WorkerJob(cf, action, "postMessage: " + Context.toString(message));

Expand All @@ -210,7 +211,7 @@ void messagePosted(final Object message) {
return null;
};

final ContextFactory cf = jsEngine.getContextFactory();
final HtmlUnitContextFactory cf = jsEngine.getContextFactory();

final JavaScriptJob job = new WorkerJob(cf, action, "messagePosted: " + Context.toString(message));

Expand Down Expand Up @@ -288,7 +289,7 @@ void loadAndExecute(final WebClient webClient, final String url,
return null;
};

final ContextFactory cf = javaScriptEngine.getContextFactory();
final HtmlUnitContextFactory cf = javaScriptEngine.getContextFactory();

if (context != null) {
action.run(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import org.htmlunit.WebWindow;
import org.htmlunit.corejs.javascript.Context;
import org.htmlunit.corejs.javascript.ContextAction;
import org.htmlunit.corejs.javascript.ContextFactory;
import org.htmlunit.corejs.javascript.Function;
import org.htmlunit.corejs.javascript.ScriptRuntime;
import org.htmlunit.corejs.javascript.Scriptable;
Expand All @@ -87,6 +86,7 @@
import org.htmlunit.html.HtmlPage;
import org.htmlunit.httpclient.HtmlUnitUsernamePasswordCredentials;
import org.htmlunit.httpclient.HttpClientConverter;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.background.BackgroundJavaScriptFactory;
import org.htmlunit.javascript.background.JavaScriptJob;
Expand Down Expand Up @@ -808,7 +808,7 @@ public void send(final Object content) {
}
else {
// Create and start a thread in which to execute the request.
final ContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final HtmlUnitContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final ContextAction<Object> action = new ContextAction<Object>() {
@Override
public Object run(final Context cx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,8 @@ public void noGlobalContextFactoryUsed() {
final WebClient client1 = getWebClient();
final WebClient client2 = createNewWebClient();

final ContextFactory cf1 = ((JavaScriptEngine) client1.getJavaScriptEngine()).getContextFactory();
final ContextFactory cf2 = ((JavaScriptEngine) client2.getJavaScriptEngine()).getContextFactory();
final HtmlUnitContextFactory cf1 = ((JavaScriptEngine) client1.getJavaScriptEngine()).getContextFactory();
final HtmlUnitContextFactory cf2 = ((JavaScriptEngine) client2.getJavaScriptEngine()).getContextFactory();

assertFalse(cf1 == cf2);
assertFalse(cf1 == ContextFactory.getGlobal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import org.htmlunit.SimpleWebTestCase;
import org.htmlunit.WebClient;
import org.htmlunit.corejs.javascript.Context;
import org.htmlunit.corejs.javascript.ContextFactory;
import org.htmlunit.corejs.javascript.JavaScriptException;
import org.htmlunit.corejs.javascript.ScriptableObject;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.junit.BrowserRunner;
import org.junit.Test;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void fixedInHtmlUnit() throws Exception {
@Test
public void needCustomFix() {
final WebClient client = getWebClient();
final ContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final HtmlUnitContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final Context ctx = cf.enterContext();
try {
final ScriptableObject topScope = ctx.initStandardObjects();
Expand Down Expand Up @@ -130,7 +130,7 @@ public void needCustomFix() {
@Test
public void matchFixNeeded() throws Exception {
final WebClient client = getWebClient();
final ContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final HtmlUnitContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final Context cx = cf.enterContext();
try {
final ScriptableObject topScope = cx.initStandardObjects();
Expand Down

0 comments on commit ceaa531

Please sign in to comment.