Skip to content

Commit 31a2df5

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[environment] Add missing builtins to Error objects
Bug: 487347678 Change-Id: I649849a5e3d9511e82e5e47a5ffc61433ca8822e Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9058837 Reviewed-by: Danylo Mocherniuk <mdanylo@google.com> Commit-Queue: Danylo Mocherniuk <mdanylo@google.com>
1 parent 713fb3f commit 31a2df5

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

Sources/Fuzzilli/Environment/JavaScriptEnvironment.swift

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ public class JavaScriptEnvironment: ComponentBase {
427427
registerObjectGroup(.jsSharedArrayBufferPrototype)
428428
for variant in ["Error", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "AggregateError", "URIError", "SuppressedError"] {
429429
registerObjectGroup(.jsError(variant))
430+
registerObjectGroup(.jsErrorPrototype(variant))
431+
registerObjectGroup(.jsErrorConstructor(variant))
430432
}
431433
registerObjectGroup(.jsWebAssemblyCompileOptions)
432434
registerObjectGroup(.jsWebAssemblyModuleConstructor)
@@ -627,10 +629,9 @@ public class JavaScriptEnvironment: ComponentBase {
627629
registerBuiltin("Iterator", ofType: .jsIteratorConstructor)
628630
registerBuiltin("BigInt", ofType: .jsBigIntConstructor)
629631
registerBuiltin("RegExp", ofType: .jsRegExpConstructor)
630-
for variant in ["Error", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "SuppressedError"] {
632+
for variant in ["Error", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "SuppressedError", "AggregateError"] {
631633
registerBuiltin(variant, ofType: .jsErrorConstructor(variant))
632634
}
633-
registerBuiltin("AggregateError", ofType: .functionAndConstructor([.plain(.iterable), .opt(.string), .opt(.object())] => .jsError("AggregateError")))
634635
registerBuiltin("ArrayBuffer", ofType: .jsArrayBufferConstructor)
635636
registerBuiltin("SharedArrayBuffer", ofType: .jsSharedArrayBufferConstructor)
636637
for variant in ["Uint8Array", "Int8Array", "Uint16Array", "Int16Array", "Uint32Array", "Int32Array", "Float16Array", "Float32Array", "Float64Array", "Uint8ClampedArray", "BigInt64Array", "BigUint64Array"] {
@@ -1197,8 +1198,16 @@ public extension ILType {
11971198

11981199
/// Type of the JavaScript Error constructor builtin
11991200
static func jsErrorConstructor(_ variant: String) -> ILType {
1200-
// TODO: Add `Error.isError()`
1201-
return .functionAndConstructor([.opt(.string)] => .jsError(variant))
1201+
let signature = if variant == "AggregateError" {
1202+
[.plain(.iterable), .opt(.string), .opt(.object())] => .jsError("AggregateError")
1203+
} else {
1204+
[.opt(.string)] => .jsError(variant)
1205+
}
1206+
return .functionAndConstructor(signature)
1207+
+ .object(
1208+
ofGroup: "\(variant)Constructor",
1209+
withProperties: ["prototype", "stackTraceLimit"],
1210+
withMethods: ["isError", "captureStackTrace"])
12021211
}
12031212

12041213
/// Type of the JavaScript ArrayBuffer constructor builtin.
@@ -2498,6 +2507,26 @@ public extension ObjectGroup {
24982507
)
24992508
}
25002509

2510+
static func jsErrorPrototype(_ variant: String) -> ObjectGroup {
2511+
return createPrototypeObjectGroup(jsError(variant), constructor: .jsErrorConstructor(variant))
2512+
}
2513+
2514+
static func jsErrorConstructor(_ variant: String) -> ObjectGroup {
2515+
return ObjectGroup(
2516+
name: "\(variant)Constructor",
2517+
constructorPath: variant,
2518+
instanceType: .jsErrorConstructor(variant),
2519+
properties: [
2520+
"prototype": jsErrorPrototype(variant).instanceType,
2521+
"stackTraceLimit": .integer,
2522+
],
2523+
methods: [
2524+
"isError": [.jsAnything] => .boolean,
2525+
"captureStackTrace": [.object(), .opt(.function())] => .undefined,
2526+
]
2527+
)
2528+
}
2529+
25012530
// TODO(mliedtke): We need to construct these to make code generators be able to provide
25022531
// somewhat reasonable compile options.
25032532
static let jsWebAssemblyCompileOptions = ObjectGroup(

0 commit comments

Comments
 (0)