From ceaa531e46dcb07459e48701eee62cf3470a6dfc Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Mon, 9 Oct 2023 13:25:04 +0200 Subject: [PATCH] start working on reducing the core-js dependencies --- .../htmlunit/activex/javascript/msxml/XMLHTTPRequest.java | 4 ++-- src/main/java/org/htmlunit/html/HtmlDialog.java | 4 ++-- .../java/org/htmlunit/javascript/host/MessagePort.java | 4 ++-- src/main/java/org/htmlunit/javascript/host/Window.java | 4 ++-- .../javascript/host/worker/DedicatedWorkerGlobalScope.java | 7 ++++--- .../org/htmlunit/javascript/host/xml/XMLHttpRequest.java | 4 ++-- .../java/org/htmlunit/javascript/JavaScriptEngineTest.java | 4 ++-- .../javascript/regexp/HtmlUnitRegExpProxy2Test.java | 6 +++--- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java b/src/main/java/org/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java index 902bd96c2bd..808e703bc60 100644 --- a/src/main/java/org/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java +++ b/src/main/java/org/htmlunit/activex/javascript/msxml/XMLHTTPRequest.java @@ -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; @@ -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 action = cx -> { // KEY_STARTING_SCOPE maintains a stack of scopes @SuppressWarnings("unchecked") diff --git a/src/main/java/org/htmlunit/html/HtmlDialog.java b/src/main/java/org/htmlunit/html/HtmlDialog.java index 28e77287505..b2b9a22b2bb 100644 --- a/src/main/java/org/htmlunit/html/HtmlDialog.java +++ b/src/main/java/org/htmlunit/html/HtmlDialog.java @@ -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; @@ -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)); } }; diff --git a/src/main/java/org/htmlunit/javascript/host/MessagePort.java b/src/main/java/org/htmlunit/javascript/host/MessagePort.java index ba2ab40ac31..4f9673f69d6 100644 --- a/src/main/java/org/htmlunit/javascript/host/MessagePort.java +++ b/src/main/java/org/htmlunit/javascript/host/MessagePort.java @@ -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; @@ -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)); } }; diff --git a/src/main/java/org/htmlunit/javascript/host/Window.java b/src/main/java/org/htmlunit/javascript/host/Window.java index 509b6fa7e72..1e76ad105dd 100644 --- a/src/main/java/org/htmlunit/javascript/host/Window.java +++ b/src/main/java/org/htmlunit/javascript/host/Window.java @@ -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; @@ -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; @@ -2062,7 +2062,7 @@ public static void postMessage(final Context cx, final Scriptable scope, public void execute() { final ContextAction contextAction = cx -> receiver.dispatchEvent(event); - final ContextFactory cf = jsEngine.getContextFactory(); + final HtmlUnitContextFactory cf = jsEngine.getContextFactory(); cf.call(contextAction); } }; diff --git a/src/main/java/org/htmlunit/javascript/host/worker/DedicatedWorkerGlobalScope.java b/src/main/java/org/htmlunit/javascript/host/worker/DedicatedWorkerGlobalScope.java index 0da5431060c..d9cdcffc507 100644 --- a/src/main/java/org/htmlunit/javascript/host/worker/DedicatedWorkerGlobalScope.java +++ b/src/main/java/org/htmlunit/javascript/host/worker/DedicatedWorkerGlobalScope.java @@ -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; @@ -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)); @@ -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)); @@ -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); diff --git a/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java b/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java index e50696268db..4af9ce74616 100644 --- a/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java +++ b/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java @@ -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; @@ -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; @@ -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 action = new ContextAction() { @Override public Object run(final Context cx) { diff --git a/src/test/java/org/htmlunit/javascript/JavaScriptEngineTest.java b/src/test/java/org/htmlunit/javascript/JavaScriptEngineTest.java index df6b1de392e..9f4e26378c1 100644 --- a/src/test/java/org/htmlunit/javascript/JavaScriptEngineTest.java +++ b/src/test/java/org/htmlunit/javascript/JavaScriptEngineTest.java @@ -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()); diff --git a/src/test/java/org/htmlunit/javascript/regexp/HtmlUnitRegExpProxy2Test.java b/src/test/java/org/htmlunit/javascript/regexp/HtmlUnitRegExpProxy2Test.java index b5bafd8a06e..d91286d5c55 100644 --- a/src/test/java/org/htmlunit/javascript/regexp/HtmlUnitRegExpProxy2Test.java +++ b/src/test/java/org/htmlunit/javascript/regexp/HtmlUnitRegExpProxy2Test.java @@ -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; @@ -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(); @@ -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();