aboutsummaryrefslogtreecommitdiff
path: root/src/javascript/jsc
diff options
context:
space:
mode:
Diffstat (limited to 'src/javascript/jsc')
-rw-r--r--src/javascript/jsc/bindings/ZigGlobalObject.cpp2
-rw-r--r--src/javascript/jsc/bindings/exports.zig17
-rw-r--r--src/javascript/jsc/javascript.zig46
-rw-r--r--src/javascript/jsc/webcore/response.zig16
4 files changed, 71 insertions, 10 deletions
diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
index 762f8b5cc..a251d49f1 100644
--- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp
+++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp
@@ -319,7 +319,7 @@ JSC::JSInternalPromise *GlobalObject::moduleLoaderFetch(JSGlobalObject *globalOb
promise->resolve(globalObject, jsSourceCode);
globalObject->vm().drainMicrotasks();
return promise;
-}
+ }
JSC::JSObject *GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObject *globalObject,
JSModuleLoader *loader,
diff --git a/src/javascript/jsc/bindings/exports.zig b/src/javascript/jsc/bindings/exports.zig
index c6a6c2b88..41e13d98e 100644
--- a/src/javascript/jsc/bindings/exports.zig
+++ b/src/javascript/jsc/bindings/exports.zig
@@ -45,6 +45,9 @@ pub const ZigGlobalObject = extern struct {
sigaction.handler = .{ .sigaction = Handler.global_signal_handler_fn };
std.os.sigaction(std.os.SIGABRT, &sigaction, null);
+ if (comptime !isDebug) {
+ std.os.sigaction(std.os.SIGTRAP, &sigaction, null);
+ }
}
return shim.cppFn("create", .{ class_ref, count, console });
@@ -421,7 +424,7 @@ pub const ZigStackFrame = extern struct {
position: ZigStackFramePosition,
enable_color: bool,
origin: *const ZigURL,
-
+ root_path: string = "",
pub fn format(this: SourceURLFormatter, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
try writer.writeAll(this.origin.displayProtocol());
try writer.writeAll("://");
@@ -429,7 +432,13 @@ pub const ZigStackFrame = extern struct {
try writer.writeAll(":");
try writer.writeAll(this.origin.port);
try writer.writeAll("/blob:");
- try writer.writeAll(this.source_url.slice());
+
+ var source_slice = this.source_url.slice();
+ if (strings.startsWith(source_slice, this.root_path)) {
+ source_slice = source_slice[this.root_path.len..];
+ }
+
+ try writer.writeAll(source_slice);
if (this.position.line > -1 and this.position.column_start > -1) {
try std.fmt.format(writer, ":{d}:{d}", .{ this.position.line + 1, this.position.column_start });
} else if (this.position.line > -1) {
@@ -491,8 +500,8 @@ pub const ZigStackFrame = extern struct {
return NameFormatter{ .function_name = this.function_name, .code_type = this.code_type, .enable_color = enable_color };
}
- pub fn sourceURLFormatter(this: *const ZigStackFrame, origin: *const ZigURL, comptime enable_color: bool) SourceURLFormatter {
- return SourceURLFormatter{ .source_url = this.source_url, .origin = origin, .position = this.position, .enable_color = enable_color };
+ pub fn sourceURLFormatter(this: *const ZigStackFrame, root_path: string, origin: *const ZigURL, comptime enable_color: bool) SourceURLFormatter {
+ return SourceURLFormatter{ .source_url = this.source_url, .origin = origin, .root_path = root_path, .position = this.position, .enable_color = enable_color };
}
};
diff --git a/src/javascript/jsc/javascript.zig b/src/javascript/jsc/javascript.zig
index 8bace87e9..7c7fb48c2 100644
--- a/src/javascript/jsc/javascript.zig
+++ b/src/javascript/jsc/javascript.zig
@@ -352,6 +352,9 @@ pub const VirtualMachine = struct {
has_loaded: bool = false,
+ transpiled_count: usize = 0,
+ resolved_count: usize = 0,
+ had_errors: bool = false,
pub var vm_loaded = false;
pub var vm: *VirtualMachine = undefined;
@@ -383,6 +386,7 @@ pub const VirtualMachine = struct {
VirtualMachine.vm.* = VirtualMachine{
.global = undefined,
.allocator = allocator,
+ .entry_point = ServerEntryPoint{},
.require_cache = RequireCacheType.init(allocator),
.event_listeners = EventListenerMixin.Map.init(allocator),
.bundler = bundler,
@@ -428,10 +432,13 @@ pub const VirtualMachine = struct {
}
pub fn flush(this: *VirtualMachine) void {
+ this.had_errors = false;
for (this.flush_list.items) |item| {
this.allocator.free(item);
}
this.flush_list.shrinkRetainingCapacity(0);
+ this.transpiled_count = 0;
+ this.resolved_count = 0;
}
inline fn _fetch(
@@ -477,6 +484,8 @@ pub const VirtualMachine = struct {
// so it consistently handles bundled imports
// we can't take the shortcut of just directly importing the file, sadly.
} else if (strings.eqlComptime(_specifier, main_file_name)) {
+ defer vm.transpiled_count += 1;
+
var bundler = &vm.bundler;
var old = vm.bundler.log;
vm.bundler.log = log;
@@ -551,6 +560,7 @@ pub const VirtualMachine = struct {
switch (loader) {
.js, .jsx, .ts, .tsx, .json => {
+ vm.transpiled_count += 1;
vm.bundler.resetStore();
const hash = http.Watcher.getHash(path.text);
@@ -584,6 +594,7 @@ pub const VirtualMachine = struct {
return error.ParseError;
};
+ const start_count = vm.bundler.linker.import_counter;
// We _must_ link because:
// - node_modules bundle won't be properly
try vm.bundler.linker.link(
@@ -592,6 +603,8 @@ pub const VirtualMachine = struct {
.absolute_path,
true,
);
+ vm.resolved_count += vm.bundler.linker.import_counter - start_count;
+ vm.bundler.linker.import_counter = 0;
if (!source_code_printer_loaded) {
var writer = try js_printer.BufferWriter.init(vm.allocator);
@@ -641,6 +654,7 @@ pub const VirtualMachine = struct {
fn _resolve(ret: *ResolveFunctionResult, global: *JSGlobalObject, specifier: string, source: string) !void {
std.debug.assert(VirtualMachine.vm_loaded);
std.debug.assert(VirtualMachine.vm.global == global);
+
if (vm.node_modules == null and strings.eqlComptime(specifier, Runtime.Runtime.Imports.Name)) {
ret.path = Runtime.Runtime.Imports.Name;
return;
@@ -658,8 +672,10 @@ pub const VirtualMachine = struct {
specifier,
.stmt,
);
+
ret.result = result;
const result_path = result.pathConst() orelse return error.ModuleNotFound;
+ vm.resolved_count += 1;
if (vm.node_modules != null and result.isLikelyNodeModule()) {
const node_modules_bundle = vm.node_modules.?;
@@ -772,7 +788,8 @@ pub const VirtualMachine = struct {
threadlocal var errors_stack: [256]*c_void = undefined;
pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void {
var log = logger.Log.init(vm.bundler.allocator);
- const result = _fetch(global, specifier.slice(), source.slice(), &log) catch |err| {
+ const spec = specifier.slice();
+ const result = _fetch(global, spec, source.slice(), &log) catch |err| {
processFetchLog(specifier, source, &log, ret, err);
return;
};
@@ -793,10 +810,17 @@ pub const VirtualMachine = struct {
ret.result.value = result;
+ const specifier_blob = brk: {
+ if (strings.startsWith(spec, VirtualMachine.vm.bundler.fs.top_level_dir)) {
+ break :brk spec[VirtualMachine.vm.bundler.fs.top_level_dir.len..];
+ }
+ break :brk spec;
+ };
+
if (vm.has_loaded) {
- vm.blobs.temporary.put(specifier.slice(), .{ .ptr = result.source_code.ptr, .len = result.source_code.len }) catch {};
+ vm.blobs.temporary.put(specifier_blob, .{ .ptr = result.source_code.ptr, .len = result.source_code.len }) catch {};
} else {
- vm.blobs.persistent.put(specifier.slice(), .{ .ptr = result.source_code.ptr, .len = result.source_code.len }) catch {};
+ vm.blobs.persistent.put(specifier_blob, .{ .ptr = result.source_code.ptr, .len = result.source_code.len }) catch {};
}
ret.success = true;
@@ -994,6 +1018,7 @@ pub const VirtualMachine = struct {
build_error.msg.formatWriter(@TypeOf(writer), writer, allow_ansi_color) catch {};
build_error.logged = true;
}
+ this.had_errors = this.had_errors or build_error.msg.kind == .err;
if (exception_list != null) {
this.log.addMsg(
build_error.msg,
@@ -1010,6 +1035,8 @@ pub const VirtualMachine = struct {
resolve_error.logged = true;
}
+ this.had_errors = this.had_errors or resolve_error.msg.kind == .err;
+
if (exception_list != null) {
this.log.addMsg(
resolve_error.msg,
@@ -1047,7 +1074,16 @@ pub const VirtualMachine = struct {
"<r> <d>at <r>{any} <d>(<r>{any}<d>)<r>\n",
allow_ansi_colors,
),
- .{ frame.nameFormatter(allow_ansi_colors), frame.sourceURLFormatter(&vm.bundler.options.origin, allow_ansi_colors) },
+ .{
+ frame.nameFormatter(
+ allow_ansi_colors,
+ ),
+ frame.sourceURLFormatter(
+ vm.bundler.fs.top_level_dir,
+ &vm.bundler.options.origin,
+ allow_ansi_colors,
+ ),
+ },
);
// if (!frame.position.isInvalid()) {
@@ -1109,6 +1145,8 @@ pub const VirtualMachine = struct {
try exception.addToErrorList(list);
}
+ this.had_errors = true;
+
var stderr: std.fs.File = Output.errorStream();
var buffered = std.io.bufferedWriter(stderr.writer());
var writer = buffered.writer();
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig
index 55e4a753e..b62645218 100644
--- a/src/javascript/jsc/webcore/response.zig
+++ b/src/javascript/jsc/webcore/response.zig
@@ -1132,7 +1132,21 @@ pub const FetchEvent = struct {
return js.JSValueMakeUndefined(ctx);
};
- defer this.request_context.arena.deinit();
+ defer {
+ if (!VirtualMachine.vm.had_errors) {
+ Output.printElapsed(@intToFloat(f64, (this.request_context.timer.lap())) / std.time.ns_per_ms);
+
+ Output.prettyError(
+ " <b>/{s}<r><d> - <b>{d}<r> <d>transpiled, <d><b>{d}<r> <d>imports<r>\n",
+ .{
+ this.request_context.matched_route.?.name,
+ VirtualMachine.vm.transpiled_count,
+ VirtualMachine.vm.resolved_count,
+ },
+ );
+ }
+ this.request_context.arena.deinit();
+ }
var needs_mime_type = true;
var content_length: ?usize = null;