Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webidl2

Package Overview
Dependencies
Maintainers
2
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webidl2 - npm Package Compare versions

Comparing version 9.0.0 to 10.0.0

test/invalid/idl/iterator.widl

19

lib/webidl2.js

@@ -583,19 +583,4 @@ "use strict";

all_ws();
if (consume(ID, "iterator")) {
all_ws();
ret.type = "iterator";
if (consume(ID, "object")) {
ret.iteratorObject = "object";
} else if (consume(OTHER, "=")) {
all_ws();
var name = consume(ID) || error("No right hand side in iterator");
ret.iteratorObject = name.value;
}
all_ws();
consume(OTHER, ";") || error("Unterminated iterator");
return ret;
} else {
operation_rest(ret, store);
return ret;
}
operation_rest(ret, store);
return ret;
};

@@ -602,0 +587,0 @@

@@ -1,49 +0,41 @@

(function() {
"use strict";
var write = function(ast, opt) {
var curPea = "",
curTPea = "",
opt = opt || {},
noop = function(str) {
return str; },
optNames = "type".split(" "),
context = [];
for (var i = 0, n = optNames.length; i < n; i++) {
var o = optNames[i];
(() => {
function write(ast, opt = {}) {
let curPea = "";
let curTPea = "";
const noop = str => str;
const optNames = "type".split(" ");
const context = [];
for (const o of optNames) {
if (!opt[o]) opt[o] = noop;
}
var literal = function(it) {
function literal(it) {
return it.value;
};
var wsPea = function(it) {
function wsPea(it) {
curPea += it.value;
return "";
};
var wsTPea = function(it) {
function wsTPea(it) {
curTPea += it.value;
return "";
};
var lineComment = function(it) {
return "//" + it.value + "\n";
function lineComment(it) {
return `//${it.value}\n`;
};
var multilineComment = function(it) {
return "/*" + it.value + "*/";
function multilineComment(it) {
return `/*${it.value}*/`;
};
var type = function(it) {
function type(it) {
if (typeof it === "string") return opt.type(it); // XXX should maintain some context
if (it.union) return "(" + it.idlType.map(type).join(" or ") + ")";
var ret = "";
if (it.generic) ret += it.generic + "<";
else if (it.sequence) ret += "sequence<";
if (Array.isArray(it.idlType)) ret += it.idlType.map(type).join(", ");
else ret += type(it.idlType);
if (it.array || it.generic === 'Array') {
for (var i = 0, n = it.nullableArray.length; i < n; i++) {
var val = it.nullableArray[i];
if (val) ret += "?";
ret += "[]";
}
let ret = extended_attributes(it.extAttrs, curPea);
if (it.union) ret += `(${it.idlType.map(type).join(" or ")})`;
else {
if (it.generic) ret += `${it.generic}<`;
if (Array.isArray(it.idlType)) ret += it.idlType.map(type).join(", ");
else ret += type(it.idlType);
if (it.generic) ret += ">";
}
if (it.generic || it.sequence) ret += ">";
if (it.nullable) ret += "?";

@@ -53,4 +45,4 @@

};
var const_value = function(it) {
var tp = it.type;
function const_value(it) {
const tp = it.type;
if (tp === "boolean") return it.value ? "true" : "false";

@@ -61,18 +53,19 @@ else if (tp === "null") return "null";

else if (tp === "number") return it.value;
else return '"' + it.value + '"';
else if (tp === "sequence") return "[]";
else return `"${it.value}"`;
};
var argument = function(arg, pea) {
var ret = extended_attributes(arg.extAttrs, pea);
function argument(arg, pea) {
let ret = extended_attributes(arg.extAttrs, pea);
if (arg.optional) ret += "optional ";
ret += type(arg.idlType);
if (arg.variadic) ret += "...";
ret += " " + arg.name;
if (arg["default"]) ret += " = " + const_value(arg["default"]);
ret += ` ${arg.name}`;
if (arg["default"]) ret += ` = ${const_value(arg["default"])}`;
return ret;
};
var args = function(its) {
var res = "",
pea = "";
for (var i = 0, n = its.length; i < n; i++) {
var arg = its[i];
function args(its) {
let res = "";
let pea = "";
for (let i = 0, n = its.length; i < n; i++) {
const arg = its[i];
if (arg.type === "ws") res += arg.value;

@@ -88,21 +81,24 @@ else if (arg.type === "ws-pea") pea += arg.value;

};
var make_ext_at = function(it) {
if (it["arguments"] === null) return it.name;
function make_ext_at(it) {
context.unshift(it);
var ret = it.name + "(" + (it["arguments"].length ? args(it["arguments"]) : "") + ")";
let ret = it.name;
if (it.rhs) {
if (it.rhs.type === "identifier-list") ret += `=(${it.rhs.value.join(',')})`;
else ret += `=${it.rhs.value}`;
}
if (it.arguments) ret += `(${it["arguments"].length ? args(it["arguments"]) : ""})`;
context.shift(); // XXX need to add more contexts, but not more than needed for ReSpec
return ret;
};
var extended_attributes = function(eats, pea) {
function extended_attributes(eats, pea) {
if (!eats || !eats.length) return "";
return "[" + eats.map(make_ext_at).join(", ") + "]" + pea;
return `[${eats.map(make_ext_at).join(", ")}]${pea}`;
};
var modifiers = "getter setter creator deleter legacycaller stringifier static".split(" ");
var operation = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
const modifiers = "getter setter creator deleter legacycaller stringifier static".split(" ");
function operation(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
if (it.stringifier && !it.idlType) return "stringifier;";
for (var i = 0, n = modifiers.length; i < n; i++) {
var mod = modifiers[i];
for (const mod of modifiers) {
if (it[mod]) ret += mod + " ";

@@ -112,8 +108,8 @@ }

if (it.name) ret += it.name;
ret += "(" + args(it["arguments"]) + ");";
ret += `(${args(it["arguments"])});`;
return ret;
};
var attribute = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function attribute(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";

@@ -124,71 +120,85 @@ if (it["static"]) ret += "static ";

if (it.inherit) ret += "inherit ";
ret += "attribute " + type(it.idlType) + " " + it.name + ";";
ret += `attribute ${type(it.idlType)} ${it.name};`;
return ret;
};
var interface_ = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function interface_(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
if (it.partial) ret += "partial ";
ret += "interface " + it.name + " ";
if (it.inheritance) ret += ": " + it.inheritance + " ";
ret += "{" + iterate(it.members) + "};";
ret += `interface ${it.name} `;
if (it.inheritance) ret += `: ${it.inheritance} `;
ret += `{${iterate(it.members)}};`;
return ret;
};
var dictionary = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function interface_mixin(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
if (it.partial) ret += "partial ";
ret += "dictionary " + it.name + " ";
ret += "{" + iterate(it.members) + "};";
ret += `interface mixin ${it.name} `;
ret += `{${iterate(it.members)}};`;
return ret;
}
function namespace(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
if (it.partial) ret += "partial ";
ret += `namespace ${it.name} `;
ret += `{${iterate(it.members)}};`;
return ret;
}
function dictionary(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
if (it.partial) ret += "partial ";
ret += `dictionary ${it.name} `;
if (it.inheritance) ret += `: ${it.inheritance} `;
ret += `{${iterate(it.members)}};`;
return ret;
};
var field = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function field(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
if (it.required) ret += "required ";
ret += type(it.idlType) + " " + it.name;
if (it["default"]) ret += " = " + const_value(it["default"]);
ret += `${type(it.idlType)} ${it.name}`;
if (it["default"]) ret += ` = ${const_value(it["default"])}`;
ret += ";";
return ret;
};
var exception = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function const_(it) {
const ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
ret += "exception " + it.name + " ";
if (it.inheritance) ret += ": " + it.inheritance + " ";
ret += "{" + iterate(it.members) + "};";
return ret;
return `${ret}const ${type(it.idlType)}${it.nullable ? "?" : ""} ${it.name} = ${const_value(it.value)};`;
};
var const_ = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function typedef(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
return ret + "const " + type(it.idlType) + " " + it.name + " = " + const_value(it.value) + ";";
ret += `typedef ${extended_attributes(it.typeExtAttrs, curTPea)}`;
curTPea = "";
return `${ret}${type(it.idlType)} ${it.name};`;
};
var typedef = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function implements_(it) {
const ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
ret += "typedef " + extended_attributes(it.typeExtAttrs, curTPea);
curTPea = "";
return ret + type(it.idlType) + " " + it.name + ";";
return `${ret}${it.target} implements ${it["implements"]};`;
};
var implements_ = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function includes(it) {
const ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
return ret + it.target + " implements " + it["implements"] + ";";
return `${ret}${it.target} includes ${it.includes};`;
};
var callback = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function callback(it) {
const ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
return ret + "callback " + it.name + " = " + type(it.idlType) +
"(" + args(it["arguments"]) + ");";
return `${ret}callback ${it.name} = ${type(it.idlType)}(${args(it["arguments"])});`;
};
var enum_ = function(it) {
var ret = extended_attributes(it.extAttrs, curPea);
function enum_(it) {
let ret = extended_attributes(it.extAttrs, curPea);
curPea = "";
ret += "enum " + it.name + " {";
for (var i = 0, n = it.values.length; i < n; i++) {
var v = it.values[i];
if (typeof v === "string") ret += '"' + v + '"';
ret += `enum ${it.name} {`;
for (const v of it.values) {
if (v.type === "string") ret += `"${v.value}"`;
else if (v.type === "ws") ret += v.value;

@@ -199,21 +209,19 @@ else if (v.type === ",") ret += ",";

};
var iterable = function(it) {
return "iterable<" + (it.idlType instanceof Array ? it.idlType.map(type).join(", ") : type(it.idlType)) + ">;";
function iterable(it) {
return `iterable<${Array.isArray(it.idlType) ? it.idlType.map(type).join(", ") : type(it.idlType)}>;`;
};
var legacyiterable = function(it) {
return "legacyiterable<" + (it.idlType instanceof Array ? it.idlType.map(type).join(", ") : type(it.idlType)) + ">;";
function legacyiterable(it) {
return `legacyiterable<${Array.isArray(it.idlType) ? it.idlType.map(type).join(", ") : type(it.idlType)}>;`;
};
var maplike = function(it) {
return (it.readonly ? "readonly " : "") + "maplike<" +
it.idlType.map(type).join(", ") + ">;";
function maplike(it) {
return `${it.readonly ? "readonly " : ""}maplike<${it.idlType.map(type).join(", ")}>;`;
};
var setlike = function(it) {
return (it.readonly ? "readonly " : "") + "setlike<" +
type(it.idlType) + ">;";
function setlike(it) {
return `${it.readonly ? "readonly " : ""}setlike<${type(it.idlType[0])}>;`;
};
var callbackInterface = function(it) {
return 'callback ' + interface_(it);
function callbackInterface(it) {
return `callback ${interface_(it)}`;
};
var table = {
const table = {
ws: literal,

@@ -225,25 +233,31 @@ "ws-pea": wsPea,

"interface": interface_,
operation: operation,
attribute: attribute,
dictionary: dictionary,
field: field,
exception: exception,
"interface mixin": interface_mixin,
namespace,
operation,
attribute,
dictionary,
field,
"const": const_,
typedef: typedef,
typedef,
"implements": implements_,
callback: callback,
includes,
callback,
"enum": enum_,
iterable: iterable,
legacyiterable: legacyiterable,
maplike: maplike,
setlike: setlike,
iterable,
legacyiterable,
maplike,
setlike,
"callback interface": callbackInterface
};
var dispatch = function(it) {
function dispatch(it) {
const dispatcher = table[it.type];
if (!dispatcher) {
throw new Error(`Type "${it.type}" is unsupported`)
}
return table[it.type](it);
};
var iterate = function(things) {
function iterate(things) {
if (!things) return;
var ret = "";
for (var i = 0, n = things.length; i < n; i++) ret += dispatch(things[i]);
let ret = "";
for (const thing of things) ret += dispatch(thing);
return ret;

@@ -255,5 +269,4 @@ };

var obj = {
write: function(ast, opt) {
if (!opt) opt = {};
const obj = {
write(ast, opt = {}) {
return write(ast, opt);

@@ -266,8 +279,6 @@ }

} else if (typeof define === 'function' && define.amd) {
define([], function() {
return obj;
});
define([], () => obj);
} else {
(self || window).WebIDL2Writer = obj;
}
}());
})();
{
"name": "webidl2",
"description": "A WebIDL Parser",
"version": "9.0.0",
"version": "10.0.0",
"contributors": [

@@ -14,3 +14,3 @@ "Robin Berjon <robin@berjon.com> (https://berjon.com)",

"devDependencies": {
"expect": "21.2.1",
"expect": "22.0.3",
"jsondiffpatch": "0.2.5",

@@ -17,0 +17,0 @@ "mocha": "4.0.1"

@@ -313,3 +313,2 @@

"type": "typedef",
"typeExtAttrs": [],
"idlType": {

@@ -340,4 +339,2 @@ "sequence": true,

* `extAttrs`: A list of [extended attributes](#extended-attributes).
* `typeExtAttrs`: A list of [extended attributes](#extended-attributes) that apply to the
type rather than to the typedef as a whole.

@@ -494,30 +491,2 @@ ### Implements

### Iterator Member
Iterator members look like this
```JS
{
"type": "iterator",
"getter": false,
"setter": false,
"deleter": false,
"static": false,
"stringifier": false,
"idlType": {
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "Session2"
},
"iteratorObject": "SessionIterator",
"extAttrs": []
}
```
* `type`: Always "iterator".
* `iteratorObject`: The string on the right-hand side; absent if there isn't one.
* the rest: same as on [operations](#operation-member).
### Arguments

@@ -617,3 +586,3 @@

* `type`: Always one of "iterable", "legacyiterable", "maplike" or "setlike".
* `idlType`: An [IDL Type](#idl-type) (or an array of two types) representing the declared type arguments.
* `idlType`: An array with one or more [IDL Types](#idl-type) representing the declared type arguments.
* `readonly`: Whether the maplike or setlike is declared as read only.

@@ -620,0 +589,0 @@ * `extAttrs`: A list of [extended attributes](#extended-attributes).

@@ -18,7 +18,8 @@ // NOTES:

.map(it => pth.join(dir, it));
const errors = idls.map(it => pth.join(__dirname, "invalid", "json", pth.basename(it).replace(/\.w?idl/, ".json")));
for (let i = 0, n = idls.length; i < n; i++) {
const idl = idls[i];
const err = JSON.parse(fs.readFileSync(errors[i], "utf8"));
for (const idl of idls) {
const err = JSON.parse(fs.readFileSync(
pth.join(__dirname, "invalid", "json", pth.basename(idl).replace(/\.w?idl/, ".json")),
"utf8"
));

@@ -28,3 +29,3 @@ it(`should produce the right error for ${idl}`, () => {

try {
var ast = wp.parse(fs.readFileSync(idl, "utf8"));
const ast = wp.parse(fs.readFileSync(idl, "utf8"));
console.log(JSON.stringify(ast, null, 4));

@@ -31,0 +32,0 @@ }

@@ -16,7 +16,5 @@ "use strict";

.map(it => pth.join(dir, it));
const jsons = idls.map(it => pth.join(__dirname, "syntax/json", pth.basename(it).replace(".widl", ".json")));
for (let i = 0, n = idls.length; i < n; i++) {
const idl = idls[i];
const json = jsons[i];
for (const idl of idls) {
const json = pth.join(__dirname, "syntax/json", pth.basename(idl).replace(".widl", ".json"));

@@ -23,0 +21,0 @@ it(`should produce the same AST for ${idl}`, () => {

@@ -167,3 +167,61 @@ [

]
},
{
"type": "interface",
"name": "I",
"partial": false,
"members": [
{
"type": "attribute",
"static": false,
"stringifier": false,
"inherit": false,
"readonly": false,
"idlType": {
"sequence": false,
"generic": null,
"nullable": false,
"union": true,
"idlType": [
{
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "long"
},
{
"sequence": false,
"generic": null,
"nullable": false,
"union": false,
"idlType": "Node"
}
],
"extAttrs": [
{
"name": "XAttr",
"arguments": null,
"type": "extended-attribute",
"rhs": null
}
]
},
"name": "attrib",
"extAttrs": []
}
],
"inheritance": null,
"extAttrs": [
{
"name": "Exposed",
"arguments": null,
"type": "extended-attribute",
"rhs": {
"type": "identifier",
"value": "Window"
}
}
]
}
]

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc