Skip to content

Commit 1c8d033

Browse files
rherouart-collabv8-internal-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[mutator] Keep isGenerator and isAsync properties when mutating method
Bug: 537297697 Change-Id: I11cf5bd8d7bd8d88428cf0c97fb7b59016281d7c Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9614595 Reviewed-by: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Raphaël Hérouart <rherouart@google.com>
1 parent e6f65a1 commit 1c8d033

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

Sources/Fuzzilli/Mutators/OperationMutator.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ public class OperationMutator: BaseInstructionMutator {
128128
newOp = ObjectLiteralAddElement(index: b.randomIndex())
129129
case .beginObjectLiteralMethod(let op):
130130
newOp = BeginObjectLiteralMethod(
131-
methodName: b.randomMethodName(), parameters: op.parameters)
131+
methodName: b.randomMethodName(), parameters: op.parameters,
132+
isGenerator: op.isGenerator, isAsync: op.isAsync)
132133
case .beginObjectLiteralGetter:
133134
newOp = BeginObjectLiteralGetter(propertyName: b.randomPropertyName())
134135
case .beginObjectLiteralSetter:
@@ -141,7 +142,8 @@ public class OperationMutator: BaseInstructionMutator {
141142
index: b.randomIndex(), hasValue: op.hasValue, isStatic: op.isStatic)
142143
case .beginClassMethod(let op):
143144
newOp = BeginClassMethod(
144-
methodName: b.randomMethodName(), parameters: op.parameters, isStatic: op.isStatic)
145+
methodName: b.randomMethodName(), parameters: op.parameters, isStatic: op.isStatic,
146+
isGenerator: op.isGenerator, isAsync: op.isAsync)
145147
case .beginClassGetter(let op):
146148
newOp = BeginClassGetter(propertyName: b.randomPropertyName(), isStatic: op.isStatic)
147149
case .beginClassSetter(let op):

Tests/FuzzilliTests/MutatorTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,4 +811,52 @@ struct MutatorTests {
811811
try testCase.verify(mutatedProg)
812812
}
813813
}
814+
815+
@Test func testOperationMutatorPreservesGeneratorAndAsyncFlagsOnClassMethod() {
816+
let fuzzer = makeMockFuzzer()
817+
fuzzer.sync {
818+
let b = fuzzer.makeBuilder()
819+
820+
b.buildClassDefinition { cls in
821+
cls.addInstanceMethod(
822+
"m", with: .parameters(n: 0), isGenerator: true, isAsync: true
823+
) { _ in }
824+
}
825+
b.buildObjectLiteral { obj in
826+
obj.addMethod("m2", with: .parameters(n: 0), isGenerator: true, isAsync: true) {
827+
_ in
828+
}
829+
}
830+
831+
let prog = b.finalize()
832+
833+
let mutator = OperationMutator()
834+
let newBuilder = fuzzer.makeBuilder()
835+
836+
newBuilder.adopting {
837+
for instr in prog.code {
838+
if instr.op is BeginClassMethod || instr.op is BeginObjectLiteralMethod {
839+
mutator.mutate(instr, newBuilder)
840+
} else {
841+
newBuilder.adopt(instr)
842+
}
843+
}
844+
}
845+
846+
let mutatedProg = newBuilder.finalize()
847+
let mutatedClassMethod =
848+
mutatedProg.code.first(where: { $0.op is BeginClassMethod })!.op
849+
as! BeginClassMethod
850+
#expect(mutatedClassMethod.isAsync == true)
851+
#expect(mutatedClassMethod.isGenerator == true)
852+
853+
let mutatedObjMethod =
854+
mutatedProg.code.first(where: { $0.op is BeginObjectLiteralMethod })!.op
855+
as! BeginObjectLiteralMethod
856+
#expect(mutatedObjMethod.isAsync == true)
857+
#expect(mutatedObjMethod.isGenerator == true)
858+
859+
mutatedProg.checkOrDie(onFailure: "Program must be statically valid")
860+
}
861+
}
814862
}

0 commit comments

Comments
 (0)