diff --git a/Sources/FuzzilliCli/Profiles/ArkProfile.swift b/Sources/FuzzilliCli/Profiles/ArkProfile.swift index 886a19df6e9612a0aafe323fab03ad9419a8d59c..71b94d91db03ed717883d2fb94b1b0e28737f8b3 100644 --- a/Sources/FuzzilliCli/Profiles/ArkProfile.swift +++ b/Sources/FuzzilliCli/Profiles/ArkProfile.swift @@ -25,16 +25,22 @@ fileprivate let RunNearStackLimitGenerator = CodeGenerator("RunNearStackLimitGen b.callFunction(fun, withArgs: [f]) } -fileprivate let StackGenerator = ValueGenerator("StackGenerator") { b, n in - let constructor = b.loadBuiltin("Stack") +/// ArkTS Generators +fileprivate let ArkTSObjectInstanceGenerator = ValueGenerator("ArkTSObjectInstanceGenerator") { b, n in + let builtin = chooseUniform(from: ["Stack", "HashMap"]) + let constructor = b.loadBuiltin(builtin) b.construct(constructor) } /// Type of a ArkTS Stack object. fileprivate let arkTSStack = ILType.iterable + ILType.object(ofGroup: "Stack", withProperties: ["length"], withMethods: ["push", "pop", "peek", "locate", "forEach", "isEmpty"]) +/// Type of a ArkTS HashMap object. +fileprivate let arkTSHashMap = ILType.iterable + ILType.object(ofGroup: "HashMap", withProperties: ["length"], withMethods: ["isEmpty", "hasKey", "hasValue", "get", "setAll", "set", "remove", "clear", "keys", "values", "replace", "forEach", "entries"]) /// Type of the ArkTS Stack constructor builtin. fileprivate let arkTSStackConstructor = ILType.constructor([] => arkTSStack) +/// Type of the ArkTS HashMap constructor builtin. +fileprivate let arkTSHashMapConstructor = ILType.constructor([] => arkTSHashMap) /// ObjectGroup modelling ArkTS Stack objects fileprivate let arkTSStacks = ObjectGroup( @@ -53,6 +59,30 @@ fileprivate let arkTSStacks = ObjectGroup( ] ) +/// ObjectGroup modelling ArkTS HashMap objects +fileprivate let arkTSHashMaps = ObjectGroup( + name: "HashMap", + instanceType: arkTSHashMap, + properties: [ + "length" : .number, + ], + methods: [ + "isEmpty" : [] => .boolean, + "hasKey" : [.anything] => .boolean, + "hasValue" : [.anything] => .boolean, + "get" : [.anything] => .anything, + "setAll" : [.object(ofGroup: "HashMap")] => .undefined, + "set" : [.anything, .anything] => .object(), + "remove" : [.anything] => .anything, + "clear" : [] => .undefined, + "keys" : [] => .object(), // returns an array iterator + "values" : [] => .object(), + "replace" : [.anything, .anything] => .boolean, + "forEach" : [.function([.opt(.anything), .opt(.anything), .opt(arkTSHashMap)] => .undefined), .opt(.object())] => .undefined, + "entries" : [] => .object(), + ] +) + let arkProfile = Profile( processArgs: { randomize in var args = [ @@ -66,11 +96,12 @@ let arkProfile = Profile( maxExecsBeforeRespawn: 10000, - timeout: 176400, + timeout: 217400, codePrefix: """ let arkPrivate = globalThis.ArkPrivate; arkPrivate.Load(arkPrivate.Stack); + arkPrivate.Load(arkPrivate.HashMap); function bgc() { for(let i=0; i<0x10000; i+=1) {new String();} @@ -93,7 +124,7 @@ let arkProfile = Profile( additionalCodeGenerators: [ (PrintGenerator, 40), (RunNearStackLimitGenerator, 5), - (StackGenerator, 20), + (ArkTSObjectInstanceGenerator, 20), ], additionalProgramTemplates: WeightedList([]), @@ -114,10 +145,12 @@ let arkProfile = Profile( "sgc" : .function([] => .undefined), "bgc" : .function([] => .undefined), "Stack" : arkTSStackConstructor, + "HashMap" : arkTSHashMapConstructor, ], additionalObjectGroups: [ arkTSStacks, + arkTSHashMaps, ], optionalPostProcessor: nil