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

Method proxyGetOwnPropertyDescriptor

proxy.go:509–558  ·  view source on GitHub ↗
(targetProp Value, target *Object, trapResult Value, name fmt.Stringer)

Source from the content-addressed store, hash-verified

507}
508
509func (p *proxyObject) proxyGetOwnPropertyDescriptor(targetProp Value, target *Object, trapResult Value, name fmt.Stringer) Value {
510 r := p.val.runtime
511 targetDesc := propToValueProp(targetProp)
512 var trapResultObj *Object
513 if trapResult != nil && trapResult != _undefined {
514 if obj, ok := trapResult.(*Object); ok {
515 trapResultObj = obj
516 } else {
517 panic(r.NewTypeError("'getOwnPropertyDescriptor' on proxy: trap returned neither object nor undefined for property '%s'", name.String()))
518 }
519 }
520 if trapResultObj == nil {
521 if targetDesc == nil {
522 return nil
523 }
524 if !targetDesc.configurable {
525 panic(r.NewTypeError())
526 }
527 if !target.self.isExtensible() {
528 panic(r.NewTypeError())
529 }
530 return nil
531 }
532 extensibleTarget := target.self.isExtensible()
533 resultDesc := r.toPropertyDescriptor(trapResultObj)
534 resultDesc.complete()
535 if !p.__isCompatibleDescriptor(extensibleTarget, &resultDesc, targetDesc) {
536 panic(r.NewTypeError("'getOwnPropertyDescriptor' on proxy: trap returned descriptor for property '%s' that is incompatible with the existing property in the proxy target", name.String()))
537 }
538
539 if resultDesc.Configurable == FLAG_FALSE {
540 if targetDesc == nil {
541 panic(r.NewTypeError("'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property '%s' which is non-existent in the proxy target", name.String()))
542 }
543
544 if targetDesc.configurable {
545 panic(r.NewTypeError("'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property '%s' which is configurable in the proxy target", name.String()))
546 }
547
548 if resultDesc.Writable == FLAG_FALSE && targetDesc.writable {
549 panic(r.NewTypeError("'getOwnPropertyDescriptor' on proxy: trap reported non-configurable and writable for property '%s' which is non-configurable, non-writable in the proxy target", name.String()))
550 }
551 }
552
553 if resultDesc.Writable == FLAG_TRUE && resultDesc.Configurable == FLAG_TRUE &&
554 resultDesc.Enumerable == FLAG_TRUE {
555 return resultDesc.Value
556 }
557 return r.toValueProp(trapResultObj)
558}
559
560func (p *proxyObject) getOwnPropStr(name unistring.String) Value {
561 target := p.target

Callers 3

getOwnPropStrMethod · 0.95
getOwnPropIdxMethod · 0.95
getOwnPropSymMethod · 0.95

Calls 8

propToValuePropFunction · 0.85
NewTypeErrorMethod · 0.80
toPropertyDescriptorMethod · 0.80
completeMethod · 0.80
toValuePropMethod · 0.80
StringMethod · 0.65
isExtensibleMethod · 0.65

Tested by

no test coverage detected