| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 to see if a Dart class name is confused with dispatch tag. Both class A | 5 // Test to see if a Dart class name is confused with dispatch tag. Both class A |
| 6 // and class Z have a JavaScript constructor named "A". The dynamic native | 6 // and class Z have a JavaScript constructor named "A". The dynamic native |
| 7 // class dispatch hook on Object.prototype should avoid patching the Dart class | 7 // class dispatch hook on Object.prototype should avoid patching the Dart class |
| 8 // A. This could be done by renaming the Dart constructor or by being able to | 8 // A. This could be done by renaming the Dart constructor or by being able to |
| 9 // check that objects are Dart classes. | 9 // check that objects are Dart classes. |
| 10 | 10 |
| 11 import "native_testing.dart"; | 11 import "native_testing.dart"; |
| 12 | 12 |
| 13 class A {} | 13 class A {} |
| 14 | 14 |
| 15 @Native("A") | 15 @Native("A") |
| 16 class Z { | 16 class Z { |
| 17 foo() => 100; | 17 foo() => 100; |
| 18 } | 18 } |
| 19 | 19 |
| 20 makeZ() native; | 20 makeZ() native; |
| 21 | 21 |
| 22 void setup() native """ | 22 void setup() { |
| 23 function A(){} | 23 JS('', r""" |
| 24 makeZ = function(){return new A}; | 24 (function(){ |
| 25 self.nativeConstructor(A); | 25 function A(){} |
| 26 """; | 26 makeZ = function(){return new A()}; |
| 27 self.nativeConstructor(A); |
| 28 })()"""); |
| 29 } |
| 27 | 30 |
| 28 main() { | 31 main() { |
| 29 nativeTesting(); | 32 nativeTesting(); |
| 30 setup(); | 33 setup(); |
| 31 | 34 |
| 32 var a = new A(); | 35 var a = new A(); |
| 33 var z = makeZ(); | 36 var z = makeZ(); |
| 34 | 37 |
| 35 Expect.equals(100, z.foo()); | 38 Expect.equals(100, z.foo()); |
| 36 | 39 |
| 37 Expect.throws(() => a.foo(), (ex) => ex is NoSuchMethodError); | 40 Expect.throws(() => a.foo(), (ex) => ex is NoSuchMethodError); |
| 38 } | 41 } |
| OLD | NEW |