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

Unified Diff: pkg/compiler/lib/src/js_backend/native_data.dart

Issue 2150313003: Add JSNative utility class with static methods methods to efficiently manipulate typed JSInterop ob… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix analyzer warnings in js_util_test, skip js_util_test in csp mode and baseline expectations for … Created 4 years, 5 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
Index: pkg/compiler/lib/src/js_backend/native_data.dart
diff --git a/pkg/compiler/lib/src/js_backend/native_data.dart b/pkg/compiler/lib/src/js_backend/native_data.dart
index 67b473b53c5c0badc6dfac4e4a0f9b8ec063bf45..31fe7d69fea1bf11dbf707181e0b4b1361f404e3 100644
--- a/pkg/compiler/lib/src/js_backend/native_data.dart
+++ b/pkg/compiler/lib/src/js_backend/native_data.dart
@@ -35,6 +35,10 @@ class NativeData {
Map<MemberElement, NativeBehavior> nativeFieldStoreBehavior =
<FieldElement, NativeBehavior>{};
+ /// Prefix used to escape JS names that are not valid Dart names
+ /// when using JSInterop.
+ static const String _jsInteropEscapePrefix = r'JS$';
+
/// Returns `true` if [element] is explicitly marked as part of JsInterop.
bool _isJsInterop(Element element) {
return jsInteropNames.containsKey(element.declaration);
@@ -93,7 +97,7 @@ class NativeData {
if (jsInteropName != null && jsInteropName.isNotEmpty) {
return jsInteropName;
}
- return element.isLibrary ? 'self' : element.name;
+ return element.isLibrary ? 'self' : getUnescapedJSInteropName(element.name);
}
/// Computes the name for [element] to use in the generated JavaScript. This
@@ -216,4 +220,12 @@ class NativeData {
FieldElement field, NativeBehavior behavior) {
nativeFieldStoreBehavior[field] = behavior;
}
+
+ /// Apply JS$ escaping scheme to convert possible escaped Dart names into
+ /// JS names.
+ String getUnescapedJSInteropName(String name) {
+ return name.startsWith(_jsInteropEscapePrefix)
+ ? name.substring(_jsInteropEscapePrefix.length)
+ : name;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698