OLD | NEW |
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) { | 7 _callConstructor(constructor, interceptor) { |
8 return (receiver) { | 8 return (receiver) { |
| 9 setNativeSubclassDispatchRecord(receiver, interceptor); |
| 10 |
9 return JS('', '#(#)', constructor, receiver); | 11 return JS('', '#(#)', constructor, receiver); |
10 }; | 12 }; |
11 } | 13 } |
12 | 14 |
13 _callEnteredView(receiver) { | 15 _callEnteredView(receiver) { |
14 return receiver.enteredView(); | 16 return receiver.enteredView(); |
15 } | 17 } |
16 | 18 |
17 _callLeftView(receiver) { | 19 _callLeftView(receiver) { |
18 return receiver.leftView(); | 20 return receiver.leftView(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // }); | 57 // }); |
56 // document.register('x-foo', { prototype: proto }); | 58 // document.register('x-foo', { prototype: proto }); |
57 // ... | 59 // ... |
58 // var e = document.createElement('x-foo'); | 60 // var e = document.createElement('x-foo'); |
59 | 61 |
60 var interceptorClass = findInterceptorConstructorForType(type); | 62 var interceptorClass = findInterceptorConstructorForType(type); |
61 if (interceptorClass == null) { | 63 if (interceptorClass == null) { |
62 throw new ArgumentError(type); | 64 throw new ArgumentError(type); |
63 } | 65 } |
64 | 66 |
| 67 var interceptor = JS('=Object', '#.prototype', interceptorClass); |
| 68 |
65 var constructor = findConstructorForNativeSubclassType(type, 'created'); | 69 var constructor = findConstructorForNativeSubclassType(type, 'created'); |
66 if (constructor == null) { | 70 if (constructor == null) { |
67 throw new ArgumentError("$type has no constructor called 'created'"); | 71 throw new ArgumentError("$type has no constructor called 'created'"); |
68 } | 72 } |
69 | 73 |
70 // Workaround for 13190- use an article element to ensure that HTMLElement's | 74 // Workaround for 13190- use an article element to ensure that HTMLElement's |
71 // interceptor is resolved correctly. | 75 // interceptor is resolved correctly. |
72 getNativeInterceptor(new Element.tag('article')); | 76 getNativeInterceptor(new Element.tag('article')); |
73 | 77 |
74 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass); | 78 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass); |
(...skipping 12 matching lines...) Expand all Loading... |
87 throw new UnsupportedError('extendsTag does not match base native class'); | 91 throw new UnsupportedError('extendsTag does not match base native class'); |
88 } | 92 } |
89 } | 93 } |
90 | 94 |
91 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); | 95 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); |
92 | 96 |
93 var properties = JS('=Object', '{}'); | 97 var properties = JS('=Object', '{}'); |
94 | 98 |
95 JS('void', '#.createdCallback = #', properties, | 99 JS('void', '#.createdCallback = #', properties, |
96 JS('=Object', '{value: #}', | 100 JS('=Object', '{value: #}', |
97 _makeCallbackMethod(_callConstructor(constructor)))); | 101 _makeCallbackMethod(_callConstructor(constructor, interceptor)))); |
98 JS('void', '#.enteredViewCallback = #', properties, | 102 JS('void', '#.enteredViewCallback = #', properties, |
99 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView))); | 103 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView))); |
100 JS('void', '#.leftViewCallback = #', properties, | 104 JS('void', '#.leftViewCallback = #', properties, |
101 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView))); | 105 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView))); |
102 JS('void', '#.attributeChangedCallback = #', properties, | 106 JS('void', '#.attributeChangedCallback = #', properties, |
103 JS('=Object', '{value: #}', _makeCallbackMethod3(_callAttributeChanged))); | 107 JS('=Object', '{value: #}', _makeCallbackMethod3(_callAttributeChanged))); |
104 | 108 |
105 // TODO(blois): Bug 13220- remove once transition is complete | 109 // TODO(blois): Bug 13220- remove once transition is complete |
106 JS('void', '#.enteredDocumentCallback = #', properties, | 110 JS('void', '#.enteredDocumentCallback = #', properties, |
107 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView))); | 111 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView))); |
108 JS('void', '#.leftDocumentCallback = #', properties, | 112 JS('void', '#.leftDocumentCallback = #', properties, |
109 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView))); | 113 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView))); |
110 | 114 |
111 var baseProto = JS('=Object', '#.prototype', baseConstructor); | 115 var baseProto = JS('=Object', '#.prototype', baseConstructor); |
112 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties); | 116 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties); |
113 | 117 |
114 var interceptor = JS('=Object', '#.prototype', interceptorClass); | |
115 | |
116 setNativeSubclassDispatchRecord(proto, interceptor); | 118 setNativeSubclassDispatchRecord(proto, interceptor); |
117 | 119 |
118 var options = JS('=Object', '{prototype: #}', proto); | 120 var options = JS('=Object', '{prototype: #}', proto); |
119 | 121 |
120 if (baseClassName != 'HTMLElement') { | 122 if (baseClassName != 'HTMLElement') { |
121 if (extendsTagName != null) { | 123 if (extendsTagName != null) { |
122 JS('=Object', '#.extends = #', options, extendsTagName); | 124 JS('=Object', '#.extends = #', options, extendsTagName); |
123 } | 125 } |
124 } | 126 } |
125 | 127 |
126 JS('void', '#.register(#, #)', document, tag, options); | 128 JS('void', '#.register(#, #)', document, tag, options); |
127 } | 129 } |
128 | 130 |
129 //// Called by Element.created to do validation & initialization. | 131 //// Called by Element.created to do validation & initialization. |
130 void _initializeCustomElement(Element e) { | 132 void _initializeCustomElement(Element e) { |
131 // TODO(blois): Add validation that this is only in response to an upgrade. | 133 // TODO(blois): Add validation that this is only in response to an upgrade. |
132 } | 134 } |
OLD | NEW |