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

webidl2

Package Overview
Dependencies
Maintainers
1
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 2.0.4 to 2.0.5

.travis.yml

293

lib/webidl2.js

@@ -34,3 +34,3 @@

var parse = function (tokens) {
var parse = function (tokens, opt) {
var line = 1;

@@ -86,3 +86,3 @@ tokens = tokens.slice();

var all_ws = function () {
var all_ws = function (store, pea) { // pea == post extended attribute, tpea = same for types
var t = { type: "whitespace", value: "" };

@@ -94,3 +94,30 @@ while (true) {

}
if (t.value.length > 0) return t;
if (t.value.length > 0) {
if (store) {
var w = t.value
, re = {
"ws": /^([\t\n\r ]+)/
, "line-comment": /^\/\/(.*)\n?/m
, "multiline-comment": /^\/\*((?:.|\n|\r)*?)\*\//
}
, wsTypes = []
;
for (var k in re) wsTypes.push(k);
while (w.length) {
var matched = false;
for (var i = 0, n = wsTypes.length; i < n; i++) {
var type = wsTypes[i];
w = w.replace(re[type], function (tok, m1) {
store.push({ type: type + (pea ? ("-" + pea) : ""), value: m1 });
matched = true;
return "";
});
if (matched) break;
}
if (matched) continue;
throw new Error("Surprising white space construct."); // this shouldn't happen
}
}
return t;
}
};

@@ -173,3 +200,3 @@

var prim = primitive_type()
, ret = { sequence: false, nullable: false, array: false, union: false }
, ret = { sequence: false, promise: false, nullable: false, array: false, union: false }
;

@@ -194,2 +221,17 @@ if (prim) {

}
else if (consume(ID, "Promise")) {
all_ws();
if (!consume(OTHER, "<")) {
ret.idlType = "Promise";
}
else {
ret.promise = true;
ret.idlType = type() || error("Error parsing Promise type");
all_ws();
if (!consume(OTHER, ">")) error("Unterminated Promise");
all_ws();
if (consume(OTHER, "?")) ret.nullable = true;
return ret;
}
}
else {

@@ -208,3 +250,3 @@ var name = consume(ID);

if (!consume(OTHER, "(")) return;
var ret = { sequence: false, nullable: false, array: false, union: true, idlType: [] };
var ret = { sequence: false, promise: false, nullable: false, array: false, union: true, idlType: [] };
var fst = type() || error("Union type with no content");

@@ -227,7 +269,8 @@ ret.idlType.push(fst);

var argument = function () {
var argument = function (store) {
var ret = { optional: false, variadic: false };
ret.extAttrs = extended_attrs();
all_ws();
if (consume(ID, "optional")) {
ret.extAttrs = extended_attrs(store);
all_ws(store, "pea");
var opt_token = consume(ID, "optional");
if (opt_token) {
ret.optional = true;

@@ -237,3 +280,7 @@ all_ws();

ret.idlType = type();
if (!ret.idlType) return;
if (!ret.idlType) {
if (opt_token) tokens.unshift(opt_token);
return;
}
var type_token = last_token;
if (!ret.optional) {

@@ -253,3 +300,8 @@ all_ws();

all_ws();
var name = consume(ID) || error("No name in argument");
var name = consume(ID);
if (!name) {
if (opt_token) tokens.unshift(opt_token);
tokens.unshift(type_token);
return;
}
ret.name = name.value;

@@ -263,11 +315,12 @@ if (ret.optional) {

var argument_list = function () {
var arg = argument(), ret = [];
if (!arg) return ret;
var argument_list = function (store) {
var ret = []
, arg = argument(store ? ret : null)
;
if (!arg) return;
ret.push(arg);
while (true) {
all_ws();
all_ws(store ? ret : null);
if (!consume(OTHER, ",")) return ret;
all_ws();
var nxt = argument() || error("Trailing comma in arguments list");
var nxt = argument(store ? ret : null) || error("Trailing comma in arguments list");
ret.push(nxt);

@@ -277,4 +330,16 @@ }

var simple_extended_attr = function () {
var type_pair = function () {
all_ws();
var k = type();
if (!k) return;
all_ws()
if (!consume(OTHER, ",")) return;
all_ws();
var v = type();
if (!v) return;
return [k, v];
};
var simple_extended_attr = function (store) {
all_ws();
var name = consume(ID);

@@ -295,5 +360,17 @@ if (!name) return;

if (consume(OTHER, "(")) {
ret["arguments"] = argument_list();
var args, pair;
// [Constructor(DOMString str)]
if (args = argument_list(store)) {
ret["arguments"] = args;
}
// [MapClass(DOMString, DOMString)]
else if (pair = type_pair()) {
ret.typePair = pair;
}
// [Constructor()]
else {
ret["arguments"] = [];
}
all_ws();
consume(OTHER, ")") || error("Unclosed argument in extended attribute");
consume(OTHER, ")") || error("Unexpected token in extended attribute argument list or type pair");
}

@@ -305,12 +382,11 @@ return ret;

// seems to be used
var extended_attrs = function () {
var extended_attrs = function (store) {
var eas = [];
all_ws();
all_ws(store);
if (!consume(OTHER, "[")) return eas;
eas[0] = simple_extended_attr() || error("Extended attribute with not content");
eas[0] = simple_extended_attr(store) || error("Extended attribute with not content");
all_ws();
while (consume(OTHER, ",")) {
eas.push(simple_extended_attr(store) || error("Trailing comma in extended attribute"));
all_ws();
eas.push(simple_extended_attr() || error("Trailing comma in extended attribute"));
all_ws();
}

@@ -337,4 +413,4 @@ consume(OTHER, "]") || error("No end of extended attribute");

var const_ = function () {
all_ws();
var const_ = function (store) {
all_ws(store, "pea");
if (!consume(ID, "const")) return;

@@ -376,3 +452,3 @@ var ret = { type: "const", nullable: false };

var operation_rest = function (ret) {
var operation_rest = function (ret, store) {
all_ws();

@@ -384,3 +460,3 @@ if (!ret) ret = {};

consume(OTHER, "(") || error("Invalid operation");
ret["arguments"] = argument_list();
ret["arguments"] = argument_list(store) || [];
all_ws();

@@ -393,4 +469,4 @@ consume(OTHER, ")") || error("Unterminated operation");

var callback = function () {
all_ws();
var callback = function (store) {
all_ws(store, "pea");
var ret;

@@ -414,3 +490,3 @@ if (!consume(ID, "callback")) return;

consume(OTHER, "(") || error("No arguments in callback");
ret["arguments"] = argument_list();
ret["arguments"] = argument_list(store) || [];
all_ws();

@@ -423,4 +499,4 @@ consume(OTHER, ")") || error("Unterminated callback");

var attribute = function () {
all_ws();
var attribute = function (store) {
all_ws(store, "pea");
var grabbed = []

@@ -483,4 +559,4 @@ , ret = {

var operation = function () {
all_ws();
var operation = function (store) {
all_ws(store, "pea");
var ret = {

@@ -508,3 +584,3 @@ type: "operation"

ret.idlType = return_type();
operation_rest(ret);
operation_rest(ret, store);
return ret;

@@ -515,3 +591,3 @@ }

ret.idlType = return_type();
operation_rest(ret);
operation_rest(ret, store);
return ret;

@@ -524,3 +600,3 @@ }

ret.idlType = return_type();
operation_rest(ret);
operation_rest(ret, store);
return ret;

@@ -546,3 +622,3 @@ }

else {
operation_rest(ret);
operation_rest(ret, store);
return ret;

@@ -564,4 +640,4 @@ }

var serialiser = function () {
all_ws();
var serialiser = function (store) {
all_ws(store, "pea");
if (!consume(ID, "serializer")) return;

@@ -624,3 +700,3 @@ var ret = { type: "serializer" };

all_ws();
ret.operation = operation_rest();
ret.operation = operation_rest(null, store);
}

@@ -630,12 +706,13 @@ return ret;

var interface_ = function (isPartial) {
all_ws();
var interface_ = function (isPartial, store) {
all_ws(isPartial ? null : store, "pea");
if (!consume(ID, "interface")) return;
all_ws();
var name = consume(ID) || error("No name for interface");
var ret = {
var mems = []
, ret = {
type: "interface"
, name: name.value
, partial: false
, members: []
, members: mems
};

@@ -646,3 +723,3 @@ if (!isPartial) ret.inheritance = inheritance() || null;

while (true) {
all_ws();
all_ws(store ? mems : null);
if (consume(OTHER, "}")) {

@@ -653,5 +730,5 @@ all_ws();

}
var ea = extended_attrs();
var ea = extended_attrs(store ? mems : null);
all_ws();
var cnt = const_();
var cnt = const_(store ? mems : null);
if (cnt) {

@@ -662,3 +739,6 @@ cnt.extAttrs = ea;

}
var mem = serialiser() || attribute() || operation() || error("Unknown member");
var mem = serialiser(store ? mems : null) ||
attribute(store ? mems : null) ||
operation(store ? mems : null) ||
error("Unknown member");
mem.extAttrs = ea;

@@ -669,6 +749,8 @@ ret.members.push(mem);

var partial = function () {
all_ws();
var partial = function (store) {
all_ws(store, "pea");
if (!consume(ID, "partial")) return;
var thing = dictionary(true) || interface_(true) || error("Partial doesn't apply to anything");
var thing = dictionary(true, store) ||
interface_(true, store) ||
error("Partial doesn't apply to anything");
thing.partial = true;

@@ -678,12 +760,13 @@ return thing;

var dictionary = function (isPartial) {
all_ws();
var dictionary = function (isPartial, store) {
all_ws(isPartial ? null : store, "pea");
if (!consume(ID, "dictionary")) return;
all_ws();
var name = consume(ID) || error("No name for dictionary");
var ret = {
var mems = []
, ret = {
type: "dictionary"
, name: name.value
, partial: false
, members: []
, members: mems
};

@@ -694,3 +777,3 @@ if (!isPartial) ret.inheritance = inheritance() || null;

while (true) {
all_ws();
all_ws(store ? mems : null);
if (consume(OTHER, "}")) {

@@ -701,4 +784,4 @@ all_ws();

}
var ea = extended_attrs();
all_ws();
var ea = extended_attrs(store ? mems : null);
all_ws(store ? mems : null, "pea");
var typ = type() || error("No type for dictionary member");

@@ -719,11 +802,12 @@ all_ws();

var exception = function () {
all_ws();
var exception = function (store) {
all_ws(store, "pea");
if (!consume(ID, "exception")) return;
all_ws();
var name = consume(ID) || error("No name for exception");
var ret = {
var mems = []
, ret = {
type: "exception"
, name: name.value
, members: []
, members: mems
};

@@ -734,3 +818,3 @@ ret.inheritance = inheritance() || null;

while (true) {
all_ws();
all_ws(store ? mems : null);
if (consume(OTHER, "}")) {

@@ -741,4 +825,4 @@ all_ws();

}
var ea = extended_attrs();
all_ws();
var ea = extended_attrs(store ? mems : null);
all_ws(store ? mems : null, "pea");
var cnt = const_();

@@ -765,11 +849,12 @@ if (cnt) {

var enum_ = function () {
all_ws();
var enum_ = function (store) {
all_ws(store, "pea");
if (!consume(ID, "enum")) return;
all_ws();
var name = consume(ID) || error("No name for enum");
var ret = {
var vals = []
, ret = {
type: "enum"
, name: name.value
, values: []
, values: vals
};

@@ -780,3 +865,3 @@ all_ws();

while (true) {
all_ws();
all_ws(store ? vals : null);
if (consume(OTHER, "}")) {

@@ -790,5 +875,6 @@ all_ws();

ret.values.push(val.value.replace(/"/g, ""));
all_ws();
all_ws(store ? vals : null);
if (consume(OTHER, ",")) {
all_ws();
if (store) vals.push({ type: "," });
all_ws(store ? vals : null);
saw_comma = true;

@@ -802,4 +888,4 @@ }

var typedef = function () {
all_ws();
var typedef = function (store) {
all_ws(store, "pea");
if (!consume(ID, "typedef")) return;

@@ -811,3 +897,3 @@ var ret = {

ret.typeExtAttrs = extended_attrs();
all_ws();
all_ws(store, "tpea");
ret.idlType = type() || error("No type in typedef");

@@ -822,4 +908,4 @@ all_ws();

var implements_ = function () {
all_ws();
var implements_ = function (store) {
all_ws(store, "pea");
var target = consume(ID);

@@ -847,20 +933,20 @@ if (!target) return;

var definition = function () {
return callback() ||
interface_() ||
partial() ||
dictionary() ||
exception() ||
enum_() ||
typedef() ||
implements_()
var definition = function (store) {
return callback(store) ||
interface_(false, store) ||
partial(store) ||
dictionary(false, store) ||
exception(store) ||
enum_(store) ||
typedef(store) ||
implements_(store)
;
};
var definitions = function () {
var definitions = function (store) {
if (!tokens.length) return [];
var defs = [];
while (true) {
var ea = extended_attrs()
, def = definition();
var ea = extended_attrs(store ? defs : null)
, def = definition(store ? defs : null);
if (!def) {

@@ -875,3 +961,3 @@ if (ea.length) error("Stray extended attributes");

};
var res = definitions();
var res = definitions(opt.ws);
if (tokens.length) error("Unrecognised tokens");

@@ -881,14 +967,13 @@ return res;

var obj = {
parse: function (str) {
var tokens = tokenise(str);
return parse(tokens);
}
var inNode = typeof module !== "undefined" && module.exports
, obj = {
parse: function (str, opt) {
if (!opt) opt = {};
var tokens = tokenise(str);
return parse(tokens, opt);
}
};
if (typeof module !== "undefined" && module.exports) {
module.exports = obj;
}
else {
window.WebIDL2 = obj;
}
if (inNode) module.exports = obj;
else window.WebIDL2 = obj;
}());
{
"name": "webidl2"
, "description": "A WebIDL Parser"
, "version": "2.0.4"
, "version": "2.0.5"
, "author": "Robin Berjon <robin@berjon.com>"
, "license": "MIT"
, "dependencies": {

@@ -12,8 +13,11 @@ }

, "underscore": "1.4.3"
, "jsondiffpatch": "*"
, "jsondiffpatch": "0.0.5"
, "benchmark": "*"
, "microtime": "*"
}
, "scripts": {
"test": "mocha"
}
, "repository": "git://github.com/darobin/webidl2.js"
, "main": "index"
}
# WebIDL 2
[![NPM version](https://badge.fury.io/js/webidl2.png)](http://badge.fury.io/js/webidl2)
Purpose

@@ -91,2 +95,3 @@ =======

"sequence": false,
"promise": false,
"nullable": false,

@@ -101,2 +106,3 @@ "array": false,

* `sequence`: Boolean indicating whether this is a sequence or not.
* `promise`: Boolean indicating whether this is a promise or not.
* `nullable`: Boolean indicating whether this is nullable or not.

@@ -109,4 +115,5 @@ * `array`: Either `false` to indicate that it is not an array, or a number for the level of

because it can take more complex values. If the type is a union, then this contains an
array of the types it unites. If it is a sequence, it contains an IDL type description
for the type in the sequence.
array of the types it unites. If it is a sequence or a promise, it contains an IDL
type description for the type in the sequence or for the eventual value of the
promise.

@@ -191,2 +198,3 @@ #### Interactions between `nullable` and `array`

"sequence": false,
"promise": false,
"nullable": false,

@@ -223,2 +231,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": true,

@@ -270,2 +279,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -329,2 +339,3 @@ "array": false,

"sequence": true,
"promise": false,
"nullable": false,

@@ -335,2 +346,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -388,2 +400,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -402,2 +415,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -441,2 +455,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -503,2 +518,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -589,2 +605,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -614,2 +631,3 @@ "array": false,

"sequence": false,
"promise": false,
"nullable": false,

@@ -659,2 +677,4 @@ "array": false,

`value`.
* `typePair`: If the extended attribute is a `MapClass` this will capture the
map's key type and value type respectively.

@@ -685,3 +705,2 @@ ### Default and Const Values

git submodule update
git pull origin master (in the submodule, once in a while)

@@ -688,0 +707,0 @@ Running

@@ -6,3 +6,3 @@

var wp = process.env.JSCOV ? require("../lib/webidl2") : require("../lib-cov/webidl2")
var wp = process.env.JSCOV ? require("../lib-cov/webidl2") : require("../lib/webidl2")
, expect = require("expect.js")

@@ -13,3 +13,3 @@ , pth = require("path")

describe("Parses all of the invalid IDLs to check that they blow up correctly", function () {
var dir = pth.join(__dirname, "widlproc/test/invalid/idl")
var dir = pth.join(__dirname, "invalid/idl")
, skip = {}

@@ -19,3 +19,3 @@ , idls = fs.readdirSync(dir)

.map(function (it) { return pth.join(dir, it); })
, errors = idls.map(function (it) { return pth.join(__dirname, "error", pth.basename(it).replace(/\.w?idl/, ".json")); })
, errors = idls.map(function (it) { return pth.join(__dirname, "invalid", "json", pth.basename(it).replace(/\.w?idl/, ".json")); })
;

@@ -22,0 +22,0 @@

@@ -10,3 +10,3 @@

describe("Parses all of the IDLs to produce the correct ASTs", function () {
var dir = pth.join(__dirname, "widlproc/test/valid/idl")
var dir = pth.join(__dirname, "syntax/idl")
, skip = {} // use if we have a broken test

@@ -16,3 +16,3 @@ , idls = fs.readdirSync(dir)

.map(function (it) { return pth.join(dir, it); })
, jsons = idls.map(function (it) { return pth.join(__dirname, "json", pth.basename(it).replace(".widl", ".json")); })
, jsons = idls.map(function (it) { return pth.join(__dirname, "syntax/json", pth.basename(it).replace(".widl", ".json")); })
;

@@ -19,0 +19,0 @@

@@ -22,8 +22,8 @@

valid: {
json: allFromDir(dir("json"), /\.json$/, true)
, idl: allFromDir(dir("widlproc/test/valid/idl"), /\.w?idl$/, false)
json: allFromDir(dir("syntax/json"), /\.json$/, true)
, idl: allFromDir(dir("syntax/idl"), /\.w?idl$/, false)
}
, invalid:{
json: allFromDir(dir("error"), /\.json$/, true)
, idl: allFromDir(dir("widlproc/test/invalid/idl"), /\.w?idl$/, false)
json: allFromDir(dir("invalid/json"), /\.json$/, true)
, idl: allFromDir(dir("invalid/idl"), /\.w?idl$/, false)
}

@@ -30,0 +30,0 @@ }

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