Skip to content

fix(nitro) fix sourcemaps and JSSink closing #5422

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

Merged
merged 6 commits into from
Sep 15, 2023
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
56 changes: 32 additions & 24 deletions src/bun.js/bindings/JSSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,17 +798,19 @@ void JSReadableArrayBufferSinkController::detach()

auto readableStream = m_weakReadableStream.get();
auto onClose = m_onClose.get();
m_onClose.clear();

if (readableStream && onClose) {
JSC::JSGlobalObject* globalObject = this->globalObject();
auto callData = JSC::getCallData(onClose);
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
if (callData.type != JSC::CallData::Type::None) {
JSC::JSGlobalObject* globalObject = this->globalObject();
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
}
}

m_onClose.clear();
m_weakReadableStream.clear();
}

Expand Down Expand Up @@ -1052,17 +1054,19 @@ void JSReadableFileSinkController::detach()

auto readableStream = m_weakReadableStream.get();
auto onClose = m_onClose.get();
m_onClose.clear();

if (readableStream && onClose) {
JSC::JSGlobalObject* globalObject = this->globalObject();
auto callData = JSC::getCallData(onClose);
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
if (callData.type != JSC::CallData::Type::None) {
JSC::JSGlobalObject* globalObject = this->globalObject();
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
}
}

m_onClose.clear();
m_weakReadableStream.clear();
}

Expand Down Expand Up @@ -1306,17 +1310,19 @@ void JSReadableHTTPResponseSinkController::detach()

auto readableStream = m_weakReadableStream.get();
auto onClose = m_onClose.get();
m_onClose.clear();

if (readableStream && onClose) {
JSC::JSGlobalObject* globalObject = this->globalObject();
auto callData = JSC::getCallData(onClose);
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
if (callData.type != JSC::CallData::Type::None) {
JSC::JSGlobalObject* globalObject = this->globalObject();
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
}
}

m_onClose.clear();
m_weakReadableStream.clear();
}

Expand Down Expand Up @@ -1560,17 +1566,19 @@ void JSReadableHTTPSResponseSinkController::detach()

auto readableStream = m_weakReadableStream.get();
auto onClose = m_onClose.get();
m_onClose.clear();

if (readableStream && onClose) {
JSC::JSGlobalObject* globalObject = this->globalObject();
auto callData = JSC::getCallData(onClose);
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
if (callData.type != JSC::CallData::Type::None) {
JSC::JSGlobalObject* globalObject = this->globalObject();
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
}
}

m_onClose.clear();
m_weakReadableStream.clear();
}

Expand Down
16 changes: 9 additions & 7 deletions src/bun.js/scripts/generate-jssink.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,17 +636,19 @@ void JS${controllerName}::detach() {

auto readableStream = m_weakReadableStream.get();
auto onClose = m_onClose.get();
m_onClose.clear();

if (readableStream && onClose) {
JSC::JSGlobalObject *globalObject = this->globalObject();
auto callData = JSC::getCallData(onClose);
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
if(callData.type != JSC::CallData::Type::None) {
JSC::JSGlobalObject *globalObject = this->globalObject();
JSC::MarkedArgumentBuffer arguments;
arguments.append(readableStream);
arguments.append(jsUndefined());
call(globalObject, onClose, callData, JSC::jsUndefined(), arguments);
}
}


m_onClose.clear();
m_weakReadableStream.clear();
}
`;
Expand Down
4 changes: 2 additions & 2 deletions src/sourcemap/sourcemap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ pub const LineOffsetTable = struct {
contents.ptr,
)) - line_byte_offset),
);
byte_offset_to_first_non_ascii = line_byte_offset;
byte_offset_to_first_non_ascii = column_byte_offset;
}

// Update the per-byte column offsets
Expand Down Expand Up @@ -1405,7 +1405,7 @@ pub const Chunk = struct {
// Use the line to compute the column
var original_column = loc.start - @as(i32, @intCast(line.byte_offset_to_start_of_line));
if (line.columns_for_non_ascii.len > 0 and original_column >= @as(i32, @intCast(line.byte_offset_to_first_non_ascii))) {
original_column = line.columns_for_non_ascii.ptr[@as(u32, @intCast(original_column)) - line.byte_offset_to_first_non_ascii];
original_column = line.columns_for_non_ascii.slice()[@as(u32, @intCast(original_column)) - line.byte_offset_to_first_non_ascii];
}

b.updateGeneratedLineAndColumn(output);
Expand Down
11 changes: 11 additions & 0 deletions test/js/bun/http/bun-server.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from "bun:test";
import { bunExe, bunEnv } from "harness";
import path from "path";

describe("Server", () => {
test("normlizes incoming request URLs", async () => {
Expand Down Expand Up @@ -368,4 +369,14 @@ describe("Server", () => {
await proc.exited;
expect(proc.exitCode).toBe(0);
});

test("should be able to parse source map and fetch small stream", async () => {
const proc = Bun.spawn({
cmd: [bunExe(), path.join("js-sink-sourmap-fixture", "index.mjs")],
cwd: import.meta.dir,
env: bunEnv,
});
await proc.exited;
expect(proc.exitCode).toBe(0);
});
});
22 changes: 22 additions & 0 deletions test/js/bun/http/js-sink-sourmap-fixture/chunks/stream.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { e as eventHandler } from "../index.mjs";
import "fs";
import "path";
import "node:async_hooks";
import "node:fs";
import "node:url";

const stream = eventHandler(() => {
const encoder = new TextEncoder();
const stream = new ReadableStream({
start(controller) {
controller.enqueue(encoder.encode("nitro"));
controller.enqueue(encoder.encode("is"));
controller.enqueue(encoder.encode("awesome"));
controller.close();
},
});
return stream;
});

export { stream as default };
//# sourceMappingURL=stream.mjs.map
Loading