How to use webidl2 - 10 common examples

To help you get started, we’ve selected a few webidl2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GENIVI / navigation / test / navigation / w3c / socket-based-poc / server.js View on Github external
// Requirement of external JS files
var resource = require('./js/resource.js');

// Requirements of nodejs modules
var http = require('http');
var url = require('url');
var fs = require('fs');
var path = require('path');
var webidl2 = require('webidl2');
var escodegen = require('escodegen');
var events = require('events');
var gcontext = require('gcontext');

// Parse the web idl files
var file = fs.readFileSync("./NavigationCoreConfiguration.widl");
var tree = webidl2.parse(file.toString());
//console.log(tree);
//console.log(escodegen.generate(tree));

// Requirements of LBS add-on modules
var navigationCoreConfigurationWrapper = require(resource.generatedNodejsModulePath+'/NavigationCoreConfigurationWrapper');

// Create instances
var i_navigationCoreConfigurationWrapper = new navigationCoreConfigurationWrapper.NavigationCoreConfigurationWrapper();

var poll = 0;
// Scan arguments if exists
if (process.argv[2] === 'poll'){
    poll = 1;
    console.log('Polling activated, no signal used');
    if (process.argv[3] === 'silent'){
        // Silentize console
github binaryage / dirac / scripts / javascript_natives / index.js View on Github external
const files = glob('../../../+(core|modules)/**/*.idl', {cwd: __dirname}, function(er, files) {
  for (const file of files) {
    if (file.includes('testing'))
      continue;
    const data = fs.readFileSync(path.join(__dirname, file), 'utf8');
    const lines = data.split('\n');
    const newLines = [];
    for (line of lines) {
      if (!line.includes(' attribute '))
        newLines.push(line);
    }

    try {
      WebIDL2.parse(newLines.join('\n')).forEach(walk);
    } catch (e) {
      // console.error(file);
    }
  }
  WebIDL2
      .parse(`
  namespace console {
    void assert(optional boolean condition = false, any... data);
    void clear();
    void count(optional DOMString label = "default");
    void debug(any... data);
    void dir(any item, optional object? options);
    void dirxml(any... data);
    void error(any... data);
    void group(any... data);
    void groupCollapsed(any... data);
github binaryage / dirac / scripts / javascript_natives / index.js View on Github external
continue;
    const data = fs.readFileSync(path.join(__dirname, file), 'utf8');
    const lines = data.split('\n');
    const newLines = [];
    for (line of lines) {
      if (!line.includes(' attribute '))
        newLines.push(line);
    }

    try {
      WebIDL2.parse(newLines.join('\n')).forEach(walk);
    } catch (e) {
      // console.error(file);
    }
  }
  WebIDL2
      .parse(`
  namespace console {
    void assert(optional boolean condition = false, any... data);
    void clear();
    void count(optional DOMString label = "default");
    void debug(any... data);
    void dir(any item, optional object? options);
    void dirxml(any... data);
    void error(any... data);
    void group(any... data);
    void groupCollapsed(any... data);
    void groupEnd();
    void info(any... data);
    void log(any... data);
    void profile(optional DOMString title);
    void profileEnd(optional DOMString title);
github jsdom / webidl2js / index.js View on Github external
module.exports.generate = function (text, outputDir, implDir, opts) {
  if (!opts) opts = {};
  if (!opts.implSuffix) opts.implSuffix = "";
  if (!opts.utilPath) opts.utilPath = path.join(outputDir, "utils.js");
  implDir = path.relative(outputDir, implDir).replace(/\\/g, "/"); // fix windows file paths

  const interfaces = {};
  const dictionaries = {};
  const customTypes = new Set();
  const idl = webidl.parse(text);
  for (var i = 0; i < idl.length; ++i) {
    switch (idl[i].type) {
      case "dictionary":
        customTypes.add(idl[i].name);
        break;
    }
  }
  for (var i = 0; i < idl.length; ++i) {
    let obj;
    switch (idl[i].type) {
      case "interface":
        if (idl[i].partial) {
          break;
        }

        obj = new Interface(idl[i], { implDir: path.resolve(outputDir, implDir), implSuffix: opts.implSuffix, customTypes });
github mdittmer / web-apis / lib / idl / idl_urls_import.es6.js View on Github external
for (let idl of data) {
      if (typeof idl !== 'string') idl = idl.toString();
      let res = parser.parseString(idl);
      if (res[0]) {
        logger.win('Storing parse from', url, ';', idl.length,
                   'length string');
        parses = parses.concat(res[1]);
        try {
          webidl2.parse(idl);
        } catch (e) {
          logger.warn('webidl2 failed to parse good fragment from', url);
        }
      } else {
        logger.warn(url, ':', idl.length, 'length string was not idl');
        try {
          webidl2.parse(idl);
          logger.assert(false, 'webidl2 parsed');
        } catch (e) {}
      }
    }

    if (parses.length === 0)
      throw new Error(`Expected parse success from ${url}`);

    if (parses.length > 0)
      fs.writeFileSync(idlCachePath, stringify({url, parses}));

    return {url, parses};
  }
}
github lunchclass / bacardi / generator / parser / parser.ts View on Github external
private static parseIDLFragment(idl_fragment: [string, string]) {
    const idl_fragment_path = idl_fragment[0];
    const idl_fragment_contents = idl_fragment[1];

    let parsed_data: {}[] = webidl.parse(idl_fragment_contents);

    parsed_data.forEach((definition_info) => {
      definition_info['idlBaseName'] = path.basename(idl_fragment_path);
      definition_info['idlDirName'] = path.dirname(idl_fragment_path);
    });

    return parsed_data;
  }
}
github lunchclass / bacardi / core / parser / parser.ts View on Github external
async function readAndParse(idlFilePath: string): Promise {
  const idlFragment: string = await file.read(idlFilePath);
  const idlDefinitionInfos: types.DefinitionInfo[] = webidl.parse(idlFragment);
  types.IDLTypeMap.update(idlDefinitionInfos);
}
github jsdom / webidl2js / lib / transformer.js View on Github external
const parsed = contents.map(content => ({
      idl: webidl.parse(content.idlContent),
      impl: content.impl
    }));
github microsoft / TSJS-lib-generator / src / widlprocess.ts View on Github external
export function convert(text: string, commentMap: Record) {
    const rootTypes = webidl2.parse(text);
    const partialInterfaces: Browser.Interface[] = [];
    const partialMixins: Browser.Interface[] = [];
    const partialDictionaries: Browser.Dictionary[] = [];
    const includes: webidl2.IncludesType[] = [];
    const namespaceNested: Record = {};
    const browser = getEmptyWebIDL();
    for (const rootType of rootTypes) {
        if (rootType.type === "interface") {
            const converted = convertInterface(rootType, commentMap);
            if (rootType.partial) {
                partialInterfaces.push(converted);
            }
            else {
                browser.interfaces!.interface[rootType.name] = converted;
            }
        }
github jsdom / webidl2js / lib / context.js View on Github external
"use strict";
const webidl = require("webidl2");
const Typedef = require("./constructs/typedef");

const builtinTypedefs = webidl.parse(`
  typedef (Int8Array or Int16Array or Int32Array or
           Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or
           Float32Array or Float64Array or DataView) ArrayBufferView;
  typedef (ArrayBufferView or ArrayBuffer) BufferSource;
  typedef unsigned long long DOMTimeStamp;
`);

class Context {
  constructor({ implSuffix = "", options } = {}) {
    this.implSuffix = implSuffix;
    this.options = options;
    this.initialize();
  }

  initialize() {
    this.typedefs = new Map();

webidl2

A WebIDL Parser

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis

Similar packages