File: yaeti-module.patch

package info (click to toggle)
node-websocket 1.0.23-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 564 kB
  • ctags: 406
  • sloc: cpp: 220; makefile: 40
file content (158 lines) | stat: -rw-r--r-- 3,229 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Description: bundle yaeti module as patch
 This module is made for node-websocket.
 https://github.com/ibc/yaeti
Author: Jérémy Lal <kapouer@melix.org>
Last-Update: 2016-12-21
Forwarded: not-needed
--- /dev/null
+++ b/node_modules/yaeti/index.js
@@ -0,0 +1,4 @@
+module.exports = {
+	EventTarget:  require('./lib/EventTarget'),
+	Event:        require('./lib/Event')
+};
--- /dev/null
+++ b/node_modules/yaeti/lib/Event.browser.js
@@ -0,0 +1,5 @@
+/**
+ * In browsers export the native Event interface.
+ */
+
+module.exports = global.Event;
--- /dev/null
+++ b/node_modules/yaeti/lib/Event.js
@@ -0,0 +1,10 @@
+/**
+ * Expose the Event class.
+ */
+module.exports = _Event;
+
+
+function _Event(type) {
+	this.type = type;
+	this.isTrusted = false;
+}
--- /dev/null
+++ b/node_modules/yaeti/lib/EventTarget.js
@@ -0,0 +1,121 @@
+/**
+ * Expose the _EventTarget class.
+ */
+module.exports = _EventTarget;
+
+
+function _EventTarget() {
+	// Do nothing if called for a native EventTarget object..
+	if (typeof this.addEventListener === 'function') {
+		return;
+	}
+
+	this._listeners = {};
+
+	this.addEventListener = _addEventListener;
+	this.removeEventListener = _removeEventListener;
+	this.dispatchEvent = _dispatchEvent;
+}
+
+
+Object.defineProperties(_EventTarget.prototype, {
+	listeners: {
+		get: function () {
+			return this._listeners;
+		}
+	}
+});
+
+
+function _addEventListener(type, newListener) {
+	var listenersType,
+		i, listener;
+
+	if (!type || !newListener) {
+		return;
+	}
+
+	listenersType = this._listeners[type];
+	if (listenersType === undefined) {
+		this._listeners[type] = listenersType = [];
+	}
+
+	for (i = 0; !!(listener = listenersType[i]); i++) {
+		if (listener === newListener) {
+			return;
+		}
+	}
+
+	listenersType.push(newListener);
+}
+
+
+function _removeEventListener(type, oldListener) {
+	var listenersType,
+		i, listener;
+
+	if (!type || !oldListener) {
+		return;
+	}
+
+	listenersType = this._listeners[type];
+	if (listenersType === undefined) {
+		return;
+	}
+
+	for (i = 0; !!(listener = listenersType[i]); i++) {
+		if (listener === oldListener) {
+			listenersType.splice(i, 1);
+			break;
+		}
+	}
+
+	if (listenersType.length === 0) {
+		delete this._listeners[type];
+	}
+}
+
+
+function _dispatchEvent(event) {
+	var type,
+		listenersType,
+		dummyListener,
+		stopImmediatePropagation = false,
+		i, listener;
+
+	if (!event || typeof event.type !== 'string') {
+		throw new Error('`event` must have a valid `type` property');
+	}
+
+	if (event._dispatched) {
+		throw new Error('event already dispatched');
+	}
+	event._dispatched = true;
+
+	// Force the event to be cancelable.
+	event.cancelable = true;
+	event.target = this;
+
+	// Override stopImmediatePropagation() function.
+	event.stopImmediatePropagation = function () {
+		stopImmediatePropagation = true;
+	};
+
+	type = event.type;
+	listenersType = (this._listeners[type] || []);
+
+	dummyListener = this['on' + type];
+	if (typeof dummyListener === 'function') {
+		listenersType.push(dummyListener);
+	}
+
+	for (i = 0; !!(listener = listenersType[i]); i++) {
+		if (stopImmediatePropagation) {
+			break;
+		}
+
+		listener.call(this, event);
+	}
+
+	return !event.defaultPrevented;
+}