Socket
Socket
Sign inDemoInstall

webidl2js

Package Overview
Dependencies
Maintainers
6
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webidl2js - npm Package Compare versions

Comparing version 16.0.0 to 16.1.0

lib/constructs/callback-function.js

2

lib/constructs/interface.js

@@ -1353,3 +1353,3 @@ "use strict";

if (body[1] !== undefined) {
addOne(`static set ${propName}`, args, body[0]);
addOne(`static set ${propName}`, args, body[1]);
}

@@ -1356,0 +1356,0 @@ }

@@ -32,2 +32,4 @@ "use strict";

const whence = this.interface.defaultWhence;
const requires = new utils.RequiresMap(this.ctx);
if (this.isPair) {

@@ -46,6 +48,5 @@ this.generateFunction("keys", "key");

}
if (typeof callback !== "function") {
throw new TypeError("Failed to execute 'forEach' on '${this.name}': The callback provided " +
"as parameter 1 is not a function.");
}
callback = ${requires.addRelative("Function")}.convert(callback, {
context: "Failed to execute 'forEach' on '${this.name}': The callback provided as parameter 1"
});
const thisArg = arguments[1];

@@ -69,5 +70,3 @@ let pairs = Array.from(this[implSymbol]);

return {
requires: new utils.RequiresMap(this.ctx)
};
return { requires };
}

@@ -74,0 +73,0 @@ }

"use strict";
const webidl = require("webidl2");
const CallbackFunction = require("./constructs/callback-function.js");
const Typedef = require("./constructs/typedef");
const builtinTypedefs = webidl.parse(`
const builtinTypes = webidl.parse(`
typedef (Int8Array or Int16Array or Int32Array or

@@ -11,2 +12,5 @@ Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or

typedef unsigned long long DOMTimeStamp;
callback Function = any (any... arguments);
callback VoidFunction = void ();
`);

@@ -24,3 +28,3 @@

processReflect = null,
options
options = { suppressErrors: false }
} = {}) {

@@ -41,7 +45,15 @@ this.implSuffix = implSuffix;

this.callbackInterfaces = new Map();
this.callbackFunctions = new Map();
this.dictionaries = new Map();
this.enumerations = new Map();
for (const typedef of builtinTypedefs) {
this.typedefs.set(typedef.name, new Typedef(this, typedef));
for (const idl of builtinTypes) {
switch (idl.type) {
case "typedef":
this.typedefs.set(idl.name, new Typedef(this, idl));
break;
case "callback":
this.callbackFunctions.set(idl.name, new CallbackFunction(this, idl));
break;
}
}

@@ -60,2 +72,5 @@ }

}
if (this.callbackFunctions.has(name)) {
return "callback";
}
if (this.dictionaries.has(name)) {

@@ -62,0 +77,0 @@ return "dictionary";

@@ -14,2 +14,3 @@ "use strict";

const CallbackInterface = require("./constructs/callback-interface.js");
const CallbackFunction = require("./constructs/callback-function");
const Dictionary = require("./constructs/dictionary");

@@ -88,3 +89,11 @@ const Enumeration = require("./constructs/enumeration");

this.ctx.initialize();
const { interfaces, interfaceMixins, callbackInterfaces, dictionaries, enumerations, typedefs } = this.ctx;
const {
interfaces,
interfaceMixins,
callbackInterfaces,
callbackFunctions,
dictionaries,
enumerations,
typedefs
} = this.ctx;

@@ -118,2 +127,6 @@ // first we're gathering all full interfaces and ignore partial ones

break;
case "callback":
obj = new CallbackFunction(this.ctx, instruction);
callbackFunctions.set(obj.name, obj);
break;
case "includes":

@@ -204,3 +217,3 @@ break; // handled later

const { interfaces, callbackInterfaces, dictionaries, enumerations } = this.ctx;
const { interfaces, callbackInterfaces, callbackFunctions, dictionaries, enumerations } = this.ctx;

@@ -235,3 +248,3 @@ let relativeUtils = path.relative(outputDir, this.utilPath).replace(/\\/g, "/");

for (const obj of [...callbackInterfaces.values(), ...dictionaries.values()]) {
for (const obj of [...callbackInterfaces.values(), ...callbackFunctions.values(), ...dictionaries.values()]) {
let source = obj.toString();

@@ -238,0 +251,0 @@

@@ -29,3 +29,3 @@ "use strict";

// Types of types that generate an output file.
const resolvedTypes = new Set(["callback interface", "dictionary", "enumeration", "interface"]);
const resolvedTypes = new Set(["callback", "callback interface", "dictionary", "enumeration", "interface"]);

@@ -95,7 +95,16 @@ function resolveType(ctx, idlType, stack = []) {

if (idlType.nullable) {
str += `
if (${name} === null || ${name} === undefined) {
${name} = null;
} else {
`;
const callbackFunction = ctx.callbackFunctions.get(idlType.idlType);
if (callbackFunction !== undefined && callbackFunction.legacyTreatNonObjectAsNull) {
str += `
if (!utils.isObject(${name})) {
${name} = null;
} else {
`;
} else {
str += `
if (${name} === null || ${name} === undefined) {
${name} = null;
} else {
`;
}
}

@@ -118,7 +127,12 @@

generateFrozenArray();
} else if (conversions[idlType.idlType]) {
} else if (
// TODO: Revert once `Function` and `VoidFunction` are removed from `webidl-conversions`:
idlType.idlType !== "Function" &&
idlType.idlType !== "VoidFunction" &&
conversions[idlType.idlType]
) {
// string or number type compatible with webidl-conversions
generateGeneric(`conversions["${idlType.idlType}"]`);
} else if (resolvedTypes.has(ctx.typeOf(idlType.idlType))) {
// callback interfaces, dictionaries, enumerations, and interfaces
// callback functions, callback interfaces, dictionaries, enumerations, and interfaces
let fn;

@@ -207,4 +221,17 @@ // Avoid requiring the interface itself

if (union.callback || union.object) {
output.push(`if (typeof ${name} === "function") {}`);
if (union.callbackFunction || union.object) {
let code = `if (typeof ${name} === "function") {`;
if (union.callbackFunction) {
const conv = generateTypeConversion(ctx, name, union.callbackFunction, [], parentName,
`${errPrefix} + " callback function"`);
requires.merge(conv.requires);
code += conv.body;
} else if (union.object) {
// noop
}
code += "}";
output.push(code);
}

@@ -335,20 +362,3 @@

function generatePromise() {
let handler;
if (idlType.idlType[0].idlType === "void") {
// Do nothing.
handler = "";
} else {
const conv = generateTypeConversion(ctx, "value", idlType.idlType[0], [], parentName,
`${errPrefix} + " promise value"`);
requires.merge(conv.requires);
handler = `
${conv.body}
return value;
`;
}
str += `
${name} = Promise.resolve(${name}).then(value => {
${handler}
}, reason => reason);
`;
str += `${name} = new Promise(resolve => resolve(${name}));`;
}

@@ -409,4 +419,3 @@

boolean: null,
// Callback function, not interface
callback: false,
callbackFunction: null,
dictionary: null,

@@ -430,3 +439,3 @@ callbackInterface: null,

}
if (seen.callback) {
if (seen.callbackFunction) {
error("Dictionary-like types are not distinguishable with callback functions");

@@ -468,3 +477,3 @@ }

}
if (seen.callback) {
if (seen.callbackFunction) {
error("Object type is not distinguishable with callback functions");

@@ -481,4 +490,3 @@ }

seen.boolean = item;
} else if (item.idlType === "Function") {
// TODO: add full support for callback functions
} else if (ctx.callbackFunctions.has(item.idlType)) {
if (seen.object) {

@@ -490,3 +498,3 @@ error("Callback functions are not distinguishable with object type");

}
seen.callback = true;
seen.callbackFunction = item.idlType;
} else if (ctx.dictionaries.has(item.idlType)) {

@@ -496,3 +504,3 @@ if (seen.object) {

}
if (seen.callback) {
if (seen.callbackFunction) {
error("Dictionary-like types are not distinguishable with callback functions");

@@ -508,3 +516,3 @@ }

}
if (seen.callback) {
if (seen.callbackFunction) {
error("Dictionary-like types are not distinguishable with callback functions");

@@ -511,0 +519,0 @@ }

{
"name": "webidl2js",
"version": "16.0.0",
"version": "16.1.0",
"description": "Auto-generates class structures for WebIDL specifications",

@@ -5,0 +5,0 @@ "main": "lib/transformer.js",

@@ -457,3 +457,3 @@ # JavaScript bindings generator for Web IDL

- Callback interfaces
- Callback function types, somewhat
- Callback functions
- Nullable types

@@ -478,2 +478,3 @@ - `sequence<>` types

- `[LegacyOverrideBuiltins]`
- `[LegacyTreatNonObjectAsNull]`
- `[LegacyUnenumerableNamedProperties]`

@@ -480,0 +481,0 @@ - `[LegacyUnforgeable]`

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