-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dart:html] Change js_interop_constuctor_name tests to use namespace
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 <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
- Loading branch information
1 parent
bc43d06
commit c7b6e6a
Showing
20 changed files
with
116 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
tests/lib/html/js_interop_constructor_name/error1_test.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
tests/lib/html/js_interop_constructor_name/error2_test.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
tests/lib/html/js_interop_constructor_name/method_test.html
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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); | ||
} | ||
"""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
tests/lib_2/html/js_interop_constructor_name/div_test.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.