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

Unified Diff: tests/compiler/dart2js_native/native_testing.dart

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 years, 1 month 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: tests/compiler/dart2js_native/native_testing.dart
diff --git a/tests/compiler/dart2js_native/native_testing.dart b/tests/compiler/dart2js_native/native_testing.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8d90b0b0475c5de10225b4c81fef46b091449122
--- /dev/null
+++ b/tests/compiler/dart2js_native/native_testing.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2016, 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.
+
+// Native testing library. Provides support for mock @Native classes and
+// collects common imports.
+
+
+import "package:expect/expect.dart";
+import 'dart:_js_helper' show Native;
+
+export "package:expect/expect.dart";
+export 'dart:_js_helper' show Creates, Native, JSName, Returns;
+export 'dart:_foreign_helper' show JS;
+
+void _setup() native r'''
+((function() {
+ var toStringResultProperty = "_toStringResult";
+ var objectToStringMethod = Object.prototype.toString;
+
+ Object.prototype.toString = function() {
+ if (this != null) {
+ var constructor = this.constructor;
+ if (constructor != null) {
+ var result = constructor[toStringResultProperty];
+ if (typeof result == "string") return result;
+ }
+ }
+ return objectToStringMethod.call(this);
+ }
+
+ // To mock a @Native class with JavaScript constructor `Foo`, add
+ //
+ // self.nativeConstructor(Foo);
+ //
+ // to the JavaScript code.
+ self.nativeConstructor = function(constructor, opt_name) {
+ var toStringResult = "[object " + (opt_name || constructor.name) + "]";
+ constructor[toStringResultProperty] = toStringResult;
+ }
+})());
+''';
+
+void nativeTesting() {
+ _setup();
+}
+
+@NoInline()
+@AssumeDynamic()
+confuse(x) => x;

Powered by Google App Engine
This is Rietveld 408576698