aboutsummaryrefslogtreecommitdiffstats
path: root/jsre/pretty.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-02-15 23:42:39 +0800
committerFelix Lange <fjl@twurst.com>2016-02-15 23:43:25 +0800
commit6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401 (patch)
tree9cbe612ff89d66304bd530136992ae7a3f8e04d5 /jsre/pretty.go
parentae5bc89cad98a4fd3176502b66678d768f2fd15f (diff)
downloadgo-tangerine-6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401.tar
go-tangerine-6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401.tar.gz
go-tangerine-6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401.tar.bz2
go-tangerine-6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401.tar.lz
go-tangerine-6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401.tar.xz
go-tangerine-6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401.tar.zst
go-tangerine-6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401.zip
jsre: include constructor properties in auto-completion
Diffstat (limited to 'jsre/pretty.go')
-rw-r--r--jsre/pretty.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/jsre/pretty.go b/jsre/pretty.go
index 64f0a95c9..d0b42cd01 100644
--- a/jsre/pretty.go
+++ b/jsre/pretty.go
@@ -187,20 +187,30 @@ func (ctx ppctx) fields(obj *otto.Object) []string {
vals = append(vals, k)
}
}
- // add own properties
- ctx.doOwnProperties(obj.Value(), add)
- // add properties of the constructor
- if cp := constructorPrototype(obj); cp != nil {
- ctx.doOwnProperties(cp.Value(), add)
- }
+ iterOwnAndConstructorKeys(ctx.vm, obj, add)
sort.Strings(vals)
sort.Strings(methods)
return append(vals, methods...)
}
-func (ctx ppctx) doOwnProperties(v otto.Value, f func(string)) {
- Object, _ := ctx.vm.Object("Object")
- rv, _ := Object.Call("getOwnPropertyNames", v)
+func iterOwnAndConstructorKeys(vm *otto.Otto, obj *otto.Object, f func(string)) {
+ seen := make(map[string]bool)
+ iterOwnKeys(vm, obj, func(prop string) {
+ seen[prop] = true
+ f(prop)
+ })
+ if cp := constructorPrototype(obj); cp != nil {
+ iterOwnKeys(vm, cp, func(prop string) {
+ if !seen[prop] {
+ f(prop)
+ }
+ })
+ }
+}
+
+func iterOwnKeys(vm *otto.Otto, obj *otto.Object, f func(string)) {
+ Object, _ := vm.Object("Object")
+ rv, _ := Object.Call("getOwnPropertyNames", obj.Value())
gv, _ := rv.Export()
switch gv := gv.(type) {
case []interface{}: