()
| 107 | } |
| 108 | |
| 109 | func (lib *celBindings) ProgramOptions() []cel.ProgramOption { |
| 110 | if lib.version >= 1 { |
| 111 | celBlockPlan := func(i interpreter.InterpretableV2) (interpreter.InterpretableV2, error) { |
| 112 | call, ok := i.(interpreter.InterpretableCall) |
| 113 | if !ok { |
| 114 | return i, nil |
| 115 | } |
| 116 | switch call.Function() { |
| 117 | case "cel.@block": |
| 118 | args := call.Args() |
| 119 | if len(args) != 2 { |
| 120 | return nil, fmt.Errorf("cel.@block expects two arguments, but got %d", len(args)) |
| 121 | } |
| 122 | expr := args[1] |
| 123 | // Non-empty block |
| 124 | if block, ok := args[0].(interpreter.InterpretableConstructor); ok { |
| 125 | slotExprs := block.InitVals() |
| 126 | return newDynamicBlock(slotExprs, expr), nil |
| 127 | } |
| 128 | // Constant valued block which can happen during runtime optimization. |
| 129 | if cons, ok := args[0].(interpreter.InterpretableConst); ok { |
| 130 | if cons.Value().Type() == types.ListType { |
| 131 | l := cons.Value().(traits.Lister) |
| 132 | if l.Size().Equal(types.IntZero) == types.True { |
| 133 | return args[1], nil |
| 134 | } |
| 135 | return newConstantBlock(l, expr), nil |
| 136 | } |
| 137 | } |
| 138 | return nil, errors.New("cel.@block expects a list constructor as the first argument") |
| 139 | default: |
| 140 | return i, nil |
| 141 | } |
| 142 | } |
| 143 | return []cel.ProgramOption{cel.CustomDecoratorV2(celBlockPlan)} |
| 144 | } |
| 145 | return []cel.ProgramOption{} |
| 146 | } |
| 147 | |
| 148 | type blockValidationExemption struct{} |
| 149 |
nothing calls this directly
no test coverage detected