mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:47:03 +00:00
912005267d
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Stephen Adams <sra@google.com>
74 lines
1.9 KiB
Dart
74 lines
1.9 KiB
Dart
// Copyright (c) 2013, 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.
|
|
|
|
import "native_testing.dart";
|
|
|
|
// Test that native classes can use ordinary Dart classes with fields
|
|
// as mixins.
|
|
|
|
@Native("A")
|
|
class A {
|
|
var foo;
|
|
}
|
|
|
|
@Native("B")
|
|
class B extends A with M1, M2 {
|
|
var bar;
|
|
}
|
|
|
|
class M1 {
|
|
var baz; // This field is not a native field, even when mixed in.
|
|
}
|
|
|
|
class M2 {
|
|
var bar;
|
|
var buz;
|
|
}
|
|
|
|
A makeA() native;
|
|
B makeB() native;
|
|
|
|
void setup() {
|
|
JS('', r"""
|
|
(function(){
|
|
function A() {this.foo='A-foo';}
|
|
function B() {A.call(this);this.bar='B-bar';this.baz='M1-baz';}
|
|
self.makeA = function(){return new A()};
|
|
self.makeB = function(){return new B()};
|
|
|
|
self.nativeConstructor(A);
|
|
self.nativeConstructor(B);
|
|
})()""");
|
|
applyTestExtensions(['A', 'B']);
|
|
}
|
|
|
|
main() {
|
|
nativeTesting();
|
|
setup();
|
|
A a = makeA();
|
|
Expect.equals("A-foo", a.foo);
|
|
Expect.throws(() => (a as dynamic).bar, (e) => e is NoSuchMethodError);
|
|
Expect.throws(() => (a as dynamic).baz, (e) => e is NoSuchMethodError);
|
|
Expect.throws(() => (a as dynamic).buz, (e) => e is NoSuchMethodError);
|
|
|
|
B b = makeB();
|
|
Expect.equals("A-foo", b.foo);
|
|
Expect.equals("B-bar", b.bar);
|
|
// Expect.equals("M1-baz", b.baz); // not true, see M1.
|
|
Expect.isNull(b.baz); // native b.baz is not the same as dart b.baz.
|
|
Expect.isNull(b.buz);
|
|
|
|
M1 m1 = new M1();
|
|
Expect.throws(() => (m1 as dynamic).foo, (e) => e is NoSuchMethodError);
|
|
Expect.throws(() => (m1 as dynamic).bar, (e) => e is NoSuchMethodError);
|
|
Expect.isNull(m1.baz);
|
|
Expect.throws(() => (m1 as dynamic).buz, (e) => e is NoSuchMethodError);
|
|
|
|
M2 m2 = new M2();
|
|
Expect.throws(() => (m2 as dynamic).foo, (e) => e is NoSuchMethodError);
|
|
Expect.isNull(m2.bar);
|
|
Expect.throws(() => (m2 as dynamic).baz, (e) => e is NoSuchMethodError);
|
|
Expect.isNull(m2.buz);
|
|
}
|