Compare commits

...

2 Commits

Author SHA1 Message Date
Jarred Sumner
c985676289 Make processBindingsConstants lazier 2024-07-30 23:16:07 -07:00
Jarred Sumner
e64971c0b2 Free more data on worker destruction 2024-07-30 23:11:04 -07:00
4 changed files with 37 additions and 3 deletions

View File

@@ -331,6 +331,16 @@ pub const All = struct {
return JSValue.jsUndefined();
}
pub fn deinit(this: *All) void {
if (Environment.isWindows) {
this.uv_timer.stop();
}
this.maps.setImmediate.clearAndFree(bun.default_allocator);
this.maps.setTimeout.clearAndFree(bun.default_allocator);
this.maps.setInterval.clearAndFree(bun.default_allocator);
}
const Shimmer = @import("../bindings/shimmer.zig").Shimmer;
pub const shim = Shimmer("Bun", "Timer", @This());

View File

@@ -3293,8 +3293,11 @@ JSValue GlobalObject_getGlobalThis(VM& vm, JSObject* globalObject)
return jsCast<Zig::GlobalObject*>(globalObject)->globalThis();
}
// This is like `putDirectBuiltinFunction` but for the global static list.
#define globalBuiltinFunction(vm, globalObject, identifier, function, attributes) JSC::JSGlobalObject::GlobalPropertyInfo(identifier, JSFunction::create(vm, function, globalObject), attributes)
JSC_DEFINE_CUSTOM_GETTER(getProcessBindingsConstants, (JSGlobalObject * globalObject, EncodedJSValue, PropertyName))
{
return JSValue::encode(jsCast<Zig::GlobalObject*>(globalObject)->processBindingConstants());
}
void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
{
@@ -3329,7 +3332,6 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
GlobalPropertyInfo(vm.propertyNames->builtinNames().ArrayBufferPrivateName(), arrayBufferConstructor(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.LoaderPrivateName(), this->moduleLoader(), PropertyAttribute::DontDelete | 0),
GlobalPropertyInfo(builtinNames.internalModuleRegistryPrivateName(), this->internalModuleRegistry(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.processBindingConstantsPrivateName(), this->processBindingConstants(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
GlobalPropertyInfo(builtinNames.requireMapPrivateName(), this->requireMap(), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly | 0),
};
addStaticGlobals(staticGlobals, std::size(staticGlobals));
@@ -3347,6 +3349,7 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm)
putDirectBuiltinFunction(vm, this, builtinNames.requireNativeModulePrivateName(), moduleRequireNativeModuleCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectBuiltinFunction(vm, this, builtinNames.overridableRequirePrivateName(), moduleOverridableRequireCodeGenerator(vm), 0);
putDirectCustomAccessor(vm, builtinNames.processBindingConstantsPrivateName(), JSC::CustomGetterSetter::create(vm, getProcessBindingsConstants, nullptr), PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectNativeFunction(vm, this, builtinNames.createUninitializedArrayBufferPrivateName(), 1, functionCreateUninitializedArrayBuffer, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);
putDirectNativeFunction(vm, this, builtinNames.resolveSyncPrivateName(), 1, functionImportMeta__resolveSyncPrivate, ImplementationVisibility::Public, NoIntrinsic, PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly);

View File

@@ -2433,6 +2433,7 @@ pub const VirtualMachine = struct {
// TODO:
pub fn deinit(this: *VirtualMachine) void {
this.timer.deinit();
this.source_mappings.deinit();
if (this.rare_data) |rare_data| {
rare_data.deinit();

View File

@@ -402,4 +402,24 @@ pub fn deinit(this: *RareData) void {
if (this.boring_ssl_engine) |engine| {
_ = bun.BoringSSL.ENGINE_free(engine);
}
if (this.stderr_store) |store| {
this.stderr_store = null;
store.deref();
}
if (this.stdout_store) |store| {
this.stdout_store = null;
store.deref();
}
if (this.stdin_store) |store| {
this.stdin_store = null;
store.deref();
}
if (this.entropy_cache) |cache| {
this.entropy_cache = null;
bun.default_allocator.destroy(cache);
}
}