-
-
Notifications
You must be signed in to change notification settings - Fork 666
/
object.ts
78 lines (63 loc) · 2.35 KB
/
object.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Object.is
assert(Object.is(+0.0, +0.0) == true);
assert(Object.is(+0.0, -0.0) == false);
assert(Object.is(-0.0, +0.0) == false);
assert(Object.is(+0.0, +1.0) == false);
assert(Object.is(+1.0, -1.0) == false);
assert(Object.is(+1.0, +1.0) == true);
assert(Object.is(+Infinity, +Infinity) == true);
assert(Object.is(-Infinity, -Infinity) == true);
assert(Object.is(+Infinity, -Infinity) == false);
assert(Object.is(-Infinity, +Infinity) == false);
assert(Object.is(+Infinity, NaN) == false);
assert(Object.is(NaN, Infinity) == false);
assert(Object.is(NaN, NaN) == true);
assert(Object.is<f32>(+0.0, +0.0) == true);
assert(Object.is<f32>(+0.0, -0.0) == false);
assert(Object.is<f32>(-0.0, +0.0) == false);
assert(Object.is<f32>(+0.0, +1.0) == false);
assert(Object.is<f32>(+1.0, -1.0) == false);
assert(Object.is<f32>(+1.0, +1.0) == true);
assert(Object.is<f32>(+Infinity, +Infinity) == true);
assert(Object.is<f32>(-Infinity, -Infinity) == true);
assert(Object.is<f32>(+Infinity, -Infinity) == false);
assert(Object.is<f32>(-Infinity, +Infinity) == false);
assert(Object.is<f32>(+Infinity, NaN) == false);
assert(Object.is<f32>(NaN, Infinity) == false);
assert(Object.is<f32>(NaN, NaN) == true);
assert(Object.is(-0.0, 1e-1 * (-1e-308)) == false);
assert(Object.is(0, 0.0) == true);
assert(Object.is<i32>(+0, -0) == true);
assert(Object.is<i32>(+1, -1) == false);
assert(Object.is(true, true) == true);
assert(Object.is(true, false) == false);
assert(Object.is(false, false) == true);
assert(Object.is("a", "a") == true);
assert(Object.is("a", "b") == false);
assert(Object.is("a", "ab") == false);
assert(Object.is<string | null>(null, null) == true);
assert(Object.is<string | null>("", null) == false);
assert(Object.is<string | null>(null, "") == false);
// Implicit and explicit inheritance
class Implicit {
constructor() {
// no super()
}
}
class Explicit extends Object {
constructor() {
super();
}
}
{
let implicit = new Implicit();
assert(implicit instanceof Object);
assert(!isDefined(Implicit.is)); // does not inherit static members
let explicit = new Explicit();
assert(explicit instanceof Object);
assert(isDefined(Explicit.is)); // does inherit static members
let object: Object = explicit;
assert(object instanceof Explicit); // dynamic check
assert((<Object>implicit) instanceof Implicit);
assert((<Object>explicit) instanceof Explicit);
}