diff --git a/Makefile b/Makefile index 2117785..80664bf 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ -Windows: +default: $(CC) build.c ./a.out || build.exe diff --git a/src/addon.cpp b/src/addon.cpp index 332813f..3fc4e88 100644 --- a/src/addon.cpp +++ b/src/addon.cpp @@ -47,28 +47,28 @@ bool BooleanValue(Isolate *isolate, Local value) { /* This has to be called in beforeExit, but exit also seems okay */ void uWS_free(const FunctionCallbackInfo &args) { - + /* Holder is exports */ + Local exports = args.Holder(); + + /* See if we even have free anymore */ + if (exports->Get(String::NewFromUtf8(args.GetIsolate(), "free", NewStringType::kNormal).ToLocalChecked()) == Undefined(args.GetIsolate())) { + return; + } + + /* Once we free uWS we remove the uWS.free function from exports */ + exports->Set(args.GetIsolate()->GetCurrentContext(), String::NewFromUtf8(args.GetIsolate(), "free", NewStringType::kNormal).ToLocalChecked(), Undefined(args.GetIsolate())); + /* We get the External holding perContextData */ PerContextData *perContextData = (PerContextData *) Local::Cast(args.Data())->Value(); - /* Todo: this will always be true */ - if (perContextData) { - /* Freeing apps here, it could be done earlier but not sooner */ - perContextData->apps.clear(); - perContextData->sslApps.clear(); - /* Freeing the loop here means we give time for our timers to close, etc */ - uWS::Loop::get()->free(); + /* Freeing apps here, it could be done earlier but not sooner */ + perContextData->apps.clear(); + perContextData->sslApps.clear(); + /* Freeing the loop here means we give time for our timers to close, etc */ + uWS::Loop::get()->free(); - - // we need to mark this - delete perContextData; - - // we can override the exports->free function to null after! - - //args.Data() - - //Local::Cast(args.Data())-> - } + /* We can safely delete this since we no longer can call uWS.free */ + delete perContextData; } /* todo: Put this function and all inits of it in its own header */ @@ -83,7 +83,7 @@ void Main(Local exports) { Isolate *isolate = exports->GetIsolate(); /* We want this so that we can redefine process.nextTick to using the V8 native microtask queue */ - // todo: setting this might be crashing nodejs? + /* Settings this crashes Node.js while debugging with breakpoints */ isolate->SetMicrotasksPolicy(MicrotasksPolicy::kAuto); /* Init the template objects, SSL and non-SSL, store it in per context data */