diff options
author | 2023-06-07 19:03:11 -0700 | |
---|---|---|
committer | 2023-06-07 19:03:11 -0700 | |
commit | 7a443f72b525f5e80ecccb581fc02eadd1d4c6a9 (patch) | |
tree | cb0f4c1beb99635ca4e528c17068f2a0d10eff05 /src/bun.js | |
parent | 4f2095d1c64467f190ac4f35209ff663bf34f39a (diff) | |
download | bun-plugin/plugindata.tar.gz bun-plugin/plugindata.tar.zst bun-plugin/plugindata.zip |
Attempt to add plugindataplugin/plugindata
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/api/JSBundler.zig | 34 | ||||
-rw-r--r-- | src/bun.js/api/server.zig | 1 | ||||
-rw-r--r-- | src/bun.js/bindings/JSBundlerPlugin.cpp | 5 |
3 files changed, 24 insertions, 16 deletions
diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index 21003eabf..4ddb46f7f 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -598,10 +598,12 @@ pub const JSBundler = struct { path: []const u8 = "", namespace: []const u8 = "", external: bool = false, + plugin_data: JSValue = JSC.JSValue.jsUndefined(), pub fn deinit(this: *@This()) void { bun.default_allocator.destroy(this.path); bun.default_allocator.destroy(this.namespace); + // bun.default_allocator.destroy(this.plugin_data); } }, no_match: void, @@ -679,6 +681,7 @@ pub const JSBundler = struct { path_value: JSValue, namespace_value: JSValue, external_value: JSValue, + plugin_data_value: JSValue, ) void { var completion = this.completion orelse { this.deinit(); @@ -689,11 +692,14 @@ pub const JSBundler = struct { } else { const path = path_value.toSliceCloneWithAllocator(completion.globalThis, bun.default_allocator) orelse @panic("Unexpected: path is not a string"); const namespace = namespace_value.toSliceCloneWithAllocator(completion.globalThis, bun.default_allocator) orelse @panic("Unexpected: namespace is not a string"); + std.debug.print("got plugin data", .{}); + const plugin_data = plugin_data_value; //.toObject(completion.globalThis).*; // orelse @panic("Unexpected: plugin_data is not an object"); this.value = .{ .success = .{ .path = path.slice(), .namespace = namespace.slice(), .external = external_value.to(bool), + .plugin_data = plugin_data, }, }; } @@ -711,6 +717,7 @@ pub const JSBundler = struct { default_loader: options.Loader, path: []const u8 = "", namespace: []const u8 = "", + plugin_data: JSValue = JSC.JSValue.jsUndefined(), /// Null means the task was aborted. completion: ?*bun.BundleV2.JSBundleCompletionTask = null, @@ -723,12 +730,7 @@ pub const JSBundler = struct { /// Faster path: skip the extra threadpool dispatch when the file is not found was_file: bool = false, - pub fn create( - completion: *bun.BundleV2.JSBundleCompletionTask, - source_index: Index, - default_loader: options.Loader, - path: Fs.Path, - ) Load { + pub fn create(completion: *bun.BundleV2.JSBundleCompletionTask, source_index: Index, default_loader: options.Loader, path: Fs.Path, plugin_data: ?JSValue) Load { completion.ref(); return Load{ .source_index = source_index, @@ -737,6 +739,7 @@ pub const JSBundler = struct { .value = .{ .pending = {} }, .path = path.text, .namespace = path.namespace, + .plugin_data = plugin_data orelse JSValue.undefined, }; } @@ -772,6 +775,11 @@ pub const JSBundler = struct { pub fn deinit(this: *Load) void { this.value.deinit(); + // seems like a reasonable place to free idk + // if (this.plugin_data != JSValue.undefined) { + // bun.default_allocator.free(this.plugin_data); + // } + if (this.completion) |completion| completion.deref(); } @@ -790,6 +798,7 @@ pub const JSBundler = struct { this.namespace, this, this.default_loader, + this.plugin_data, ); } @@ -876,14 +885,7 @@ pub const JSBundler = struct { bool, ) bool; - extern fn JSBundlerPlugin__matchOnLoad( - *JSC.JSGlobalObject, - *Plugin, - namespaceString: *const ZigString, - path: *const ZigString, - context: *anyopaque, - u8, - ) void; + extern fn JSBundlerPlugin__matchOnLoad(*JSC.JSGlobalObject, *Plugin, namespaceString: *const ZigString, path: *const ZigString, context: *anyopaque, u8, pluginData: *const JSValue) void; extern fn JSBundlerPlugin__matchOnResolve( *JSC.JSGlobalObject, @@ -920,6 +922,7 @@ pub const JSBundler = struct { namespace: []const u8, context: *anyopaque, default_loader: options.Loader, + plugin_data: JSValue, ) void { JSC.markBinding(@src()); const tracer = bun.tracy.traceNamed(@src(), "JSBundler.matchOnLoad"); @@ -929,7 +932,8 @@ pub const JSBundler = struct { else ZigString.fromUTF8(namespace); const path_string = ZigString.fromUTF8(path); - JSBundlerPlugin__matchOnLoad(globalThis, this, &namespace_string, &path_string, context, @enumToInt(default_loader)); + std.debug.print("matchonload\n", .{}); + JSBundlerPlugin__matchOnLoad(globalThis, this, &namespace_string, &path_string, context, @enumToInt(default_loader), &plugin_data); } pub fn matchOnResolve( diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 30889964d..1554ee886 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -5224,6 +5224,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { } pub fn listen(this: *ThisServer) void { + JSC.markBinding(@src()); httplog("listen", .{}); if (ssl_enabled) { BoringSSL.load(); diff --git a/src/bun.js/bindings/JSBundlerPlugin.cpp b/src/bun.js/bindings/JSBundlerPlugin.cpp index de936ab05..7bb4b0478 100644 --- a/src/bun.js/bindings/JSBundlerPlugin.cpp +++ b/src/bun.js/bindings/JSBundlerPlugin.cpp @@ -279,10 +279,12 @@ extern "C" bool JSBundlerPlugin__anyMatches(Bun::JSBundlerPlugin* pluginObject, return pluginObject->plugin.anyMatchesCrossThread(pluginObject->vm(), namespaceString, path, isOnLoad); } -extern "C" void JSBundlerPlugin__matchOnLoad(JSC::JSGlobalObject* globalObject, Bun::JSBundlerPlugin* plugin, const ZigString* namespaceString, const ZigString* path, void* context, uint8_t defaultLoaderId) +extern "C" void JSBundlerPlugin__matchOnLoad(JSC::JSGlobalObject* globalObject, Bun::JSBundlerPlugin* plugin, const ZigString* namespaceString, const ZigString* path, void* context, uint8_t defaultLoaderId, JSValue* pluginData) { WTF::String namespaceStringStr = namespaceString ? Zig::toStringCopy(*namespaceString) : WTF::String(); WTF::String pathStr = path ? Zig::toStringCopy(*path) : WTF::String(); + // get value from pointer + JSValue pluginDataValue = *pluginData; JSFunction* function = plugin->onLoadFunction.get(plugin); if (UNLIKELY(!function)) @@ -299,6 +301,7 @@ extern "C" void JSBundlerPlugin__matchOnLoad(JSC::JSGlobalObject* globalObject, arguments.append(JSC::jsString(plugin->vm(), pathStr)); arguments.append(JSC::jsString(plugin->vm(), namespaceStringStr)); arguments.append(JSC::jsNumber(defaultLoaderId)); + arguments.append(pluginDataValue); auto result = call(globalObject, function, callData, plugin, arguments); |