Skip to content

Commit 7d31ea3

Browse files
committed
Attempt at fixing memory leak related to foreignObjects and nested SVG elements.
1 parent b365287 commit 7d31ea3

4 files changed

Lines changed: 27 additions & 41 deletions

File tree

dist/snap.svg-min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/snap.svg.js

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,33 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616
//
17-
// build: 2017-02-07
17+
// build: 2021-08-18
1818

19-
// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
20-
//
19+
// Copyright (c) 2017 Adobe Systems Incorporated. All rights reserved.
20+
//
2121
// Licensed under the Apache License, Version 2.0 (the "License");
2222
// you may not use this file except in compliance with the License.
2323
// You may obtain a copy of the License at
24-
//
24+
//
2525
// http://www.apache.org/licenses/LICENSE-2.0
26-
//
26+
//
2727
// Unless required by applicable law or agreed to in writing, software
2828
// distributed under the License is distributed on an "AS IS" BASIS,
2929
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3030
// See the License for the specific language governing permissions and
3131
// limitations under the License.
3232
// ┌────────────────────────────────────────────────────────────┐ \\
33-
// │ Eve 0.5.0 - JavaScript Events Library │ \\
33+
// │ Eve 0.5.4 - JavaScript Events Library │ \\
3434
// ├────────────────────────────────────────────────────────────┤ \\
3535
// │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\
3636
// └────────────────────────────────────────────────────────────┘ \\
3737

3838
(function (glob) {
39-
var version = "0.5.0",
39+
var version = "0.5.4",
4040
has = "hasOwnProperty",
4141
separator = /[\.\/]/,
4242
comaseparator = /\s*,\s*/,
4343
wildcard = "*",
44-
fun = function () {},
4544
numsort = function (a, b) {
4645
return a - b;
4746
},
@@ -67,34 +66,29 @@
6766
Str = String,
6867
isArray = Array.isArray || function (ar) {
6968
return ar instanceof Array || objtos.call(ar) == "[object Array]";
70-
};
69+
},
7170
/*\
7271
* eve
7372
[ method ]
7473
7574
* Fires event with given `name`, given scope and other parameters.
7675
77-
> Arguments
78-
7976
- name (string) name of the *event*, dot (`.`) or slash (`/`) separated
8077
- scope (object) context for the event handlers
8178
- varargs (...) the rest of arguments will be sent to event handlers
8279
8380
= (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value.
8481
\*/
8582
eve = function (name, scope) {
86-
var e = events,
87-
oldstop = stop,
83+
var oldstop = stop,
8884
args = Array.prototype.slice.call(arguments, 2),
8985
listeners = eve.listeners(name),
9086
z = 0,
91-
f = false,
9287
l,
9388
indexed = [],
9489
queue = {},
9590
out = [],
96-
ce = current_event,
97-
errors = [];
91+
ce = current_event;
9892
out.firstDefined = firstDefined;
9993
out.lastDefined = lastDefined;
10094
current_event = name;
@@ -144,16 +138,14 @@
144138
current_event = ce;
145139
return out;
146140
};
147-
// Undocumented. Debug only.
148-
eve._events = events;
141+
// Undocumented. Debug only.
142+
eve._events = events;
149143
/*\
150144
* eve.listeners
151145
[ method ]
152146
153147
* Internal method which gives you array of all event handlers that will be triggered by the given `name`.
154148
155-
> Arguments
156-
157149
- name (string) name of the event, dot (`.`) or slash (`/`) separated
158150
159151
= (array) array of event handlers
@@ -223,7 +215,7 @@
223215
- name (array) if you don’t want to use separators, you can use array of strings
224216
- f (function) event handler function
225217
**
226-
= (function) returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment.
218+
= (function) returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment.
227219
> Example:
228220
| eve.on("mouse", eatIt)(2);
229221
| eve.on("mouse", scream);
@@ -237,7 +229,7 @@
237229
if (typeof f != "function") {
238230
return function () {};
239231
}
240-
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator);
232+
var names = isArray(name) ? isArray(name[0]) ? name : [name] : Str(name).split(comaseparator);
241233
for (var i = 0, ii = names.length; i < ii; i++) {
242234
(function (name) {
243235
var names = isArray(name) ? name : Str(name).split(separator),
@@ -272,7 +264,6 @@
272264
| eve.on("click", function (a, b, c) {
273265
| console.log(a, b, c); // 1, 2, [event object]
274266
| });
275-
> Arguments
276267
- event (string) event name
277268
- varargs (…) and any other arguments
278269
= (function) possible event handler function
@@ -298,8 +289,6 @@
298289
**
299290
* Could be used inside event handler to figure out actual name of the event.
300291
**
301-
> Arguments
302-
**
303292
- subname (string) #optional subname of the event
304293
**
305294
= (string) name of the event, if `subname` is not specified
@@ -332,8 +321,6 @@
332321
* Removes given function from the list of event listeners assigned to given name.
333322
* If no arguments specified all the events will be cleared.
334323
**
335-
> Arguments
336-
**
337324
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
338325
- f (function) event handler function
339326
\*/
@@ -348,7 +335,7 @@
348335
eve._events = events = {n: {}};
349336
return;
350337
}
351-
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator);
338+
var names = isArray(name) ? isArray(name[0]) ? name : [name] : Str(name).split(comaseparator);
352339
if (names.length > 1) {
353340
for (var i = 0, ii = names.length; i < ii; i++) {
354341
eve.off(names[i], f);
@@ -439,8 +426,6 @@
439426
| eve("login"); // no listeners
440427
* Use @eve to trigger the listener.
441428
**
442-
> Arguments
443-
**
444429
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
445430
- f (function) event handler function
446431
**
@@ -463,8 +448,9 @@
463448
eve.toString = function () {
464449
return "You are running Eve " + version;
465450
};
466-
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define === "function" && define.amd ? (define("eve", [], function() { return eve; })) : (glob.eve = eve));
467-
})(this);
451+
glob.eve = eve;
452+
typeof module != "undefined" && module.exports ? module.exports = eve : typeof define === "function" && define.amd ? define("eve", [], function () { return eve; }) : glob.eve = eve;
453+
})(typeof window != "undefined" ? window : this);
468454

469455
(function (glob, factory) {
470456
// AMD support
@@ -2178,7 +2164,7 @@ setInterval(function () {
21782164
for (var key in hub) if (hub[has](key)) {
21792165
var el = hub[key],
21802166
node = el.node;
2181-
if (el.type != "svg" && !node.ownerSVGElement || el.type == "svg" && (!node.parentNode || "ownerSVGElement" in node.parentNode && !node.ownerSVGElement)) {
2167+
if (!node.isConnected) {
21822168
delete hub[key];
21832169
}
21842170
}
@@ -7614,7 +7600,7 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
76147600
Snap.plugin(function (Snap, Element, Paper, glob) {
76157601
var elproto = Element.prototype,
76167602
has = "hasOwnProperty",
7617-
supportsTouch = "createTouch" in glob.doc,
7603+
supportsTouch = (('ontouchstart' in window) || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch),
76187604
events = [
76197605
"click", "dblclick", "mousedown", "mousemove", "mouseout",
76207606
"mouseover", "mouseup", "touchstart", "touchmove", "touchend",

doc/reference.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6530,8 +6530,8 @@ <h2 class="dr-method">Element.setStops(str)
65306530
<div class="dr-method">
65316531
<p>Only for gradients! Updates stops of the gradient
65326532
based on passed gradient descriptor. See
6533-
<a href="#Paper.gradient"
6534-
class="dr-link">Paper.gradient</a>
6533+
<a href="#Ppaer.gradient"
6534+
class="dr-link">Ppaer.gradient</a>
65356535
</p>
65366536
<div class="params">
65376537
<h3 class="params">Parameters</h3>

src/svg.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ setInterval(function () {
13231323
for (var key in hub) if (hub[has](key)) {
13241324
var el = hub[key],
13251325
node = el.node;
1326-
if (el.type != "svg" && !node.ownerSVGElement || el.type == "svg" && (!node.parentNode || "ownerSVGElement" in node.parentNode && !node.ownerSVGElement)) {
1326+
if (!node.isConnected) {
13271327
delete hub[key];
13281328
}
13291329
}

0 commit comments

Comments
 (0)