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/src/dart2js_CustomElementSupport.dart

Issue 2827793002: Format all files under tools and utils directory. (Closed)
Patch Set: Format all files under tools and utils directory. Created 3 years, 8 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/src/dart2js_CssClassSet.dart ('k') | tools/dom/src/dart2js_DOMImplementation.dart » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart.dom.html; 5 part of dart.dom.html;
6 6
7 _callConstructor(constructor, interceptor) { 7 _callConstructor(constructor, interceptor) {
8 return (receiver) { 8 return (receiver) {
9 setNativeSubclassDispatchRecord(receiver, interceptor); 9 setNativeSubclassDispatchRecord(receiver, interceptor);
10 10
11 // Mirrors uses the constructor property to cache lookups, so we need it to 11 // Mirrors uses the constructor property to cache lookups, so we need it to
12 // be set correctly, including on IE where it is not automatically picked 12 // be set correctly, including on IE where it is not automatically picked
13 // up from the __proto__. 13 // up from the __proto__.
14 JS('', '#.constructor = #.__proto__.constructor', receiver, receiver); 14 JS('', '#.constructor = #.__proto__.constructor', receiver, receiver);
15 return JS('', '#(#)', constructor, receiver); 15 return JS('', '#(#)', constructor, receiver);
16 }; 16 };
17 } 17 }
18 18
19 _callAttached(receiver) { 19 _callAttached(receiver) {
20 return receiver.attached(); 20 return receiver.attached();
21 } 21 }
22 22
23 _callDetached(receiver) { 23 _callDetached(receiver) {
24 return receiver.detached(); 24 return receiver.detached();
25 } 25 }
26 _callAttributeChanged(receiver, name, oldValue, newValue) { 26
27 _callAttributeChanged(receiver, name, oldValue, newValue) {
27 return receiver.attributeChanged(name, oldValue, newValue); 28 return receiver.attributeChanged(name, oldValue, newValue);
28 } 29 }
29 30
30 _makeCallbackMethod(callback) { 31 _makeCallbackMethod(callback) {
31 return JS('', 32 return JS(
33 '',
32 '''((function(invokeCallback) { 34 '''((function(invokeCallback) {
33 return function() { 35 return function() {
34 return invokeCallback(this); 36 return invokeCallback(this);
35 }; 37 };
36 })(#))''', 38 })(#))''',
37 convertDartClosureToJS(callback, 1)); 39 convertDartClosureToJS(callback, 1));
38 } 40 }
39 41
40 _makeCallbackMethod3(callback) { 42 _makeCallbackMethod3(callback) {
41 return JS('', 43 return JS(
44 '',
42 '''((function(invokeCallback) { 45 '''((function(invokeCallback) {
43 return function(arg1, arg2, arg3) { 46 return function(arg1, arg2, arg3) {
44 return invokeCallback(this, arg1, arg2, arg3); 47 return invokeCallback(this, arg1, arg2, arg3);
45 }; 48 };
46 })(#))''', 49 })(#))''',
47 convertDartClosureToJS(callback, 4)); 50 convertDartClosureToJS(callback, 4));
48 } 51 }
49 52
50 /// Checks whether the given [element] correctly extends from the native class 53 /// Checks whether the given [element] correctly extends from the native class
51 /// with the given [baseClassName]. This method will throw if the base class 54 /// with the given [baseClassName]. This method will throw if the base class
52 /// doesn't match, except when the element extends from `template` and it's base 55 /// doesn't match, except when the element extends from `template` and it's base
53 /// class is `HTMLUnknownElement`. This exclusion is needed to support extension 56 /// class is `HTMLUnknownElement`. This exclusion is needed to support extension
54 /// of template elements (used heavily in Polymer 1.0) on IE11 when using the 57 /// of template elements (used heavily in Polymer 1.0) on IE11 when using the
55 /// webcomponents-lite.js polyfill. 58 /// webcomponents-lite.js polyfill.
56 void _checkExtendsNativeClassOrTemplate( 59 void _checkExtendsNativeClassOrTemplate(
57 Element element, String extendsTag, String baseClassName) { 60 Element element, String extendsTag, String baseClassName) {
58 if (!JS('bool', '(# instanceof window[#])', element, baseClassName) && 61 if (!JS('bool', '(# instanceof window[#])', element, baseClassName) &&
59 !((extendsTag == 'template' && 62 !((extendsTag == 'template' &&
60 JS('bool', '(# instanceof window["HTMLUnknownElement"])', element)))) { 63 JS('bool', '(# instanceof window["HTMLUnknownElement"])',
64 element)))) {
61 throw new UnsupportedError('extendsTag does not match base native class'); 65 throw new UnsupportedError('extendsTag does not match base native class');
62 } 66 }
63 } 67 }
64 68
65 void _registerCustomElement(context, document, String tag, Type type, 69 void _registerCustomElement(
66 String extendsTagName) { 70 context, document, String tag, Type type, String extendsTagName) {
67 // Function follows the same pattern as the following JavaScript code for 71 // Function follows the same pattern as the following JavaScript code for
68 // registering a custom element. 72 // registering a custom element.
69 // 73 //
70 // var proto = Object.create(HTMLElement.prototype, { 74 // var proto = Object.create(HTMLElement.prototype, {
71 // createdCallback: { 75 // createdCallback: {
72 // value: function() { 76 // value: function() {
73 // window.console.log('here'); 77 // window.console.log('here');
74 // } 78 // }
75 // } 79 // }
76 // }); 80 // });
(...skipping 29 matching lines...) Expand all
106 } 110 }
107 } else { 111 } else {
108 var element = document.createElement(extendsTagName); 112 var element = document.createElement(extendsTagName);
109 _checkExtendsNativeClassOrTemplate(element, extendsTagName, baseClassName); 113 _checkExtendsNativeClassOrTemplate(element, extendsTagName, baseClassName);
110 } 114 }
111 115
112 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); 116 var baseConstructor = JS('=Object', '#[#]', context, baseClassName);
113 117
114 var properties = JS('=Object', '{}'); 118 var properties = JS('=Object', '{}');
115 119
116 JS('void', '#.createdCallback = #', properties, 120 JS(
121 'void',
122 '#.createdCallback = #',
123 properties,
117 JS('=Object', '{value: #}', 124 JS('=Object', '{value: #}',
118 _makeCallbackMethod(_callConstructor(constructor, interceptor)))); 125 _makeCallbackMethod(_callConstructor(constructor, interceptor))));
119 JS('void', '#.attachedCallback = #', properties, 126 JS('void', '#.attachedCallback = #', properties,
120 JS('=Object', '{value: #}', _makeCallbackMethod(_callAttached))); 127 JS('=Object', '{value: #}', _makeCallbackMethod(_callAttached)));
121 JS('void', '#.detachedCallback = #', properties, 128 JS('void', '#.detachedCallback = #', properties,
122 JS('=Object', '{value: #}', _makeCallbackMethod(_callDetached))); 129 JS('=Object', '{value: #}', _makeCallbackMethod(_callDetached)));
123 JS('void', '#.attributeChangedCallback = #', properties, 130 JS('void', '#.attributeChangedCallback = #', properties,
124 JS('=Object', '{value: #}', _makeCallbackMethod3(_callAttributeChanged))); 131 JS('=Object', '{value: #}', _makeCallbackMethod3(_callAttributeChanged)));
125 132
126 var baseProto = JS('=Object', '#.prototype', baseConstructor); 133 var baseProto = JS('=Object', '#.prototype', baseConstructor);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // Only exact type matches are supported- cannot be a subclass. 194 // Only exact type matches are supported- cannot be a subclass.
188 if (element.runtimeType != _nativeType) { 195 if (element.runtimeType != _nativeType) {
189 throw new ArgumentError('element is not subclass of $_nativeType'); 196 throw new ArgumentError('element is not subclass of $_nativeType');
190 } 197 }
191 198
192 setNativeSubclassDispatchRecord(element, _interceptor); 199 setNativeSubclassDispatchRecord(element, _interceptor);
193 JS('', '#(#)', _constructor, element); 200 JS('', '#(#)', _constructor, element);
194 return element; 201 return element;
195 } 202 }
196 } 203 }
OLDNEW
« no previous file with comments | « tools/dom/src/dart2js_CssClassSet.dart ('k') | tools/dom/src/dart2js_DOMImplementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698