60f1e8c9e3ca90f9f1ebbe2431db82611bfc49c1
[platform/framework/web/crosswalk-tizen.git] /
1 'use strict';
2
3 var setPrototypeOf    = require('es5-ext/object/set-prototype-of')
4   , d                 = require('d')
5   , Iterator          = require('es6-iterator')
6   , toStringTagSymbol = require('es6-symbol').toStringTag
7   , kinds             = require('./iterator-kinds')
8
9   , defineProperties = Object.defineProperties
10   , unBind = Iterator.prototype._unBind
11   , MapIterator;
12
13 MapIterator = module.exports = function (map, kind) {
14         if (!(this instanceof MapIterator)) return new MapIterator(map, kind);
15         Iterator.call(this, map.__mapKeysData__, map);
16         if (!kind || !kinds[kind]) kind = 'key+value';
17         defineProperties(this, {
18                 __kind__: d('', kind),
19                 __values__: d('w', map.__mapValuesData__)
20         });
21 };
22 if (setPrototypeOf) setPrototypeOf(MapIterator, Iterator);
23
24 MapIterator.prototype = Object.create(Iterator.prototype, {
25         constructor: d(MapIterator),
26         _resolve: d(function (i) {
27                 if (this.__kind__ === 'value') return this.__values__[i];
28                 if (this.__kind__ === 'key') return this.__list__[i];
29                 return [this.__list__[i], this.__values__[i]];
30         }),
31         _unBind: d(function () {
32                 this.__values__ = null;
33                 unBind.call(this);
34         }),
35         toString: d(function () { return '[object Map Iterator]'; })
36 });
37 Object.defineProperty(MapIterator.prototype, toStringTagSymbol,
38         d('c', 'Map Iterator'));