diff --git a/Sources/FuzzilliCli/Profiles/ArkProfile.swift b/Sources/FuzzilliCli/Profiles/ArkProfile.swift index 9e498b4ff932dd0b31ba62cf0ff0701665d86726..28b9cebebdbd5d9d319b8d3487f24c17a738ca49 100644 --- a/Sources/FuzzilliCli/Profiles/ArkProfile.swift +++ b/Sources/FuzzilliCli/Profiles/ArkProfile.swift @@ -27,7 +27,7 @@ fileprivate let RunNearStackLimitGenerator = CodeGenerator("RunNearStackLimitGen /// ArkTS Generators fileprivate let ArkTSObjectInstanceGenerator = ValueGenerator("ArkTSObjectInstanceGenerator") { b, n in - let builtin = chooseUniform(from: ["Stack", "HashMap", "HashSet", "LinkedList", "List", "ArrayList", "TreeMap", "TreeSet"]) + let builtin = chooseUniform(from: ["Stack", "HashMap", "HashSet", "LinkedList", "List", "ArrayList", "TreeMap", "TreeSet", "LightWeightMap", "LightWeightSet"]) let constructor = b.loadBuiltin(builtin) if ["TreeMap", "TreeSet"].contains(builtin) && probability(0.2) { //custom comparator for TreeMap and TreeSet will be generated only in 20% of cases let comparator = b.buildPlainFunction(with: .parameters(n: 2)) { args in @@ -65,6 +65,10 @@ fileprivate let arkTSArrayList = ILType.iterable + ILType.object(ofGroup: "Array fileprivate let arkTSTreeMap = ILType.iterable + ILType.object(ofGroup: "TreeMap", withProperties: ["length"], withMethods: ["isEmpty", "hasKey", "hasValue", "get", "getFirstKey", "getLastKey", "setAll", "set", "remove", "getLowerKey", "getHigherKey", "replace", "clear", "keys", "values", "forEach", "entries"]) /// Type of a ArkTS TreeSet object. fileprivate let arkTSTreeSet = ILType.iterable + ILType.object(ofGroup: "TreeSet", withProperties: ["length"], withMethods: ["isEmpty", "has", "getFirstValue", "getLastValue", "add", "remove", "getLowerValue", "getHigherValue", "popFirst", "popLast", "clear", "values", "forEach", "entries"]) +/// Type of a ArkTS LightWeightMap object. +fileprivate let arkTSLightWeightMap = ILType.iterable + ILType.object(ofGroup: "LightWeightMap", withProperties: ["length"], withMethods: ["isEmpty", "hasAll", "hasKey", "hasValue", "increaseCapacityTo", "get", "getIndexOfKey", "getIndexOfValue", "getKeyAt", "setAll", "set", "remove", "removeAt", "setValueAt", "getValueAt", "clear", "keys", "values", "forEach", "entries", "toString"]) +/// Type of a ArkTS LightWeightSet object. +fileprivate let arkTSLightWeightSet = ILType.iterable + ILType.object(ofGroup: "LightWeightSet", withProperties: ["length"], withMethods: ["isEmpty", "add", "addAll", "hasAll", "has", "equal", "increaseCapacityTo", "getIndexOf", "remove", "removeAt", "getValueAt", "clear", "toString", "toArray", "values", "forEach", "entries"]) /// Tpye of a ArkTS CollectionsMap object fileprivate let collectionsMap = ILType.iterable + ILType.object(ofGroup: "SharedMap", withProperties: ["size"], withMethods: ["entries", "keys", "values", "clear", "delete", "forEach", "get", "has", "set"]) @@ -85,6 +89,10 @@ fileprivate let arkTSArrayListConstructor = ILType.constructor([] => arkTSArrayL fileprivate let arkTSTreeMapConstructor = ILType.constructor([.opt(.function([.anything, .anything] => .boolean))] => arkTSTreeMap) /// Type of the ArkTS TreeSet constructor builtin. fileprivate let arkTSTreeSetConstructor = ILType.constructor([.opt(.function([.anything, .anything] => .boolean))] => arkTSTreeSet) +/// Type of the ArkTS LightWeightMap constructor builtin. +fileprivate let arkTSLightWeightMapConstructor = ILType.constructor([] => arkTSLightWeightMap) +/// Type of the ArkTS LightWeightSet constructor builtin. +fileprivate let arkTSLightWeightSetConstructor = ILType.constructor([] => arkTSLightWeightSet) /// Type of the ArkTs CollectionsMap constructor builtin. fileprivate let collectionsMapConstructor = ILType.constructor([.object()] => collectionsMap) @@ -314,6 +322,66 @@ fileprivate let arkTSTreeSets = ObjectGroup( ] ) +fileprivate let arkTSLightWeightMaps = ObjectGroup( + name: "LightWeightMap", + instanceType: arkTSLightWeightMap, + properties: [ + "length" : .number, + ], + methods: [ + "isEmpty" : [] => .boolean, + "hasAll" : [.object(ofGroup: "LightWeightMap")] => .boolean, + "hasKey" : [.anything] => .boolean, + "hasValue" : [.anything] => .boolean, + "increaseCapacityTo" : [.number] => .undefined, + "get" : [.anything] => .anything, + "getIndexOfKey" : [.anything] => .number, + "getIndexOfValue" : [.anything] => .number, + "getKeyAt" : [.number] => .anything, + "setAll" : [.object(ofGroup: "LightWeightMap")] => .undefined, + "set" : [.anything, .anything] => .object(), + "remove" : [.anything] => .anything, + "removeAt" : [.number] => .boolean, + "setValueAt" : [.number, .anything] => .boolean, + "getValueAt" : [.number] => .anything, + "clear" : [] => .undefined, + "keys" : [] => .object(), + "values" : [] => .object(), + "forEach" : [.function([.opt(.anything), .opt(.anything), .opt(arkTSLightWeightMap)] => .undefined), .opt(.object())] => .undefined, + "entries" : [] => .object(), + "toString" : [] => .string + ] +) + +/// ObjectGroup modelling ArkTS LightWeightSet objects +fileprivate let arkTSLightWeightSets = ObjectGroup( + name: "LightWeightSet", + instanceType: arkTSLightWeightSet, + properties: [ + "length" : .number, + ], + methods: [ + "isEmpty" : [] => .boolean, + "add" : [.anything] => .boolean, + "addAll" : [.object(ofGroup: "LightWeightSet")] => .boolean, + "hasAll" : [.object(ofGroup: "LightWeightSet")] => .boolean, + "has" : [.anything] => .boolean, + "equal" : [.object()] => .boolean, + "increaseCapacityTo" : [.number] => .undefined, + "getIndexOf" : [.anything] => .number, + "remove" : [.anything] => .anything, + "removeAt" : [.number] => .boolean, + "getValueAt" : [.number] => .anything, + "clear" : [] => .undefined, + "toString" : [] => .string, + "toArray" : [] => .object(), + "values" : [] => .object(), + "forEach" : [.function([.opt(.anything), .opt(.anything), .opt(arkTSLightWeightSet)] => .undefined), .opt(.object())] => .undefined, + "entries" : [] => .object(), + ] +) + + let arkProfile = Profile( processArgs: { randomize in var args = [ @@ -339,6 +407,8 @@ let arkProfile = Profile( var ArrayList = arkPrivate.Load(arkPrivate.ArrayList); var TreeMap = arkPrivate.Load(arkPrivate.TreeMap); var TreeSet = arkPrivate.Load(arkPrivate.TreeSet); + var LightWeightMap = arkPrivate.Load(arkPrivate.LightWeightMap); + var LightWeightSet = arkPrivate.Load(arkPrivate.LightWeightSet); function bgc() { for(let i=0; i<0x10000; i+=1) {new String();} @@ -391,6 +461,8 @@ let arkProfile = Profile( "ArrayList" : arkTSArrayListConstructor, "TreeMap" : arkTSTreeMapConstructor, "TreeSet" : arkTSTreeSetConstructor, + "LightWeightMap" : arkTSLightWeightMapConstructor, + "LightWeightSet" : arkTSLightWeightSetConstructor, ], additionalObjectGroups: [ @@ -403,6 +475,8 @@ let arkProfile = Profile( arkTSArrayLists, arkTSTreeMaps, arkTSTreeSets, + arkTSLightWeightMaps, + arkTSLightWeightSets, ], optionalPostProcessor: nil