diff --git a/src/AppWrapper.h b/src/AppWrapper.h index ad92ad5..2361def 100644 --- a/src/AppWrapper.h +++ b/src/AppWrapper.h @@ -7,6 +7,7 @@ using namespace v8; template void uWS_App_ws(const FunctionCallbackInfo &args) { APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0); + /* This one is default constructed with defaults */ typename APP::WebSocketBehavior behavior = {}; NativeString pattern(args.GetIsolate(), args[0]); @@ -27,14 +28,29 @@ void uWS_App_ws(const FunctionCallbackInfo &args) { if (args.Length() == 2) { Local behaviorObject = Local::Cast(args[1]); - /* maxPayloadLength */ - behavior.maxPayloadLength = behaviorObject->Get(String::NewFromUtf8(isolate, "maxPayloadLength"))->Int32Value(isolate->GetCurrentContext()).ToChecked(); + /* maxPayloadLength or default */ + MaybeLocal maybeMaxPayloadLength = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxPayloadLength")); + if (!maybeMaxPayloadLength.IsEmpty() && !maybeMaxPayloadLength.ToLocalChecked()->IsUndefined()) { + behavior.maxPayloadLength = maybeMaxPayloadLength.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); + } - /* idleTimeout */ - behavior.idleTimeout = behaviorObject->Get(String::NewFromUtf8(isolate, "idleTimeout"))->Int32Value(isolate->GetCurrentContext()).ToChecked(); + /* idleTimeout or default */ + MaybeLocal maybeIdleTimeout = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "idleTimeout")); + if (!maybeIdleTimeout.IsEmpty() && !maybeIdleTimeout.ToLocalChecked()->IsUndefined()) { + behavior.idleTimeout = maybeIdleTimeout.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); + } - /* Compression, map from 0, 1, 2 to disabled, shared, dedicated. This is actually the enum */ - behavior.compression = (uWS::CompressOptions) behaviorObject->Get(String::NewFromUtf8(isolate, "compression"))->Int32Value(isolate->GetCurrentContext()).ToChecked(); + /* Compression or default, map from 0, 1, 2 to disabled, shared, dedicated. This is actually the enum */ + MaybeLocal maybeCompression = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "compression")); + if (!maybeCompression.IsEmpty() && !maybeCompression.ToLocalChecked()->IsUndefined()) { + behavior.compression = (uWS::CompressOptions) maybeCompression.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); + } + + /* maxBackpressure or default */ + MaybeLocal maybeMaxBackpressure = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxBackpressure")); + if (!maybeMaxBackpressure.IsEmpty() && !maybeMaxBackpressure.ToLocalChecked()->IsUndefined()) { + behavior.maxBackpressure = maybeMaxBackpressure.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked(); + } /* Open */ openPf.Reset(args.GetIsolate(), Local::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "open"))));