Skip to content

Commit

Permalink
Some basic fixes and spec updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebmaster committed Sep 29, 2016
1 parent 2cbc9d9 commit 3269ada
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions lib/constructs/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,43 @@ Interface.prototype.generateNamedPropertiesObject = function () {
}

let overrideBuiltins = false;
const unforgeables = new Set();
let parent = this.idl;
while (parent) {
if (utils.getExtAttr(parent.extAttrs, 'Unforgeable')) {
unforgeables.add('valueOf').add('toString');
}
if (utils.getExtAttr(parent.extAttrs, 'OverrideBuiltins')) {
overrideBuiltins = true;
}

const members = parent.members.filter((m) =>
m.type === 'attribute' && utils.getExtAttr(m.extAttrs, 'Unforgeable')
);
for (const member of members) {
unforgeables.add(member.name);
}
const parentInterface = this.opts.interfaces[parent.inheritance];
parent = parentInterface && parentInterface.idl;
}

this.str += `
function namedPropertiesIsVisible(P, O) {
if (P of ${JSON.stringify(Array.from(unforgeables))}) {
if (!true) { // is supported
return false;
}
if (!supported) {
if (Object.getOwnPropertyDescriptor(O, P)) {
return false;
}`;
}
`;

if (overrideBuiltins) {
this.str += `
return true;`;
} else {
this.str += `
if (Object.getOwnPropertyDescriptor(O, P)) {
return false;
}

this.str += `
let prototype = Object.getPrototypeOf(O);
while (prototype) {
if (prototype.constructor.name.endsWith("PropertiesConstructor") && Object.getOwnPropertyDescriptor(prototype, P)) {
return false;
}
prototype = Object.getPrototypeOf(prototype);
}`;
}
this.str += `
return true;
}`;
Expand All @@ -88,9 +79,13 @@ function namedPropertiesIsVisible(P, O) {

if (this.idl.inheritance) {
this.str += `${this.name}PropertiesConstructor.prototype = Object.create(${this.idl.inheritance}.interface.prototype);
${this.name}PropertiesConstructor.prototype.constructor = ${this.name}PropertiesConstructor;\n`;
} else if (utils.getExtAttr(this.idl.extAttrs, 'LegacyArrayClass')) {
this.str += `${this.name}PropertiesConstructor.prototype = Object.create(Array.prototype);
${this.name}PropertiesConstructor.prototype.constructor = ${this.name}PropertiesConstructor;\n`;
}

const getter = this.idl.members.filter((m) => m.getter)[0].name;
this.str += `
const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.prototype, {
defineProperty() {
Expand All @@ -100,11 +95,11 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
return false;
},
getOwnPropertyDescriptor(target, key) {
if (true) { // is visible
if (namedPropertiesIsVisible(key, target)) { // is visible
const value = target${getter ? "." + getter : "[utils.anonymousGetter]"}(key);
return {
value,
enumerable: ${legacyunenumerable ? "false" : "true"},
enumerable: true,
writable: true,
configurable: true
};
Expand All @@ -113,15 +108,15 @@ const ${this.name}Properties = new Proxy(${this.name}PropertiesConstructor.proto
}
},
get(target, key) {
if (true) { // is visible
if (namedPropertiesIsVisible(key, target)) { // is visible
const value = target${getter ? "." + getter : "[utils.anonymousGetter]"}(key);
return value;
} else {
return target[key];
}
},
has(target, key) {
if (true) { // is visible
if (namedPropertiesIsVisible(key, target)) { // is visible
return true;
} else {
return key in target;
Expand Down

0 comments on commit 3269ada

Please sign in to comment.