Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky zlib dictionary test #15976

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading