(defs *jsOpts, opts ...JSOpt)
| 1767 | } |
| 1768 | |
| 1769 | func getJSContextOpts(defs *jsOpts, opts ...JSOpt) (*jsOpts, context.CancelFunc, error) { |
| 1770 | var o jsOpts |
| 1771 | for _, opt := range opts { |
| 1772 | if err := opt.configureJSContext(&o); err != nil { |
| 1773 | return nil, nil, err |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | // Check for option collisions. Right now just timeout and context. |
| 1778 | if o.ctx != nil && o.wait != 0 { |
| 1779 | return nil, nil, ErrContextAndTimeout |
| 1780 | } |
| 1781 | if o.wait == 0 && o.ctx == nil { |
| 1782 | o.wait = defs.wait |
| 1783 | } |
| 1784 | var cancel context.CancelFunc |
| 1785 | if o.ctx == nil && o.wait > 0 { |
| 1786 | o.ctx, cancel = context.WithTimeout(context.Background(), o.wait) |
| 1787 | } |
| 1788 | if o.pre == _EMPTY_ { |
| 1789 | o.pre = defs.pre |
| 1790 | } |
| 1791 | if o.ctx != nil { |
| 1792 | // if context does not have a deadline, use timeout from js context |
| 1793 | if _, hasDeadline := o.ctx.Deadline(); !hasDeadline { |
| 1794 | o.ctx, cancel = context.WithTimeout(o.ctx, defs.wait) |
| 1795 | } |
| 1796 | } |
| 1797 | return &o, cancel, nil |
| 1798 | } |
no test coverage detected