Skip to content

Commit

Permalink
refactor: allocate response buffer in script method more elegantly
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed May 30, 2024
1 parent 259c4a8 commit 02f0229
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.v
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ pub fn (w Window) run(script string) {
// script executes JavaScript and returns the response (Make sure the response buffer can hold the response).
// The default max_response_size is 8KiB.
pub fn (w Window) script(javascript string, opts ScriptOptions) !string {
mut buffer := []u8{len: int(opts.max_response_size)}.str().str
if !C.webui_script(w, &char(javascript.str), opts.timeout, &char(buffer), opts.max_response_size) {
mut buffer := []u8{len: int(opts.max_response_size)}
if !C.webui_script(w, &char(javascript.str), opts.timeout, &char(buffer.data), opts.max_response_size) {
return error('Failed running script. `${javascript}`')
}
return unsafe { buffer.vstring() }
return unsafe { buffer.bytestr() }
}

// set_runtime sets the runtime for .js and .ts files to Deno or Nodejs.
Expand Down

0 comments on commit 02f0229

Please sign in to comment.