Skip to content

Commit

Permalink
feat: force check on new arrays and new obj props
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabri3l committed Nov 27, 2024
1 parent 755ea92 commit 94ce8a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion builtin_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,19 @@ func relToIdx(rel, l int64) int64 {
return max(l+rel, 0)
}

func (r *Runtime) newArrayValues(values []Value) *Object {
func (r *Runtime) newArrayValues(values valueStack) *Object {
if r.shouldForceMemCheck {
memCtx := newMemUsageContextClone()
if memCtx != nil {
memUsage, err := valuesMemUsage(values, memCtx)
if err != nil {
panic(err)
}
if memCtx.MemUsageLimitExceeded(memUsage) {
panic("memory limit exceeded")
}
}
}
return setArrayValues(r.newArrayObject(), values).val
}

Expand Down
12 changes: 12 additions & 0 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,18 @@ func (o *baseObject) setOwnStr(name unistring.String, val Value, throw bool) boo
o.val.runtime.typeErrorResult(throw, "Cannot add property %s, object is not extensible", name)
return false
} else {
if o.val.runtime.shouldForceMemCheck {
memCtx := newMemUsageContextClone()
if memCtx != nil {
memUsage, err := val.MemUsage(memCtx)
if err != nil {
panic(err)
}
if memCtx.MemUsageLimitExceeded(memUsage) {
panic("memory limit exceeded")
}
}
}
o.values[name] = val
names := copyNamesIfNeeded(o.propNames, 1)
o.propNames = append(names, name)
Expand Down

0 comments on commit 94ce8a6

Please sign in to comment.