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

Side by Side Diff: tools/dom/src/dart2js_CustomElementSupport.dart

Issue 22642002: 'extends Element' (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « tests/html/html.status ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of dart.dom.html;
6
7 _callOnCreated(receiver) {
8 return receiver.onCreated();
9 }
10
11 _makeCreatedCallbackMethod() {
12 return JS('',
13 '''((function(invokeCallback) {
14 return function() {
15 return invokeCallback(this);
16 };
17 })(#))''',
18 convertDartClosureToJS(_callOnCreated, 1));
19 }
20
21 void _registerCustomElement(context, document, String tag, Type type) {
22 // Function follows the same pattern as the following JavaScript code for
23 // registering a custom element.
24 //
25 // var proto = Object.create(HTMLElement.prototype, {
26 // createdCallback: {
27 // value: function() {
28 // window.console.log('here');
29 // }
30 // }
31 // });
32 // document.register('x-foo', { prototype: proto });
33 // ...
34 // var e = document.createElement('x-foo');
35
36 var interceptorClass = findInterceptorConstructorForType(type);
37 if (interceptorClass == null) {
38 throw new ArgumentError(type);
39 }
40
41 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
42 if (baseClassName == null) {
43 throw new ArgumentError(type);
44 }
45 if (baseClassName == 'Element') baseClassName = 'HTMLElement';
46
47 var baseConstructor = JS('=Object', '#[#]', context, baseClassName);
48 if (JS('bool', "typeof(#) != 'function'", baseConstructor)) {
49 throw new ArgumentError(type);
50 }
51
52 var properties = JS('=Object', '{}');
53
54 var jsCreatedCallback = _makeCreatedCallbackMethod();
55
56 JS('void', '#.createdCallback = #', properties,
57 JS('=Object', '{value: #}', jsCreatedCallback));
58
59 var baseProto = JS('=Object', '#.prototype', baseConstructor);
60 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties);
61
62 var interceptor = JS('=Object', '#.prototype', interceptorClass);
63
64 setNativeSubclassDispatchRecord(proto, interceptor);
65
66 JS('void', '#.register(#, #)',
67 document, tag, JS('', '{prototype: #}', proto));
68 }
OLDNEW
« no previous file with comments | « tests/html/html.status ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698