| 472 | } |
| 473 | |
| 474 | func (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 | |
| 507 | func (o *baseObject) setOwnIdx(idx valueInt, val Value, throw bool) bool { |
| 508 | return o.val.self.setOwnStr(idx.string(), val, throw) |