Skip to content

Commit 281729b

Browse files
marjakhv8-internal-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[tools] Add a ":load" command to the REPRL helper
With this command, we can run the REPRL with existing files, no need to convert each file to one line and copy-paste it to the REPRL tool. Change-Id: Ic78082ce7aeb5977e2f49e07701bd4d5c1b82a45 Reviewed-on: https://chrome-internal-review.googlesource.com/c/v8/fuzzilli/+/9865575 Commit-Queue: Marja Hölttä <marja@google.com> Reviewed-by: Leon Bettscheider <bettscheider@chromium.org> Reviewed-by: Raphaël Hérouart <rherouart@google.com>
1 parent 135a77a commit 281729b

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎Sources/REPRLRun/main.swift‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,29 @@ if execute("").status != 0 {
104104
// Run a couple of tests now
105105
runREPRLTests()
106106

107-
print("Enter code to run, then hit enter to execute it")
107+
print("Enter code to run, then hit enter to execute it, or enter :load <file> to execute a file")
108108
while true {
109109
print("> ", terminator: "")
110-
guard let code = readLine(strippingNewline: false) else {
110+
guard var code = readLine(strippingNewline: false) else {
111111
print("Bye")
112112
break
113113
}
114114

115+
// TODO(fuzzilli): If we extend this with more commands, handle them elegantly (e.g., add a "command -> callback" map).
116+
let loadCommand = ":load "
117+
if code.hasPrefix(loadCommand) {
118+
let path = NSString(
119+
string: code.dropFirst(loadCommand.count).trimmingCharacters(
120+
in: .whitespacesAndNewlines)
121+
).expandingTildeInPath
122+
do {
123+
code = try String(contentsOfFile: path, encoding: .utf8)
124+
} catch {
125+
print("Failed to read \(path): \(error.localizedDescription)")
126+
continue
127+
}
128+
}
129+
115130
let (status, exec_time) = execute(code)
116131

117132
if status < 0 {

0 commit comments

Comments
 (0)