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

Method setStr

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

Source from the content-addressed store, hash-verified

1472}
1473
1474func (o *Object) setStr(name unistring.String, val, receiver Value, throw bool) bool {
1475 if receiver == o {
1476 return o.self.setOwnStr(name, val, throw)
1477 }
1478
1479 if res, ok := o.self.setForeignStr(name, val, receiver, throw); !ok {
1480 if robj, ok := receiver.(*Object); ok {
1481 if prop := robj.self.getOwnPropStr(name); prop != nil {
1482 if desc, ok := prop.(*valueProperty); ok {
1483 if desc.accessor {
1484 o.runtime.typeErrorResult(throw, "Receiver property %s is an accessor", name)
1485 return false
1486 }
1487 if !desc.writable {
1488 o.runtime.typeErrorResult(throw, "Cannot assign to read only property '%s'", name)
1489 return false
1490 }
1491 }
1492 return robj.self.defineOwnPropertyStr(name, PropertyDescriptor{Value: val}, throw)
1493 }
1494
1495 return robj.self.defineOwnPropertyStr(name, PropertyDescriptor{
1496 Value: val,
1497 Writable: FLAG_TRUE,
1498 Configurable: FLAG_TRUE,
1499 Enumerable: FLAG_TRUE,
1500 }, throw)
1501 }
1502
1503 o.runtime.typeErrorResult(throw, "Receiver is not an object: %v", receiver)
1504 return false
1505 } else {
1506 return res
1507 }
1508}
1509
1510func (o *Object) set(name Value, val, receiver Value, throw bool) bool {
1511 switch name := name.(type) {

Callers 1

setMethod · 0.95

Calls 5

typeErrorResultMethod · 0.80
setOwnStrMethod · 0.65
setForeignStrMethod · 0.65
getOwnPropStrMethod · 0.65
defineOwnPropertyStrMethod · 0.65

Tested by

no test coverage detected