| // Copyright (c) 2012, 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; |
| |
| class $FACTORYPROVIDER { |
| static $CONSTRUCTOR create$(CONSTRUCTOR)(MutationCallback callback) { |
| |
| // This is a hack to cause MutationRecord to appear to be instantiated. |
| // |
| // MutationCallback has a parameter type List<MutationRecord>. From this we |
| // infer a list is created in the browser, but not the element type, because |
| // other native fields and methods return plain List which is too general |
| // and would imply creating anything. This statement is a work-around. |
| JS('MutationRecord','0'); |
| |
| return _create$(CONSTRUCTOR)(callback); |
| } |
| |
| static $CONSTRUCTOR _create$(CONSTRUCTOR)(MutationCallback callback) native ''' |
| var constructor = |
| window.MutationObserver || window.WebKitMutationObserver || |
| window.MozMutationObserver; |
| return new constructor(callback); |
| '''; |
| |
| // TODO(sra): Dart2js inserts a conversion when a Dart function (i.e. an |
| // object with a call method) is passed to a native method. This is so the |
| // native code sees a JavaScript function. |
| // |
| // This does not happen when a function is 'passed' to a JS-form so it is not |
| // possible to rewrite the above code to, e.g. (simplified): |
| // |
| // static createMutationObserver(MutationCallback callback) => |
| // JS('var', 'new (window.MutationObserver)(#)', callback); |
| } |