Skip to content

Commit

Permalink
Fix flaky zlib dictionary test (oven-sh#15976)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored and probably-neb committed Jan 7, 2025
1 parent a01b7c5 commit 8f11780
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bun.js/api/zlib.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function generate(name: string) {
estimatedSize: true,
klass: {},
JSType: "0b11101110",
values: ["writeCallback", "errorCallback"],
values: ["writeCallback", "errorCallback", "dictionary"],

proto: {
init: { fn: "init" },
Expand Down
10 changes: 8 additions & 2 deletions src/bun.js/node/node_zlib_binding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ pub const SNativeZlib = struct {

pub fn init(this: *SNativeZlib, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
const arguments = callframe.argumentsUndef(7).slice();
const this_value = callframe.this();

if (arguments.len != 7) {
return globalThis.ERR_MISSING_ARGS("init(windowBits, level, memLevel, strategy, writeResult, writeCallback, dictionary)", .{}).throw();
Expand All @@ -373,7 +374,12 @@ pub const SNativeZlib = struct {
const dictionary = if (arguments[6].isUndefined()) null else arguments[6].asArrayBuffer(globalThis).?.byteSlice();

this.write_result = writeResult;
SNativeZlib.writeCallbackSetCached(callframe.this(), globalThis, writeCallback);
SNativeZlib.writeCallbackSetCached(this_value, globalThis, writeCallback);

// Keep the dictionary alive by keeping a reference to it in the JS object.
if (dictionary != null) {
SNativeZlib.dictionarySetCached(this_value, globalThis, arguments[6]);
}

this.stream.init(level, windowBits, memLevel, strategy, dictionary);

Expand Down Expand Up @@ -723,7 +729,7 @@ pub const SNativeBrotli = struct {
};
}

pub fn init(this: *@This(), globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
pub fn init(this: *SNativeBrotli, globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
const arguments = callframe.argumentsUndef(3).slice();
const this_value = callframe.this();
if (arguments.len != 3) {
Expand Down

0 comments on commit 8f11780

Please sign in to comment.