| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012, 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 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 6 $!MEMBERS |
| 7 void observe(Node target, |
| 8 [Map options, |
| 9 bool childList, |
| 10 bool attributes, |
| 11 bool characterData, |
| 12 bool subtree, |
| 13 bool attributeOldValue, |
| 14 bool characterDataOldValue, |
| 15 List<String> attributeFilter]) { |
| 16 |
| 17 // Parse options into map of known type. |
| 18 var parsedOptions = _createDict(); |
| 19 |
| 20 if (options != null) { |
| 21 options.forEach((k, v) { |
| 22 if (_boolKeys.containsKey(k)) { |
| 23 _add(parsedOptions, k, true === v); |
| 24 } else if (k == 'attributeFilter') { |
| 25 _add(parsedOptions, k, _fixupList(v)); |
| 26 } else { |
| 27 throw new IllegalArgumentException( |
| 28 "Illegal MutationObserver.observe option '$k'"); |
| 29 } |
| 30 }); |
| 31 } |
| 32 |
| 33 // Override options passed in the map with named optional arguments. |
| 34 override(key, value) { |
| 35 if (value != null) _add(parsedOptions, key, value); |
| 36 } |
| 37 |
| 38 override('childList', childList); |
| 39 override('attributes', attributes); |
| 40 override('characterData', characterData); |
| 41 override('subtree', subtree); |
| 42 override('attributeOldValue', attributeOldValue); |
| 43 override('characterDataOldValue', characterDataOldValue); |
| 44 if (attributeFilter != null) { |
| 45 override('attributeFilter', _fixupList(attributeFilter)); |
| 46 } |
| 47 |
| 48 _call(target, parsedOptions); |
| 49 } |
| 50 |
| 51 // TODO: Change to a set when const Sets are available. |
| 52 static final _boolKeys = |
| 53 const {'childList': true, |
| 54 'attributes': true, |
| 55 'characterData': true, |
| 56 'subtree': true, |
| 57 'attributeOldValue': true, |
| 58 'characterDataOldValue': true }; |
| 59 |
| 60 $if DARTIUM |
| 61 static _createDict() => {}; |
| 62 static _add(m, String key, value) { m[key] = value; } |
| 63 static _fixupList(list) => list; |
| 64 |
| 65 _call(Node target, options) { |
| 66 _observe(target, options); |
| 67 } |
| 68 $endif |
| 69 |
| 70 $if FROG |
| 71 static _createDict() => JS('var', '{}'); |
| 72 static _add(m, String key, value) { JS('void', '#[#] = #', m, key, value); } |
| 73 static _fixupList(list) => list; // TODO: Ensure is a JavaScript Array. |
| 74 |
| 75 // Call native function with no conversions. |
| 76 _call(target, options) native 'observe'; |
| 77 $endif |
| 78 } |
| OLD | NEW |