Skip to content

Commit 0fdbaec

Browse files
Googlercopybara-github
authored andcommitted
[WASM] JsInterop - Correct JsExternsGenerator to look at isJsConstructor to make it more consistent with AddJsExportBridgesWasm since it is no longer needed to use the synthetic factory since reordering
Also revert the change in NormalizeInstantiationThroughFactoryMethods since we no longer need to mark synthetic factories as JS members (see ebb1132) Also make the js property check to be more specific to jsproperties. See: 7255073 PiperOrigin-RevId: 888321679
1 parent 19b2e54 commit 0fdbaec

File tree

3 files changed

+5
-20
lines changed

3 files changed

+5
-20
lines changed

transpiler/java/com/google/j2cl/transpiler/backend/wasm/JsExternsGenerator.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void appendConstructor(SourceBuilder sb, Type type) {
9898
String jsDoc = closureEnvironment.getJsDocForType(type, /* isWasmExtern= */ true);
9999
Method constructor =
100100
type.getMethods().stream()
101-
.filter(m -> isConstructor(m.getDescriptor()))
101+
.filter(m -> m.getDescriptor().isJsConstructor())
102102
.findFirst()
103103
.orElse(null);
104104

@@ -131,9 +131,9 @@ private void appendMethods(SourceBuilder sb, Type type) {
131131
MethodDescriptor methodDescriptor = method.getDescriptor();
132132
if (!AstUtils.needsWasmJsExport(methodDescriptor)
133133
// Constructors handled elsewhere.
134-
|| isConstructor(methodDescriptor)
134+
|| methodDescriptor.isJsConstructor()
135135
// TODO(b/458472428): Support JsProperty.
136-
|| !methodDescriptor.isJsMethod()) {
136+
|| methodDescriptor.isJsProperty()) {
137137
continue;
138138
}
139139

@@ -169,11 +169,6 @@ private void appendJsDoc(SourceBuilder sb, String jsDoc) {
169169
}
170170
}
171171

172-
private static boolean isConstructor(MethodDescriptor methodDescriptor) {
173-
return methodDescriptor.getOrigin()
174-
== MethodDescriptor.MethodOrigin.SYNTHETIC_FACTORY_FOR_CONSTRUCTOR;
175-
}
176-
177172
private void generateExternsWiring(Type type) {
178173
SourceBuilder sb = new SourceBuilder();
179174
sb.appendln(String.format("goog.module('%s');", type.getDeclaration().getModuleName()));

transpiler/java/com/google/j2cl/transpiler/backend/wasm/SummaryBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ private JsInfo getJsInfo(Type type) {
143143
// TODO(b/458472428): Support JsProperty/Getter/Setter.
144144
for (var method : type.getMethods()) {
145145
MethodDescriptor methodDescriptor = method.getDescriptor();
146-
if (!(methodDescriptor.getOrigin().isWasmJsExport()
147-
|| methodDescriptor.getOrigin().isWasmJsConstructorExport())) {
146+
if (!methodDescriptor.getOrigin().isWasmJsExport()) {
148147
continue;
149148
}
150149

transpiler/java/com/google/j2cl/transpiler/passes/NormalizeInstantiationThroughFactoryMethods.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.google.j2cl.transpiler.ast.DeclaredTypeDescriptor;
2626
import com.google.j2cl.transpiler.ast.Expression;
2727
import com.google.j2cl.transpiler.ast.JsInfo;
28-
import com.google.j2cl.transpiler.ast.JsMemberType;
2928
import com.google.j2cl.transpiler.ast.Member;
3029
import com.google.j2cl.transpiler.ast.Method;
3130
import com.google.j2cl.transpiler.ast.MethodCall;
@@ -229,14 +228,6 @@ private static MethodDescriptor getCtorMethodDescriptorForConstructor(
229228
/** Method descriptor for $create methods. */
230229
private static MethodDescriptor getFactoryDescriptorForConstructor(MethodDescriptor constructor) {
231230
checkArgument(constructor.isConstructor());
232-
// Note: For JS constructors, we mark mark the corresponding factory method as a JS method so
233-
// that the summary builder picks it up.
234-
JsInfo newJsInfo =
235-
constructor.isJsConstructor()
236-
? JsInfo.Builder.from(constructor.getOriginalJsInfo())
237-
.setJsMemberType(JsMemberType.METHOD)
238-
.build()
239-
: JsInfo.NONE;
240231
return constructor.transform(
241232
builder ->
242233
builder
@@ -250,7 +241,7 @@ private static MethodDescriptor getFactoryDescriptorForConstructor(MethodDescrip
250241
.getTypeDeclaration()
251242
.getTypeParameterDescriptors())
252243
.setOrigin(MethodOrigin.SYNTHETIC_FACTORY_FOR_CONSTRUCTOR)
253-
.setOriginalJsInfo(newJsInfo)
244+
.setOriginalJsInfo(JsInfo.NONE)
254245
.setVisibility(constructor.getVisibility()));
255246
}
256247

0 commit comments

Comments
 (0)