@@ -686,6 +686,52 @@ public let FastApiCallFuzzer = ProgramTemplate("FastApiCallFuzzer") { b in
686686 b. build ( n: 10 )
687687}
688688
689+ public let ProtoAssignSeqOptFuzzer = ProgramTemplate ( " ProtoAssignSeqOptFuzzer " ) { b in
690+ b. buildPrefix ( )
691+
692+ let containingFct = b. buildPlainFunction ( with: b. randomParameters ( ) ) { args in
693+ // The function to install the prototypes on.
694+ let params = b. randomParameters ( )
695+ let body = { ( args: [ Variable ] ) in
696+ b. build ( n: 20 )
697+ b. doReturn ( b. randomVariable ( forUseAs: . object( ) ) )
698+ }
699+ let fct = withEqualProbability (
700+ { b. buildPlainFunction ( with: params, body) } ,
701+ { b. buildArrowFunction ( with: params, body) } ,
702+ { b. buildGeneratorFunction ( with: params, body) } , // not a valid constructor
703+ { b. buildAsyncFunction ( with: params, body) } , // not a valid constructor
704+ { b. buildConstructor ( with: params, body) } ,
705+ { b. buildClassDefinition ( withSuperclass: b. randomVariable ( forUseAs: . object( ) ) ) { _ in
706+ b. build ( n: 30 )
707+ } }
708+ )
709+ // Explicitly expose the prototype property to make modifications of it more likely.
710+ b. getProperty ( " prototype " , of: fct)
711+ // Allow further modifications on the function.
712+ b. build ( n: 10 )
713+ // Perform the prototype assignments.
714+ for _ in 0 ..< Int . random ( in: 2 ... 10 ) {
715+ let val = b. randomVariable ( forUseAs: . primitive)
716+ let name = b. randomCustomPropertyName ( )
717+ // TODO(mliedtke): This should be a setProperty(getProperty("prototype")) instead of
718+ // treating `prototype.name` as a single property.
719+ b. setProperty ( " prototype. \( name) " , of: fct, to: val)
720+ }
721+ // Allow further modifications after the optimized sequence.
722+ b. build ( n: 10 )
723+ // Construct the object with the `new` keyword. Add a guard because not all chosen functions
724+ // are valid constructors.
725+ b. construct ( fct, withArgs: b. randomArguments ( forCalling: fct) , guard: true )
726+ // Generate arbitrary code that could also use the constructed object.
727+ b. build ( n: 30 )
728+ b. doReturn ( b. randomJsVariable ( ) )
729+ }
730+ let sig = b. type ( of: containingFct) . signature ?? Signature . forUnknownFunction
731+ b. callFunction ( containingFct, withArgs: b. randomArguments ( forCalling: containingFct) )
732+ b. build ( n: 10 )
733+ }
734+
689735// Configure V8 invocation arguments. `forSandbox` is used by the V8SandboxProfile. As the sandbox
690736// fuzzer does not crash on regular assertions, most validation flags do not make sense in that
691737// configuraiton.
0 commit comments