| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 // DO NOT EDIT | |
| 6 // Auto-generated Dart DOM implementation. | |
| 7 | |
| 8 $!CODE | |
| 9 | |
| 10 function __dom_native_TimeoutHander_method(_this, callback, timeout, operation)
{ | |
| 11 try { | |
| 12 return _this.$dom[operation](__dom_unwrap_TimeoutHandler_function(callback), | |
| 13 __dom_unwrap(timeout)); | |
| 14 } catch (e) { | |
| 15 throw __dom_wrap_exception(e); | |
| 16 } | |
| 17 } | |
| 18 | |
| 19 function native__DOMWindowWrappingImplementation__setInterval(_this, callback, t
imeout) { | |
| 20 return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setInterva
l'); | |
| 21 } | |
| 22 | |
| 23 function native__DOMWindowWrappingImplementation__setTimeout(_this, callback, ti
meout) { | |
| 24 return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setTimeout
'); | |
| 25 } | |
| 26 | |
| 27 function native__WorkerContextWrappingImplementation__setInterval(_this, callbac
k, timeout) { | |
| 28 return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setInterva
l'); | |
| 29 } | |
| 30 | |
| 31 function native__WorkerContextWrappingImplementation__setTimeout(_this, callback
, timeout) { | |
| 32 return __dom_native_TimeoutHander_method(_this, callback, timeout, 'setTimeout
'); | |
| 33 } | |
| 34 | |
| 35 function native__DOMWindowWrappingImplementation__get_localStorage(_this) { | |
| 36 var domWindow = _this.$dom; | |
| 37 try { | |
| 38 var isolatetoken = __dom_isolate_token(); | |
| 39 var wrapper = __dom_get_cached('dart_storage', domWindow, isolatetoken); | |
| 40 if (wrapper) return wrapper; | |
| 41 wrapper = native__StorageWrappingImplementation_create__StorageWrappingImple
mentation(); | |
| 42 wrapper.$dom = domWindow.localStorage; | |
| 43 __dom_set_cached('dart_storage', domWindow, isolatetoken, wrapper) | |
| 44 return wrapper; | |
| 45 } catch (e) { | |
| 46 throw __dom_wrap_exception(e); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 // Native methods for factory providers. | |
| 51 | |
| 52 function native__AudioContextFactoryProvider_create() { | |
| 53 try { | |
| 54 var constructor = window.AudioContext || window.webkitAudioContext; | |
| 55 return __dom_wrap(new constructor()); | |
| 56 } catch (e) { | |
| 57 throw __dom_wrap_exception(e); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 function native__FileReaderFactoryProvider_create() { | |
| 62 try { | |
| 63 return __dom_wrap(new FileReader()); | |
| 64 } catch (e) { | |
| 65 throw __dom_wrap_exception(e); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 function native__TypedArrayFactoryProvider__F32(arg) { | |
| 70 try { | |
| 71 return __dom_wrap(new Float32Array(__dom_unwrap(arg))); | |
| 72 } catch (e) { | |
| 73 throw __dom_wrap_exception(e); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 function native__TypedArrayFactoryProvider__F64(arg) { | |
| 78 try { | |
| 79 return __dom_wrap(new Float64Array(__dom_unwrap(arg))); | |
| 80 } catch (e) { | |
| 81 throw __dom_wrap_exception(e); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 function native__TypedArrayFactoryProvider__I8(arg) { | |
| 86 try { | |
| 87 return __dom_wrap(new Int8Array(__dom_unwrap(arg))); | |
| 88 } catch (e) { | |
| 89 throw __dom_wrap_exception(e); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 function native__TypedArrayFactoryProvider__I16(arg) { | |
| 94 try { | |
| 95 return __dom_wrap(new Int16Array(__dom_unwrap(arg))); | |
| 96 } catch (e) { | |
| 97 throw __dom_wrap_exception(e); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 function native__TypedArrayFactoryProvider__I32(arg) { | |
| 102 try { | |
| 103 return __dom_wrap(new Int32Array(__dom_unwrap(arg))); | |
| 104 } catch (e) { | |
| 105 throw __dom_wrap_exception(e); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 function native__TypedArrayFactoryProvider__U8(arg) { | |
| 110 try { | |
| 111 return __dom_wrap(new Uint8Array(__dom_unwrap(arg))); | |
| 112 } catch (e) { | |
| 113 throw __dom_wrap_exception(e); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 function native__TypedArrayFactoryProvider__U16(arg) { | |
| 118 try { | |
| 119 return __dom_wrap(new Uint16Array(__dom_unwrap(arg))); | |
| 120 } catch (e) { | |
| 121 throw __dom_wrap_exception(e); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 function native__TypedArrayFactoryProvider__U32(arg) { | |
| 126 try { | |
| 127 return __dom_wrap(new Uint32Array(__dom_unwrap(arg))); | |
| 128 } catch (e) { | |
| 129 throw __dom_wrap_exception(e); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 function native__WebKitCSSMatrixFactoryProvider_create(spec) { | |
| 134 try { | |
| 135 return __dom_wrap(new WebKitCSSMatrix(spec)); // string doesn't need unwrap
. | |
| 136 } catch (e) { | |
| 137 throw __dom_wrap_exception(e); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 function native__WebKitPointFactoryProvider_create(x, y) { | |
| 142 try { | |
| 143 return __dom_wrap(new WebKitPoint(x, y)); // nums don't need unwrap. | |
| 144 } catch (e) { | |
| 145 throw __dom_wrap_exception(e); | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 function native__WebSocketFactoryProvider_create(url) { | |
| 150 try { | |
| 151 return __dom_wrap(new WebSocket(url)); // string doesn't need unwrap. | |
| 152 } catch (e) { | |
| 153 throw __dom_wrap_exception(e); | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 function native__XMLHttpRequestFactoryProvider_create() { | |
| 158 try { | |
| 159 return __dom_wrap(new XMLHttpRequest()); | |
| 160 } catch (e) { | |
| 161 throw __dom_wrap_exception(e); | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 | |
| 166 var __dom_type_map = { | |
| 167 $!MAP | |
| 168 // Patches for non-WebKit browsers | |
| 169 'Window': native__DOMWindowWrappingImplementation_create__DOMWindowWrappingImp
lementation, | |
| 170 'global': native__DOMWindowWrappingImplementation_create__DOMWindowWrappingImp
lementation, | |
| 171 'KeyEvent': native__KeyboardEventWrappingImplementation_create__KeyboardEventW
rappingImplementation, // Opera | |
| 172 'HTMLPhraseElement': native__HTMLElementWrappingImplementation_create__HTMLEle
mentWrappingImplementation, // IE9 | |
| 173 'MSStyleCSSProperties': native__CSSStyleDeclarationWrappingImplementation_crea
te__CSSStyleDeclarationWrappingImplementation // IE9 | |
| 174 }; | |
| 175 | |
| 176 function __dom_get_class_chrome(ptr) { | |
| 177 return __dom_type_map[ptr.constructor.name]; | |
| 178 } | |
| 179 | |
| 180 function __dom_get_class_generic(ptr) { | |
| 181 var str = Object.prototype.toString.call(ptr); | |
| 182 var name = str.substring(8, str.length - 1); | |
| 183 var cls = __dom_type_map[name]; | |
| 184 return cls; | |
| 185 } | |
| 186 | |
| 187 if (Object.__proto__) { | |
| 188 __dom_get_class_generic = function(ptr) { | |
| 189 var isolatetoken = __dom_isolate_token(); | |
| 190 var result = __dom_get_cached('dart_class', ptr.__proto__, isolatetoken); | |
| 191 if (result) { | |
| 192 return result; | |
| 193 } | |
| 194 var str = Object.prototype.toString.call(ptr); | |
| 195 var name = str.substring(8, str.length - 1); | |
| 196 var cls = __dom_type_map[name]; | |
| 197 __dom_set_cached('dart_class', ptr.__proto__, isolatetoken, cls); | |
| 198 return cls; | |
| 199 } | |
| 200 } | |
| 201 | |
| 202 var __dom_get_class = __dom_get_class_generic; | |
| 203 if (typeof window !== 'undefined' && // webworkers don't have a window | |
| 204 window.constructor.name == "DOMWindow") { | |
| 205 __dom_get_class = __dom_get_class_chrome; | |
| 206 } | |
| 207 | |
| 208 function __dom_get_cached(hashtablename, obj, isolatetoken) { | |
| 209 if (!obj.hasOwnProperty(hashtablename)) return (void 0); | |
| 210 var hashtable = obj[hashtablename]; | |
| 211 var hash = isolatetoken.hashCode; | |
| 212 // Issue 1005 part (1), may be undefined in CSSStyleDeclaration. | |
| 213 hashtable = hashtable || {}; | |
| 214 while (true) { | |
| 215 var result = hashtable[hash]; | |
| 216 if (result) { | |
| 217 if (result.$token === isolatetoken) { | |
| 218 return result; | |
| 219 } else { | |
| 220 hash++; | |
| 221 } | |
| 222 } else { | |
| 223 return (void 0); | |
| 224 } | |
| 225 } | |
| 226 } | |
| 227 | |
| 228 function __dom_set_cached(hashtablename, obj, isolatetoken, value) { | |
| 229 var hashtable; | |
| 230 if (!obj.hasOwnProperty(hashtablename)) { | |
| 231 hashtable = {}; | |
| 232 obj[hashtablename] = hashtable; | |
| 233 } else { | |
| 234 hashtable = obj[hashtablename]; | |
| 235 if (!hashtable) obj[hashtablename] = hashtable = {}; // Issue 1005 part (1) | |
| 236 } | |
| 237 var hash = isolatetoken.hashCode; | |
| 238 while (true) { | |
| 239 var entry = hashtable[hash]; | |
| 240 if (entry) { | |
| 241 if (entry.$token === isolatetoken) { | |
| 242 throw "Wrapper already exists for this object: " + obj; | |
| 243 } else { | |
| 244 hash++; | |
| 245 } | |
| 246 } else { | |
| 247 value.$token = isolatetoken; | |
| 248 hashtable[hash] = value; | |
| 249 return; | |
| 250 } | |
| 251 } | |
| 252 } | |
| 253 | |
| 254 function __dom_isolate_token() { | |
| 255 return isolate$current.token; | |
| 256 } | |
| 257 | |
| 258 /** @suppress {duplicate} */ | |
| 259 function __dom_wrap(ptr) { | |
| 260 if (ptr == null) { | |
| 261 return (void 0); | |
| 262 } | |
| 263 var type = typeof(ptr); | |
| 264 if (type != "object" && type != "function") { | |
| 265 return ptr; | |
| 266 } | |
| 267 var isolatetoken = __dom_isolate_token(); | |
| 268 var wrapper = __dom_get_cached('dart_wrapper', ptr, isolatetoken); | |
| 269 if (wrapper) { | |
| 270 return wrapper; | |
| 271 } | |
| 272 var factory = __dom_get_class(ptr); | |
| 273 if (!factory) { | |
| 274 return ptr; | |
| 275 } | |
| 276 wrapper = factory(); | |
| 277 wrapper.$dom = ptr; | |
| 278 __dom_set_cached('dart_wrapper', ptr, isolatetoken, wrapper); | |
| 279 return wrapper; | |
| 280 } | |
| 281 | |
| 282 function __dom_wrap_exception(e) { | |
| 283 return __dom_wrap(e); | |
| 284 } | |
| 285 | |
| 286 function __dom_wrap_primitive(ptr) { | |
| 287 return (ptr === null) ? (void 0) : ptr; | |
| 288 } | |
| 289 | |
| 290 /** @suppress {duplicate} */ | |
| 291 function __dom_unwrap(obj, dropargs) { | |
| 292 if (obj == null) { | |
| 293 return (void 0); | |
| 294 } | |
| 295 if (obj.$dom) { | |
| 296 return obj.$dom; | |
| 297 } | |
| 298 if (obj instanceof Function) { // BUGBUG: function from other IFrame | |
| 299 var isolatetoken = __dom_isolate_token(); | |
| 300 var unwrapped = __dom_get_cached('dart_unwrapped', obj, isolatetoken); | |
| 301 if (unwrapped) { | |
| 302 return unwrapped; | |
| 303 } | |
| 304 var isolate = isolate$current; | |
| 305 unwrapped = function () { | |
| 306 var old = isolate$current; | |
| 307 isolate$current = isolate; | |
| 308 try { | |
| 309 if (dropargs) { | |
| 310 return $dartcall(obj, []); | |
| 311 } else { | |
| 312 var args = Array.prototype.slice.call(arguments); | |
| 313 return $dartcall(obj, args.map(__dom_wrap)); | |
| 314 } | |
| 315 } finally { | |
| 316 isolate$current = old; | |
| 317 // TODO(vsm): This really needs to go elsewhere. | |
| 318 isolate$runEventLoop(); | |
| 319 } | |
| 320 // BUGBUG? Should the result be unwrapped? Or is it always void/bool ? | |
| 321 }; | |
| 322 __dom_set_cached('dart_unwrapped', obj, isolatetoken, unwrapped); | |
| 323 return unwrapped; | |
| 324 } | |
| 325 return obj; | |
| 326 } | |
| 327 | |
| 328 function __dom_unwrap_TimeoutHandler_function(fn) { | |
| 329 // Some browsers (e.g. FF) pass data to the timeout function, others do not. | |
| 330 // Dart's TimeoutHandler takes no arguments, so drop any arguments passed to | |
| 331 // the unwrapped callback. | |
| 332 return __dom_unwrap(fn, true); | |
| 333 } | |
| 334 | |
| 335 // Declared in src/GlobalProperties.dart | |
| 336 function native__NativeDomGlobalProperties_getWindow() { | |
| 337 // TODO: Should the window be obtained from an isolate? | |
| 338 return __dom_wrap(window); | |
| 339 } | |
| 340 | |
| 341 // Declared in src/GlobalProperties.dart | |
| 342 function native__NativeDomGlobalProperties_getDocument() { | |
| 343 // TODO: Should the window be obtained from an isolate? | |
| 344 return __dom_wrap(window.document); | |
| 345 } | |
| OLD | NEW |