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

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..10b0f1b7a531ade80ee1aac3455c5e47a814d89f
--- /dev/null
+++ b/tools/dom/src/dart2js_CustomElementSupport.dart
@@ -0,0 +1,74 @@
+// 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 html;
blois 2013/08/09 16:06:23 should be dart.dom.html
sra1 2013/08/12 23:31:26 Done.
+
+
+/*
+ var proto = Object.create(HTMLElement.prototype, {
+ createdCallback: {
+ get: function() {
+ window.console.log('here');
+ }
+ }
+ });
+ document.register('x-foo', {
+ prototype: proto
+ });
+
+ var e = document.createElement('x-foo');
+
+ */
+
+callOnCreated(receiver) {
blois 2013/08/09 16:06:23 Can these either be private or not top-level?
sra1 2013/08/12 23:31:26 Done.
+ return receiver.onCreated();
+}
+
+makeCreatedCallbackMethod() {
+ return JS('',
+ '''((function(invokeCallback) {
blois 2013/08/09 16:06:23 Is this outer function closure needed?
sra1 2013/08/12 23:31:26 Yes, see https://code.google.com/p/dart/source/bro
+ return function() {
+ return invokeCallback(this);
+ };
+ })(#))''',
+ convertDartClosureToJS(callOnCreated, 1));
+}
+
+void registerCustomElement(context, document, String tag, Type type) {
+ 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));
+
+ print('Registered $type');
blois 2013/08/09 16:06:23 Debugging
sra1 2013/08/12 23:31:26 Done.
+}
« 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