From 32d3e81b81c94eb1116e8ca0a5635fa6ea846dd4 Mon Sep 17 00:00:00 2001 From: z30061262 Date: Sun, 9 Jun 2024 18:29:38 +0800 Subject: [PATCH 1/2] Added LightWeightMap API --- Sources/FuzzilliCli/Profiles/ArkProfile.swift | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Sources/FuzzilliCli/Profiles/ArkProfile.swift b/Sources/FuzzilliCli/Profiles/ArkProfile.swift index aec2a76..64d0c37 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", "ArrayList"]) + let builtin = chooseUniform(from: ["Stack", "HashMap", "HashSet", "ArrayList", "LightWeightMap"]) let constructor = b.loadBuiltin(builtin) b.construct(constructor) } @@ -40,6 +40,9 @@ fileprivate let arkTSHashMap = ILType.iterable + ILType.object(ofGroup: "HashMap fileprivate let arkTSHashSet = ILType.iterable + ILType.object(ofGroup: "HashSet", withProperties: ["length"], withMethods: ["isEmpty", "has", "add", "remove", "clear", "values", "forEach", "entries"]) /// Type of a ArkTS ArrayList object. fileprivate let arkTSArrayList = ILType.iterable + ILType.object(ofGroup: "ArrayList", withProperties: ["length"], withMethods: ["add", "insert", "has", "getIndexOf", "getLastIndexOf", "removeByIndex", "remove", "removeByRange", "replaceAllElements", "forEach", "sort", "subArrayList", "clear", "clone", "getCapacity", "convertToArray", "isEmpty", "increaseCapacityTo", "trimToCurrentLength"]) +/// 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 the ArkTS Stack constructor builtin. fileprivate let arkTSStackConstructor = ILType.constructor([] => arkTSStack) @@ -49,6 +52,8 @@ fileprivate let arkTSHashMapConstructor = ILType.constructor([] => arkTSHashMap) fileprivate let arkTSHashSetConstructor = ILType.constructor([] => arkTSHashSet) /// Type of the ArkTS ArrayList constructor builtin. fileprivate let arkTSArrayListConstructor = ILType.constructor([] => arkTSArrayList) +/// Type of the ArkTS LightWeightMap constructor builtin. +fileprivate let arkTSLightWeightMapConstructor = ILType.constructor([] => arkTSLightWeightMap) /// ObjectGroup modelling ArkTS Stack objects @@ -140,6 +145,37 @@ fileprivate let arrayLists = 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 + ] +) + let arkProfile = Profile( processArgs: { randomize in var args = [ @@ -161,6 +197,7 @@ let arkProfile = Profile( var HashMap = arkPrivate.Load(arkPrivate.HashMap); var HashSet = arkPrivate.Load(arkPrivate.HashSet); var ArrayList = arkPrivate.Load(arkPrivate.ArrayList); + var LightWeightMap = arkPrivate.Load(arkPrivate.LightWeightMap); function bgc() { for(let i=0; i<0x10000; i+=1) {new String();} @@ -207,6 +244,7 @@ let arkProfile = Profile( "HashMap" : arkTSHashMapConstructor, "HashSet" : arkTSHashSetConstructor, "ArrayList" : arkTSArrayListConstructor, + "LightWeightMap" : arkTSLightWeightMapConstructor, ], additionalObjectGroups: [ @@ -214,6 +252,7 @@ let arkProfile = Profile( arkTSHashMaps, arkTSHashSets, arrayLists, + arkTSLightWeightMaps, ], optionalPostProcessor: nil -- Gitee From deda957a26325727ad2242d859b54dc80e2be3f5 Mon Sep 17 00:00:00 2001 From: z30061262 Date: Fri, 14 Jun 2024 11:58:44 +0800 Subject: [PATCH 2/2] Fix merge problem --- Sources/FuzzilliCli/Profiles/ArkProfile.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/FuzzilliCli/Profiles/ArkProfile.swift b/Sources/FuzzilliCli/Profiles/ArkProfile.swift index 606df05..d4e936c 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", "List", "ArrayList", "LightWeightMap"]) + let builtin = chooseUniform(from: ["Stack", "HashMap", "HashSet", "LinkedList", "List", "ArrayList", "LightWeightMap"]) let constructor = b.loadBuiltin(builtin) b.construct(constructor) } @@ -353,7 +353,7 @@ let arkProfile = Profile( "LinkedList" : arkTSLinkedListConstructor, "List" : arkTSListConstructor, "ArrayList" : arkTSArrayListConstructor, - "LightWeightMap" : arkTSLightWeightMapConstructor, + "LightWeightMap" : arkTSLightWeightMapConstructor, ], additionalObjectGroups: [ -- Gitee