Skip to content

Commit 808a9b2

Browse files
committed
Use local date, remove workarounds
1 parent 94e6639 commit 808a9b2

File tree

3 files changed

+10
-92
lines changed

3 files changed

+10
-92
lines changed

dev/core/src/com/google/gwt/dev/shell/HostedModePluginObject.java

-9
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,6 @@ public boolean connect(String url, String sessionKey, String address,
185185
return false;
186186
}
187187
// TODO: add whitelist and default-port support?
188-
189-
// We know that legacy dev mode is running, we need to tell HtmlUnit that it is safe
190-
// to permit plain Java objects to leak into JS - the JavaObject type will return a
191-
// Object[] with a success boolean and a value, and HtmlUnit will guard against this.
192-
// The simplest way to do that here is to mark java.lang.Object as the java equivalent
193-
// of some JS type - the name of the type doesn't matter.
194-
// webClient.setActiveXObjectMap(Collections.singletonMap(
195-
// "GwtLegacyDevModeExceptionOrReturnValue", "java.lang.Object"));
196-
197188
try {
198189
HtmlUnitSessionHandler htmlUnitSessionHandler = new HtmlUnitSessionHandler(
199190
window, jsEngine, webClient);

user/src/com/google/gwt/junit/RunStyleHtmlUnit.java

+2-80
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import com.google.gwt.thirdparty.guava.common.collect.ImmutableSet;
2121
import com.google.gwt.thirdparty.guava.common.collect.Maps;
2222

23-
import org.apache.commons.logging.Log;
24-
import org.apache.commons.logging.LogFactory;
2523
import org.htmlunit.AlertHandler;
2624
import org.htmlunit.BrowserVersion;
2725
import org.htmlunit.FailingHttpStatusCodeException;
@@ -31,9 +29,6 @@
3129
import org.htmlunit.ScriptException;
3230
import org.htmlunit.WebClient;
3331
import org.htmlunit.WebWindow;
34-
import org.htmlunit.corejs.javascript.Context;
35-
import org.htmlunit.corejs.javascript.Function;
36-
import org.htmlunit.corejs.javascript.JavaScriptException;
3732
import org.htmlunit.corejs.javascript.ScriptableObject;
3833
import org.htmlunit.html.HtmlPage;
3934
import org.htmlunit.javascript.JavaScriptEngine;
@@ -177,7 +172,7 @@ protected void setupWebClient(WebClient webClient) {
177172
treeLogger);
178173
webClient.setJavaScriptEngine(hostedEngine);
179174
} else {
180-
JavaScriptEngine webEngine = new WebJavaScriptEngine(webClient);
175+
JavaScriptEngine webEngine = new JavaScriptEngine(webClient);
181176
webClient.setJavaScriptEngine(webEngine);
182177
}
183178
if (System.getProperty("gwt.htmlunit.debug") != null) {
@@ -207,85 +202,12 @@ private static class HostedJavaScriptEngine extends JavaScriptEngine {
207202
public void initialize(WebWindow webWindow, Page page) {
208203
// Hook in the hosted-mode plugin after initializing the JS engine.
209204
super.initialize(webWindow, page);
210-
Window window = (Window) webWindow.getScriptableObject();
205+
Window window = webWindow.getScriptableObject();
211206
window.defineProperty("__gwt_HostedModePlugin",
212207
new HostedModePluginObject(this, webClient, logger), ScriptableObject.READONLY);
213208
}
214209
}
215210

216-
/**
217-
* JavaScriptEngine subclass that fixes a bug when calling {@code window.onerror}.
218-
* Make sure to remove when updating HtmlUnit.
219-
*
220-
* @see <a href="https://sourceforge.net/p/htmlunit/bugs/1924/">HtmlUnit bug #1924</a>
221-
*/
222-
private static class WebJavaScriptEngine extends JavaScriptEngine {
223-
private static final Log LOG = LogFactory.getLog(JavaScriptEngine.class);
224-
private final WebClient webClient;
225-
226-
WebJavaScriptEngine(WebClient webClient) {
227-
super(webClient);
228-
this.webClient = webClient;
229-
}
230-
231-
@Override
232-
protected void handleJavaScriptException(ScriptException scriptException,
233-
boolean triggerOnError) {
234-
// XXX(tbroyer): copied from JavaScriptEngine to call below triggerOnError
235-
// instead of Window's triggerOnError.
236-
237-
// Trigger window.onerror, if it has been set.
238-
final HtmlPage page = scriptException.getPage();
239-
if (triggerOnError && page != null) {
240-
final WebWindow window = page.getEnclosingWindow();
241-
if (window != null) {
242-
final Window w = (Window) window.getScriptableObject();
243-
if (w != null) {
244-
try {
245-
triggerOnError(w, scriptException);
246-
} catch (final Exception e) {
247-
handleJavaScriptException(new ScriptException(page, e, null), false);
248-
}
249-
}
250-
}
251-
}
252-
final JavaScriptErrorListener javaScriptErrorListener =
253-
webClient.getJavaScriptErrorListener();
254-
if (javaScriptErrorListener != null) {
255-
javaScriptErrorListener.scriptException(page, scriptException);
256-
}
257-
// Throw a Java exception if the user wants us to.
258-
if (webClient.getOptions().isThrowExceptionOnScriptError()) {
259-
throw scriptException;
260-
}
261-
// Log the error; ScriptException instances provide good debug info.
262-
LOG.info("Caught script exception", scriptException);
263-
}
264-
265-
private void triggerOnError(Window w, ScriptException e) {
266-
// XXX(tbroyer): copied from HtmlUnit's javascript.host.Window
267-
// with fix unwrapping the JS exception before passing it back to JS.
268-
final Object o = w.getOnerror();
269-
if (o instanceof Function) {
270-
final Function f = (Function) o;
271-
final String msg = e.getMessage();
272-
final String url = e.getPage().getUrl().toExternalForm();
273-
final int line = e.getFailingLineNumber();
274-
275-
final int column = e.getFailingColumnNumber();
276-
277-
Object jsError = null;
278-
if (e.getCause() instanceof JavaScriptException) {
279-
jsError = ((JavaScriptException) e.getCause()).getValue();
280-
}
281-
282-
Object[] args = new Object[]{msg, url, line, column, jsError};
283-
284-
f.call(Context.getCurrentContext(), w, w, args);
285-
}
286-
}
287-
}
288-
289211
private static final Map<String, BrowserVersion> BROWSER_MAP = Maps.newHashMap();
290212
private static final Map<BrowserVersion, String> USER_AGENT_MAP = Maps.newHashMap();
291213

user/test/com/google/gwt/emultest/java/util/DateTest.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -571,17 +571,17 @@ public void testToLocaleString() {
571571
// /////////////////////////////
572572
// Past
573573
// /////////////////////////////
574-
Date accum1 = create(PAST);
574+
Date accum1 = createLocal("1/5/1890");
575575
String a1 = accum1.toLocaleString();
576576
assertTrue(a1 + " should describe 1/5/1890",
577577
a1.contains("1890") || a1.contains("1/5/90"));
578578
// /////////////////////////////
579579
// Future
580580
// /////////////////////////////
581-
Date accum2 = create(FUTURE);
581+
Date accum2 = createLocal("12/30/2030 3:4:5");
582582
String a2 = accum2.toLocaleString();
583583
assertTrue(a2 + " should describe 12/30/2030",
584-
a2.contains("2030") || a2.contains("12/30/2030"));
584+
a2.contains("2030") || a2.contains("12/30/30"));
585585
}
586586
}
587587

@@ -897,6 +897,11 @@ Date create(String s) {
897897
}
898898
}
899899

900+
Date createLocal(String s) {
901+
// aligned with the TZ used in CI
902+
return new Date(s + " GMT-8:00");
903+
}
904+
900905
private String createString(String s) {
901906
if (s.equals(FUTURE)) {
902907
return "12/30/2030 3:4:5 GMT";

0 commit comments

Comments
 (0)