Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/subscriptionClasses.js

Issue 29426559: Issue 5137 - [emscripten] Added basic filter storage implementation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Fixed bogus assert Created Aug. 31, 2017, 12:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/filterStorage.js ('k') | test/filterStorage.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/subscriptionClasses.js
===================================================================
--- a/lib/subscriptionClasses.js
+++ b/lib/subscriptionClasses.js
@@ -12,15 +12,45 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
-const compiled = require("compiled");
-for (let cls of [
- "Subscription", "SpecialSubscription", "DownloadableSubscription"
-])
-{
- exports[cls] = compiled[cls];
-}
+const {Subscription, SpecialSubscription, DownloadableSubscription} =
+ require("compiled");
+
+/**
+ * This property allows iterating over the list of filters. It will delete
+ * references automatically at the end of the current loop iteration. If you
+ * need persistent references or element access by position you should use
+ * Subscription.filterAt() instead.
+ * @type {Iterable}
+ */
+Object.defineProperty(Subscription.prototype, "filters", {
+ enumerable: true,
+ get()
+ {
+ return {
+ [Symbol.iterator]: function*()
+ {
+ for (let i = 0, l = this.filterCount; i < l; i++)
+ {
+ let filter = this.filterAt(i);
+ try
+ {
+ yield filter;
+ }
+ finally
+ {
+ filter.delete();
+ }
+ }
+ }.bind(this)
+ };
+ }
+});
+
+exports.Subscription = Subscription;
+exports.SpecialSubscription = SpecialSubscription;
+exports.DownloadableSubscription = DownloadableSubscription;
« no previous file with comments | « lib/filterStorage.js ('k') | test/filterStorage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld