Skip to content

Commit 713fb3f

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[environment] Add Atomics builtin and its methods
Bug: 487347678 Change-Id: I5fdc080270ee713b71c46faf867a800180c1ec22 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9058836 Commit-Queue: Danylo Mocherniuk <mdanylo@google.com> Reviewed-by: Danylo Mocherniuk <mdanylo@google.com> Auto-Submit: Matthias Liedtke <mliedtke@google.com>
1 parent 3c4083d commit 713fb3f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ public class JavaScriptEnvironment: ComponentBase {
415415
registerObjectGroup(.jsBooleanConstructor)
416416
registerObjectGroup(.jsNumberConstructor)
417417
registerObjectGroup(.jsMathObject)
418+
registerObjectGroup(.jsAtomicsObject)
418419
registerObjectGroup(.jsDate)
419420
registerObjectGroup(.jsDateConstructor)
420421
registerObjectGroup(.jsDatePrototype)
@@ -648,6 +649,7 @@ public class JavaScriptEnvironment: ComponentBase {
648649
registerBuiltin("DisposableStack", ofType: .jsDisposableStackConstructor)
649650
registerBuiltin("AsyncDisposableStack", ofType: .jsAsyncDisposableStackConstructor)
650651
registerBuiltin("Math", ofType: .jsMathObject)
652+
registerBuiltin("Atomics", ofType: .jsAtomicsObject)
651653
registerBuiltin("JSON", ofType: .jsJSONObject)
652654
registerBuiltin("Reflect", ofType: .jsReflectObject)
653655
registerBuiltin("isNaN", ofType: .jsIsNaNFunction)
@@ -1151,6 +1153,10 @@ public extension ILType {
11511153

11521154
static let jsUint8Array = jsTypedArray("Uint8Array")
11531155

1156+
// TODO(mliedtke): Saying "any typed array" isn't really easily possible right now, so we type
1157+
// the expected parameter type as any object.
1158+
fileprivate static let someTypedArray = ILType.object()
1159+
11541160
/// Type of a JavaScript function.
11551161
/// A JavaScript function is also constructors. Moreover, it is also an object as it has a number of properties and methods.
11561162
static func jsFunction(_ signature: Signature = Signature.forUnknownFunction) -> ILType {
@@ -1248,6 +1254,9 @@ public extension ILType {
12481254
/// Type of the JavaScript Math constructor builtin.
12491255
static let jsMathObject = ILType.object(ofGroup: "Math", withProperties: ["E", "PI", "LN10", "LN2", "LOG10E", "LOG2E", "SQRT1_2", "SQRT2"], withMethods: ["abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", "atan2", "ceil", "cbrt", "expm1", "clz32", "cos", "cosh", "exp", "floor", "fround", "f16round", "hypot", "imul", "log", "log1p", "log2", "log10", "max", "min", "pow", "random", "round", "sign", "sin", "sinh", "sqrt", "sumPrecise", "tan", "tanh", "trunc"])
12501256

1257+
/// Type of the JavaScript Atomics builtin.
1258+
static let jsAtomicsObject = ILType.object(ofGroup: "Atomics", withProperties: [], withMethods: ["add", "and", "compareExchange", "exchange", "isLockFree", "load", "notify", "or", "pause", "store", "sub", "wait", "waitAsync", "xor"])
1259+
12511260
/// Type of the JavaScript Date object
12521261
static let jsDate = ILType.object(ofGroup: "Date", withMethods: ["toISOString", "toDateString", "toTimeString", "toLocaleString", "getTime", "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate", "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes", "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds", "getUTCMilliseconds", "getTimezoneOffset", "getYear", "setTime", "setMilliseconds", "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes", "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate", "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "setYear", "toJSON", "toUTCString", "toGMTString", "toTemporalInstant"])
12531262

@@ -2409,6 +2418,34 @@ public extension ObjectGroup {
24092418
]
24102419
)
24112420

2421+
/// Object group modelling the JavaScript Atomics builtin
2422+
/// Note that the typing here is not perfect: .someTypedArray doesn't have precise type
2423+
/// information. The parameters and results typed as .jsAnything are either .number or .bigint
2424+
/// depending on the type of the TypedArray that is passed as the first argument.
2425+
static let jsAtomicsObject = ObjectGroup(
2426+
name: "Atomics",
2427+
instanceType: .jsAtomicsObject,
2428+
properties: [:],
2429+
methods: [
2430+
"add" : [.plain(.someTypedArray), .integer, .jsAnything] => .jsAnything,
2431+
"and" : [.plain(.someTypedArray), .integer, .jsAnything] => .jsAnything,
2432+
"compareExchange" : [.plain(.someTypedArray), .integer, .jsAnything, .jsAnything] => .jsAnything,
2433+
"exchange" : [.plain(.someTypedArray), .integer, .jsAnything] => .jsAnything,
2434+
"isLockFree" : [.integer] => .boolean,
2435+
"load" : [.plain(.someTypedArray), .integer] => .jsAnything,
2436+
"notify" : [.oneof(.jsTypedArray("Int32Array"), .jsTypedArray("BigInt64Array")), .integer, .opt(.integer)] => .integer,
2437+
"or" : [.plain(.someTypedArray), .integer, .jsAnything] => .jsAnything,
2438+
"pause" : [.opt(.integer)] => .undefined,
2439+
"store" : [.plain(.someTypedArray), .integer, .jsAnything] => .jsAnything,
2440+
"sub" : [.plain(.someTypedArray), .integer, .jsAnything] => .jsAnything,
2441+
"wait" : [.oneof(.jsTypedArray("Int32Array"), .jsTypedArray("BigInt64Array")),
2442+
.integer, .jsAnything, .opt(.number)] => .string,
2443+
"waitAsync" : [.oneof(.jsTypedArray("Int32Array"), .jsTypedArray("BigInt64Array")),
2444+
.integer, .jsAnything, .opt(.number)] => .object(withProperties: ["async", "value"]),
2445+
"xor" : [.plain(.someTypedArray), .integer, .jsAnything] => .jsAnything,
2446+
]
2447+
)
2448+
24122449
/// ObjectGroup modelling the JavaScript JSON builtin
24132450
static let jsJSONObject = ObjectGroup(
24142451
name: "JSON",

0 commit comments

Comments
 (0)