Skip to content

Commit

Permalink
usage: report usage of global
Browse files Browse the repository at this point in the history
As part of #3864 it will be nice to
know how much this is used if at all.
  • Loading branch information
mstoykov committed Sep 13, 2024
1 parent 88629d3 commit 9cc8131
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion js/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,17 @@ func (b *Bundle) setupJSRuntime(rt *sobek.Runtime, vuID int64, logger logrus.Fie
}

if b.CompatibilityMode == lib.CompatibilityModeExtended {
err = rt.Set("global", rt.GlobalObject())
globalThis := rt.GlobalObject()
err = globalThis.DefineAccessorProperty("global",
rt.ToValue(func() sobek.Value {
if err := b.preInitState.Usage.Uint64("usage/global", 1); err != nil {
b.preInitState.Logger.WithError(err).Warn("couldn't report usage")
}
return globalThis
}), rt.ToValue(func(newGlobal *sobek.Object) { // probably not a thing that will happen but still
globalThis = newGlobal
}),
sobek.FLAG_TRUE, sobek.FLAG_TRUE)
if err != nil {
return err
}
Expand Down

0 comments on commit 9cc8131

Please sign in to comment.