dart-sdk/tests/lib_2/js/prototype_access_test.dart
Vijay Menon 8602a8446e Fix LazyJsType check
This type is used for JS instanceof checks.  dart.dynamic doesn't work for that.  In general, this fall back looks dodgy (with or without this change), but this unblocks an internal user.

Change-Id: Id7401bbbef1aeddd93f40932b84f1928b4238edb
Reviewed-on: https://dart-review.googlesource.com/28121
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Jacob Richman <jacobr@google.com>
2017-12-11 16:51:48 +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());
}