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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/html/html.status ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/dart2js_CustomElementSupport.dart
diff --git a/tools/dom/src/dart2js_CustomElementSupport.dart b/tools/dom/src/dart2js_CustomElementSupport.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a40e81c69a13e304bc5c7d0a0936275308781c3a
--- /dev/null
+++ b/tools/dom/src/dart2js_CustomElementSupport.dart
@@ -0,0 +1,68 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of dart.dom.html;
+
+_callOnCreated(receiver) {
+ return receiver.onCreated();
+}
+
+_makeCreatedCallbackMethod() {
+ return JS('',
+ '''((function(invokeCallback) {
+ return function() {
+ return invokeCallback(this);
+ };
+ })(#))''',
+ convertDartClosureToJS(_callOnCreated, 1));
+}
+
+void _registerCustomElement(context, document, String tag, Type type) {
+ // Function follows the same pattern as the following JavaScript code for
+ // registering a custom element.
+ //
+ // var proto = Object.create(HTMLElement.prototype, {
+ // createdCallback: {
+ // value: function() {
+ // window.console.log('here');
+ // }
+ // }
+ // });
+ // document.register('x-foo', { prototype: proto });
+ // ...
+ // var e = document.createElement('x-foo');
+
+ var interceptorClass = findInterceptorConstructorForType(type);
+ if (interceptorClass == null) {
+ throw new ArgumentError(type);
+ }
+
+ String baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
+ if (baseClassName == null) {
+ throw new ArgumentError(type);
+ }
+ if (baseClassName == 'Element') baseClassName = 'HTMLElement';
+
+ var baseConstructor = JS('=Object', '#[#]', context, baseClassName);
+ if (JS('bool', "typeof(#) != 'function'", baseConstructor)) {
+ throw new ArgumentError(type);
+ }
+
+ var properties = JS('=Object', '{}');
+
+ var jsCreatedCallback = _makeCreatedCallbackMethod();
+
+ JS('void', '#.createdCallback = #', properties,
+ JS('=Object', '{value: #}', jsCreatedCallback));
+
+ var baseProto = JS('=Object', '#.prototype', baseConstructor);
+ var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties);
+
+ var interceptor = JS('=Object', '#.prototype', interceptorClass);
+
+ setNativeSubclassDispatchRecord(proto, interceptor);
+
+ JS('void', '#.register(#, #)',
+ document, tag, JS('', '{prototype: #}', proto));
+}
« 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