Skip to content

Commit 5827a55

Browse files
LiedtkeV8-internal LUCI CQ
authored andcommitted
[js] Test that all global builtins are registered
and document those globals that aren't registered, yet. Change-Id: Iea9be27be5f2f7cdeebb1621d98fe3949ab7b7c5 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/8635957 Reviewed-by: Michael Achenbach <[email protected]> Commit-Queue: Matthias Liedtke <[email protected]>
1 parent 3e9962b commit 5827a55

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Tests/FuzzilliTests/EnvironmentTest.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,63 @@ class EnvironmentTests: XCTestCase {
7373
testForOutput(program: jsProg, runner: runner, outputString: "")
7474
}
7575

76+
/// Test that all interesting properties on the globalThis object are registered as builtins.
77+
func testJSEnvironmentRegisteredBuiltins() throws {
78+
let runner = try GetJavaScriptExecutorOrSkipTest(type: .user, withArguments: [])
79+
let liveTestConfig = Configuration(logLevel: .error, enableInspection: true)
80+
let fuzzer = makeMockFuzzer(config: liveTestConfig, environment: JavaScriptEnvironment())
81+
let b = fuzzer.makeBuilder()
82+
83+
let globalThis = b.createNamedVariable(forBuiltin: "globalThis")
84+
let object = b.createNamedVariable(forBuiltin: "Object")
85+
let names = b.callMethod("getOwnPropertyNames", on: object, withArgs: [globalThis])
86+
let namesString = b.callMethod("join", on: names, withArgs: [b.loadString(",")])
87+
b.callFunction(b.createNamedVariable(forBuiltin: "output"), withArgs: [namesString])
88+
89+
let prog = b.finalize()
90+
let jsProg = fuzzer.lifter.lift(prog, withOptions: [])
91+
let jsEnvironment = b.fuzzer.environment
92+
let result = testExecuteScript(program: jsProg, runner: runner)
93+
XCTAssert(result.isSuccess, "\(result.error)\n\(result.output)")
94+
var output = result.output
95+
XCTAssertEqual(output.removeLast(), "\n")
96+
97+
// Global builtins available in d8 that should not be fuzzed.
98+
let skipped = [
99+
"fuzzilli", "testRunner", "quit", "load", "read", "readline", "readbuffer",
100+
"writeFile", "write", "print", "printErr", "version", "os", "d8", "arguments", "Realm"
101+
]
102+
// Global builtins that we probably should register but haven't done so, yet.
103+
let TODO = [
104+
"globalThis",
105+
"Iterator",
106+
"setTimeout",
107+
"console",
108+
"escape",
109+
"unescape",
110+
"encodeURIComponent",
111+
"encodeURI",
112+
"decodeURIComponent",
113+
"decodeURI",
114+
// https://github.com/tc39/proposal-ecmascript-sharedmem/tree/main
115+
"Atomics",
116+
// https://github.com/tc39/proposal-explicit-resource-management
117+
"DisposableStack",
118+
"AsyncDisposableStack",
119+
// https://github.com/tc39/proposal-float16array
120+
"Float16Array",
121+
// Web APIs
122+
"performance",
123+
"Worker",
124+
]
125+
let ignore = Set(skipped + TODO)
126+
127+
for builtin in output.split(separator: ",") where !ignore.contains(String(builtin)) {
128+
XCTAssert(jsEnvironment.builtins.contains(String(builtin)),
129+
"Unregistered builtin \(builtin)")
130+
}
131+
}
132+
76133
func convertTypedArrayToHex(_ b: ProgramBuilder, _ array: Variable) -> Variable {
77134
let toHex = b.buildArrowFunction(with: .parameters(n: 1)) { args in
78135
let hex = b.callMethod("toString", on: args[0], withArgs: [b.loadInt(16)])

0 commit comments

Comments
 (0)