mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Threader
Former-commit-id: a13dd6402f54527e87e9afdbbf48e5ff1501c8f9
This commit is contained in:
@@ -53,6 +53,7 @@ namespace JSCastingHelpers = JSC::JSCastingHelpers;
|
||||
extern "C" JSC__JSGlobalObject *Zig__GlobalObject__create(JSClassRef *globalObjectClass, int count,
|
||||
void *console_client) {
|
||||
std::set_terminate([]() { Zig__GlobalObject__onCrash(); });
|
||||
WTF::initializeMainThread();
|
||||
JSC::initialize();
|
||||
|
||||
JSC::VM &vm = JSC::VM::create(JSC::LargeHeap).leakRef();
|
||||
|
||||
@@ -437,60 +437,66 @@ void JSC__SourceCode__fromString(JSC__SourceCode *arg0, const WTF__String *arg1,
|
||||
|
||||
JSC__JSValue JSC__JSFunction__callWithArguments(JSC__JSValue JSValue0, JSC__JSGlobalObject *arg1,
|
||||
JSC__JSValue *arg2, size_t arg3,
|
||||
JSC__Exception **arg4, const char *arg5) {
|
||||
JSC__Exception **arg4, const unsigned char *arg5) {
|
||||
auto args = makeArgs(arg2, arg3);
|
||||
return JSC::JSValue::encode(
|
||||
JSC::call(arg1, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue0), args, arg5));
|
||||
return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0),
|
||||
JSC::JSValue::decode(JSValue0), args, (const char *)arg5));
|
||||
}
|
||||
JSC__JSValue JSC__JSFunction__callWithArgumentsAndThis(JSC__JSValue JSValue0, JSC__JSValue JSValue1,
|
||||
JSC__JSGlobalObject *arg2,
|
||||
JSC__JSValue *arg3, size_t arg4,
|
||||
JSC__Exception **arg5, const char *arg6) {
|
||||
JSC__Exception **arg5,
|
||||
const unsigned char *arg6) {
|
||||
auto args = makeArgs(arg3, arg4);
|
||||
return JSC::JSValue::encode(
|
||||
JSC::call(arg2, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue1), args, arg6));
|
||||
return JSC::JSValue::encode(JSC::call(arg2, JSC::JSValue::decode(JSValue0),
|
||||
JSC::JSValue::decode(JSValue1), args, (const char *)arg6));
|
||||
}
|
||||
JSC__JSValue JSC__JSFunction__callWithoutAnyArgumentsOrThis(JSC__JSValue JSValue0,
|
||||
JSC__JSGlobalObject *arg1,
|
||||
JSC__Exception **arg2,
|
||||
const char *arg3) {
|
||||
const unsigned char *arg3) {
|
||||
return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0),
|
||||
JSC::JSValue::decode(JSValue0), JSC::ArgList(), arg3));
|
||||
JSC::JSValue::decode(JSValue0), JSC::ArgList(),
|
||||
(const char *)arg3));
|
||||
}
|
||||
JSC__JSValue JSC__JSFunction__callWithThis(JSC__JSValue JSValue0, JSC__JSGlobalObject *arg1,
|
||||
JSC__JSValue JSValue2, JSC__Exception **arg3,
|
||||
const char *arg4) {
|
||||
const unsigned char *arg4) {
|
||||
return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0),
|
||||
JSC::JSValue::decode(JSValue2), JSC::ArgList(), arg4));
|
||||
JSC::JSValue::decode(JSValue2), JSC::ArgList(),
|
||||
(const char *)arg4));
|
||||
}
|
||||
JSC__JSValue JSC__JSFunction__constructWithArguments(JSC__JSValue JSValue0,
|
||||
JSC__JSGlobalObject *arg1, JSC__JSValue *arg2,
|
||||
size_t arg3, JSC__Exception **arg4,
|
||||
const char *arg5) {
|
||||
const unsigned char *arg5) {
|
||||
auto args = makeArgs(arg2, arg3);
|
||||
return JSC::JSValue::encode(JSC::construct(arg1, JSC::JSValue::decode(JSValue0), args, arg5));
|
||||
return JSC::JSValue::encode(
|
||||
JSC::construct(arg1, JSC::JSValue::decode(JSValue0), args, (const char *)arg5));
|
||||
}
|
||||
|
||||
JSC__JSValue JSC__JSFunction__constructWithArgumentsAndNewTarget(
|
||||
JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject *arg2, JSC__JSValue *arg3,
|
||||
size_t arg4, JSC__Exception **arg5, const char *arg6) {
|
||||
size_t arg4, JSC__Exception **arg5, const unsigned char *arg6) {
|
||||
auto args = makeArgs(arg3, arg4);
|
||||
return JSC::JSValue::encode(JSC::construct(arg2, JSC::JSValue::decode(JSValue0),
|
||||
JSC::JSValue::decode(JSValue0), args, arg6));
|
||||
JSC::JSValue::decode(JSValue0), args,
|
||||
(const char *)arg6));
|
||||
}
|
||||
JSC__JSValue JSC__JSFunction__constructWithNewTarget(JSC__JSValue JSValue0,
|
||||
JSC__JSGlobalObject *arg1,
|
||||
JSC__JSValue JSValue2, JSC__Exception **arg3,
|
||||
const char *arg4) {
|
||||
const unsigned char *arg4) {
|
||||
return JSC::JSValue::encode(JSC::construct(arg1, JSC::JSValue::decode(JSValue0),
|
||||
JSC::JSValue::decode(JSValue2), JSC::ArgList(), arg4));
|
||||
JSC::JSValue::decode(JSValue2), JSC::ArgList(),
|
||||
(const char *)arg4));
|
||||
}
|
||||
JSC__JSValue JSC__JSFunction__constructWithoutAnyArgumentsOrNewTarget(JSC__JSValue JSValue0,
|
||||
JSC__JSGlobalObject *arg1,
|
||||
JSC__Exception **arg2,
|
||||
const char *arg3) {
|
||||
const unsigned char *arg3) {
|
||||
return JSC::JSValue::encode(
|
||||
JSC::construct(arg1, JSC::JSValue::decode(JSValue0), JSC::ArgList(), arg3));
|
||||
JSC::construct(arg1, JSC::JSValue::decode(JSValue0), JSC::ArgList(), (const char *)arg3));
|
||||
}
|
||||
|
||||
JSC__JSFunction *JSC__JSFunction__createFromNative(JSC__JSGlobalObject *arg0, uint16_t arg1,
|
||||
|
||||
@@ -224,8 +224,8 @@ extern "C" const size_t Zig__GlobalObject_object_align_ = alignof(Zig::GlobalObj
|
||||
extern "C" const size_t Zig__ConsoleClient_object_size_ = sizeof(Zig::ConsoleClient);
|
||||
extern "C" const size_t Zig__ConsoleClient_object_align_ = alignof(Zig::ConsoleClient);
|
||||
|
||||
const size_t sizes[28] = {sizeof(JSC::JSObject), sizeof(ZigString), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(Inspector::ScriptArguments), sizeof(JSC::JSModuleLoader), sizeof(JSC::JSModuleRecord), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::SourceOrigin), sizeof(JSC::SourceCode), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(WTF::URL), sizeof(WTF::String), sizeof(JSC::JSValue), sizeof(JSC::PropertyName), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(JSC::CallFrame), sizeof(JSC::Identifier), sizeof(WTF::StringImpl), sizeof(WTF::ExternalStringImpl), sizeof(WTF::StringView), sizeof(Zig::GlobalObject), sizeof(ZigException)};
|
||||
const size_t sizes[26] = {sizeof(JSC::JSObject), sizeof(JSC::JSCell), sizeof(JSC::JSString), sizeof(Inspector::ScriptArguments), sizeof(JSC::JSModuleLoader), sizeof(JSC::JSModuleRecord), sizeof(JSC::JSPromise), sizeof(JSC::JSInternalPromise), sizeof(JSC::SourceOrigin), sizeof(JSC::SourceCode), sizeof(JSC::JSFunction), sizeof(JSC::JSGlobalObject), sizeof(WTF::URL), sizeof(WTF::String), sizeof(JSC::JSValue), sizeof(JSC::PropertyName), sizeof(JSC::Exception), sizeof(JSC::VM), sizeof(JSC::ThrowScope), sizeof(JSC::CatchScope), sizeof(JSC::CallFrame), sizeof(JSC::Identifier), sizeof(WTF::StringImpl), sizeof(WTF::ExternalStringImpl), sizeof(WTF::StringView), sizeof(Zig::GlobalObject), };
|
||||
|
||||
const char* names[28] = {"JSC__JSObject", "ZigString", "JSC__JSCell", "JSC__JSString", "Inspector__ScriptArguments", "JSC__JSModuleLoader", "JSC__JSModuleRecord", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__SourceOrigin", "JSC__SourceCode", "JSC__JSFunction", "JSC__JSGlobalObject", "WTF__URL", "WTF__String", "JSC__JSValue", "JSC__PropertyName", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "JSC__CallFrame", "JSC__Identifier", "WTF__StringImpl", "WTF__ExternalStringImpl", "WTF__StringView", "Zig__GlobalObject", "ZigException"};
|
||||
const char* names[26] = {"JSC__JSObject", "JSC__JSCell", "JSC__JSString", "Inspector__ScriptArguments", "JSC__JSModuleLoader", "JSC__JSModuleRecord", "JSC__JSPromise", "JSC__JSInternalPromise", "JSC__SourceOrigin", "JSC__SourceCode", "JSC__JSFunction", "JSC__JSGlobalObject", "WTF__URL", "WTF__String", "JSC__JSValue", "JSC__PropertyName", "JSC__Exception", "JSC__VM", "JSC__ThrowScope", "JSC__CatchScope", "JSC__CallFrame", "JSC__Identifier", "WTF__StringImpl", "WTF__ExternalStringImpl", "WTF__StringView", "Zig__GlobalObject", };
|
||||
|
||||
const size_t aligns[28] = {alignof(JSC::JSObject), alignof(ZigString), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(Inspector::ScriptArguments), alignof(JSC::JSModuleLoader), alignof(JSC::JSModuleRecord), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::SourceOrigin), alignof(JSC::SourceCode), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(WTF::URL), alignof(WTF::String), alignof(JSC::JSValue), alignof(JSC::PropertyName), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(JSC::CallFrame), alignof(JSC::Identifier), alignof(WTF::StringImpl), alignof(WTF::ExternalStringImpl), alignof(WTF::StringView), alignof(Zig::GlobalObject), alignof(ZigException)};
|
||||
const size_t aligns[26] = {alignof(JSC::JSObject), alignof(JSC::JSCell), alignof(JSC::JSString), alignof(Inspector::ScriptArguments), alignof(JSC::JSModuleLoader), alignof(JSC::JSModuleRecord), alignof(JSC::JSPromise), alignof(JSC::JSInternalPromise), alignof(JSC::SourceOrigin), alignof(JSC::SourceCode), alignof(JSC::JSFunction), alignof(JSC::JSGlobalObject), alignof(WTF::URL), alignof(WTF::String), alignof(JSC::JSValue), alignof(JSC::PropertyName), alignof(JSC::Exception), alignof(JSC::VM), alignof(JSC::ThrowScope), alignof(JSC::CatchScope), alignof(JSC::CallFrame), alignof(JSC::Identifier), alignof(WTF::StringImpl), alignof(WTF::ExternalStringImpl), alignof(WTF::StringView), alignof(Zig::GlobalObject), };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Auto-generated by src/javascript/jsc/headergen/sizegen.cpp at 2021-07-26 01:37:1627288660.
|
||||
// Auto-generated by src/javascript/jsc/headergen/sizegen.cpp at 2021-08-03 17:20:1628036419.
|
||||
// These are the byte sizes for the different object types with bindings in JavaScriptCore.
|
||||
// This allows us to safely return stack allocated C++ types to Zig.
|
||||
// It is only safe to do this when these sizes are correct.
|
||||
@@ -21,8 +21,6 @@ pub const JSC__JSString = 16;
|
||||
pub const JSC__JSString_align = 8;
|
||||
pub const Inspector__ScriptArguments = 32;
|
||||
pub const Inspector__ScriptArguments_align = 8;
|
||||
pub const Zig__GlobalObject = 2400;
|
||||
pub const Zig__GlobalObject_align = 8;
|
||||
pub const JSC__JSModuleLoader = 16;
|
||||
pub const JSC__JSModuleLoader_align = 8;
|
||||
pub const JSC__JSModuleRecord = 216;
|
||||
@@ -65,3 +63,5 @@ pub const WTF__ExternalStringImpl = 32;
|
||||
pub const WTF__ExternalStringImpl_align = 8;
|
||||
pub const WTF__StringView = 16;
|
||||
pub const WTF__StringView_align = 8;
|
||||
pub const Zig__GlobalObject = 2400;
|
||||
pub const Zig__GlobalObject_align = 8;
|
||||
|
||||
@@ -166,7 +166,7 @@ pub const Cli = struct {
|
||||
|
||||
var diag = clap.Diagnostic{};
|
||||
|
||||
var args = clap.parse(clap.Help, ¶ms, .{ .diagnostic = &diag }) catch |err| {
|
||||
var args = clap.parse(clap.Help, ¶ms, .{ .diagnostic = &diag, .allocator = allocator }) catch |err| {
|
||||
// Report useful error and exit
|
||||
diag.report(stderr.writer(), err) catch {};
|
||||
return err;
|
||||
@@ -365,6 +365,35 @@ pub const Cli = struct {
|
||||
pub const src = "var headers = new Headers(); headers.set(\"hey\", \"hi\"); console.log(headers.get(\"hey\")); \"HELLO\";";
|
||||
};
|
||||
|
||||
pub fn Threader(comptime Stdout: type, comptime Stderr: type) type {
|
||||
return struct {
|
||||
allocator: *std.mem.Allocator,
|
||||
stdout: Stdout,
|
||||
stderr: Stderr,
|
||||
args: Api.TransformOptions,
|
||||
pub fn spawn(this: @This()) !void {
|
||||
try alloc.setup(std.heap.c_allocator);
|
||||
var stdout = std.io.getStdOut();
|
||||
// var stdout = std.io.bufferedWriter(stdout_file.writer());
|
||||
var stderr = std.io.getStdErr();
|
||||
// var stderr = std.io.bufferedWriter(stderr_file.writer());
|
||||
var output_source = Output.Source.init(stdout, stderr);
|
||||
// defer stdout.flush() catch {};
|
||||
// defer stderr.flush() catch {};
|
||||
Output.Source.set(&output_source);
|
||||
Output.enable_ansi_colors = stderr.isTty();
|
||||
|
||||
var log = logger.Log.init(this.allocator);
|
||||
|
||||
var vm = try VirtualMachine.init(this.allocator, this.args, null, &log);
|
||||
var promise = try vm.loadEntryPoint(vm.bundler.options.entry_points[0]);
|
||||
if (promise.status(vm.global.vm()) == js.JSPromise.Status.Rejected) {
|
||||
vm.defaultErrorHandler(promise.result(vm.global.vm()));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn start(allocator: *std.mem.Allocator, stdout: anytype, stderr: anytype) anyerror!void {
|
||||
const start_time = std.time.nanoTimestamp();
|
||||
var log = logger.Log.init(allocator);
|
||||
@@ -377,17 +406,16 @@ pub const Cli = struct {
|
||||
|
||||
// var results = try bundler.Bundler.bundle(allocator, &log, args);
|
||||
// var file = results.output_files[0];
|
||||
var vm = try VirtualMachine.init(allocator, args, null, &log);
|
||||
|
||||
// var resolved_entry_point = try vm.bundler.resolver.resolve(
|
||||
// vm.bundler.fs.top_level_dir,
|
||||
// vm.bundler.normalizeEntryPointPath(vm.bundler.options.entry_points[0]),
|
||||
// .entry_point,
|
||||
// );
|
||||
|
||||
var promise = try vm.loadEntryPoint(vm.bundler.options.entry_points[0]);
|
||||
if (promise.status(vm.global.vm()) == js.JSPromise.Status.Rejected) {
|
||||
vm.defaultRejectionHandler(promise.result(vm.global.vm()));
|
||||
}
|
||||
const Threadable = Threader(@TypeOf(stdout), @TypeOf(stderr));
|
||||
const runner = Threadable{ .allocator = allocator, .stdout = stdout, .stderr = stderr, .args = args };
|
||||
var thread = try std.Thread.spawn(.{}, Threadable.spawn, .{runner});
|
||||
thread.join();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user