OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Test for initialization of dispatchPropertyName. | 5 // Test for initialization of dispatchPropertyName. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import 'native_testing.dart'; |
8 import 'dart:_foreign_helper' show JS; | |
9 import 'dart:_js_helper' show Native; | |
10 | 8 |
11 @Native("Foo") | 9 @Native("Foo") |
12 class Foo { | 10 class Foo { |
13 String method(String x) native; | 11 String method(String x) native; |
14 } | 12 } |
15 | 13 |
16 makeFoo() native; | 14 makeFoo() native; |
17 | 15 |
18 void setup() native r""" | 16 void setup() native r""" |
19 function Foo() {} | 17 function Foo() {} |
20 Foo.prototype.method = function(x) { return 'Foo ' + x; } | 18 Foo.prototype.method = function(x) { return 'Foo ' + x; } |
21 | 19 |
22 self.makeFoo = function() { return new Foo(); } | 20 self.makeFoo = function() { return new Foo(); } |
| 21 |
| 22 self.nativeConstructor(Foo); |
23 """; | 23 """; |
24 | 24 |
25 | 25 |
26 main() { | 26 main() { |
| 27 nativeTesting(); |
27 setup(); | 28 setup(); |
28 | 29 |
29 // If the dispatchPropertyName is uninitialized, it will be `undefined` or | 30 // If the dispatchPropertyName is uninitialized, it will be `undefined` or |
30 // `null` instead of the secret string or Symbol. These properties on | 31 // `null` instead of the secret string or Symbol. These properties on |
31 // `Object.prototype` will be retrieved by the lookup instead of `undefined` | 32 // `Object.prototype` will be retrieved by the lookup instead of `undefined` |
32 // for the dispatch record. | 33 // for the dispatch record. |
33 JS('', r'self.Object.prototype["undefined"] = {}'); | 34 JS('', r'self.Object.prototype["undefined"] = {}'); |
34 JS('', r'self.Object.prototype["null"] = {}'); | 35 JS('', r'self.Object.prototype["null"] = {}'); |
35 Expect.equals('Foo A', makeFoo().method('A')); | 36 Expect.equals('Foo A', makeFoo().method('A')); |
36 | 37 |
37 // Slightly different version that has malformed dispatch records. | 38 // Slightly different version that has malformed dispatch records. |
38 JS('', r'self.Object.prototype["undefined"] = {p: false}'); | 39 JS('', r'self.Object.prototype["undefined"] = {p: false}'); |
39 JS('', r'self.Object.prototype["null"] = {p: false}'); | 40 JS('', r'self.Object.prototype["null"] = {p: false}'); |
40 Expect.equals('Foo B', makeFoo().method('B')); | 41 Expect.equals('Foo B', makeFoo().method('B')); |
41 } | 42 } |
OLD | NEW |