dart-sdk/tests/lib/js/prototype_access_test.dart
Robert Nystrom 352b41f289 Migrate lib_2/js to NNBD.
Change-Id: I5832ab61eabbbbc03e0620be2f831b85663a7ac9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128340
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
2019-12-17 20:28:14 +00:00

49 lines
1.2 KiB
Dart

// Copyright (c) 2017, 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.
@JS()
library prototest;
import 'package:js/js.dart';
import 'package:expect/expect.dart';
@JS('window.ArrayBuffer')
external Class get arrayBufferClass;
@JS('Function')
class Class {
external dynamic get prototype;
external Constructor get constructor;
external String get name;
}
class Normal {
int prototype = 42;
Normal constructor() {
return this;
}
int operator [](int i) => prototype;
}
@JS()
class Constructor {
external String get name;
}
void main() {
Expect.isTrue(arrayBufferClass.prototype != null);
var normal = new Normal();
Expect.equals(42, normal.prototype);
Expect.equals(42, normal[0]);
Expect.isTrue(arrayBufferClass.constructor != null);
Expect.isTrue(arrayBufferClass.constructor is Function);
Expect.isTrue(arrayBufferClass.constructor is Constructor);
Expect.equals("ArrayBuffer", arrayBufferClass.name);
Expect.equals("Function", arrayBufferClass.constructor.name);
Expect.isTrue(normal.constructor is Function);
Expect.equals(normal, normal.constructor());
}