Skip to content

Commit 3b018e2

Browse files
Merge pull request #325 from lightpanda-io/await_promise
cdp: runtime, replace `"awaitPromise":true` only if present
2 parents d4939c8 + 0217e3f commit 3b018e2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/cdp/runtime.zig

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,16 @@ fn sendInspector(
119119
// remove awaitPromise true params
120120
// TODO: delete when Promise are correctly handled by zig-js-runtime
121121
if (method == .callFunctionOn or method == .evaluate) {
122-
const buf = try alloc.alloc(u8, msg.json.len + 1);
123-
defer alloc.free(buf);
124-
_ = std.mem.replace(u8, msg.json, "\"awaitPromise\":true", "\"awaitPromise\":false", buf);
125-
ctx.sendInspector(buf);
126-
} else {
127-
ctx.sendInspector(msg.json);
122+
if (std.mem.indexOf(u8, msg.json, "\"awaitPromise\":true")) |_| {
123+
const buf = try alloc.alloc(u8, msg.json.len + 1);
124+
defer alloc.free(buf);
125+
_ = std.mem.replace(u8, msg.json, "\"awaitPromise\":true", "\"awaitPromise\":false", buf);
126+
ctx.sendInspector(buf);
127+
return "";
128+
}
128129
}
130+
131+
ctx.sendInspector(msg.json);
129132
return "";
130133
}
131134

0 commit comments

Comments
 (0)