MCPcopy Create free account
hub / github.com/dop251/goja / setOwnStr

Method setOwnStr

object.go:474–505  ·  view source on GitHub ↗
(name unistring.String, val Value, throw bool)

Source from the content-addressed store, hash-verified

472}
473
474func (o *baseObject) setOwnStr(name unistring.String, val Value, throw bool) bool {
475 ownDesc := o.values[name]
476 if ownDesc == nil {
477 if proto := o.prototype; proto != nil {
478 // we know it's foreign because prototype loops are not allowed
479 if res, handled := proto.self.setForeignStr(name, val, o.val, throw); handled {
480 return res
481 }
482 }
483 // new property
484 if !o.extensible {
485 o.val.runtime.typeErrorResult(throw, "Cannot add property %s, object is not extensible", name)
486 return false
487 } else {
488 o.values[name] = val
489 names := copyNamesIfNeeded(o.propNames, 1)
490 o.propNames = append(names, name)
491 }
492 return true
493 }
494 if prop, ok := ownDesc.(*valueProperty); ok {
495 if !prop.isWritable() {
496 o.val.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name)
497 return false
498 } else {
499 prop.set(o.val, val)
500 }
501 } else {
502 o.values[name] = val
503 }
504 return true
505}
506
507func (o *baseObject) setOwnIdx(idx valueInt, val Value, throw bool) bool {
508 return o.val.self.setOwnStr(idx.string(), val, throw)

Callers 3

createSymbolProtoMethod · 0.95
BenchmarkPutStrFunction · 0.95
createRegexpGroupsObjMethod · 0.95

Calls 5

copyNamesIfNeededFunction · 0.85
typeErrorResultMethod · 0.80
isWritableMethod · 0.80
setForeignStrMethod · 0.65
setMethod · 0.65

Tested by 1

BenchmarkPutStrFunction · 0.76