da01ce02fc
Changes in type hierarchy will have JavaScriptObject as the new parent class of interop and native types instead. Also modifies js_interop_constructor_name tests to reflect addition of static interop. Change-Id: I74957ca89aea1726a01e0677548fbb3c5c981323 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215949 Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com>
58 lines
1.3 KiB
Dart
58 lines
1.3 KiB
Dart
// Copyright (c) 2020, 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.
|
|
|
|
@JS()
|
|
library util;
|
|
|
|
import 'package:js/js.dart';
|
|
|
|
@JS()
|
|
external void eval(String code);
|
|
|
|
@JS()
|
|
external makeDiv(String text);
|
|
|
|
// Static error to name @JS class the same as a @Native class, so we use a
|
|
// namespace `Foo` to avoid conflicting with the native class.
|
|
@JS('Foo.HTMLDivElement')
|
|
class HTMLDivElement {
|
|
external String bar();
|
|
}
|
|
|
|
@JS('Foo.HTMLDivElement')
|
|
@staticInterop
|
|
class StaticHTMLDivElement {}
|
|
|
|
extension StaticHTMLDivElementExtension on StaticHTMLDivElement {
|
|
external String bar();
|
|
external StaticHTMLDivElement cloneNode(bool? deep);
|
|
}
|
|
|
|
@pragma('dart2js:noInline')
|
|
@pragma('dart2js:assumeDynamic')
|
|
confuse(x) => x;
|
|
|
|
void setUpJS() {
|
|
eval(r"""
|
|
var Foo = {}
|
|
|
|
// A constructor function with the same name as a HTML element.
|
|
Foo.HTMLDivElement = function(a) {
|
|
this.a = a;
|
|
}
|
|
|
|
Foo.HTMLDivElement.prototype.bar = function() {
|
|
return this.a;
|
|
}
|
|
|
|
Foo.HTMLDivElement.prototype.toString = function() {
|
|
return "HTMLDivElement(" + this.a + ")";
|
|
}
|
|
|
|
self.makeDiv = function(text) {
|
|
return new Foo.HTMLDivElement(text);
|
|
}
|
|
""");
|
|
}
|