Skip to content

Commit 6a7e5d6

Browse files
committed
fix: simplify proxy interface
1 parent 8935494 commit 6a7e5d6

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

vm/runtime/runtime.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@ import (
1313
// Proxy is an interface that allows intercepting object property access.
1414
type Proxy interface {
1515
// GetProperty returns the value of the property with the given key.
16-
GetProperty(key any) (any, bool)
16+
GetProperty(key any) any
1717
}
1818

1919
func Fetch(from, i any) any {
2020
if proxy, ok := from.(Proxy); ok {
21-
r, ok := proxy.GetProperty(i)
22-
if !ok {
23-
panic(fmt.Sprintf("cannot fetch %v from proxy", i))
24-
}
25-
26-
return r
21+
return proxy.GetProperty(i)
2722
}
2823

2924
v := reflect.ValueOf(from)

vm/vm_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,14 @@ type proxyNode struct {
275275
values map[any]any
276276
}
277277

278-
func (n *proxyNode) GetProperty(key any) (any, bool) {
278+
func (n *proxyNode) GetProperty(key any) any {
279279
if value, ok := n.values[key]; ok {
280-
return value, true
280+
return value
281281
}
282282
if n.parent != nil {
283283
return n.parent.GetProperty(key)
284284
}
285-
return nil, false
285+
return nil
286286
}
287287

288288
func (n *proxyNode) SetProperty(key any, value any) {

0 commit comments

Comments
 (0)