From 3e06de88d57f9692cf8af487421f00d4369f049c Mon Sep 17 00:00:00 2001 From: maorun1 <13830476+maorun1@user.noreply.gitee.com> Date: Thu, 30 May 2024 14:38:11 +0800 Subject: [PATCH] add arkts.collectionsMap codegenerator Change-Id: Ic3e66a1920067727135bada2fa3022a69e47eb9f --- .../CodeGen/CodeGeneratorWeights.swift | 1 + Sources/Fuzzilli/CodeGen/CodeGenerators.swift | 6 ++++ .../Environment/JavaScriptEnvironment.swift | 28 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift index 8699e2c..d06e80a 100644 --- a/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift +++ b/Sources/Fuzzilli/CodeGen/CodeGeneratorWeights.swift @@ -30,6 +30,7 @@ public let codeGeneratorWeights = [ "IntArrayGenerator": 10, "TypedArrayGenerator": 20, "BuiltinObjectInstanceGenerator": 10, + "ArkTsMapObjectInstanceGnenrator": 5, "ObjectBuilderFunctionGenerator": 10, "ObjectConstructorGenerator": 10, "ClassDefinitionGenerator": 20, diff --git a/Sources/Fuzzilli/CodeGen/CodeGenerators.swift b/Sources/Fuzzilli/CodeGen/CodeGenerators.swift index c7d6970..3b50293 100644 --- a/Sources/Fuzzilli/CodeGen/CodeGenerators.swift +++ b/Sources/Fuzzilli/CodeGen/CodeGenerators.swift @@ -110,6 +110,12 @@ public let CodeGenerators: [CodeGenerator] = [ } }, + ValueGenerator("ArkTsMapObjectInstanceGnenrator") { b, n in + let builtin = "ArkTsMap" + let constructor = b.loadBuiltin(builtin) + b.construct(constructor) + }, + ValueGenerator("TypedArrayGenerator") { b, n in for _ in 0.. .jsMap) + /// Type of the ArkTs Map constructor builtin. + static let collectionsMapConstructor = JSType.constructor([.object()] => .collectionsMap) + /// Type of the JavaScript WeakMap constructor builtin. static let jsWeakMapConstructor = ILType.constructor([.object()] => .jsWeakMap) @@ -920,6 +928,26 @@ public extension ObjectGroup { ] ) + ///ObjectGroup modelling ArkTs Map objects + static let collectionsMaps = ObjectGroup( + name: "ArkTsMap", + instanceType: .collectionsMap, + properties: [ + "size" : .integer + ], + methods: [ + "entries" : [] => .object(), + "keys" : [] => .object(), + "values" : [] => .object(), + "clear" : [] => .undefined, + "delete" : [.anything] => .boolean, + "forEach" : [.function(), .opt(.object())] => .undefined, + "get" : [.anything] => .anything, + "has" : [.anything] => .boolean, + "set" : [.anything, .anything] => .collectionsMap, + ] + ) + /// ObjectGroup modelling JavaScript WeakMap objects static let jsWeakMaps = ObjectGroup( name: "WeakMap", -- Gitee