Skip to content

Commit

Permalink
Merge branch 'main' into 9923-deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Oct 15, 2024
2 parents d7bbd01 + 53606b5 commit e81faf3
Show file tree
Hide file tree
Showing 33 changed files with 259 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ private void implementEquals(JRecordType type, JMethod method, SourceInfo info)
myField,
otherField);
} else {
// we would like to use Objects.equals here to be more consise, but we would need
// We would like to use Objects.equals here to be more concise, but we would need
// to look up the right impl based on the field - just as simple to insert a null check
// and get it a little closer to all being inlined away

// Make another field ref to call equals() on
JFieldRef myField2 = new JFieldRef(info, new JThisRef(info, type), field, type);
equals = new JBinaryOperation(info, JPrimitiveType.BOOLEAN, JBinaryOperator.AND,
new JBinaryOperation(info, JPrimitiveType.BOOLEAN, JBinaryOperator.NEQ,
myField, JNullLiteral.INSTANCE),
new JMethodCall(info, myField, objectEquals, otherField));
new JMethodCall(info, myField2, objectEquals, otherField));
}
if (componentCheck != JBooleanLiteral.TRUE) {
componentCheck = new JBinaryOperation(info, JPrimitiveType.BOOLEAN,
Expand Down
37 changes: 34 additions & 3 deletions dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ public boolean visit(JThisRef x, Context ctx) {
}
}

/**
* Determines if the given expression can be inlined. Any switch expression will fail this check.
*/
private static class CannotBeInlinedVisitor extends JVisitor {
private boolean succeed = true;
public static boolean check(JExpression expr) {
CannotBeInlinedVisitor v = new CannotBeInlinedVisitor();
v.accept(expr);
return v.succeed;
}

@Override
public boolean visit(JStatement x, Context ctx) {
// To ensure we didn't miss an important case, throw if we see a statement, as those cannot
// be inlined.
throw new IllegalStateException("Should never visit statements");
}

@Override
public boolean visit(JSwitchExpression x, Context ctx) {
succeed = false;
return false;
}
}

/**
* Method inlining visitor.
*/
Expand Down Expand Up @@ -148,6 +173,7 @@ private InlineResult tryInlineMethodCall(JMethodCall x, Context ctx) {
if (expressions == null) {
// If it will never be possible to inline the method, add it to a
// blacklist

return InlineResult.BLACKLIST;
}

Expand Down Expand Up @@ -242,6 +268,9 @@ private List<JExpression> extractExpressionsFromBody(JMethodBody body) {
if (initializer == null) {
continue;
}
if (!CannotBeInlinedVisitor.check(initializer)) {
return null;
}
JLocal local = (JLocal) declStatement.getVariableRef().getTarget();
JExpression clone = new JBinaryOperation(stmt.getSourceInfo(), local.getType(),
JBinaryOperator.ASG,
Expand All @@ -251,17 +280,19 @@ private List<JExpression> extractExpressionsFromBody(JMethodBody body) {
} else if (stmt instanceof JExpressionStatement) {
JExpressionStatement exprStmt = (JExpressionStatement) stmt;
JExpression expr = exprStmt.getExpr();
if (expr instanceof JSwitchExpression) {
// Switch expressions can't be cloned in this way, though we wouldn't want to inline
// such a large block anyway.
if (!CannotBeInlinedVisitor.check(expr)) {
return null;
}
JExpression clone = cloner.cloneExpression(expr);
expressions.add(clone);
} else if (stmt instanceof JReturnStatement) {
JReturnStatement returnStatement = (JReturnStatement) stmt;
JExpression expr = returnStatement.getExpr();

if (expr != null) {
if (!CannotBeInlinedVisitor.check(expr)) {
return null;
}
JExpression clone = cloner.cloneExpression(expr);
clone = maybeCast(clone, body.getMethod().getType());
expressions.add(clone);
Expand Down
18 changes: 14 additions & 4 deletions user/src/com/google/gwt/user/client/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ public HandlerManager getHandlers() {
// Package protected for testing.
static WindowHandlers handlers;
private static boolean closeHandlersInitialized;
private static boolean beforeCloseHandlersInitialized;
private static boolean scrollHandlersInitialized;
private static boolean resizeHandlersInitialized;
private static int lastResizeWidth;
Expand All @@ -518,7 +519,10 @@ public HandlerManager getHandlers() {
*
* @param handler the handler
* @return returns the handler registration
* @deprecated This method requires the use of the {@code unload} browser event, which is
* deprecated in all browsers.
*/
@Deprecated
public static HandlerRegistration addCloseHandler(CloseHandler<Window> handler) {
maybeInitializeCloseHandlers();
return addHandler(CloseEvent.getType(), handler);
Expand All @@ -531,7 +535,6 @@ public static HandlerRegistration addCloseHandler(CloseHandler<Window> handler)
* @return returns the handler registration
*/
public static HandlerRegistration addResizeHandler(ResizeHandler handler) {
maybeInitializeCloseHandlers();
maybeInitializeResizeHandlers();
return addHandler(ResizeEvent.getType(), handler);
}
Expand All @@ -556,7 +559,7 @@ public static void addWindowCloseListener(WindowCloseListener listener) {
*/
public static HandlerRegistration addWindowClosingHandler(
ClosingHandler handler) {
maybeInitializeCloseHandlers();
maybeInitializeBeforeCloseHandlers();
return addHandler(Window.ClosingEvent.getType(), handler);
}

Expand All @@ -579,7 +582,6 @@ public static void addWindowResizeListener(WindowResizeListener listener) {
*/
public static HandlerRegistration addWindowScrollHandler(
Window.ScrollHandler handler) {
maybeInitializeCloseHandlers();
maybeInitializeScrollHandlers();
return addHandler(Window.ScrollEvent.getType(), handler);
}
Expand Down Expand Up @@ -910,13 +912,21 @@ private static WindowHandlers getHandlers() {
return handlers;
}

@Deprecated
private static void maybeInitializeCloseHandlers() {
if (GWT.isClient() && !closeHandlersInitialized) {
impl.initWindowCloseHandler();
impl.initWindowUnloadHandler();
closeHandlersInitialized = true;
}
}

private static void maybeInitializeBeforeCloseHandlers() {
if (GWT.isClient() && !beforeCloseHandlersInitialized) {
impl.initWindowBeforeUnloadHandler();
beforeCloseHandlersInitialized = true;
}
}

private static void maybeInitializeResizeHandlers() {
if (GWT.isClient() && !resizeHandlersInitialized) {
impl.initWindowResizeHandler();
Expand Down
39 changes: 23 additions & 16 deletions user/src/com/google/gwt/user/client/impl/WindowImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,30 @@ public native String getHash() /*-{
public native String getQueryString() /*-{
return $wnd.location.search;
}-*/;

public native void initWindowCloseHandler() /*-{

@Deprecated
public void initWindowCloseHandler() {
initWindowUnloadHandler();
initWindowBeforeUnloadHandler();
}

@Deprecated
public native void initWindowUnloadHandler() /*-{
var oldOnUnload = $wnd.onunload;
$wnd.onunload = $entry(function(evt) {
try {
@com.google.gwt.user.client.Window::onClosed()();
} finally {
oldOnUnload && oldOnUnload(evt);
$wnd.onunload = null;
}
});
}-*/;

public native void initWindowBeforeUnloadHandler() /*-{
var oldOnBeforeUnload = $wnd.onbeforeunload;
var oldOnUnload = $wnd.onunload;
// Old mozilla doesn't like $entry's explicit return statement and
// will always pop up a confirmation dialog. This is worked around by
// just wrapping the call to onClosing(), which still has the semantics
Expand All @@ -55,18 +74,6 @@ public native void initWindowCloseHandler() /*-{
}
// returns undefined.
};
$wnd.onunload = $entry(function(evt) {
try {
@com.google.gwt.user.client.Window::onClosed()();
} finally {
oldOnUnload && oldOnUnload(evt);
$wnd.onresize = null;
$wnd.onscroll = null;
$wnd.onbeforeunload = null;
$wnd.onunload = null;
}
});
}-*/;

public native void initWindowResizeHandler() /*-{
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/Anchor.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Anchor extends FocusWidget implements HasHorizontalAlignment,
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Button extends ButtonBase {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/FileUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class FileUpload extends FocusWidget implements HasName, HasChangeHandler
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
4 changes: 2 additions & 2 deletions user/src/com/google/gwt/user/client/ui/FormPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ interface IFrameTemplate extends SafeHtmlTemplates {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* <p>
* The specified form element's target attribute will not be set, and the
Expand All @@ -280,7 +280,7 @@ public static FormPanel wrap(Element element) {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* <p>
* If the createIFrame parameter is set to <code>true</code>, then the wrapped
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Frame extends Widget implements HasLoadHandlers {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/HTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class HTML extends Label
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/HTMLPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static String createUniqueId() {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/Hidden.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Hidden extends Widget implements HasName, TakesValue<String>, IsEdi
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public static void prefetch(SafeUri url) {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/InlineHTML.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class InlineHTML extends HTML {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/InlineLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class InlineLabel extends Label {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class Label extends LabelBase<String> implements HasDirectionalText,
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/ListBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class ListBox extends FocusWidget implements SourcesChangeEvents,
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
* @return list box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class PasswordTextBox extends TextBox {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/ui/ResetButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ResetButton extends Button {
*
* This element must already be attached to the document. If the element is
* removed from the document, you must call
* {@link RootPanel#detachNow(Widget)}.
* {@link Widget#removeFromParent()}.
*
* @param element the element to be wrapped
*/
Expand Down
Loading

0 comments on commit e81faf3

Please sign in to comment.