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

Commit

Permalink
fix(websocket): fix #824, patch websocket onproperties correctly in p…
Browse files Browse the repository at this point in the history
…hantomjs
  • Loading branch information
JiaLiPassion committed Jul 7, 2017
1 parent b3a76d3 commit 18f17de
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/browser/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ export function apply(_global: any) {
const socket = arguments.length > 1 ? new WS(a, b) : new WS(a);
let proxySocket: any;

let proxySocketProto: any;

// Safari 7.0 has non-configurable own 'onmessage' and friends properties on the socket instance
const onmessageDesc = Object.getOwnPropertyDescriptor(socket, 'onmessage');
if (onmessageDesc && onmessageDesc.configurable === false) {
proxySocket = Object.create(socket);
// socket have own property descriptor 'onopen', 'onmessage', 'onclose', 'onerror'
// but proxySocket not, so we will keep socket as prototype and pass it to
// patchOnProperties method
proxySocketProto = socket;
['addEventListener', 'removeEventListener', 'send', 'close'].forEach(function(propName) {
proxySocket[propName] = function() {
return socket[propName].apply(socket, arguments);
Expand All @@ -35,7 +41,7 @@ export function apply(_global: any) {
proxySocket = socket;
}

patchOnProperties(proxySocket, ['close', 'error', 'message', 'open']);
patchOnProperties(proxySocket, ['close', 'error', 'message', 'open'], proxySocketProto);

return proxySocket;
};
Expand Down

0 comments on commit 18f17de

Please sign in to comment.