c7b6e6aa99
These tests test to make sure that @JS interop classes can have the same name as native classes but in a separate namespace. Since there now exists a static error for @JS classes that have the same name as a @Native class, the class is defined in a separate namespace. This CL also refactors some of the code to avoid duplication and removes html files in favor of `eval`. Change-Id: I5cbba7e4b49ea726234fc86848638cac6ad8065b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176200 Commit-Queue: Srujan Gaddam <srujzs@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Stephen Adams <sra@google.com>
50 lines
1.1 KiB
Dart
50 lines
1.1 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:expect/expect.dart' show NoInline, AssumeDynamic;
|
|
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();
|
|
}
|
|
|
|
@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);
|
|
}
|
|
""");
|
|
}
|