MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / buildModel

Function buildModel

javascript/selenium-webdriver/generate_bidi.mjs:630–654  ·  view source on GitHub ↗

* Build the binding-neutral model from the AST. Type refs are CDDL names. * Shape per domain key: * { commands: [{ method, name, params, result }], * events: [{ method, name, params }] } * `params`/`result` are null when there are no params / no return value.

(ast)

Source from the content-addressed store, hash-verified

628 * `params`/`result` are null when there are no params / no return value.
629 */
630function buildModel(ast) {
631 const model = {}
632 const resultTypes = buildResultTypeNames(ast)
633 const ensure = (domain) => (model[domain] ??= { commands: [], events: [] })
634
635 for (const c of extractCommands(ast)) {
636 const result = c.cddlName + 'Result'
637 ensure(c.domain).commands.push({
638 method: c.methodStr,
639 name: c.methodName,
640 params: c.hasParams ? c.paramsCddl : null,
641 result: resultTypes.has(result) ? result : null,
642 })
643 }
644
645 for (const e of extractEvents(ast)) {
646 ensure(e.domain).events.push({
647 method: e.methodStr,
648 name: e.eventName,
649 params: e.paramsCddl || null,
650 })
651 }
652
653 return model
654}
655
656/** Result type names the spec defines with a value; an absent or `EmptyResult`-aliased result is void. */
657function buildResultTypeNames(ast) {

Callers 1

mainFunction · 0.85

Calls 5

buildResultTypeNamesFunction · 0.85
extractCommandsFunction · 0.85
ensureFunction · 0.85
extractEventsFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected