Comparing version 2.1.0 to 3.0.0
39
index.js
@@ -15,2 +15,3 @@ "use strict"; | ||
if (!opts.utilPath) opts.utilPath = path.join(outputDir, "utils.js"); | ||
implDir = path.relative(outputDir, implDir).replace(/\\/g, "/"); // fix windows file paths | ||
@@ -42,2 +43,6 @@ const interfaces = {}; | ||
case "dictionary": | ||
if (idl[i].partial) { | ||
break; | ||
} | ||
obj = new Dictionary(idl[i], { customTypes }); | ||
@@ -69,2 +74,14 @@ dictionaries[obj.name] = obj; | ||
break; | ||
case "dictionary": | ||
if (!idl[i].partial) { | ||
break; | ||
} | ||
if (opts.suppressErrors && !dictionaries[idl[i].name]) { | ||
break; | ||
} | ||
oldMembers = dictionaries[idl[i].name].idl.members; | ||
oldMembers.push.apply(oldMembers, idl[i].members); | ||
extAttrs = dictionaries[idl[i].name].idl.extAttrs; | ||
extAttrs.push.apply(oldMembers, idl[i].extAttrs); | ||
break; | ||
case "implements": | ||
@@ -79,3 +96,12 @@ if (opts.suppressErrors && !interfaces[idl[i].target]) { | ||
let keys = Object.keys(interfaces); | ||
let utilsText = fs.readFileSync(__dirname + "/lib/output/utils.js"); | ||
fs.writeFileSync(opts.utilPath, utilsText); | ||
let keys = Object.keys(interfaces).concat(Object.keys(dictionaries)); | ||
for (let key of keys) { | ||
const obj = interfaces[key] || dictionaries[key]; | ||
fs.writeFileSync(path.join(outputDir, obj.name + ".js"), ""); | ||
} | ||
keys = Object.keys(interfaces); | ||
for (let i = 0; i < keys.length; ++i) { | ||
@@ -85,3 +111,3 @@ const obj = interfaces[keys[i]]; | ||
let implFile = path.join(implDir, obj.name + opts.implSuffix); | ||
let implFile = implDir + "/" + obj.name + opts.implSuffix; | ||
if (implFile[0] !== ".") { | ||
@@ -122,11 +148,2 @@ implFile = "./" + implFile; | ||
} | ||
let utilsText = fs.readFileSync(__dirname + "/lib/output/utils.js"); | ||
const interfaceNames = opts.utilSymbols || []; | ||
interfaceNames.push.apply(interfaceNames, Object.keys(interfaces)); | ||
for (let i = 0; i < interfaceNames.length; ++i) { | ||
utilsText += `module.exports.implSymbols["${interfaceNames[i]}"] = Symbol("${interfaceNames[i]} implementation");\n`; | ||
} | ||
fs.writeFileSync(opts.utilPath, utilsText); | ||
}; |
@@ -62,3 +62,3 @@ "use strict"; | ||
str += `${this.obj.name}.prototype.toString = function () { | ||
if (!this || !this[impl]) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
@@ -65,0 +65,0 @@ } |
@@ -72,8 +72,8 @@ "use strict"; | ||
if (field.default.type === "null") { | ||
this.str += `null`; | ||
this.str += `null;`; | ||
} else { | ||
this.str += JSON.stringify(field.default.value); | ||
this.str += JSON.stringify(field.default.value) + ';'; | ||
} | ||
} | ||
this.str += `; | ||
this.str += ` | ||
}`; | ||
@@ -80,0 +80,0 @@ }); |
@@ -78,3 +78,3 @@ "use strict"; | ||
requireStr += `const impl = utils.implSymbols["${this.name}"];\n`; | ||
requireStr += `const impl = utils.implSymbol;\n`; | ||
@@ -144,10 +144,8 @@ if (this.mixins.length !== 0) { | ||
let implClass = null; | ||
try { | ||
implClass = require(this.opts.implDir + "/" + this.name + this.opts.implSuffix); | ||
} catch (e) {} | ||
// since we don't have spread arg calls, we can't do new Interface(...arguments) yet | ||
// add initialized symbol as to not destroy the object shape and cause deopts | ||
this.str += `\nmodule.exports = { | ||
is(obj) { | ||
return !!obj && obj[impl] instanceof Impl.implementation; | ||
}, | ||
create(constructorArgs, privateData) { | ||
@@ -160,8 +158,3 @@ let obj = Object.create(${this.name}.prototype); | ||
if (!privateData) privateData = {}; | ||
privateData.wrapper = obj;`; | ||
if (this.idl.inheritance !== null) { | ||
this.str += ` | ||
${this.idl.inheritance}.setup(obj, constructorArgs, privateData);`; | ||
} | ||
this.str += `\n`; | ||
privateData.wrapper = obj;\n`; | ||
@@ -184,4 +177,4 @@ for (let i = 0; i < this.idl.members.length; ++i) { | ||
if (implClass) { | ||
this.str += ` | ||
const implClass = require(this.opts.implDir + "/" + this.name + this.opts.implSuffix); | ||
this.str += ` | ||
obj[impl] = new Impl.implementation(constructorArgs, privateData); | ||
@@ -192,6 +185,2 @@ obj[impl][utils.wrapperSymbol] = obj;`; | ||
Impl.init(obj[impl], privateData);`; | ||
} | ||
} else { | ||
this.str += ` | ||
obj[impl] = {};`; | ||
} | ||
@@ -198,0 +187,0 @@ this.str += ` |
@@ -39,3 +39,3 @@ "use strict"; | ||
str += ` | ||
if (!this || !this[impl]) { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
@@ -42,0 +42,0 @@ }`; |
@@ -11,3 +11,3 @@ "use strict"; | ||
module.exports.wrapperSymbol = Symbol("wrapper"); | ||
module.exports.implSymbols = {}; | ||
module.exports.implSymbol = Symbol("impl"); | ||
@@ -18,5 +18,5 @@ module.exports.wrapperForImpl = function (impl) { | ||
module.exports.implForWrapper = function (wrapper, name) { | ||
return wrapper[module.exports.implSymbols[name]]; | ||
module.exports.implForWrapper = function (wrapper) { | ||
return wrapper[module.exports.implSymbol]; | ||
}; | ||
@@ -34,3 +34,3 @@ "use strict"; | ||
} | ||
if (conversion.optional) { | ||
if (conversion.optional && !customTypes.has(idlType.idlType)) { // always (try to) force-convert dictionaries | ||
str += ` | ||
@@ -48,3 +48,3 @@ if (${name} !== undefined) {`; | ||
} | ||
if (conversion.optional) { | ||
if (conversion.optional && !customTypes.has(idlType.idlType)) { | ||
str += ` | ||
@@ -51,0 +51,0 @@ }`; |
{ | ||
"name": "webidl2js", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Auto-generates class structures for WebIDL specifications", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28609
820