OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // Native testing library. Provides support for mock @Native classes and | |
6 // collects common imports. | |
7 | |
8 | |
9 import "package:expect/expect.dart"; | |
10 import 'dart:_js_helper' show Native; | |
11 | |
12 export "package:expect/expect.dart"; | |
13 export 'dart:_js_helper' show Creates, Native, JSName, Returns; | |
14 export 'dart:_foreign_helper' show JS; | |
15 | |
16 void _setup() native r''' | |
17 ((function() { | |
18 var toStringResultProperty = "_toStringResult"; | |
19 var objectToStringMethod = Object.prototype.toString; | |
20 | |
21 Object.prototype.toString = function() { | |
22 if (this != null) { | |
23 var constructor = this.constructor; | |
24 if (constructor != null) { | |
25 var result = constructor[toStringResultProperty]; | |
26 if (typeof result == "string") return result; | |
27 } | |
28 } | |
29 return objectToStringMethod.call(this); | |
30 } | |
31 | |
32 // To mock a @Native class with JavaScript constructor `Foo`, add | |
33 // | |
34 // self.nativeConstructor(Foo); | |
35 // | |
36 // to the JavaScript code. | |
37 self.nativeConstructor = function(constructor, opt_name) { | |
38 var toStringResult = "[object " + (opt_name || constructor.name) + "]"; | |
39 constructor[toStringResultProperty] = toStringResult; | |
40 } | |
41 })()); | |
42 '''; | |
43 | |
44 void nativeTesting() { | |
45 _setup(); | |
46 } | |
47 | |
48 @NoInline() | |
49 @AssumeDynamic() | |
50 confuse(x) => x; | |
OLD | NEW |