blob: 62911e2c25d0a924ee93c64d5ff798f91ab32989 [file] [log] [blame]
// 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.
// @dart = 2.7
import 'native_testing.dart';
// Test to see runtimeType works on native classes and does not use the native
// constructor name.
@Native("TAGX")
class A {}
@Native("TAGY")
class B extends A {}
makeA() native;
makeB() native;
void setup() {
JS('', r"""
(function(){
// This code is inside 'setup' and so not accessible from the global scope.
function inherits(child, parent) {
function tmp() {};
tmp.prototype = parent.prototype;
child.prototype = new tmp();
child.prototype.constructor = child;
}
function TAGX(){}
function TAGY(){}
inherits(TAGY, TAGX);
self.makeA = function(){return new TAGX()};
self.makeB = function(){return new TAGY()};
self.nativeConstructor(TAGX);
self.nativeConstructor(TAGY);
})()""");
applyTestExtensions(['TAGX', 'TAGY']);
}
testDynamicContext() {
var a = makeA();
var b = makeB();
var aT = a.runtimeType;
var bT = b.runtimeType;
Expect.notEquals('TAGX', '$aT');
Expect.notEquals('TAGY', '$bT');
}
testStaticContext() {
var a = JS('A', '#', makeA()); // Force compiler to know type.
var b = JS('B', '#', makeB());
var aT = a.runtimeType;
var bT = b.runtimeType;
Expect.notEquals('TAGX', '$aT');
Expect.notEquals('TAGY', '$bT');
}
main() {
nativeTesting();
setup();
testDynamicContext();
testStaticContext();
}