| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 // Test that Frog does not try to put JS get and set properties on a hidden | |
| 6 // native class. | |
| 7 // | |
| 8 // I.e If B was not a hidden native class, Frog could generate the following: | |
| 9 // | |
| 10 // Object.defineProperty(B.prototype, "field", { | |
| 11 // get: B.prototype.get$field, | |
| 12 // set: B.prototype.set$field | |
| 13 // }); | |
| 14 // | |
| 15 // This is clearly not possible when the prototype of B is hidden. | |
| 16 | |
| 17 class A native "*A" { | |
| 18 int field; | |
| 19 } | |
| 20 | |
| 21 class B extends A native "*B" { | |
| 22 int get field() native 'return this.field*100'; | |
| 23 void set field(int x) { super.field = x; } | |
| 24 } | |
| 25 | |
| 26 | |
| 27 makeA() native; | |
| 28 makeB() native; | |
| 29 | |
| 30 void setup1() native """ | |
| 31 // Poison hidden native names 'A' and 'B' to prove the compiler didn't place | |
| 32 // anthing on the hidden native class. | |
| 33 A = null; | |
| 34 B = null; | |
| 35 """; | |
| 36 | |
| 37 void setup2() native """ | |
| 38 // This code is all inside 'setup' and so not accesible from the global scope. | |
| 39 function A(){} | |
| 40 function B(){} | |
| 41 makeA = function(){return new A}; | |
| 42 makeB = function(){return new B}; | |
| 43 """; | |
| 44 | |
| 45 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); | |
| 46 | |
| 47 main() { | |
| 48 setup1(); | |
| 49 setup2(); | |
| 50 | |
| 51 var things = [makeA(), makeB()]; | |
| 52 { | |
| 53 var a = things[inscrutable(0)]; | |
| 54 var b = things[inscrutable(1)]; | |
| 55 | |
| 56 a.field = 2; | |
| 57 Expect.equals(2, a.field); | |
| 58 | |
| 59 b.field = 3; | |
| 60 Expect.equals(300, b.field); | |
| 61 } | |
| 62 | |
| 63 { | |
| 64 A a = things[inscrutable(0)]; | |
| 65 B b = things[inscrutable(1)]; | |
| 66 | |
| 67 a.field = 2; | |
| 68 Expect.equals(2, a.field); | |
| 69 | |
| 70 b.field = 3; | |
| 71 Expect.equals(300, b.field); | |
| 72 } | |
| 73 | |
| 74 { | |
| 75 A a = things[inscrutable(1)]; // Actually a B. | |
| 76 | |
| 77 a.field = 4; | |
| 78 Expect.equals(400, a.field); | |
| 79 } | |
| 80 } | |
| OLD | NEW |