Browse Source

Fix potential memory leak

Gerald 10 years ago
parent
commit
5cf4cd9726
3 changed files with 7 additions and 8 deletions
  1. 1 1
      README.md
  2. 1 1
      package.json
  3. 5 6
      src/injected.js

+ 1 - 1
README.md

@@ -19,7 +19,7 @@ Development
 Run command below:
 
 ``` sh
-$ gulp
+$ npm run dev
 ```
 
 Then you can load the extension from `dist/`.

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
   "name": "Violentmonkey",
   "version": "2.2.4",
   "scripts": {
-    "develop": "gulp build && gulp watch",
+    "dev": "gulp build && gulp watch",
     "update": "node scripts/updateLib"
   },
   "description": "Violentmonkey",

+ 5 - 6
src/injected.js

@@ -202,7 +202,8 @@ var comm = {
         if (req) req.callback(r);
       },
       UpdateValues: function (data) {
-        if (comm.values) comm.values[data.uri] = data.values;
+        var values = comm.values;
+        if (values && values[data.uri]) values[data.uri] = data.values;
       },
       // advanced inject
       Injected: function (id) {
@@ -309,10 +310,7 @@ var comm = {
   getWrapper: getWrapper,
   wrapGM: function(script, cache) {
     function getValues() {
-      var uri = script.uri;
-      var values = comm.values[uri];
-      if (!values) comm.values[uri] = values = {};
-      return values;
+      return comm.values[script.uri];
     }
     function propertyToString() {
       return '[Violentmonkey property]';
@@ -553,7 +551,7 @@ var comm = {
     comm.command = {};
     comm.ainject = {};
     comm.version = data.version;
-    comm.values = data.values;
+    comm.values = {};
     // reset load and checkLoad
     comm.load = function() {
       run(end);
@@ -567,6 +565,7 @@ var comm = {
       if (comm.state) comm.load();
     };
     comm.forEach(data.scripts, function(script) {
+      comm.values[script.uri] = data.values[script.uri] || {};
       var list;
       if(script && script.enabled) {
         switch (script.custom['run-at'] || script.meta['run-at']) {