| 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 _Utils { | |
| 6 static List convertToList(List list) { | |
| 7 // FIXME: [possible optimization]: do not copy the array if Dart_IsArray is
fine w/ it. | |
| 8 final length = list.length; | |
| 9 List result = new List(length); | |
| 10 result.setRange(0, length, list); | |
| 11 return result; | |
| 12 } | |
| 13 | |
| 14 static List convertMapToList(Map map) { | |
| 15 List result = []; | |
| 16 map.forEach((k, v) => result.addAll([k, v])); | |
| 17 return result; | |
| 18 } | |
| 19 | |
| 20 static void populateMap(Map result, List list) { | |
| 21 for (int i = 0; i < list.length; i += 2) { | |
| 22 result[list[i]] = list[i + 1]; | |
| 23 } | |
| 24 } | |
| 25 | |
| 26 static bool isMap(obj) => obj is Map; | |
| 27 | |
| 28 static Map createMap() => {}; | |
| 29 | |
| 30 static makeNotImplementedException(String fileName, int lineNo) { | |
| 31 return new UnsupportedOperationException('[info: $fileName:$lineNo]'); | |
| 32 } | |
| 33 | |
| 34 static window() native "Utils_window"; | |
| 35 static print(String message) native "Utils_print"; | |
| 36 static SendPort spawnDomFunctionImpl(Function topLevelFunction) native "Utils_
spawnDomFunction"; | |
| 37 static int _getNewIsolateId() native "Utils_getNewIsolateId"; | |
| 38 } | |
| 39 | |
| 40 class _NPObject extends NativeFieldWrapperClass1 { | |
| 41 _NPObject(); | |
| 42 static _NPObject retrieve(String key) native "NPObject_retrieve"; | |
| 43 property(String propertyName) native "NPObject_property"; | |
| 44 invoke(String methodName, [ObjectArray args = null]) native "NPObject_invoke"; | |
| 45 } | |
| 46 | |
| 47 class _DOMWindowCrossFrameImpl extends NativeFieldWrapperClass1 implements Windo
w { | |
| 48 _DOMWindowCrossFrameImpl(); | |
| 49 | |
| 50 // Fields. | |
| 51 History get history() native "DOMWindow_history_cross_frame_Getter"; | |
| 52 Location get location() native "DOMWindow_location_cross_frame_Getter"; | |
| 53 bool get closed() native "DOMWindow_closed_Getter"; | |
| 54 int get length() native "DOMWindow_length_Getter"; | |
| 55 DOMWindow get opener() native "DOMWindow_opener_Getter"; | |
| 56 DOMWindow get parent() native "DOMWindow_parent_Getter"; | |
| 57 DOMWindow get top() native "DOMWindow_top_Getter"; | |
| 58 | |
| 59 // Methods. | |
| 60 void focus() native "DOMWindow_focus_Callback"; | |
| 61 void blur() native "DOMWindow_blur_Callback"; | |
| 62 void close() native "DOMWindow_close_Callback"; | |
| 63 void postMessage(/*SerializedScriptValue*/ message, String targetOrigin, [List
messagePorts]) native "DOMWindow_postMessage_Callback"; | |
| 64 | |
| 65 // Implementation support. | |
| 66 String get typeName => "DOMWindow"; | |
| 67 } | |
| 68 | |
| 69 class _HistoryCrossFrameImpl extends NativeFieldWrapperClass1 implements History
{ | |
| 70 _HistoryCrossFrameImpl(); | |
| 71 | |
| 72 // Methods. | |
| 73 void back() native "History_back_Callback"; | |
| 74 void forward() native "History_forward_Callback"; | |
| 75 void go(int distance) native "History_go_Callback"; | |
| 76 | |
| 77 // Implementation support. | |
| 78 String get typeName => "History"; | |
| 79 } | |
| 80 | |
| 81 class _LocationCrossFrameImpl extends NativeFieldWrapperClass1 implements Locati
on { | |
| 82 _LocationCrossFrameImpl(); | |
| 83 | |
| 84 // Fields. | |
| 85 void set href(String) native "Location_href_Setter"; | |
| 86 | |
| 87 // Implementation support. | |
| 88 String get typeName => "Location"; | |
| 89 } | |
| 90 | |
| 91 class _DOMStringMapImpl extends NativeFieldWrapperClass1 implements Map<String,
String> { | |
| 92 _DOMStringMapImpl(); | |
| 93 | |
| 94 bool containsValue(String value) => Maps.containsValue(this, value); | |
| 95 bool containsKey(String key) native "DOMStringMap_containsKey_Callback"; | |
| 96 String operator [](String key) native "DOMStringMap_item_Callback"; | |
| 97 void operator []=(String key, String value) native "DOMStringMap_setItem_Callb
ack"; | |
| 98 String putIfAbsent(String key, String ifAbsent()) => Maps.putIfAbsent(this, ke
y, ifAbsent); | |
| 99 String remove(String key) native "DOMStringMap_remove_Callback"; | |
| 100 void clear() => Maps.clear(this); | |
| 101 void forEach(void f(String key, String value)) => Maps.forEach(this, f); | |
| 102 Collection<String> getKeys() native "DOMStringMap_getKeys_Callback"; | |
| 103 Collection<String> getValues() => Maps.getValues(this); | |
| 104 int get length => Maps.length(this); | |
| 105 bool isEmpty() => Maps.isEmpty(this); | |
| 106 } | |
| 107 | |
| 108 get _printClosure => (s) { | |
| 109 try { | |
| 110 window.console.log(s); | |
| 111 } on Dynamic catch(_) { | |
| 112 _Utils.print(s); | |
| 113 } | |
| 114 }; | |
| OLD | NEW |