Skip to content

Commit

Permalink
Merge branch 'main' into 9727-jakarta-servlet-support
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Dec 6, 2023
2 parents 2925e34 + f9028fe commit f0eafec
Show file tree
Hide file tree
Showing 20 changed files with 213 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ function setupInstallLocation() {
// throwing away the current document.
//
// In IE, it ensures that the <body> element is immediately available.
frameDoc.open();
var doctype = (document.compatMode == 'CSS1Compat') ? '<!doctype html>' : '';
frameDoc.write(doctype + '<html><head></head><body></body></html>');
frameDoc.close();
if (navigator.userAgent.indexOf("Chrome") == -1) {
frameDoc.open();
var doctype = (document.compatMode == 'CSS1Compat') ? '<!doctype html>' : '';
frameDoc.write(doctype + '<html><head></head><body></body></html>');
frameDoc.close();
}
}
24 changes: 15 additions & 9 deletions dev/core/src/com/google/gwt/core/linker/SingleScriptTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ function __MODULE_FUNC__() {
,markerId = "__gwt_marker___MODULE_NAME__"
,markerScript;

$doc.write('<script id="' + markerId + '"></script>');
markerScript = $doc.getElementById(markerId);

// Our script element is assumed to be the closest previous script element
// to the marker, so start at the marker and walk backwards until we find
// a script.
thisScript = markerScript && markerScript.previousSibling;
while (thisScript && thisScript.tagName != 'SCRIPT') {
thisScript = thisScript.previousSibling;
if ($doc.currentScript) {
// document.currentScript is not supported by IE 11.
thisScript = $doc.currentScript;
} else {
// may fail in extension or anywhere else with inability to use document.write
$doc.write('<script id="' + markerId + '"></script>');
markerScript = $doc.getElementById(markerId);

// Our script element is assumed to be the closest previous script element
// to the marker, so start at the marker and walk backwards until we find
// a script.
thisScript = markerScript && markerScript.previousSibling;
while (thisScript && thisScript.tagName != 'SCRIPT') {
thisScript = thisScript.previousSibling;
}
}

// Gets the part of a url up to and including the 'path' portion.
Expand Down
2 changes: 1 addition & 1 deletion dev/core/src/com/google/gwt/dev/javac/JdtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static String signature(MethodBinding binding) {
}

public static String signature(TypeBinding binding) {
assert !binding.isIntersectionType18() && !binding.isIntersectionType();
assert !binding.isIntersectionType18() && !binding.isIntersectionType() : binding.debugName();
if (binding.isBaseType()) {
return String.valueOf(binding.sourceName());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ public void endVisit(JsNameRef x, JsContext ctx) {
// method description including actual signature) so that dispatch everywhere is consistent
// with the one resolved here.
ident = jsniRef.getResolvedReference();
JsNameRef newRef = new JsNameRef(x.getSourceInfo(), ident);
newRef.setQualifier(x.getQualifier());
JsNameRef newRef = new JsNameRef(x.getSourceInfo(), ident, x.getQualifier());
ctx.replaceMe(newRef);
}
if (binding != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public void exportMember(JMember x, JsExpression bridgeMethodOrAlias) {
ensureProvideNamespace(x, null);

// _.memberName = RHS
JsNameRef lhs = new JsNameRef(x.getSourceInfo(), x.getJsName());
lhs.setQualifier(globalTemp.makeRef(x.getSourceInfo()));
JsNameRef lhs = new JsNameRef(x.getSourceInfo(), x.getJsName(),
globalTemp.makeRef(x.getSourceInfo()));
exportStmts.add(createAssignment(lhs, bridgeMethodOrAlias).makeStmt());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2351,8 +2351,7 @@ private void generatePrototypeDefinitionAlias(JMethod method, JsName alias) {
}

private JsExprStmt outputDisplayName(JsNameRef function, JMethod method) {
JsNameRef displayName = new JsNameRef(function.getSourceInfo(), "displayName");
displayName.setQualifier(function);
JsNameRef displayName = new JsNameRef(function.getSourceInfo(), "displayName", function);
String displayStringName = getDisplayName(method);
JsStringLiteral displayMethodName =
new JsStringLiteral(function.getSourceInfo(), displayStringName);
Expand Down Expand Up @@ -3133,7 +3132,19 @@ private JsName getIndexedFieldJsName(String indexedName) {
return names.get(program.getIndexedField(indexedName));
}

private static JsNameRef createGlobalQualifier(String qualifier, SourceInfo sourceInfo) {
return JsUtils.createQualifiedNameRef(JsInteropUtil.normalizeQualifier(qualifier), sourceInfo);
private JsNameRef createGlobalQualifier(String qualifier, SourceInfo sourceInfo) {
List<String> parts =
Lists.newArrayList(JsInteropUtil.normalizeQualifier(qualifier).split("\\."));
// Make the top level name unobfuscatable in the top scope, and remove from parts.
String topScopeName = parts.remove(0);
JsNameRef ref =
jsProgram.getScope().declareUnobfuscatableName(topScopeName).makeRef(sourceInfo);

for (String part : parts) {
// The rest can be left as a name ref to be resolved by JsSymbolResolver later.
ref = new JsNameRef(sourceInfo, part, ref);
}

return ref;
}
}
38 changes: 36 additions & 2 deletions dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,14 @@ public void endVisit(CompoundAssignment x, BlockScope scope) {
public void endVisit(ConditionalExpression x, BlockScope scope) {
try {
SourceInfo info = makeSourceInfo(x);
JType type = typeMap.get(x.resolvedType);
JType type;
if (x.resolvedType instanceof IntersectionTypeBinding18) {
type = typeMap.get(
getFirstNonObjectInIntersection((IntersectionTypeBinding18) x.resolvedType)
);
} else {
type = typeMap.get(x.resolvedType);
}
JExpression valueIfFalse = pop(x.valueIfFalse);
JExpression valueIfTrue = pop(x.valueIfTrue);
JExpression condition = pop(x.condition);
Expand All @@ -648,6 +655,27 @@ public void endVisit(ConditionalExpression x, BlockScope scope) {
}
}

/**
* Returns the first non-Object type in the intersection. As intersections can only contain one
* class, and that class must be first, this ensures that if there is a class it will be the
* returned type, but if there are only interfaces, the first interface will be selected.
* <p></p>
* This behavior is consistent with ReferenceMapper.get() with assertions disabled - that is,
* where {@code referenceMapper.get(foo)} would fail due to an assertion, if assertions are
* disabled then {@code
* referenceMapper.get(foo).equals(referenceMapper.get(getFirstNonObjectInIntersection(foo))
* } will be true.
*/
private TypeBinding getFirstNonObjectInIntersection(IntersectionTypeBinding18 resolvedType) {
for (ReferenceBinding type : resolvedType.intersectingTypes) {
if (type != curCud.cud.scope.getJavaLangObject()) {
return type;
}
}
throw new IllegalStateException("Type doesn't have a non-java.lang.Object it intersects "
+ resolvedType);
}

@Override
public void endVisit(ConstructorDeclaration x, ClassScope scope) {
try {
Expand Down Expand Up @@ -2941,7 +2969,13 @@ private JLocal createLocal(LocalDeclaration x) {
TypeBinding resolvedType = x.type.resolvedType;
JType localType;
if (resolvedType.constantPoolName() != null) {
localType = typeMap.get(resolvedType);
if (resolvedType instanceof IntersectionTypeBinding18) {
localType = typeMap.get(
getFirstNonObjectInIntersection((IntersectionTypeBinding18) resolvedType)
);
} else {
localType = typeMap.get(resolvedType);
}
} else {
// Special case, a statically unreachable local type.
localType = JReferenceType.NULL_TYPE;
Expand Down
3 changes: 1 addition & 2 deletions dev/core/src/com/google/gwt/dev/js/CoverageInstrumentor.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ private CoverageInstrumentor(JsProgram jsProgram, Multimap<String, Integer> inst
}

private void addBeforeUnloadListener(SourceInfo info) {
JsNameRef onbeforeunload = new JsNameRef(info, "onbeforeunload");
onbeforeunload.setQualifier(new JsNameRef(info, "window"));
JsNameRef onbeforeunload = new JsNameRef(info, "onbeforeunload", new JsNameRef(info, "window"));
JsNameRef handler = onBeforeUnloadFnName.makeRef(info);
JsBinaryOperation assignment = new JsBinaryOperation(info, JsBinaryOperator.ASG,
onbeforeunload, handler);
Expand Down
7 changes: 2 additions & 5 deletions dev/core/src/com/google/gwt/dev/js/JsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ public static JsExpression createQualifiedNameRef(
SourceInfo info, JsExpression base, String... names) {
JsExpression result = base;
for (String name : names) {
JsNameRef nameRef = new JsNameRef(info, name);
nameRef.setQualifier(result);
result = nameRef;
result = new JsNameRef(info, name, result);
}
return result;
}
Expand Down Expand Up @@ -284,8 +282,7 @@ private static JsExpression prepareArgumentsForApply(SourceInfo sourceInfo,
}

JsArrayLiteral argumentsArray = new JsArrayLiteral(sourceInfo, nonVarargsArguments);
JsNameRef argumentsConcat = new JsNameRef(sourceInfo,"concat");
argumentsConcat.setQualifier(argumentsArray);
JsNameRef argumentsConcat = new JsNameRef(sourceInfo,"concat", argumentsArray);
return new JsInvocation(sourceInfo, argumentsConcat, varargsArgument);
}

Expand Down
5 changes: 5 additions & 0 deletions dev/core/src/com/google/gwt/dev/js/ast/JsNameRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public JsNameRef(SourceInfo sourceInfo, JsName name) {
this.name = name;
}

public JsNameRef(SourceInfo sourceInfo, String ident, JsExpression qualifier) {
this(sourceInfo, ident);
setQualifier(qualifier);
}

public JsNameRef(SourceInfo sourceInfo, String ident) {
super(sourceInfo);
this.ident = StringInterner.get().intern(ident);
Expand Down
2 changes: 1 addition & 1 deletion user/build.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project name="user" default="build" basedir=".">
<property name="gwt.root" location=".."/>
<property name="project.tail" value="user"/>
<property name="test.args" value="-ea"/>
<property name="test.args" value="-ea -sourceLevel auto"/>
<property name="test.jvmargs" value="-ea"/>

<!-- support old variables names -->
Expand Down
4 changes: 2 additions & 2 deletions user/src/com/google/gwt/junit/JUnitShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.google.gwt.core.ext.Linker;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.TreeLogger.Type;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.linker.impl.StandardLinkerContext;
import com.google.gwt.core.ext.typeinfo.JClassType;
Expand Down Expand Up @@ -1092,7 +1091,8 @@ void compileForWebMode(ModuleDef module, Set<String> userAgents)
try {
success = Compiler.compile(getTopLogger(), options, module);
} catch (Exception e) {
getTopLogger().log(Type.ERROR, "Compiler aborted with an exception ", e);
// noinspection ThrowableNotThrown
CompilationProblemReporter.logAndTranslateException(getTopLogger(), e);
}
if (!success) {
throw new UnableToCompleteException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ public Type[] getActualTypeArguments() {
Object genericDeclaration = variable.getGenericDeclaration();
if (genericDeclaration instanceof Class<?>) {
Class<?> declaration = (Class<?>) genericDeclaration;
if (declaration.equals(containingType)) {
return ensureBaseType(type);
}
// could probably optimize, but would involve duplicating a bunch of
// getParameterization's code
Type[] types = getParameterization(declaration, containingType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ default Predicate<T> or(Predicate<? super T> other) {
checkCriticalNotNull(other);
return t -> test(t) || other.test(t);
}

@SuppressWarnings("unchecked")
static <T> Predicate<T> not(Predicate<? super T> other) {
return (Predicate<T>) other.negate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import java.util.ArrayList;
import java.util.function.Supplier;

import java.io.Serializable;

/**
* Tests Java 10 features. It is super sourced so that gwt can be compiles under Java 7.
* Tests Java 10 features. It is super sourced so that gwt can be compiled under Java 7.
*
* IMPORTANT: For each test here there must exist the corresponding method in the non super sourced
* version.
Expand Down Expand Up @@ -65,6 +67,29 @@ public void testLocalVarType_Anonymous() {
assertEquals("42", o.s);
}

public void testLocalVarType_Ternary() {
var value = true ? "a" : 'c';
checkSerializableDispatch(value);
checkComparableDispatch(value);
assertEquals("a", value.toString());
}

private void checkSerializableDispatch(Object fail) {
fail("should not be treated as object");
}

private void checkSerializableDispatch(Serializable pass) {
// pass
}

private void checkComparableDispatch(Object fail) {
fail("should not be treated as object");
}

private void checkComparableDispatch(Comparable<?> pass) {
// pass
}

public void testLocalVarType_LambdaCapture() {
var s = "42";
Supplier<String> supplier = () -> s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import jsinterop.annotations.JsType;

/**
* Tests Miscelaneous fixes.
* Tests Miscellaneous fixes.
*/
public class CompilerMiscRegressionTest extends GWTTestCase {

Expand All @@ -67,11 +67,11 @@ native double minusAndDecrement(double val) /*-{

/**
* The array {@code map.get("one")[0]} gets normalized (by {@link ImplementCastsAndTypeChecks}) to
* {@code Cast.dynamicCast(map.get("one"), ...)[0]}. The expression resulting from dynamiCast
* {@code Cast.dynamicCast(map.get("one"), ...)[0]}. The expression resulting from dynamicCast
* would have type Object and that would not be a valid type for an array access operation.
*/
public void testOverridingReturnType() {
Map<String, String[]> map = new HashMap();
Map<String, String[]> map = new HashMap<>();
map.put("one", new String[10]);

map.get("one")[0] = "one";
Expand Down Expand Up @@ -429,11 +429,11 @@ private static native Object newArrayThroughCtorReference() /*-{
return ctor();
}-*/;

private static native boolean isNan(double number) /*-{
private static native boolean jsniIsNan(double number) /*-{
return @Global::isNan(D)(number);
}-*/;

private static native double getNan() /*-{
private static native double jsniGetNan() /*-{
return @Global::Nan;
}-*/;

Expand All @@ -453,8 +453,17 @@ public void testNativeConstructorJSNI() {
assertTrue(nativeArray instanceof NativeArray);
assertEquals(2, arrayLength(nativeArray));
assertTrue(newArrayThroughCtorReference() instanceof NativeArray);
assertTrue(Double.isNaN(getNan()));
assertTrue(isNan(Double.NaN));
assertTrue(Double.isNaN(jsniGetNan()));
assertTrue(jsniIsNan(Double.NaN));
}

@JsMethod(namespace = "<window>", name = "isNaN")
public static native boolean isNaN(double number);

// Regression tests for issue #9573
public void testTopLevelNameClash() {
boolean isNaN = isNaN(Global.Nan);
assertTrue(isNaN);
}

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
Expand All @@ -466,7 +475,7 @@ final NativeObjectWithOverlay getThis() {
}
}

public void testOveralyDispatchOnNull() {
public void testOverlayDispatchOnNull() {
// Define a variable where the compiler can not statically determine that it is actually null.
NativeObjectWithOverlay objectWithOverlay =
Math.random() > 1000 ? new NativeObjectWithOverlay() : null;
Expand Down
3 changes: 3 additions & 0 deletions user/test/com/google/gwt/dev/jjs/test/CompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ public void testConditionals() {
assertFalse(FALSE ? TRUE : false);
assertFalse(TRUE ? FALSE : true);
assertTrue(FALSE ? FALSE : true);

assertEquals("abc", "ab" + (TRUE ? "c" : 'z'));
assertEquals("abz", "ab" + (FALSE ? "c" : 'z'));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions user/test/com/google/gwt/dev/jjs/test/Java10Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void testLocalVarType_Anonymous() {
assertFalse(isGwtSourceLevel10());
}

public void testLocalVarType_Ternary() {
assertFalse(isGwtSourceLevel10());
}

public void testLocalVarType_LambdaCapture() {
assertFalse(isGwtSourceLevel10());
}
Expand Down
Loading

0 comments on commit f0eafec

Please sign in to comment.