@@ -102,22 +102,31 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
102102 Isolate *isolate = perContextData->isolate ;
103103 HandleScope hs (isolate);
104104
105- printf (" Open event called!\n " );
106-
107- /* Retrieve temporary userData object */
108- PerSocketData *perSocketData = (PerSocketData *) ws->getUserData ();
109-
110- // if socketPf is nullptr we have nothing to copy
111- Local<Object> userData = Local<Object>::New (isolate, *(perSocketData->socketPf ));
112-
113105 /* Create a new websocket object */
114106 Local<Object> wsObject = perContextData->wsTemplate [getAppTypeIndex<APP >()].Get (isolate)->Clone ();
115107 wsObject->SetAlignedPointerInInternalField (0 , ws);
116108
117- /* Copy entires from userData */
118- wsObject->Set (isolate->GetCurrentContext (), String::NewFromUtf8 (isolate, " userData" ), userData);
109+ /* Retrieve temporary userData object */
110+ PerSocketData *perSocketData = (PerSocketData *) ws->getUserData ();
111+
112+ /* Copy entires from userData, only if we have it set */
113+ if (perSocketData->socketPf ) {
114+ /* socketPf points to a stack allocated UniquePersistent, or nullptr, at this point */
115+ Local<Object> userData = Local<Object>::New (isolate, *(perSocketData->socketPf ));
116+
117+ /* Merge userData and wsObject; this code is exceedingly horrible */
118+ Local<Array> keys;
119+ if (userData->GetOwnPropertyNames (isolate->GetCurrentContext ()).ToLocal (&keys)) {
120+ for (int i = 0 ; i < keys->Length (); i++) {
121+ wsObject->Set (isolate->GetCurrentContext (),
122+ keys->Get (isolate->GetCurrentContext (), i).ToLocalChecked (),
123+ userData->Get (isolate->GetCurrentContext (), keys->Get (isolate->GetCurrentContext (), i).ToLocalChecked ()).ToLocalChecked ()
124+ );
125+ }
126+ }
127+ }
119128
120- /* Attach a new V8 object with pointer to us, to us */
129+ /* Attach a new V8 object with pointer to us, to it */
121130 perSocketData->socketPf = new UniquePersistent<Object>;
122131 perSocketData->socketPf ->Reset (isolate, wsObject);
123132
0 commit comments