UNPKG

@doodad-js/xml

Version:
87 lines (72 loc) 2.37 kB
// Copyright 2015-2018 Claude Petit, licensed under Apache License version 2.0 "use strict"; exports.add = function add(modules) { modules = (modules || {}); modules['Doodad.Tools.Xml.Parsers.Libxml2.Loader'] = { version: '5.2.0b', dependencies: [ 'Doodad.Tools.Xml', ], create: function create(root, /*optional*/_options) { //=================================== // Get namespaces //=================================== const doodad = root.Doodad, //types = doodad.Types, tools = doodad.Tools, modules = doodad.Modules, xml = tools.Xml, xmlParsers = xml.Parsers, libxml2 = xmlParsers.Libxml2, libxml2Loader = libxml2.Loader; //=================================== // Internal //=================================== // <FUTURE> Thread context const __Internal__ = { libxml2: null, }; //=================================== // libxml2 Parser //=================================== // NOTE: libxml2 is optional libxml2Loader.ADD('get', root.DD_DOC( { author: "Claude Petit", revision: 0, params: null, returns: 'object', description: "Returns parser from the libxml2 library when available. Otherwise, returns 'null'.", } , function get() { return __Internal__.libxml2; })); //=================================== // Init //=================================== return function init(/*optional*/options) { // <PRB> Emscripten calls "process.exit" on "unhandledRejection" !!! const unhandledListeners = process.listeners('unhandledRejection'); const handledListeners = process.listeners('rejectionHandled'); return modules.import('@doodad-js/xml/lib/libxml2/libxml2.js') .then(function(exports) { process.listeners('unhandledRejection').forEach(function(listener) { if (tools.indexOf(unhandledListeners, listener) < 0) { process.removeListener('unhandledRejection', listener); }; }); process.listeners('rejectionHandled').forEach(function(listener) { if (tools.indexOf(handledListeners, listener) < 0) { process.removeListener('rejectionHandled', listener); }; }); __Internal__.libxml2 = exports.default; }) .catch(function(err) { // Do nothing }); }; }, }; return modules; };