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

Side by Side Diff: tools/dom/templates/html/dartium/html_dartium.darttemplate

Issue 1330163010: Revert "Dartium w/ JsInterop enabled" (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // DO NOT EDIT 5 // DO NOT EDIT
6 // Auto-generated dart:html library. 6 // Auto-generated dart:html library.
7 7
8 /** 8 /**
9 * HTML elements and other resources for web-based applications that need to 9 * HTML elements and other resources for web-based applications that need to
10 * interact with the browser and the DOM (Document Object Model). 10 * interact with the browser and the DOM (Document Object Model).
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return null; 243 return null;
244 } 244 }
245 245
246 Type _getSvgType(String key) { 246 Type _getSvgType(String key) {
247 if (svgBlinkMap.containsKey(key)) { 247 if (svgBlinkMap.containsKey(key)) {
248 return svgBlinkMap[key](); 248 return svgBlinkMap[key]();
249 } 249 }
250 return null; 250 return null;
251 } 251 }
252 252
253
253 $if JSINTEROP 254 $if JSINTEROP
254 // FIXME: Can we make this private? 255 // FIXME: Can we make this private?
255 final htmlBlinkFunctionMap = { 256 final htmlBlinkFunctionMap = {
256 $!TYPE_FUNCTION_MAP 257 $!TYPE_FUNCTION_MAP
257 }; 258 };
258 259
259 // TODO(terry): We may want to move this elsewhere if html becomes 260 // TODO(terry): We may want to move this elsewhere if html becomes
260 // a package to avoid dartium depending on pkg:html. 261 // a package to avoid dartium depending on pkg:html.
261 getHtmlCreateFunction(String key) { 262 getHtmlCreateFunction(String key) {
262 var result; 263 var result;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 296
296 // Check the svg library. 297 // Check the svg library.
297 result = _getSvgFunction(key); 298 result = _getSvgFunction(key);
298 if (result != null) { 299 if (result != null) {
299 return result; 300 return result;
300 } 301 }
301 302
302 return null; 303 return null;
303 } 304 }
304 305
305 Function _getHtmlFunction(String key) { 306 Type _getHtmlFunction(String key) {
306 if (htmlBlinkFunctionMap.containsKey(key)) { 307 if (htmlBlinkFunctionMap.containsKey(key)) {
307 return htmlBlinkFunctionMap[key](); 308 return htmlBlinkFunctionMap[key]();
308 } 309 }
309 return null; 310 return null;
310 } 311 }
311 312
312 Function _getWebGlFunction(String key) { 313 Type _getWebGlFunction(String key) {
313 if (web_glBlinkFunctionMap.containsKey(key)) { 314 if (web_glBlinkFunctionMap.containsKey(key)) {
314 return web_glBlinkFunctionMap[key](); 315 return web_glBlinkFunctionMap[key]();
315 } 316 }
316 return null; 317 return null;
317 } 318 }
318 319
319 Function _getIndexDbFunction(String key) { 320 Type _getIndexDbFunction(String key) {
320 if (indexed_dbBlinkFunctionMap.containsKey(key)) { 321 if (indexed_dbBlinkFunctionMap.containsKey(key)) {
321 return indexed_dbBlinkFunctionMap[key](); 322 return indexed_dbBlinkFunctionMap[key]();
322 } 323 }
323 return null; 324 return null;
324 } 325 }
325 326
326 Function _getWebAudioFunction(String key) { 327 Type _getWebAudioFunction(String key) {
327 if (web_audioBlinkFunctionMap.containsKey(key)) { 328 if (web_audioBlinkFunctionMap.containsKey(key)) {
328 return web_audioBlinkFunctionMap[key](); 329 return web_audioBlinkFunctionMap[key]();
329 } 330 }
330 return null; 331 return null;
331 } 332 }
332 333
333 Function _getWebSqlFunction(String key) { 334 Type _getWebSqlFunction(String key) {
334 if (web_sqlBlinkFunctionMap.containsKey(key)) { 335 if (web_sqlBlinkFunctionMap.containsKey(key)) {
335 return web_sqlBlinkFunctionMap[key](); 336 return web_sqlBlinkFunctionMap[key]();
336 } 337 }
337 return null; 338 return null;
338 } 339 }
339 340
340 Function _getSvgFunction(String key) { 341 Type _getSvgFunction(String key) {
341 if (svgBlinkFunctionMap.containsKey(key)) { 342 if (svgBlinkFunctionMap.containsKey(key)) {
342 return svgBlinkFunctionMap[key](); 343 return svgBlinkFunctionMap[key]();
343 } 344 }
344 return null; 345 return null;
345 } 346 }
346 347
347 348
348 /****************************************************************************** 349 /******************************************************************************
349 ********** ********** 350 ********** **********
350 ********** JS Interop Support ********** 351 ********** JS Interop Support **********
351 ********** ********** 352 ********** **********
352 ******************************************************************************/ 353 ******************************************************************************/
353 354
354 Rectangle make_dart_rectangle(r) => 355 Rectangle make_dart_rectangle(r) => new Rectangle(r['top'], r['left'], r['width' ], r['height']);
355 r == null ? null : new Rectangle(r['left'], r['top'], r['width'], r['height' ]);
356 356
357 // Need a default constructor for constructing classes with mixins that are
358 // also extending NativeFieldWrapperClass2. Defining JsoNativeFieldWrapper
359 // extending NativeFieldWrapperClass2 creates a default constructor.
360 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {}
361
362 // Flag to disable JS interop asserts. Setting to false will speed up the
363 // wrap_jso calls.
364 bool __interop_checks = true;
365 357
366 /** Expando for JsObject, used by every Dart class associated with a Javascript 358 /** Expando for JsObject, used by every Dart class associated with a Javascript
367 * class (e.g., DOM, WebAudio, etc.). 359 * class (e.g., DOM, WebAudio, etc.).
368 */ 360 */
369 361
370 /** 362 /**
371 * Return the JsObject associated with a Dart class [dartClass_instance]. 363 * Return the JsObject associated with a Dart class [dartClass_instance].
372 */ 364 */
373 unwrap_jso(dartClass_instance) { 365 js.JsObject unwrap_jso(dartClass_instance) {
374 try { 366 try {
375 if (dartClass_instance != null) 367 if (dartClass_instance != null)
376 return dartClass_instance is NativeFieldWrapperClass2 ? 368 return dartClass_instance is! Function ? dartClass_instance.blink_jsOb ject : dartClass_instance;
377 dartClass_instance.blink_jsObject : dartClass_instance; 369 else
378 else 370 return null;
379 return null; 371 // return dartClass_instance.dartium_expando[dartClass_instance.expandoJsOb ject];
380 } catch(NoSuchMethodException) { 372 } catch(NoSuchMethodException) {
381 // No blink_jsObject then return the dartClass_instance is probably an 373 // No blink_jsObject then return the dartClass_instance is probably an
382 // array that was already converted to a Dart class e.g., Uint8ClampedList. 374 // array that was already converted to a Dart class e.g., Uint8ClampedList .
383 return dartClass_instance; 375 return dartClass_instance;
384 } 376 }
385 } 377 }
386 378
387 /** 379 /**
388 * Create Dart class that maps to the JS Type, add the JsObject as an expando 380 * Create Dart class that maps to the JS Type, add the JsObject as an expando
389 * on the Dart class and return the created Dart class. 381 * on the Dart class and return the created Dart class.
390 */ 382 */
391 wrap_jso(jsObject) { 383 wrap_jso(jsObject) {
392 try { 384 try {
393 if (jsObject is! js.JsObject) { 385 // debug_or_assert("jsObject != null", jsObject != null);
386 if (jsObject is! js.JsObject) {
394 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. 387 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
395 return jsObject; 388 return jsObject;
396 }
397 var constructor = jsObject['constructor'];
398 if (__interop_checks) {
399 if (jsObject is js.JsArray) {
400 return jsObject;
401 }
402
403 debug_or_assert("constructor != null", constructor != null);
404 }
405 if (constructor == js.context['Object']) {
406 return convertNativeObjectToDartMap(jsObject);
407 }
408 if (constructor == js.context['Promise']) {
409 return convertNativePromiseToDartFuture(jsObject);
410 }
411 var jsTypeName = constructor['name'];
412 if (__interop_checks) {
413 debug_or_assert("constructor != null && jsTypeName.length > 0", constructo r != null && jsTypeName.length > 0);
414 }
415
416 var dartClass_instance;
417 if (jsObject.hasProperty('dart_class')) {
418 // Got a dart_class (it's a custom element) use it it's already set up.
419 dartClass_instance = jsObject['dart_class'];
420 } else {
421 var func = getHtmlCreateFunction(jsTypeName);
422 if (func != null) {
423 dartClass_instance = func();
424 dartClass_instance.blink_jsObject = jsObject;
425 }
426 }
427 return dartClass_instance;
428 } catch(e, stacktrace){
429 if (__interop_checks) {
430 if (e is DebugAssertException)
431 window.console.log("${e.message}\n ${stacktrace}");
432 else
433 window.console.log("${stacktrace}");
434 }
435 } 389 }
436 390 var constructor = jsObject['constructor'];
437 return null; 391 debug_or_assert("constructor != null", constructor != null);
392 var jsTypeName = constructor['name'];
393 debug_or_assert("constructor != null && jsTypeName.length > 0", constructor != null && jsTypeName.length > 0);
394 var func = getHtmlCreateFunction(jsTypeName);
395 debug_or_assert("func != null name = ${jsTypeName}", func != null);
396 var dartClass_instance = func();
397 dartClass_instance.blink_jsObject = jsObject;
398 // dartClass_instance.dartium_expando[dartClass_instance.expandoJsObject] = jsO bject;
399 return dartClass_instance;
400 } catch(e, stacktrace){
401 if (e is DebugAssertException)
402 window.console.log("${e.message}\n ${stacktrace}");
403 else
404 window.console.log("${stacktrace}");
438 } 405 }
439
440 /**
441 * Create Dart class that maps to the JS Type that is the JS type being
442 * extended using JS interop createCallback (we need the base type of the
443 * custom element) not the Dart created constructor.
444 */
445 wrap_jso_custom_element(jsObject) {
446 try {
447 if (jsObject is! js.JsObject) {
448 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
449 return jsObject;
450 }
451
452 // Find out what object we're extending.
453 var objectName = jsObject.toString();
454 // Expect to see something like '[object HTMLElement]'.
455 if (!objectName.startsWith('[object ')) {
456 return jsObject;
457 }
458
459 var extendsClass = objectName.substring(8, objectName.length - 1);
460 var func = getHtmlCreateFunction(extendsClass);
461 if (__interop_checks)
462 debug_or_assert("func != null name = ${extendsClass}", func != null);
463 var dartClass_instance = func();
464 dartClass_instance.blink_jsObject = jsObject;
465 return dartClass_instance;
466 } catch(e, stacktrace){
467 if (__interop_checks) {
468 if (e is DebugAssertException)
469 window.console.log("${e.message}\n ${stacktrace}");
470 else
471 window.console.log("${stacktrace}");
472 }
473
474 // Problem?
475 return null;
476 }
477 } 406 }
478 407
479 class DebugAssertException implements Exception { 408 class DebugAssertException implements Exception {
480 String message; 409 String message;
481 DebugAssertException(this.message); 410 DebugAssertException(this.message);
482 } 411 }
483 412
484 debug_or_assert(message, expression) { 413 debug_or_assert(message, expression) {
485 if (!expression) { 414 if (!expression) {
486 throw new DebugAssertException("$message"); 415 throw new DebugAssertException("$message");
487 } 416 }
488 } 417 }
489 418
490 // TODO(terry): Manage JS interop JsFunctions for each listener used for add/ 419 // Wrap JsObject node list to return a List<node>.
491 // removeEventListener. These JsFunctions will leak look at 420 List<Node> wrap_jso_list(jso_nodes) {
492 // fixing with weak-refs in C++. The key are the hashcodes of the 421 List<Node> nodes = new List<Node>();
493 // user's this (this is needed for futures) and listener function. 422 var collectionLen = jso_nodes['length'];
494 Map<int, Map<int, js.JsFunction>> _knownListeners = {}; 423 for (var i = 0; i < collectionLen; i++) {
495 424 nodes.add(wrap_jso(jso_nodes.callMethod('item', [i])));
496 js.JsFunction wrap_event_listener(theObject, Function listener) { 425 }
497 var thisHashCode = theObject.hashCode; 426 var frozen_nodes = new _FrozenElementList._wrap(nodes);
498 var listenerHashCode = identityHashCode(listener); 427 frozen_nodes.dartClass_instance = jso_nodes;
499 428 return frozen_nodes;
500 _knownListeners.putIfAbsent(thisHashCode, () => new Map<int, js.JsFunction>()) ;
501 _knownListeners[thisHashCode].putIfAbsent(listenerHashCode, () =>
502 new js.JsFunction.withThis((theObject, event) => listener(wrap_jso(event)))) ;
503
504 return _knownListeners[thisHashCode][listenerHashCode];
505 } 429 }
506
507 Map<String, dynamic> convertNativeObjectToDartMap(js.JsObject jsObject) {
508 var result = new Map();
509 var keys = js.context['Object'].callMethod('keys', [jsObject]);
510 for (var key in keys) {
511 result[key] = wrap_jso(jsObject[key]);
512 }
513 return result;
514 }
515
516 // Converts a flat Dart map into a JavaScript object with properties this is
517 // is the Dartium only version it uses dart:js.
518 convertDartToNative_Dictionary(Map dict) {
519 if (dict == null) return null;
520 var jsObject = new js.JsObject(js.context['Object']);
521 dict.forEach((String key, value) {
522 if (value is List) {
523 var jsArray = new js.JsArray();
524 value.forEach((elem) {
525 jsArray.add(elem is Map ? convertDartToNative_Dictionary(elem): elem);
526 });
527 jsObject[key] = jsArray;
528 } else {
529 jsObject[key] = value;
530 }
531 });
532 return jsObject;
533 }
534
535 // Converts a Dart list into a JsArray. For the Dartium version only.
536 convertDartToNative_List(List input) => new js.JsArray()..addAll(input);
537
538 // Conversion function place holder (currently not used in dart2js or dartium).
539 List convertDartToNative_StringArray(List<String> input) => input;
540
541 Future convertNativePromiseToDartFuture(js.JsObject promise) {
542 var completer = new Completer();
543 var newPromise = promise
544 .callMethod("then", [(result) => completer.complete(result)])
545 .callMethod("catch", [(result) => completer.completeError(result)]);
546 return completer.future;
547 }
548
549 $else 430 $else
550 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {}
551
552 unwrap_jso(dartClass_instance) => dartClass_instance; 431 unwrap_jso(dartClass_instance) => dartClass_instance;
553 wrap_jso(jsObject) => jsObject; 432 wrap_jso(jsObject) => jsObject;
433 wrap_jso_list(jso_nodes) => jso_nodes;
554 make_dart_rectangle(r) => r; 434 make_dart_rectangle(r) => r;
555 convertDartToNative_Dictionary(Map dict) => dict;
556 List convertDartToNative_StringArray(List<String> input) => input;
557 convertDartToNative_List(List input) => input;
558
559 $endif 435 $endif
OLDNEW
« no previous file with comments | « tools/dom/src/native_DOMImplementation.dart ('k') | tools/dom/templates/html/dartium/indexed_db_dartium.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698