Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit d502e1d

Browse files
committed
fix(websocket): fix #824, patch websocket onproperties correctly in phantomjs
1 parent 98f3903 commit d502e1d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/browser/websocket.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ export function apply(_global: any) {
2020
const socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
2121
let proxySocket: any;
2222

23+
let proxySocketProto: any;
24+
2325
// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
2426
const onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage');
2527
if (onmessageDesc && onmessageDesc.configurable === false) {
2628
proxySocket = Object.create(socket);
29+
// socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror'
30+
// but proxySocket not, so we will keep socket as prototype and pass it to
31+
// patchOnProperties method
32+
proxySocketProto = socket;
2733
['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function(propName) {
2834
proxySocket[propName] = function() {
2935
return socket[propName].apply(socket, arguments);
@@ -34,7 +40,7 @@ export function apply(_global: any) {
3440
proxySocket = socket;
3541
}
3642

37-
patchOnProperties(proxySocket, ['close', 'error', 'message', 'open']);
43+
patchOnProperties(proxySocket, ['close', 'error', 'message', 'open'], proxySocketProto);
3844

3945
return proxySocket;
4046
};

0 commit comments

Comments
 (0)