From 56396d6bb234071f9d1f16402749d9d600488fde Mon Sep 17 00:00:00 2001 From: Vadim Afanasyev Date: Tue, 28 May 2024 21:27:36 +0800 Subject: [PATCH] ArkTS Environment class added with initial Stack API implementation --- .../Environment/ArkTSEnvironment.swift | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Sources/Fuzzilli/Environment/ArkTSEnvironment.swift diff --git a/Sources/Fuzzilli/Environment/ArkTSEnvironment.swift b/Sources/Fuzzilli/Environment/ArkTSEnvironment.swift new file mode 100644 index 0000000..b3d5caa --- /dev/null +++ b/Sources/Fuzzilli/Environment/ArkTSEnvironment.swift @@ -0,0 +1,34 @@ +public class ArkTSEnvironment: JavaScriptEnvironment { + public override init(additionalBuiltins: [String: ILType] = [:], additionalObjectGroups: [ObjectGroup] = []) { + var mutableAdditionalObjectGroups = additionalObjectGroups + mutableAdditionalObjectGroups.append(ArkTSEnvironment.arkTSStacks) + + var mutableAdditionalBuiltins = additionalBuiltins + mutableAdditionalBuiltins["Stack"] = ArkTSEnvironment.arkTSStackConstructor + + super.init(additionalBuiltins: mutableAdditionalBuiltins, additionalObjectGroups: mutableAdditionalObjectGroups) + } + + /// Type of a ArkTS Stack object. + static let arkTSStack = ILType.iterable + ILType.object(ofGroup: "Stack", withProperties: ["length"], withMethods: ["push", "pop", "peek", "locate", "forEach", "isEmpty"]) + + /// Type of the ArkTS Stack constructor builtin. + static let arkTSStackConstructor = ILType.constructor([] => arkTSStack) + + /// ObjectGroup modelling ArkTS Stack objects + static let arkTSStacks = ObjectGroup( + name: "Stack", + instanceType: arkTSStack, + properties: [ + "length" : .number, + ], + methods: [ + "push" : [.anything] => .anything, + "pop" : [] => .anything, + "peek" : [] => .anything, + "locate" : [.anything] => .number, + "forEach" : [.function([.anything, .opt(.number), .opt(arkTSStack)] => .undefined), .opt(.object())] => .undefined, + "isEmpty" : [] => .boolean, + ] + ) +} -- Gitee