-
Notifications
You must be signed in to change notification settings - Fork 5
/
go114_js.go
54 lines (47 loc) · 1.06 KB
/
go114_js.go
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
// +build js
// +build go1.14
package js
import (
"github.com/gopherjs/gopherjs/js"
)
func (v Value) IsNull() bool {
return v.Type() == TypeNull
}
func (v Value) IsUndefined() bool {
return !v.inited
}
func (v Value) IsNaN() bool {
return js.Global.Call("isNaN", v.internal()).Bool()
}
func (v Value) Equal(w Value) bool {
//return v.internal() == w.internal() && !v.IsNaN()
if v.Type() != w.Type() {
return false
}
switch v.Type() {
case TypeString:
return v.internal().String() == w.internal().String()
case TypeUndefined:
return true
case TypeNull:
return true
case TypeBoolean:
return v.internal().Bool() == w.internal().Bool()
case TypeNumber:
return v.internal().Float() == w.internal().Float()
case TypeSymbol:
return v.internal() == w.internal()
case TypeObject:
return v.internal() == w.internal()
case TypeFunction:
return v.internal() == w.internal()
default:
panic("bad type")
}
}
func (v Value) Delete(p string) {
if vType := v.Type(); vType != TypeObject {
panic(&ValueError{"Value.Delete", vType})
}
v.internal().Delete(p)
}