Skip to content

Commit

Permalink
revert symbol rename
Browse files Browse the repository at this point in the history
  • Loading branch information
pmdartus committed Jan 22, 2020
1 parent bb4a763 commit a2ba621
Show file tree
Hide file tree
Showing 5 changed files with 1,152 additions and 1,032 deletions.
6 changes: 3 additions & 3 deletions lib/constructs/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class Attribute {
throw new TypeError("Illegal invocation");
}
`;
let getterBody = `return utils.tryWrapperForImpl(${objName}[implSymbol]["${this.idl.name}"]);`;
let setterBody = `${objName}[implSymbol]["${this.idl.name}"] = V;`;
let getterBody = `return utils.tryWrapperForImpl(${objName}[impl]["${this.idl.name}"]);`;
let setterBody = `${objName}[impl]["${this.idl.name}"] = V;`;
if (conversions[this.idl.idlType.idlType]) {
getterBody = `return ${objName}[implSymbol]["${this.idl.name}"];`;
getterBody = `return ${objName}[impl]["${this.idl.name}"];`;
}

const addMethod = this.static ?
Expand Down
102 changes: 53 additions & 49 deletions lib/constructs/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class Interface {
value: function next() {
const internal = this[utils.iterInternalSymbol];
const { target, kind, index } = internal;
const values = Array.from(target[implSymbol]);
const values = Array.from(target[impl]);
const len = values.length;
if (index >= len) {
return { value: undefined, done: true };
Expand Down Expand Up @@ -498,9 +498,9 @@ class Interface {
}

generateRequires() {
this.requires.addRaw("implSymbol", "utils.implSymbol");
this.requires.addRaw("impl", "utils.implSymbol");
this.requires.addRaw("ctorRegistry", "utils.ctorRegistrySymbol");
this.requires.addRaw("wrapperSymbol", "utils.wrapperSymbol");
this.requires.addRaw("ctorRegistrySymbol", "utils.ctorRegistrySymbol");
this.requires.addRaw("globalObjectSymbol", "utils.globalObjectSymbol");
this.requires.addRaw("createWrapperSymbol", "utils.createWrapperSymbol");

Expand Down Expand Up @@ -537,7 +537,7 @@ class Interface {
exports._mixedIntoPredicates = [];
exports.is = function is(obj) {
if (obj) {
if (utils.hasOwn(obj, implSymbol) && obj[implSymbol] instanceof Impl.implementation) {
if (utils.hasOwn(obj, impl) && obj[impl] instanceof Impl.implementation) {
return true;
}
for (const isMixedInto of exports._mixedIntoPredicates) {
Expand Down Expand Up @@ -598,10 +598,10 @@ class Interface {
}
if (unsupportedValue) {
const func = this.indexedGetter.name ? `.${this.indexedGetter.name}` : "[utils.indexedGet]";
const value = indexedValue || `${O}[implSymbol]${func}(${index})`;
const value = indexedValue || `${O}[impl]${func}(${index})`;
return `${value} !== ${unsupportedValue}`;
}
return `${O}[implSymbol][utils.supportsPropertyIndex](${index})`;
return `${O}[impl][utils.supportsPropertyIndex](${index})`;
};

const supportsPropertyName = (O, P, namedValue) => {
Expand All @@ -611,10 +611,10 @@ class Interface {
}
if (unsupportedValue) {
const func = this.namedGetter.name ? `.${this.namedGetter.name}` : "[utils.namedGet]";
const value = namedValue || `${O}[implSymbol]${func}(${P})`;
const value = namedValue || `${O}[impl]${func}(${P})`;
return `${value} !== ${unsupportedValue}`;
}
return `${O}[implSymbol][utils.supportsPropertyName](${P})`;
return `${O}[impl][utils.supportsPropertyName](${P})`;
};

// "named property visibility algorithm"
Expand Down Expand Up @@ -651,14 +651,14 @@ class Interface {
str += `
const creating = !(${supportsPropertyIndex(O, "index")});
if (creating) {
${O}[implSymbol][utils.indexedSetNew](index, indexedValue);
${O}[impl][utils.indexedSetNew](index, indexedValue);
} else {
${O}[implSymbol][utils.indexedSetExisting](index, indexedValue);
${O}[impl][utils.indexedSetExisting](index, indexedValue);
}
`;
} else {
str += `
${O}[implSymbol].${this.indexedSetter.name}(index, indexedValue);
${O}[impl].${this.indexedSetter.name}(index, indexedValue);
`;
}

Expand All @@ -682,14 +682,14 @@ class Interface {
str += `
const creating = !(${supportsPropertyName(O, P)});
if (creating) {
${O}[implSymbol][utils.namedSetNew](${P}, namedValue);
${O}[impl][utils.namedSetNew](${P}, namedValue);
} else {
${O}[implSymbol][utils.namedSetExisting](${P}, namedValue);
${O}[impl][utils.namedSetExisting](${P}, namedValue);
}
`;
} else {
str += `
${O}[implSymbol].${this.namedSetter.name}(${P}, namedValue);
${O}[impl].${this.namedSetter.name}(${P}, namedValue);
`;
}

Expand Down Expand Up @@ -752,14 +752,14 @@ class Interface {
`;
if (this.supportsIndexedProperties) {
this.str += `
for (const key of target[implSymbol][utils.supportedPropertyIndices]) {
for (const key of target[impl][utils.supportedPropertyIndices]) {
keys.add(\`\${key}\`);
}
`;
}
if (this.supportsNamedProperties) {
this.str += `
for (const key of target[implSymbol][utils.supportedPropertyNames]) {
for (const key of target[impl][utils.supportedPropertyNames]) {
if (${namedPropertyVisible("key", "target", true)}) {
keys.add(\`\${key}\`);
}
Expand Down Expand Up @@ -792,10 +792,10 @@ class Interface {
let preamble = "";
let condition;
if (utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
this.str += `const indexedValue = target[implSymbol]${func}(index);`;
this.str += `const indexedValue = target[impl]${func}(index);`;
condition = supportsPropertyIndex("target", "index", "indexedValue");
} else {
preamble = `const indexedValue = target[implSymbol]${func}(index);`;
preamble = `const indexedValue = target[impl]${func}(index);`;
condition = supportsPropertyIndex("target", "index");
}

Expand All @@ -820,13 +820,13 @@ class Interface {
const conditions = [];
if (utils.getExtAttr(this.namedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
this.str += `
const namedValue = target[implSymbol]${func}(P);
const namedValue = target[impl]${func}(P);
`;
conditions.push(supportsPropertyName("target", "index", "namedValue"));
conditions.push(namedPropertyVisible("P", "target", true));
} else {
preamble = `
const namedValue = target[implSymbol]${func}(P);
const namedValue = target[impl]${func}(P);
`;
conditions.push(namedPropertyVisible("P", "target", false));
}
Expand Down Expand Up @@ -902,10 +902,10 @@ class Interface {
let preamble = "";
let condition;
if (utils.getExtAttr(this.indexedGetter.extAttrs, "WebIDL2JSValueAsUnsupported")) {
this.str += `const indexedValue = target[implSymbol]${func}(index);`;
this.str += `const indexedValue = target[impl]${func}(index);`;
condition = supportsPropertyIndex("target", "index", "indexedValue");
} else {
preamble = `const indexedValue = target[implSymbol]${func}(index);`;
preamble = `const indexedValue = target[impl]${func}(index);`;
condition = supportsPropertyIndex("target", "index");
}

Expand Down Expand Up @@ -1071,11 +1071,11 @@ class Interface {
const func = this.namedDeleter.name ? `.${this.namedDeleter.name}` : "[utils.namedDelete]";
if (this.namedDeleter.idlType.idlType === "bool") {
this.str += `
return target[implSymbol]${func}(P);
return target[impl]${func}(P);
`;
} else {
this.str += `
target[implSymbol]${func}(P);
target[impl]${func}(P);
return true;
`;
}
Expand Down Expand Up @@ -1103,51 +1103,55 @@ class Interface {

generateIface() {
this.str += `
function createWrapper(impl) {
const globalObject = impl[globalObjectSymbol];
function createWrapper(implObject) {
const globalObject = implObject[globalObjectSymbol];
if (globalObject[ctorRegistrySymbol] === undefined) {
if (globalObject[ctorRegistry] === undefined) {
throw new Error('Internal error: invalid global object');
}
const ctor = globalObject[ctorRegistrySymbol]["${this.name}"];
const ctor = globalObject[ctorRegistry]["${this.name}"];
if (ctor === undefined) {
throw new Error('Internal error: constructor ${this.name} is not installed on the passed global object');
}
let wrapper = Object.create(ctor.prototype);
exports._internalSetup(wrapper);
let wrapperObject = Object.create(ctor.prototype);
exports._internalSetup(wrapperObject);
`;

if (this.isLegacyPlatformObj) {
this.str += `
wrapper = new Proxy(wrapper, proxyHandler);
wrapperObject = new Proxy(wrapperObject, proxyHandler);
`;
}

this.str += `
impl[wrapperSymbol] = wrapper;
wrapper[implSymbol] = impl;
return wrapper;
implObject[wrapperSymbol] = wrapperObject;
wrapperObject[impl] = implObject;
return wrapperObject;
};
exports.create = function create(globalObject, constructorArgs, privateData) {
const impl = exports.createImpl(globalObject, constructorArgs, privateData);
return utils.wrapperForImpl(impl);
const implObject = exports.createImpl(globalObject, constructorArgs, privateData);
return utils.wrapperForImpl(implObject);
};
exports.createImpl = function createImpl(globalObject, constructorArgs = [], privateData = {}) {
const impl = new Impl.implementation(globalObject, constructorArgs, privateData);
const implObject = new Impl.implementation(globalObject, constructorArgs, privateData);
impl[wrapperSymbol] = null;
impl[globalObjectSymbol] = globalObject;
impl[createWrapperSymbol] = createWrapper;
implObject[wrapperSymbol] = null;
implObject[globalObjectSymbol] = globalObject;
implObject[createWrapperSymbol] = createWrapper;
return impl;
return implObject;
};
exports.setup = function setup(wrapper, globalObject, constructorArgs = [], privateData = {}) {
const impl = exports.createImpl(globalObject, constructorArgs, privateData);
impl[wrapperSymbol] = wrapper;
wrapper[implSymbol] = impl;
return wrapper;
exports.setup = function setup(wrapperObject, globalObject, constructorArgs = [], privateData = {}) {
const implObject = exports.createImpl(globalObject, constructorArgs, privateData);
implObject[wrapperSymbol] = wrapperObject;
wrapperObject[impl] = implObject;
exports._internalSetup(wrapperObject);
return wrapperObject;
};
exports._internalSetup = function _internalSetup(obj) {
`;
Expand Down Expand Up @@ -1445,10 +1449,10 @@ class Interface {
this.generateOffInstanceAfterClass();

this.str += `
if (globalObject[ctorRegistrySymbol] === undefined) {
globalObject[ctorRegistrySymbol] = Object.create(null);
if (globalObject[ctorRegistry] === undefined) {
globalObject[ctorRegistry] = Object.create(null);
}
globalObject[ctorRegistrySymbol]["${name}"] = ${name};
globalObject[ctorRegistry]["${name}"] = ${name};
Object.defineProperty(globalObject, "${name}", {
configurable: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/constructs/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Operation {
`;
}

const callOn = this.static ? "Impl.implementation" : "this[implSymbol]";
const callOn = this.static ? "Impl.implementation" : "this[impl]";
// In case of stringifiers, use the named implementation function rather than hardcoded "toString".
// All overloads will have the same name, so pick the first one.
const implFunc = this.idls[0].name || this.name;
Expand Down
18 changes: 9 additions & 9 deletions lib/reflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

module.exports.boolean = {
get(objName, attrName) {
return `return this[implSymbol].hasAttributeNS(null, "${attrName}");`;
return `return this[impl].hasAttributeNS(null, "${attrName}");`;
},
set(objName, attrName) {
return `
if (V) {
this[implSymbol].setAttributeNS(null, "${attrName}", "");
this[impl].setAttributeNS(null, "${attrName}", "");
} else {
this[implSymbol].removeAttributeNS(null, "${attrName}");
this[impl].removeAttributeNS(null, "${attrName}");
}
`;
}
Expand All @@ -18,35 +18,35 @@ module.exports.boolean = {
module.exports.DOMString = {
get(objName, attrName) {
return `
const value = this[implSymbol].getAttributeNS(null, "${attrName}");
const value = this[impl].getAttributeNS(null, "${attrName}");
return value === null ? "" : value;
`;
},
set(objName, attrName) {
return `this[implSymbol].setAttributeNS(null, "${attrName}", V);`;
return `this[impl].setAttributeNS(null, "${attrName}", V);`;
}
};

module.exports.long = {
get(objName, attrName) {
return `
const value = parseInt(this[implSymbol].getAttributeNS(null, "${attrName}"));
const value = parseInt(this[impl].getAttributeNS(null, "${attrName}"));
return isNaN(value) || value < -2147483648 || value > 2147483647 ? 0 : value
`;
},
set(objName, attrName) {
return `this[implSymbol].setAttributeNS(null, "${attrName}", String(V));`;
return `this[impl].setAttributeNS(null, "${attrName}", String(V));`;
}
};

module.exports["unsigned long"] = {
get(objName, attrName) {
return `
const value = parseInt(this[implSymbol].getAttributeNS(null, "${attrName}"));
const value = parseInt(this[impl].getAttributeNS(null, "${attrName}"));
return isNaN(value) || value < 0 || value > 2147483647 ? 0 : value
`;
},
set(objName, attrName) {
return `this[implSymbol].setAttributeNS(null, "${attrName}", String(V > 2147483647 ? 0 : V));`;
return `this[impl].setAttributeNS(null, "${attrName}", String(V > 2147483647 ? 0 : V));`;
}
};
Loading

0 comments on commit a2ba621

Please sign in to comment.