Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(849)

Side by Side Diff: dart/third_party/pkg/js/lib/src/wrapping/js/object_to_map_adapter.dart

Issue 57393002: Version 0.8.10.2 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of js.wrapping;
6
7 class JsObjectToMapAdapter<V> extends TypedProxy implements Map<String,V> {
8 static JsObjectToMapAdapter cast(Proxy proxy, [Translator translator]) =>
9 proxy == null ? null :
10 new JsObjectToMapAdapter.fromProxy(proxy, translator);
11 static JsObjectToMapAdapter castMapOfSerializables(Proxy proxy,
12 Mapper<dynamic, Serializable> fromJs, {mapOnlyNotNull: false}) =>
13 proxy == null ? null : new JsObjectToMapAdapter.fromProxy(proxy,
14 new TranslatorForSerializable(fromJs,
15 mapOnlyNotNull: mapOnlyNotNull));
16
17 final Translator<V> _translator;
18
19 JsObjectToMapAdapter.fromProxy(Proxy proxy, [Translator<V> translator]) :
20 super.fromProxy(proxy), this._translator = translator;
21
22 @override V operator [](String key) => _fromJs($unsafe[key]);
23 @override void operator []=(String key, V value) {
24 $unsafe[key] = _toJs(value);
25 }
26 @override V remove(String key) {
27 final value = this[key];
28 deleteProperty($unsafe, key);
29 return value;
30 }
31 @override Iterable<String> get keys =>
32 JsArrayToListAdapter.cast(context['Object'].keys($unsafe));
33
34 // use Maps to implement functions
35 @override bool containsValue(V value) => Maps.containsValue(this, value);
36 @override bool containsKey(String key) =>
37 context['Object'].keys($unsafe).indexOf(key) != -1;
38 @override V putIfAbsent(String key, V ifAbsent()) =>
39 Maps.putIfAbsent(this, key, ifAbsent);
40 @override void addAll(Map<String, V> other) {
41 if (other != null) {
42 other.forEach((k,v) => this[k] = v);
43 }
44 }
45 @override void clear() => Maps.clear(this);
46 @override void forEach(void f(String key, V value)) => Maps.forEach(this, f);
47 @override Iterable<V> get values => Maps.getValues(this);
48 @override int get length => Maps.length(this);
49 @override bool get isEmpty => Maps.isEmpty(this);
50 @override bool get isNotEmpty => Maps.isNotEmpty(this);
51
52 dynamic _toJs(V e) => _translator == null ? e : _translator.toJs(e);
53 V _fromJs(dynamic value) => _translator == null ? value :
54 _translator.fromJs(value);
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698