Skip to content

Commit

Permalink
Attempt at fixing memory leak related to foreignObjects and nested SV…
Browse files Browse the repository at this point in the history
…G elements.
  • Loading branch information
eturpin committed Aug 18, 2021
1 parent b365287 commit 7d31ea3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 41 deletions.
8 changes: 4 additions & 4 deletions dist/snap.svg-min.js

Large diffs are not rendered by default.

54 changes: 20 additions & 34 deletions dist/snap.svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,33 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// build: 2017-02-07
// build: 2021-08-18

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

(function (glob) {
var version = "0.5.0",
var version = "0.5.4",
has = "hasOwnProperty",
separator = /[\.\/]/,
comaseparator = /\s*,\s*/,
wildcard = "*",
fun = function () {},
numsort = function (a, b) {
return a - b;
},
Expand All @@ -67,34 +66,29 @@
Str = String,
isArray = Array.isArray || function (ar) {
return ar instanceof Array || objtos.call(ar) == "[object Array]";
};
},
/*\
* eve
[ method ]
* Fires event with given `name`, given scope and other parameters.
> Arguments
- name (string) name of the *event*, dot (`.`) or slash (`/`) separated
- scope (object) context for the event handlers
- varargs (...) the rest of arguments will be sent to event handlers
= (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value.
\*/
eve = function (name, scope) {
var e = events,
oldstop = stop,
var oldstop = stop,
args = Array.prototype.slice.call(arguments, 2),
listeners = eve.listeners(name),
z = 0,
f = false,
l,
indexed = [],
queue = {},
out = [],
ce = current_event,
errors = [];
ce = current_event;
out.firstDefined = firstDefined;
out.lastDefined = lastDefined;
current_event = name;
Expand Down Expand Up @@ -144,16 +138,14 @@
current_event = ce;
return out;
};
// Undocumented. Debug only.
eve._events = events;
// Undocumented. Debug only.
eve._events = events;
/*\
* eve.listeners
[ method ]
* Internal method which gives you array of all event handlers that will be triggered by the given `name`.
> Arguments
- name (string) name of the event, dot (`.`) or slash (`/`) separated
= (array) array of event handlers
Expand Down Expand Up @@ -223,7 +215,7 @@
- name (array) if you don’t want to use separators, you can use array of strings
- f (function) event handler function
**
= (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.
= (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.
> Example:
| eve.on("mouse", eatIt)(2);
| eve.on("mouse", scream);
Expand All @@ -237,7 +229,7 @@
if (typeof f != "function") {
return function () {};
}
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator);
var names = isArray(name) ? isArray(name[0]) ? name : [name] : Str(name).split(comaseparator);
for (var i = 0, ii = names.length; i < ii; i++) {
(function (name) {
var names = isArray(name) ? name : Str(name).split(separator),
Expand Down Expand Up @@ -272,7 +264,6 @@
| eve.on("click", function (a, b, c) {
| console.log(a, b, c); // 1, 2, [event object]
| });
> Arguments
- event (string) event name
- varargs (…) and any other arguments
= (function) possible event handler function
Expand All @@ -298,8 +289,6 @@
**
* Could be used inside event handler to figure out actual name of the event.
**
> Arguments
**
- subname (string) #optional subname of the event
**
= (string) name of the event, if `subname` is not specified
Expand Down Expand Up @@ -332,8 +321,6 @@
* Removes given function from the list of event listeners assigned to given name.
* If no arguments specified all the events will be cleared.
**
> Arguments
**
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
- f (function) event handler function
\*/
Expand All @@ -348,7 +335,7 @@
eve._events = events = {n: {}};
return;
}
var names = isArray(name) ? (isArray(name[0]) ? name : [name]) : Str(name).split(comaseparator);
var names = isArray(name) ? isArray(name[0]) ? name : [name] : Str(name).split(comaseparator);
if (names.length > 1) {
for (var i = 0, ii = names.length; i < ii; i++) {
eve.off(names[i], f);
Expand Down Expand Up @@ -439,8 +426,6 @@
| eve("login"); // no listeners
* Use @eve to trigger the listener.
**
> Arguments
**
- name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards
- f (function) event handler function
**
Expand All @@ -463,8 +448,9 @@
eve.toString = function () {
return "You are running Eve " + version;
};
(typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define === "function" && define.amd ? (define("eve", [], function() { return eve; })) : (glob.eve = eve));
})(this);
glob.eve = eve;
typeof module != "undefined" && module.exports ? module.exports = eve : typeof define === "function" && define.amd ? define("eve", [], function () { return eve; }) : glob.eve = eve;
})(typeof window != "undefined" ? window : this);

(function (glob, factory) {
// AMD support
Expand Down Expand Up @@ -2178,7 +2164,7 @@ setInterval(function () {
for (var key in hub) if (hub[has](key)) {
var el = hub[key],
node = el.node;
if (el.type != "svg" && !node.ownerSVGElement || el.type == "svg" && (!node.parentNode || "ownerSVGElement" in node.parentNode && !node.ownerSVGElement)) {
if (!node.isConnected) {
delete hub[key];
}
}
Expand Down Expand Up @@ -7614,7 +7600,7 @@ Snap.plugin(function (Snap, Element, Paper, glob) {
Snap.plugin(function (Snap, Element, Paper, glob) {
var elproto = Element.prototype,
has = "hasOwnProperty",
supportsTouch = "createTouch" in glob.doc,
supportsTouch = (('ontouchstart' in window) || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch),
events = [
"click", "dblclick", "mousedown", "mousemove", "mouseout",
"mouseover", "mouseup", "touchstart", "touchmove", "touchend",
Expand Down
4 changes: 2 additions & 2 deletions doc/reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -6530,8 +6530,8 @@ <h2 class="dr-method">Element.setStops(str)
<div class="dr-method">
<p>Only for gradients! Updates stops of the gradient
based on passed gradient descriptor. See
<a href="#Paper.gradient"
class="dr-link">Paper.gradient</a>
<a href="#Ppaer.gradient"
class="dr-link">Ppaer.gradient</a>
</p>
<div class="params">
<h3 class="params">Parameters</h3>
Expand Down
2 changes: 1 addition & 1 deletion src/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ setInterval(function () {
for (var key in hub) if (hub[has](key)) {
var el = hub[key],
node = el.node;
if (el.type != "svg" && !node.ownerSVGElement || el.type == "svg" && (!node.parentNode || "ownerSVGElement" in node.parentNode && !node.ownerSVGElement)) {
if (!node.isConnected) {
delete hub[key];
}
}
Expand Down

0 comments on commit 7d31ea3

Please sign in to comment.