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

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

Issue 1349293006: Start using the dart2js type conversions in Dartium as well. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged 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
« no previous file with comments | « tools/dom/scripts/systemnative.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 /** 387 /**
388 * Create Dart class that maps to the JS Type, add the JsObject as an expando 388 * 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. 389 * on the Dart class and return the created Dart class.
390 */ 390 */
391 wrap_jso(jsObject) { 391 wrap_jso(jsObject) {
392 try { 392 try {
393 if (jsObject is! js.JsObject) { 393 if (jsObject is! js.JsObject) {
394 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. 394 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
395 return jsObject; 395 return jsObject;
396 } 396 }
397 // Try the most general type conversions on it.
398 // TODO(alanknight): We may be able to do better. This maintains identity,
399 // which is useful, but expensive. And if we nest something that only
400 // this conversion handles, how does that work? e.g. a list of maps of eleme nts.
401 var converted = convertNativeToDart_SerializedScriptValue(jsObject);
402 if (!identical(converted, jsObject)) {
403 return converted;
404 }
397 var constructor = jsObject['constructor']; 405 var constructor = jsObject['constructor'];
398 if (__interop_checks) { 406 if (__interop_checks) {
399 if (jsObject is js.JsArray) {
400 return jsObject;
401 }
402
403 debug_or_assert("constructor != null", constructor != null); 407 debug_or_assert("constructor != null", constructor != null);
404 } 408 }
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']; 409 var jsTypeName = constructor['name'];
412 if (__interop_checks) { 410 if (__interop_checks) {
413 debug_or_assert("constructor != null && jsTypeName.length > 0", constructo r != null && jsTypeName.length > 0); 411 debug_or_assert("constructor != null && jsTypeName.length > 0", constructo r != null && jsTypeName.length > 0);
414 } 412 }
415 413
416 var dartClass_instance; 414 var dartClass_instance;
417 if (jsObject.hasProperty('dart_class')) { 415 if (jsObject.hasProperty('dart_class')) {
418 // Got a dart_class (it's a custom element) use it it's already set up. 416 // Got a dart_class (it's a custom element) use it it's already set up.
419 dartClass_instance = jsObject['dart_class']; 417 dartClass_instance = jsObject['dart_class'];
420 } else { 418 } else {
(...skipping 10 matching lines...) Expand all
431 window.console.log("${e.message}\n ${stacktrace}"); 429 window.console.log("${e.message}\n ${stacktrace}");
432 else 430 else
433 window.console.log("${stacktrace}"); 431 window.console.log("${stacktrace}");
434 } 432 }
435 } 433 }
436 434
437 return null; 435 return null;
438 } 436 }
439 437
440 /** 438 /**
441 * Create Dart class that maps to the JS Type that is the JS type being 439 * 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 440 * extended using JS interop createCallback (we need the base type of the
443 * custom element) not the Dart created constructor. 441 * custom element) not the Dart created constructor.
444 */ 442 */
445 wrap_jso_custom_element(jsObject) { 443 wrap_jso_custom_element(jsObject) {
446 try { 444 try {
447 if (jsObject is! js.JsObject) { 445 if (jsObject is! js.JsObject) {
448 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList. 446 // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
449 return jsObject; 447 return jsObject;
450 } 448 }
451 449
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 var result = new Map(); 506 var result = new Map();
509 var keys = js.context['Object'].callMethod('keys', [jsObject]); 507 var keys = js.context['Object'].callMethod('keys', [jsObject]);
510 for (var key in keys) { 508 for (var key in keys) {
511 result[key] = wrap_jso(jsObject[key]); 509 result[key] = wrap_jso(jsObject[key]);
512 } 510 }
513 return result; 511 return result;
514 } 512 }
515 513
516 // Converts a flat Dart map into a JavaScript object with properties this is 514 // Converts a flat Dart map into a JavaScript object with properties this is
517 // is the Dartium only version it uses dart:js. 515 // is the Dartium only version it uses dart:js.
516 // TODO(alanknight): This could probably be unified with the dart2js conversions
517 // code in html_common and be more general.
518 convertDartToNative_Dictionary(Map dict) { 518 convertDartToNative_Dictionary(Map dict) {
519 if (dict == null) return null; 519 if (dict == null) return null;
520 var jsObject = new js.JsObject(js.context['Object']); 520 var jsObject = new js.JsObject(js.context['Object']);
521 dict.forEach((String key, value) { 521 dict.forEach((String key, value) {
522 if (value is List) { 522 if (value is List) {
523 var jsArray = new js.JsArray(); 523 var jsArray = new js.JsArray();
524 value.forEach((elem) { 524 value.forEach((elem) {
525 jsArray.add(elem is Map ? convertDartToNative_Dictionary(elem): elem); 525 jsArray.add(elem is Map ? convertDartToNative_Dictionary(elem): elem);
526 }); 526 });
527 jsObject[key] = jsArray; 527 jsObject[key] = jsArray;
528 } else { 528 } else {
529 jsObject[key] = value; 529 jsObject[key] = value;
530 } 530 }
531 }); 531 });
532 return jsObject; 532 return jsObject;
533 } 533 }
534 534
535 // Converts a Dart list into a JsArray. For the Dartium version only. 535 // Converts a Dart list into a JsArray. For the Dartium version only.
536 convertDartToNative_List(List input) => new js.JsArray()..addAll(input); 536 convertDartToNative_List(List input) => new js.JsArray()..addAll(input);
537 537
538 // Conversion function place holder (currently not used in dart2js or dartium). 538 // Conversion function place holder (currently not used in dart2js or dartium).
539 List convertDartToNative_StringArray(List<String> input) => input; 539 List convertDartToNative_StringArray(List<String> input) => input;
540 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 541 $else
550 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {} 542 class JsoNativeFieldWrapper extends NativeFieldWrapperClass2 {}
551 543
552 unwrap_jso(dartClass_instance) => dartClass_instance; 544 unwrap_jso(dartClass_instance) => dartClass_instance;
553 wrap_jso(jsObject) => jsObject; 545 wrap_jso(jsObject) => jsObject;
554 make_dart_rectangle(r) => r; 546 make_dart_rectangle(r) => r;
555 convertDartToNative_Dictionary(Map dict) => dict; 547 convertDartToNative_Dictionary(Map dict) => dict;
556 List convertDartToNative_StringArray(List<String> input) => input; 548 List convertDartToNative_StringArray(List<String> input) => input;
557 convertDartToNative_List(List input) => input; 549 convertDartToNative_List(List input) => input;
558 550
559 $endif 551 $endif
OLDNEW
« no previous file with comments | « tools/dom/scripts/systemnative.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698