diff --git a/builtin_object.go b/builtin_object.go index 918037a9..4ccd6c5a 100644 --- a/builtin_object.go +++ b/builtin_object.go @@ -607,9 +607,9 @@ func (r *Runtime) initObject() { o._putProp("setPrototypeOf", r.newNativeFunc(r.object_setPrototypeOf, nil, "setPrototypeOf", nil, 2), true, false, true) o._putProp("values", r.newNativeFunc(r.object_values, nil, "values", nil, 1), true, false, true) - // entriesFunc := r.newNativeFunc(r.object_entries, nil, "entries", nil, 1) - // o._putSym(symIterator, valueProp(entriesFunc, true, false, true)) - // o._putSym(symToStringTag, valueProp(asciiString(classObject), false, false, true)) + entriesFunc := r.newNativeFunc(r.object_entries, nil, "entries", nil, 1) + o._putSym(SymIterator, valueProp(entriesFunc, true, false, true)) + o._putSym(SymToStringTag, valueProp(asciiString(classObject), false, false, true)) o._putProp("values", r.newNativeFunc(r.object_values, nil, "values", nil, 1), true, false, true) o._putProp("entries", r.newNativeFunc(r.object_entries, nil, "entries", nil, 1), true, false, true) diff --git a/builtin_proxy.go b/builtin_proxy.go index 494547a9..6641f7db 100644 --- a/builtin_proxy.go +++ b/builtin_proxy.go @@ -385,3 +385,42 @@ func (r *Runtime) initProxy() { r.global.Proxy = r.newLazyObject(r.createProxy) r.addToGlobal("Proxy", r.global.Proxy) } + +func (np *nativeProxyHandler) MemUsage(ctx *MemUsageContext) (uint64, error) { + // p := np.handler + // if p == nil || ctx.IsObjVisited(p) { + // return SizeEmpty, nil + // } + // ctx.VisitObj(p) + + // if err := ctx.Descend(); err != nil { + // return 0, err + // } + + // total := SizeEmpty + // inc, baseObjetErr := p.baseObject.MemUsage(ctx) + // total += inc + // if baseObjetErr != nil { + // return total, baseObjetErr + // } + + // if p.target != nil { + // inc, err := p.target.MemUsage(ctx) + // total += inc + // if err != nil { + // return total, err + // } + // } + + // if p.handler != nil { + // inc, err := p.handler.MemUsage(ctx) + // total += inc + // if err != nil { + // return total, err + // } + // } + + // ctx.Ascend() + + return 0, nil +} diff --git a/builtin_string.go b/builtin_string.go index 106460e2..4446fd44 100644 --- a/builtin_string.go +++ b/builtin_string.go @@ -365,6 +365,7 @@ func (r *Runtime) stringproto_match(call FunctionCall) Value { if matcher, ok := r.toObject(rx.getSym(SymMatch, nil)).self.assertCallable(); ok { return matcher(FunctionCall{ + ctx: r.vm.ctx, This: rx.val, Arguments: []Value{call.This.toString()}, }) @@ -388,6 +389,7 @@ func (r *Runtime) stringproto_matchAll(call FunctionCall) Value { } if matcher := toMethod(r.getV(regexp, SymMatchAll)); matcher != nil { return matcher(FunctionCall{ + ctx: r.vm.ctx, This: regexp, Arguments: []Value{call.This}, }) diff --git a/proxy.go b/proxy.go index 6a838e22..fe3845b0 100644 --- a/proxy.go +++ b/proxy.go @@ -156,6 +156,8 @@ type proxyHandler interface { construct(target *Object, args []Value, newTarget *Object) (Value, bool) toObject(*Runtime) *Object + + MemUsage(ctx *MemUsageContext) (uint64, error) } type jsProxyHandler struct { @@ -1078,3 +1080,41 @@ func (p *proxyObject) MemUsage(ctx *MemUsageContext) (uint64, error) { return total, nil } + +func (p *jsProxyHandler) MemUsage(ctx *MemUsageContext) (uint64, error) { + if p == nil || ctx.IsObjVisited(p.handler.self) { + return SizeEmpty, nil + } + ctx.VisitObj(p.handler.self) + + if err := ctx.Descend(); err != nil { + return 0, err + } + + total := SizeEmpty + // inc, baseObjetErr := p.handler.MemUsage(ctx) + // total += inc + // if baseObjetErr != nil { + // return total, baseObjetErr + // } + + // if p.target != nil { + // inc, err := p.target.MemUsage(ctx) + // total += inc + // if err != nil { + // return total, err + // } + // } + + if p.handler != nil { + inc, err := p.handler.MemUsage(ctx) + total += inc + if err != nil { + return total, err + } + } + + ctx.Ascend() + + return total, nil +} diff --git a/value.go b/value.go index 23793771..80df273f 100644 --- a/value.go +++ b/value.go @@ -1430,6 +1430,13 @@ func (o valueUnresolved) assertString() (valueString, bool) { return nil, false } +func (s *Symbol) IsNumber() bool { + return false +} + +func (s *Symbol) IsObject() bool { + return false +} func (s *Symbol) ToInteger() int64 { panic(typeError("Cannot convert a Symbol value to a number")) } @@ -1488,10 +1495,6 @@ func (s *Symbol) ToNumber() Value { panic(typeError("Cannot convert a Symbol value to a number")) } -func (s *Symbol) IsNumber() bool { - return false -} - func (s *Symbol) ToBoolean() bool { return true } @@ -1535,10 +1538,6 @@ func (s *Symbol) MemUsage(ctx *MemUsageContext) (uint64, error) { return 0, nil } -func (s *Symbol) IsObject() bool { - return false -} - func exportValue(v Value, ctx *objectExportCtx) interface{} { if obj, ok := v.(*Object); ok { return obj.self.export(ctx)