Upgrade to latest Zig, remove dependency on patched version of Zig (#96)

* Prepare to upgrade zig

* zig fmt

* AllocGate

* Update data_url.zig

* wip

* few files

* just headers now?

* I think everything works?

* Update mimalloc

* Update hash_map.zig

* Perf improvements to compensate for Allocgate

* Bump

* 📷

* Update bun.lockb

* Less branching

* [js parser] Slightly reduce memory usage

* Update js_parser.zig

* WIP remove unused

* [JS parser] WIP support for `with` keyword

* Remove more dead code

* Fix all the build errors!

* cleanup

* Move `network_thread` up

* Bump peechy

* Update README.md
This commit is contained in:
Jarred Sumner
2021-12-30 21:12:32 -08:00
committed by GitHub
parent 8d031f13c0
commit e75c711c68
154 changed files with 4564 additions and 6274 deletions

View File

@@ -1,4 +1,22 @@
const std = @import("std");
const is_bindgen: bool = std.meta.globalOption("bindgen", bool) orelse false;
const StaticExport = @import("./bindings/static_export.zig");
const c_char = StaticExport.c_char;
const _global = @import("../../global.zig");
const string = _global.string;
const Output = _global.Output;
const Global = _global.Global;
const Environment = _global.Environment;
const strings = _global.strings;
const MutableString = _global.MutableString;
const stringZ = _global.stringZ;
const default_allocator = _global.default_allocator;
const StoredFileDescriptorType = _global.StoredFileDescriptorType;
const C = _global.C;
pub fn zigCast(comptime Destination: type, value: anytype) *Destination {
return @ptrCast(*Destination, @alignCast(@alignOf(*Destination), value));
}
const Fs = @import("../../fs.zig");
const Resolver = @import("../../resolver/resolver.zig");
@@ -18,11 +36,7 @@ const http = @import("../../http.zig");
const NodeFallbackModules = @import("../../node_fallbacks.zig");
const ImportKind = ast.ImportKind;
const Analytics = @import("../../analytics/analytics_thread.zig");
usingnamespace @import("./base.zig");
usingnamespace @import("./webcore/response.zig");
usingnamespace @import("./config.zig");
usingnamespace @import("./bindings/exports.zig");
usingnamespace @import("./bindings/bindings.zig");
const ZigString = @import("javascript_core").ZigString;
const Runtime = @import("../../runtime.zig");
const Router = @import("./api/router.zig");
const ImportRecord = ast.ImportRecord;
@@ -30,6 +44,37 @@ const DotEnv = @import("../../env_loader.zig");
const ParseResult = @import("../../bundler.zig").ParseResult;
const PackageJSON = @import("../../resolver/package_json.zig").PackageJSON;
const MacroRemap = @import("../../resolver/package_json.zig").MacroMap;
const WebCore = @import("javascript_core").WebCore;
const Request = WebCore.Request;
const Response = WebCore.Response;
const Headers = WebCore.Headers;
const Fetch = WebCore.Fetch;
const FetchEvent = WebCore.FetchEvent;
const js = @import("javascript_core").C;
const JSError = @import("./base.zig").JSError;
const d = @import("./base.zig").d;
const MarkedArrayBuffer = @import("./base.zig").MarkedArrayBuffer;
const getAllocator = @import("./base.zig").getAllocator;
const JSValue = @import("javascript_core").JSValue;
const NewClass = @import("./base.zig").NewClass;
const Microtask = @import("javascript_core").Microtask;
const JSGlobalObject = @import("javascript_core").JSGlobalObject;
const ExceptionValueRef = @import("javascript_core").ExceptionValueRef;
const JSPrivateDataPtr = @import("javascript_core").JSPrivateDataPtr;
const ZigConsoleClient = @import("javascript_core").ZigConsoleClient;
const ZigException = @import("javascript_core").ZigException;
const ZigStackTrace = @import("javascript_core").ZigStackTrace;
const ErrorableResolvedSource = @import("javascript_core").ErrorableResolvedSource;
const ResolvedSource = @import("javascript_core").ResolvedSource;
const JSPromise = @import("javascript_core").JSPromise;
const JSInternalPromise = @import("javascript_core").JSInternalPromise;
const JSModuleLoader = @import("javascript_core").JSModuleLoader;
const JSPromiseRejectionOperation = @import("javascript_core").JSPromiseRejectionOperation;
const Exception = @import("javascript_core").Exception;
const ErrorableZigString = @import("javascript_core").ErrorableZigString;
const ZigGlobalObject = @import("javascript_core").ZigGlobalObject;
const VM = @import("javascript_core").VM;
const Config = @import("./config.zig");
pub const GlobalClasses = [_]type{
Request.Class,
@@ -60,7 +105,7 @@ pub const Bun = struct {
pub fn onImportCSS(
resolve_result: *const Resolver.Result,
import_record: *ImportRecord,
source_dir: string,
_: string,
) void {
if (!css_imports_buf_loaded) {
css_imports_buf = std.ArrayList(u8).initCapacity(
@@ -99,10 +144,13 @@ pub const Bun = struct {
}
pub fn registerMacro(
this: void,
// this
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
// function
_: js.JSObjectRef,
// thisObject
_: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
) js.JSValueRef {
@@ -134,60 +182,60 @@ pub const Bun = struct {
}
pub fn getCWD(
this: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: void,
_: js.JSContextRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(VirtualMachine.vm.bundler.fs.top_level_dir).toValue(VirtualMachine.vm.global).asRef();
}
pub fn getOrigin(
this: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: void,
_: js.JSContextRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(VirtualMachine.vm.bundler.options.origin.origin).toValue(VirtualMachine.vm.global).asRef();
}
pub fn enableANSIColors(
this: void,
_: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return js.JSValueMakeBoolean(ctx, Output.enable_ansi_colors);
}
pub fn getMain(
this: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: void,
_: js.JSContextRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(VirtualMachine.vm.main).toValue(VirtualMachine.vm.global).asRef();
}
pub fn getAssetPrefix(
this: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: void,
_: js.JSContextRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(VirtualMachine.vm.bundler.options.routes.asset_prefix_path).toValue(VirtualMachine.vm.global).asRef();
}
pub fn getArgv(
this: void,
_: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
if (comptime Environment.isWindows) {
@compileError("argv not supported on windows");
@@ -205,11 +253,11 @@ pub const Bun = struct {
}
pub fn getRoutesDir(
this: void,
_: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
if (!VirtualMachine.vm.bundler.options.routes.routes_enabled or VirtualMachine.vm.bundler.options.routes.dir.len == 0) {
return js.JSValueMakeUndefined(ctx);
@@ -287,12 +335,12 @@ pub const Bun = struct {
}
pub fn getImportedStyles(
this: void,
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
_: []const js.JSValueRef,
_: js.ExceptionRef,
) js.JSValueRef {
defer flushCSSImports();
const styles = getCSSImports();
@@ -386,12 +434,12 @@ pub const Bun = struct {
}
pub fn getRouteFiles(
this: void,
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
_: []const js.JSValueRef,
_: js.ExceptionRef,
) js.JSValueRef {
if (VirtualMachine.vm.bundler.router == null) return js.JSValueMakeNull(ctx);
@@ -407,12 +455,12 @@ pub const Bun = struct {
}
pub fn getRouteNames(
this: void,
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
_: []const js.JSValueRef,
_: js.ExceptionRef,
) js.JSValueRef {
if (VirtualMachine.vm.bundler.router == null) return js.JSValueMakeNull(ctx);
@@ -428,10 +476,10 @@ pub const Bun = struct {
}
pub fn readFileAsBytes(
this: void,
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
) js.JSValueRef {
@@ -445,10 +493,10 @@ pub const Bun = struct {
}
pub fn readFileAsString(
this: void,
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
) js.JSValueRef {
@@ -478,12 +526,12 @@ pub const Bun = struct {
}
pub fn sleepSync(
this: void,
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
_: js.ExceptionRef,
) js.JSValueRef {
if (js.JSValueIsNumber(ctx, arguments[0])) {
const ms = JSValue.fromRef(arguments[0]).asNumber();
@@ -496,12 +544,12 @@ pub const Bun = struct {
var public_path_temp_str: [std.fs.MAX_PATH_BYTES]u8 = undefined;
pub fn getPublicPathJS(
this: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
_: void,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
_: js.ExceptionRef,
) js.JSValueRef {
var zig_str: ZigString = ZigString.Empty;
JSValue.toZigString(JSValue.fromRef(arguments[0]), &zig_str, VirtualMachine.vm.global);
@@ -647,11 +695,11 @@ pub const Bun = struct {
);
pub fn getter(
this: void,
_: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return js.JSObjectMake(ctx, EnvironmentVariables.Class.get().*, null);
}
@@ -663,9 +711,9 @@ pub const Bun = struct {
pub fn getProperty(
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
_: js.JSObjectRef,
propertyName: js.JSStringRef,
exception: js.ExceptionRef,
_: js.ExceptionRef,
) callconv(.C) js.JSValueRef {
const len = js.JSStringGetLength(propertyName);
var ptr = js.JSStringGetCharacters8Ptr(propertyName);
@@ -685,8 +733,8 @@ pub const Bun = struct {
}
pub fn hasProperty(
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
_: js.JSContextRef,
_: js.JSObjectRef,
propertyName: js.JSStringRef,
) callconv(.C) bool {
const len = js.JSStringGetLength(propertyName);
@@ -696,8 +744,8 @@ pub const Bun = struct {
}
pub fn getPropertyNames(
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
_: js.JSContextRef,
_: js.JSObjectRef,
props: js.JSPropertyNameAccumulatorRef,
) callconv(.C) void {
var iter = VirtualMachine.vm.bundler.env.map.iter();
@@ -726,12 +774,12 @@ pub const Performance = struct {
);
pub fn now(
this: void,
_: void,
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
arguments: []const js.JSValueRef,
exception: js.ExceptionRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
_: []const js.JSValueRef,
_: js.ExceptionRef,
) js.JSValueRef {
return js.JSValueMakeNumber(
ctx,
@@ -760,7 +808,7 @@ pub const Task = TaggedPointerUnion(.{
// Its unavailable on Linux
pub const VirtualMachine = struct {
global: *JSGlobalObject,
allocator: *std.mem.Allocator,
allocator: std.mem.Allocator,
node_modules: ?*NodeModuleBundle = null,
bundler: Bundler,
watcher: ?*http.Watcher = null,
@@ -858,7 +906,7 @@ pub const VirtualMachine = struct {
}
pub fn init(
allocator: *std.mem.Allocator,
allocator: std.mem.Allocator,
_args: Api.TransformOptions,
existing_bundle: ?*NodeModuleBundle,
_log: ?*logger.Log,
@@ -878,7 +926,7 @@ pub const VirtualMachine = struct {
const bundler = try Bundler.init(
allocator,
log,
try configureTransformOptionsForBunVM(allocator, _args),
try Config.configureTransformOptionsForBunVM(allocator, _args),
existing_bundle,
env_loader,
);
@@ -957,7 +1005,7 @@ pub const VirtualMachine = struct {
inline fn _fetch(
global: *JSGlobalObject,
_specifier: string,
source: string,
_: string,
log: *logger.Log,
) !ResolvedSource {
std.debug.assert(VirtualMachine.vm_loaded);
@@ -1083,7 +1131,7 @@ pub const VirtualMachine = struct {
vm.bundler.resetStore();
const hash = http.Watcher.getHash(path.text);
var allocator = if (vm.has_loaded) &vm.arena.allocator else vm.allocator;
var allocator = if (vm.has_loaded) vm.arena.allocator() else vm.allocator;
var fd: ?StoredFileDescriptorType = null;
var package_json: ?*PackageJSON = null;
@@ -1178,7 +1226,7 @@ pub const VirtualMachine = struct {
}
return ResolvedSource{
.allocator = if (vm.has_loaded) vm.allocator else null,
.allocator = if (vm.has_loaded) &vm.allocator else null,
.source_code = ZigString.init(vm.allocator.dupe(u8, source_code_printer.ctx.written) catch unreachable),
.specifier = ZigString.init(specifier),
.source_url = ZigString.init(path.text),
@@ -1188,7 +1236,7 @@ pub const VirtualMachine = struct {
},
else => {
return ResolvedSource{
.allocator = vm.allocator,
.allocator = &vm.allocator,
.source_code = ZigString.init(try strings.quotedAlloc(VirtualMachine.vm.allocator, path.pretty)),
.specifier = ZigString.init(path.text),
.source_url = ZigString.init(path.text),
@@ -1271,7 +1319,7 @@ pub const VirtualMachine = struct {
const package = &node_modules_bundle.bundle.packages[pkg_id];
if (isDebug) {
if (Environment.isDebug) {
std.debug.assert(strings.eql(node_modules_bundle.str(package.name), package_json.name));
}
@@ -1324,7 +1372,7 @@ pub const VirtualMachine = struct {
};
{
res.* = ErrorableZigString.err(err, @ptrCast(*c_void, ResolveError.create(vm.allocator, msg, source.slice())));
res.* = ErrorableZigString.err(err, @ptrCast(*anyopaque, ResolveError.create(vm.allocator, msg, source.slice())));
}
return;
@@ -1356,13 +1404,13 @@ pub const VirtualMachine = struct {
}
// This double prints
pub fn promiseRejectionTracker(global: *JSGlobalObject, promise: *JSPromise, rejection: JSPromiseRejectionOperation) callconv(.C) JSValue {
pub fn promiseRejectionTracker(_: *JSGlobalObject, _: *JSPromise, _: JSPromiseRejectionOperation) callconv(.C) JSValue {
// VirtualMachine.vm.defaultErrorHandler(promise.result(global.vm()), null);
return JSValue.jsUndefined();
}
const main_file_name: string = "bun:main";
threadlocal var errors_stack: [256]*c_void = undefined;
threadlocal var errors_stack: [256]*anyopaque = undefined;
pub fn fetch(ret: *ErrorableResolvedSource, global: *JSGlobalObject, specifier: ZigString, source: ZigString) callconv(.C) void {
var log = logger.Log.init(vm.bundler.allocator);
const spec = specifier.slice();
@@ -1418,7 +1466,7 @@ pub const VirtualMachine = struct {
.data = logger.rangeData(null, logger.Range.None, std.fmt.allocPrint(vm.allocator, "{s} while building {s}", .{ @errorName(err), specifier.slice() }) catch unreachable),
};
{
ret.* = ErrorableResolvedSource.err(err, @ptrCast(*c_void, BuildError.create(vm.bundler.allocator, msg)));
ret.* = ErrorableResolvedSource.err(err, @ptrCast(*anyopaque, BuildError.create(vm.bundler.allocator, msg)));
}
return;
},
@@ -1463,7 +1511,7 @@ pub const VirtualMachine = struct {
}
// TODO:
pub fn deinit(this: *VirtualMachine) void {}
pub fn deinit(_: *VirtualMachine) void {}
pub const ExceptionList = std.ArrayList(Api.JsException);
@@ -1594,7 +1642,7 @@ pub const VirtualMachine = struct {
pub fn iteratorWithOutColor(_vm: [*c]VM, globalObject: [*c]JSGlobalObject, nextValue: JSValue) callconv(.C) void {
iterator(_vm, globalObject, nextValue, false);
}
inline fn iterator(_vm: [*c]VM, globalObject: [*c]JSGlobalObject, nextValue: JSValue, comptime color: bool) void {
inline fn iterator(_: [*c]VM, _: [*c]JSGlobalObject, nextValue: JSValue, comptime color: bool) void {
VirtualMachine.vm.printErrorlikeObject(nextValue, null, current_exception_list, color);
}
};
@@ -1618,7 +1666,7 @@ pub const VirtualMachine = struct {
was_internal = this.printErrorFromMaybePrivateData(value.asRef(), exception_list, allow_ansi_color);
}
pub fn printErrorFromMaybePrivateData(this: *VirtualMachine, value: ?*c_void, exception_list: ?*ExceptionList, comptime allow_ansi_color: bool) bool {
pub fn printErrorFromMaybePrivateData(this: *VirtualMachine, value: ?*anyopaque, exception_list: ?*ExceptionList, comptime allow_ansi_color: bool) bool {
const private_data_ptr = JSPrivateDataPtr.from(value);
switch (private_data_ptr.tag()) {
@@ -1658,7 +1706,7 @@ pub const VirtualMachine = struct {
},
else => {
this.printErrorInstance(@intToEnum(JSValue, @intCast(i64, (@ptrToInt(value)))), exception_list, allow_ansi_color) catch |err| {
if (comptime isDebug) {
if (comptime Environment.isDebug) {
// yo dawg
Output.printErrorln("Error while printing Error-like object: {s}", .{@errorName(err)});
Output.flush();
@@ -1944,7 +1992,7 @@ pub const EventListenerMixin = struct {
var listeners = vm.event_listeners.get(EventType.fetch) orelse (return onError(ctx, error.NoListeners, JSValue.jsUndefined(), request_context) catch {});
if (listeners.items.len == 0) return onError(ctx, error.NoListeners, JSValue.jsUndefined(), request_context) catch {};
const FetchEventRejectionHandler = struct {
pub fn onRejection(_ctx: *c_void, err: anyerror, fetch_event: *FetchEvent, value: JSValue) void {
pub fn onRejection(_ctx: *anyopaque, err: anyerror, fetch_event: *FetchEvent, value: JSValue) void {
onError(
@intToPtr(*CtxType, @ptrToInt(_ctx)),
err,
@@ -1960,14 +2008,12 @@ pub const EventListenerMixin = struct {
fetch_event.* = FetchEvent{
.request_context = request_context,
.request = Request{ .request_context = request_context },
.onPromiseRejectionCtx = @as(*c_void, ctx),
.onPromiseRejectionCtx = @as(*anyopaque, ctx),
.onPromiseRejectionHandler = FetchEventRejectionHandler.onRejection,
};
var fetch_args: [1]js.JSObjectRef = undefined;
for (listeners.items) |listener_ref| {
var listener = @intToEnum(JSValue, @intCast(i64, @ptrToInt(listener_ref)));
fetch_args[0] = FetchEvent.Class.make(vm.global.ref(), fetch_event);
var result = js.JSObjectCallAsFunctionReturnValue(vm.global.ref(), listener_ref, null, 1, &fetch_args);
@@ -2002,11 +2048,11 @@ pub const EventListenerMixin = struct {
const Handler = struct {
pub fn addListener(
ctx: js.JSContextRef,
function: js.JSObjectRef,
thisObject: js.JSObjectRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
argumentCount: usize,
_arguments: [*c]const js.JSValueRef,
exception: js.ExceptionRef,
_: js.ExceptionRef,
) callconv(.C) js.JSValueRef {
const arguments = _arguments[0..argumentCount];
if (arguments.len == 0 or arguments.len == 1 or !js.JSValueIsString(ctx, arguments[0]) or !js.JSValueIsObject(ctx, arguments[arguments.len - 1]) or !js.JSObjectIsFunction(ctx, arguments[arguments.len - 1])) {
@@ -2054,11 +2100,11 @@ pub const EventListenerMixin = struct {
pub const ResolveError = struct {
msg: logger.Msg,
allocator: *std.mem.Allocator,
allocator: std.mem.Allocator,
referrer: ?Fs.Path = null,
logged: bool = false,
pub fn fmt(allocator: *std.mem.Allocator, specifier: string, referrer: string, err: anyerror) !string {
pub fn fmt(allocator: std.mem.Allocator, specifier: string, referrer: string, err: anyerror) !string {
switch (err) {
error.ModuleNotFound => {
if (Resolver.isPackagePath(specifier)) {
@@ -2119,7 +2165,7 @@ pub const ResolveError = struct {
);
pub fn create(
allocator: *std.mem.Allocator,
allocator: std.mem.Allocator,
msg: logger.Msg,
referrer: string,
) js.JSObjectRef {
@@ -2137,8 +2183,8 @@ pub const ResolveError = struct {
pub fn getPosition(
this: *ResolveError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
_: js.JSObjectRef,
_: js.JSStringRef,
exception: js.ExceptionRef,
) js.JSValueRef {
return BuildError.generatePositionObject(this.msg, ctx, exception);
@@ -2146,30 +2192,30 @@ pub const ResolveError = struct {
pub fn getMessage(
this: *ResolveError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(this.msg.data.text).toValue(VirtualMachine.vm.global).asRef();
}
pub fn getSpecifier(
this: *ResolveError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(this.msg.metadata.resolve.specifier.slice(this.msg.data.text)).toValue(VirtualMachine.vm.global).asRef();
}
pub fn getImportKind(
this: *ResolveError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(@tagName(this.msg.metadata.resolve.import_kind)).toValue(VirtualMachine.vm.global).asRef();
}
@@ -2177,9 +2223,9 @@ pub const ResolveError = struct {
pub fn getReferrer(
this: *ResolveError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSObjectRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
if (this.referrer) |referrer| {
return ZigString.init(referrer.text).toValue(VirtualMachine.vm.global).asRef();
@@ -2190,11 +2236,11 @@ pub const ResolveError = struct {
const BuildErrorName = "ResolveError";
pub fn getName(
this: *ResolveError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: *ResolveError,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(BuildErrorName).toValue(VirtualMachine.vm.global).asRef();
}
@@ -2203,7 +2249,7 @@ pub const ResolveError = struct {
pub const BuildError = struct {
msg: logger.Msg,
// resolve_result: Resolver.Result,
allocator: *std.mem.Allocator,
allocator: std.mem.Allocator,
logged: bool = false,
pub const Class = NewClass(
@@ -2231,7 +2277,7 @@ pub const BuildError = struct {
);
pub fn create(
allocator: *std.mem.Allocator,
allocator: std.mem.Allocator,
msg: logger.Msg,
// resolve_result: *const Resolver.Result,
) js.JSObjectRef {
@@ -2250,8 +2296,8 @@ pub const BuildError = struct {
pub fn getPosition(
this: *BuildError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
_: js.JSObjectRef,
_: js.JSStringRef,
exception: js.ExceptionRef,
) js.JSValueRef {
return generatePositionObject(this.msg, ctx, exception);
@@ -2383,21 +2429,21 @@ pub const BuildError = struct {
pub fn getMessage(
this: *BuildError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(this.msg.data.text).toValue(VirtualMachine.vm.global).asRef();
}
const BuildErrorName = "BuildError";
pub fn getName(
this: *BuildError,
ctx: js.JSContextRef,
thisObject: js.JSObjectRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
_: *BuildError,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
return ZigString.init(BuildErrorName).toValue(VirtualMachine.vm.global).asRef();
}