jsre: include constructor properties in auto-completion
This commit is contained in:
@ -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{}:
|
||||
|
Reference in New Issue
Block a user