| OLD | NEW |
| 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 part of html; | 5 part of html; |
| 6 | 6 |
| 7 class _ConsoleVariables { | 7 class _ConsoleVariables { |
| 8 Map<String, Object> _data = new Map<String, Object>(); | 8 Map<String, Object> _data = new Map<String, Object>(); |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 static String addTrailingDot(String str) => '${str}.'; | 388 static String addTrailingDot(String str) => '${str}.'; |
| 389 | 389 |
| 390 static String demangle(String str) { | 390 static String demangle(String str) { |
| 391 var atPos = str.indexOf('@'); | 391 var atPos = str.indexOf('@'); |
| 392 return atPos == -1 ? str : str.substring(0, atPos); | 392 return atPos == -1 ? str : str.substring(0, atPos); |
| 393 } | 393 } |
| 394 | 394 |
| 395 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError; | 395 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError; |
| 396 | 396 |
| 397 static bool _isBuiltinType(ClassMirror cls) { | |
| 398 // TODO(vsm): Find a less hackish way to do this. | |
| 399 LibraryMirror lib = cls.owner; | |
| 400 String libName = lib.uri.toString(); | |
| 401 return libName.startsWith('dart:'); | |
| 402 } | |
| 403 | |
| 404 static void register(Document document, String tag, Type type, | 397 static void register(Document document, String tag, Type type, |
| 405 String extendsTagName) { | 398 String extendsTagName) { |
| 406 // TODO(vsm): Move these checks into native code. | 399 var nativeClass = _validateCustomType(type); |
| 407 ClassMirror cls = reflectClass(type); | |
| 408 if (_isBuiltinType(cls)) { | |
| 409 throw new UnsupportedError("Invalid custom element from ${(cls.owner as Li
braryMirror).uri}."); | |
| 410 } | |
| 411 var className = MirrorSystem.getName(cls.simpleName); | |
| 412 var createdConstructor = cls.declarations[new Symbol('$className.created')]; | |
| 413 if (createdConstructor == null || | |
| 414 createdConstructor is! MethodMirror || | |
| 415 !createdConstructor.isConstructor) { | |
| 416 throw new UnsupportedError( | |
| 417 'Class is missing constructor $className.created'); | |
| 418 } | |
| 419 | 400 |
| 420 if (createdConstructor.parameters.length > 0) { | |
| 421 throw new UnsupportedError( | |
| 422 'Constructor $className.created must take zero arguments'); | |
| 423 } | |
| 424 | |
| 425 Symbol objectName = reflectClass(Object).qualifiedName; | |
| 426 bool isRoot(ClassMirror cls) => | |
| 427 cls == null || cls.qualifiedName == objectName; | |
| 428 Symbol elementName = reflectClass(HtmlElement).qualifiedName; | |
| 429 bool isElement(ClassMirror cls) => | |
| 430 cls != null && cls.qualifiedName == elementName; | |
| 431 ClassMirror superClass = cls.superclass; | |
| 432 ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null; | |
| 433 while(!isRoot(superClass) && !isElement(superClass)) { | |
| 434 superClass = superClass.superclass; | |
| 435 if (nativeClass == null && _isBuiltinType(superClass)) { | |
| 436 nativeClass = superClass; | |
| 437 } | |
| 438 } | |
| 439 if (extendsTagName == null) { | 401 if (extendsTagName == null) { |
| 440 if (nativeClass.reflectedType != HtmlElement) { | 402 if (nativeClass.reflectedType != HtmlElement) { |
| 441 throw new UnsupportedError('Class must provide extendsTag if base ' | 403 throw new UnsupportedError('Class must provide extendsTag if base ' |
| 442 'native class is not HTMLElement'); | 404 'native class is not HTMLElement'); |
| 443 } | 405 } |
| 444 } | 406 } |
| 445 | 407 |
| 446 _register(document, tag, type, extendsTagName); | 408 _register(document, tag, type, extendsTagName); |
| 447 } | 409 } |
| 448 | 410 |
| 449 static void _register(Document document, String tag, Type customType, | 411 static void _register(Document document, String tag, Type customType, |
| 450 String extendsTagName) native "Utils_register"; | 412 String extendsTagName) native "Utils_register"; |
| 451 | 413 |
| 452 static Element createElement(Document document, String tagName) native "Utils_
createElement"; | 414 static Element createElement(Document document, String tagName) native "Utils_
createElement"; |
| 453 | 415 |
| 454 static void initializeCustomElement(HtmlElement element) native "Utils_initial
izeCustomElement"; | 416 static void initializeCustomElement(HtmlElement element) native "Utils_initial
izeCustomElement"; |
| 417 |
| 418 static void changeElementWrapper(HtmlElement element, Type type) native "Utils
_changeElementWrapper"; |
| 455 } | 419 } |
| 456 | 420 |
| 457 class _DOMWindowCrossFrame extends NativeFieldWrapperClass2 implements | 421 class _DOMWindowCrossFrame extends NativeFieldWrapperClass2 implements |
| 458 WindowBase { | 422 WindowBase { |
| 459 _DOMWindowCrossFrame.internal(); | 423 _DOMWindowCrossFrame.internal(); |
| 460 | 424 |
| 461 // Fields. | 425 // Fields. |
| 462 HistoryBase get history native "Window_history_cross_frame_Getter"; | 426 HistoryBase get history native "Window_history_cross_frame_Getter"; |
| 463 LocationBase get location native "Window_location_cross_frame_Getter"; | 427 LocationBase get location native "Window_location_cross_frame_Getter"; |
| 464 bool get closed native "Window_closed_Getter"; | 428 bool get closed native "Window_closed_Getter"; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 _scheduleImmediateHelper._schedule(callback); | 579 _scheduleImmediateHelper._schedule(callback); |
| 616 }; | 580 }; |
| 617 | 581 |
| 618 get _pureIsolateScheduleImmediateClosure => ((void callback()) => | 582 get _pureIsolateScheduleImmediateClosure => ((void callback()) => |
| 619 throw new UnimplementedError("scheduleMicrotask in background isolates " | 583 throw new UnimplementedError("scheduleMicrotask in background isolates " |
| 620 "are not supported in the browser")); | 584 "are not supported in the browser")); |
| 621 | 585 |
| 622 void _initializeCustomElement(Element e) { | 586 void _initializeCustomElement(Element e) { |
| 623 _Utils.initializeCustomElement(e); | 587 _Utils.initializeCustomElement(e); |
| 624 } | 588 } |
| OLD | NEW |