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