DefinePropertyAtom defines a property using a full descriptor and a pre-built atom.
(atom *Atom, desc PropertyDescriptor)
| 598 | |
| 599 | // DefinePropertyAtom defines a property using a full descriptor and a pre-built atom. |
| 600 | func (v *Value) DefinePropertyAtom(atom *Atom, desc PropertyDescriptor) bool { |
| 601 | if !v.isAlive() || atom == nil || atom.ctx == nil || atom.ctx != v.ctx || !atom.ctx.hasValidRef() { |
| 602 | return false |
| 603 | } |
| 604 | if desc.Value != nil && !desc.Value.belongsTo(v.ctx) { |
| 605 | return false |
| 606 | } |
| 607 | if desc.Getter != nil && !desc.Getter.belongsTo(v.ctx) { |
| 608 | return false |
| 609 | } |
| 610 | if desc.Setter != nil && !desc.Setter.belongsTo(v.ctx) { |
| 611 | return false |
| 612 | } |
| 613 | |
| 614 | value := C.JS_NewUndefined() |
| 615 | if desc.Value != nil { |
| 616 | // JS_DefineProperty borrows descriptor values; do not transfer caller ownership. |
| 617 | value = desc.Value.ref |
| 618 | } |
| 619 | getter := C.JS_NewUndefined() |
| 620 | if desc.Getter != nil { |
| 621 | // Borrowed argument: keep caller-managed getter handle valid after the call. |
| 622 | getter = desc.Getter.ref |
| 623 | } |
| 624 | setter := C.JS_NewUndefined() |
| 625 | if desc.Setter != nil { |
| 626 | // Borrowed argument: keep caller-managed setter handle valid after the call. |
| 627 | setter = desc.Setter.ref |
| 628 | } |
| 629 | |
| 630 | ret := C.JS_DefineProperty(v.ctx.ref, v.ref, atom.ref, value, getter, setter, C.int(desc.Flags)) |
| 631 | if ret < 0 { |
| 632 | return false |
| 633 | } |
| 634 | return ret == 1 |
| 635 | } |
| 636 | |
| 637 | // DefinePropertyValue defines a value property by name. |
| 638 | func (v *Value) DefinePropertyValue(name string, value *Value, flags int) bool { |