Comparing version 7.0.0 to 7.0.1
@@ -26,3 +26,3 @@ "use strict"; | ||
let definedOn = this.obj.name + (this.idl.static ? "" : ".prototype"); | ||
if (!configurable || utils.isGlobal(this.interface)) { // we're in a setup method | ||
if (utils.isOnInstance(this.idl, this.interface)) { // we're in a setup method | ||
objName = `obj`; | ||
@@ -87,9 +87,27 @@ definedOn = `obj`; | ||
if (this.idl.stringifier) { | ||
str += `${this.obj.name}.prototype.toString = function () { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
const functionExpression = ` | ||
function toString() { | ||
if (!this || !module.exports.is(this)) { | ||
throw new TypeError("Illegal invocation"); | ||
} | ||
${getterBody}; | ||
} | ||
`; | ||
if (utils.getExtAttr(this.idl.extAttrs, "Unforgeable")) { | ||
str += ` | ||
Object.defineProperty(${definedOn}, "toString", { | ||
writable: false, | ||
enumerable: true, | ||
configurable: false, | ||
value: ${functionExpression} | ||
}); | ||
`; | ||
} else { | ||
str += ` | ||
${definedOn}.toString = ${functionExpression}; | ||
`; | ||
} | ||
str += "\n"; | ||
} | ||
${getterBody}; | ||
};\n\n`; | ||
} | ||
@@ -96,0 +114,0 @@ return { |
@@ -261,16 +261,22 @@ "use strict"; | ||
const memberIdl = this.idl.members[i]; | ||
if (memberIdl.type === "attribute" && (utils.getExtAttr(memberIdl.extAttrs, "Unforgeable") || utils.isGlobal(this.idl))) { | ||
const member = new Attribute(this.ctx, this, this.idl, memberIdl); | ||
this.str += "\n " + member.generate().body.replace(/\n/g, '\n '); | ||
if (utils.isOnInstance(memberIdl, this.idl)) { | ||
let member; | ||
switch (memberIdl.type) { | ||
case "operation": { | ||
member = new Operation(this.ctx, this, this.idl, memberIdl); | ||
break; | ||
} | ||
case "attribute": { | ||
member = new Attribute(this.ctx, this, this.idl, memberIdl); | ||
break; | ||
} | ||
default: { | ||
throw new Error("Cannot handle on-instance members that are not operations or attributes"); | ||
} | ||
} | ||
this.str += "\n" + member.generate().body; | ||
} | ||
} | ||
if (utils.getExtAttr(this.idl.extAttrs, "Unforgeable")) { | ||
this.str += ` | ||
Object.defineProperty(obj, "valueOf", { | ||
value: function valueOf() { return this; }, | ||
enumerable: true | ||
});\n`; | ||
} | ||
this.str += ` | ||
@@ -324,2 +330,5 @@ }, | ||
case "operation": | ||
if (utils.isOnInstance(memberIdl, this.idl)) { | ||
break; | ||
} | ||
member = new Operation(this.ctx, this, this.idl, memberIdl); | ||
@@ -354,3 +363,3 @@ if (done[member.name]) { | ||
case "attribute": | ||
if (utils.getExtAttr(memberIdl.extAttrs, "Unforgeable") || utils.isGlobal(this.idl)) { | ||
if (utils.isOnInstance(memberIdl, this.idl)) { | ||
break; | ||
@@ -357,0 +366,0 @@ } |
"use strict"; | ||
const conversions = require("webidl-conversions"); | ||
const utils = require("../utils"); | ||
const Overloads = require("../overloads"); | ||
@@ -19,3 +21,7 @@ const Parameters = require("../parameters"); | ||
let str = ""; | ||
const targetObj = this.idl.static ? "" : ".prototype"; | ||
if (this.idl.name === null) { | ||
return { requires: {}, body: "" }; | ||
} | ||
let name = this.idl.name; | ||
@@ -26,3 +32,7 @@ if (this.idl.stringifier && !name) { | ||
if (this.idl.name === null) return { requires: {}, body: "" }; | ||
let targetObj = this.obj.name + (this.idl.static ? "" : ".prototype"); | ||
if (utils.isOnInstance(this.idl, this.interface)) { | ||
targetObj = "obj"; | ||
} | ||
const overloads = Overloads.getEffectiveOverloads(name, 0, this.interface, null); | ||
@@ -40,3 +50,3 @@ let minConstructor = overloads[0]; | ||
str += `\n${this.obj.name + targetObj}.${name} = function ${fnName}(${minConstructor.nameList.join(", ")}) {`; | ||
str += `\n${targetObj}.${name} = function ${fnName}(${minConstructor.nameList.join(", ")}) {`; | ||
if (!this.idl.static) { | ||
@@ -43,0 +53,0 @@ str += ` |
@@ -88,4 +88,3 @@ "use strict"; | ||
const result = Object.create(null); | ||
const keys = Object.getOwnPropertyNames(${name}); | ||
for (let key of keys) { | ||
for (const key of Reflect.ownKeys(${name})) { | ||
const desc = Object.getOwnPropertyDescriptor(${name}, key); | ||
@@ -92,0 +91,0 @@ if (desc && desc.enumerable) { |
@@ -22,1 +22,5 @@ "use strict"; | ||
}; | ||
module.exports.isOnInstance = (memberIDL, interfaceIDL) => { | ||
return module.exports.getExtAttr(memberIDL.extAttrs, "Unforgeable") || module.exports.isGlobal(interfaceIDL); | ||
}; |
{ | ||
"name": "webidl2js", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "Auto-generates class structures for WebIDL specifications", | ||
@@ -5,0 +5,0 @@ "main": "lib/transformer.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
46884
1397