Skip to content

Commit

Permalink
Merge branch 'main' into better-pr-check
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Jul 11, 2024
2 parents 889dd3b + aabb575 commit 50a7c4d
Show file tree
Hide file tree
Showing 11 changed files with 1,303 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/full-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
-Dtest.emma.htmlunit.disable=true
- name: Report test results
uses: mikepenz/action-junit-report@v4.2.1
uses: mikepenz/action-junit-report@v4.3.1
if: always()
with:
report_paths: 'gwt/build/out/**/test/**/reports/TEST-*.xml'
Expand Down
17 changes: 14 additions & 3 deletions dev/codeserver/java/com/google/gwt/dev/codeserver/dev_mode_on.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@
return dialog;
}

function makeBookmarklet(name, javascript) {
function makeBookmarklet(name, javascript, javascriptFunction) {
var result = makeTextElt('a', '12pt', name);
result.style.fontFamily = 'sans';
result.style.textDecoration = 'none';
result.style.background = '#ddd';
result.style.border = '2px outset #ddd';
result.style.padding = '3pt';
result.setAttribute('href', 'javascript:' + encodeURIComponent(javascript));
result.onclick = javascriptFunction; // used in CSP case (clicking the button)
result.setAttribute('href', 'javascript:' + encodeURIComponent(javascript)); // used in bookmarklet case
result.title = 'Tip: drag this button to the bookmark bar';
return result;
}
Expand All @@ -135,7 +136,17 @@
+ ' var s = document.createElement(\'script\');'
+ ' s.src = \'' + bookmarklets_js + '\';'
+ ' void(document.getElementsByTagName(\'head\')[0].appendChild(s));}';
return makeBookmarklet('Compile', javascript);
var javascriptFunction = function(e) {
e.preventDefault(); // avoid CSP warning
window.__gwt_bookmarklet_params = {
server_url: codeserver_url,
module_name: module_name
};
var s = document.createElement('script');
s.src = bookmarklets_js;
void(document.getElementsByTagName('head')[0].appendChild(s));
};
return makeBookmarklet('Compile', javascript, javascriptFunction);
}

/**
Expand Down
70 changes: 67 additions & 3 deletions dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import com.google.gwt.dev.jjs.ast.JUnaryOperator;
import com.google.gwt.dev.jjs.ast.JUnsafeTypeCoercion;
import com.google.gwt.dev.jjs.ast.JVariable;
import com.google.gwt.dev.jjs.ast.JVariableRef;
import com.google.gwt.dev.jjs.ast.JWhileStatement;
import com.google.gwt.dev.jjs.ast.js.JMultiExpression;
import com.google.gwt.dev.jjs.ast.js.JsniClassLiteral;
Expand Down Expand Up @@ -1095,9 +1096,71 @@ public void endVisit(Initializer x, MethodScope scope) {
public void endVisit(InstanceOfExpression x, BlockScope scope) {
try {
SourceInfo info = makeSourceInfo(x);
JExpression expr = pop(x.expression);
JExpression expr;
JDeclarationStatement jDeclarationStatement = null;
if (x.pattern != null) {
jDeclarationStatement = (JDeclarationStatement) pop();
}
expr = pop(x.expression);
JReferenceType testType = (JReferenceType) typeMap.get(x.type.resolvedType);
push(new JInstanceOf(info, testType, expr));

if (jDeclarationStatement == null) {
push(new JInstanceOf(info, testType, expr));
} else {
// If <expr> is of type X, then
//
// rewrite (<expr> instanceof Foo foo)
// to
// Foo foo;
// X $instanceof_1;
// (($instanceof_1 = <expr>) instanceof Foo && null != (foo = (Foo) $instanceof_1))
//
// to avoid side effects from evaluating the original expression twice

// Foo foo;
String patternDeclarationName = jDeclarationStatement.getVariableRef().getTarget()
.getName();
if (!curMethod.instanceOfDeclarations.containsKey(patternDeclarationName)) {
curMethod.body.getBlock().addStmt(0, jDeclarationStatement);
curMethod.instanceOfDeclarations.put(patternDeclarationName, jDeclarationStatement);
}

// X $instanceof_1;
JType expressionType = typeMap.get(x.expression.resolvedType);
JLocal local =
createLocal(info, "$instanceOfExpr", expressionType);
JDeclarationStatement expressionDeclaration =
makeDeclaration(info, local, null);
curMethod.body.getBlock().addStmt(0, expressionDeclaration);
curMethod.instanceOfDeclarations.put(local.getName(), expressionDeclaration);

// (Foo) $instanceof_1
JVariableRef variableRef = jDeclarationStatement.getVariableRef();
JCastOperation jCastOperation =
new JCastOperation(info, variableRef.getType(), local.createRef(info));

// foo = (Foo) $instanceof_1
JBinaryOperation assignOperation =
new JBinaryOperation(info, variableRef.getType(), JBinaryOperator.ASG, variableRef,
jCastOperation);

// null != (foo = (Foo) $instanceof_1)
JBinaryOperation nullCheckOperation =
new JBinaryOperation(info, JPrimitiveType.BOOLEAN, JBinaryOperator.NEQ,
JNullLiteral.INSTANCE, assignOperation);

// $instanceof_1 = o
JBinaryOperation assignLocalOperation =
new JBinaryOperation(info, expressionType, JBinaryOperator.ASG, local.createRef(info),
expr);

// (($instanceof_1 = o) instanceof Foo && null != (foo = (Foo) $instanceof_1))
JBinaryOperation rewrittenSwitch =
new JBinaryOperation(info, JPrimitiveType.BOOLEAN, JBinaryOperator.AND,
new JInstanceOf(info, testType, assignLocalOperation), nullCheckOperation);

push(rewrittenSwitch);
}
} catch (Throwable e) {
throw translateException(x, e);
}
Expand Down Expand Up @@ -3847,8 +3910,9 @@ static class MethodInfo {
public final Map<LocalVariableBinding, JVariable> locals = Maps.newIdentityHashMap();
public final JMethod method;
public final MethodScope scope;
public final Map<String, JStatement> instanceOfDeclarations = Maps.newHashMap();

public MethodInfo(JMethod method, JMethodBody methodBody, MethodScope methodScope) {
MethodInfo(JMethod method, JMethodBody methodBody, MethodScope methodScope) {
this.method = method;
this.body = methodBody;
this.scope = methodScope;
Expand Down
Loading

0 comments on commit 50a7c4d

Please sign in to comment.