removeProperties: delete more unused code from the original es-lab version
MODIFY
src/removeProperties.js
src/removeProperties.js
var cleaning = new WeakMap();
- /**
- * Delete the property if possible, else try to poison.
- */
- function cleanProperty(base, name, path) {
- if (path === 'Promise.all.arguments') {
- debugger;
- }
- if (path === 'Q.all.arguments') {
- debugger;
- }
- var poison = ses.getAnonIntrinsics().ThrowTypeError;
- var diagnostic;
-
- if (typeof base === 'function' && !ses.noFuncPoison) {
- if (name === 'caller') {
- diagnostic = ses.makeCallerHarmless(base, path);
- // We can use a severity of SAFE here since if this isn't
- // safe, it is the responsibility of repairES5.js to tell us
- // so. All the same, we should inspect the reports on all
- // platforms we care about to see if there are any surprises.
- reportProperty(ses.severities.SAFE,
- diagnostic, path);
- return true;
- }
- if (name === 'arguments') {
- diagnostic = ses.makeArgumentsHarmless(base, path);
- // We can use a severity of SAFE here since if this isn't
- // safe, it is the responsibility of repairES5.js to tell us
- // so. All the same, we should inspect the reports on all
- // platforms we care about to see if there are any surprises.
- reportProperty(ses.severities.SAFE,
- diagnostic, path);
- return true;
- }
- }
-
- if (name === '__proto__') {
- // At least Chrome Version 27.0.1428.0 canary, Safari Version
- // 6.0.2 (8536.26.17), and Opera 12.14 include '__proto__' in the
- // result of Object.getOwnPropertyNames. However, the meaning of
- // deleting this isn't clear, so here we effectively whitelist
- // it on all objects.
- //
- // We do not whitelist it in whitelist.js, as that would involve
- // creating a property {@code __proto__: '*'} which, on some
- // engines (and perhaps as standard on ES6) attempt to make this
- // portion of the whitelist inherit from {@code '*'}, which
- // would fail in amusing ways.
- reportProperty(ses.severities.SAFE_SPEC_VIOLATION,
- 'Skipped', path);
- return true;
- }
-
- var deleted = void 0;
- var err = void 0;
- try {
- deleted = delete base[name];
- } catch (er) { err = er; }
- var exists = hop.call(base, name);
- if (deleted) {
- if (!exists) {
- reportProperty(ses.severities.SAFE,
- 'Deleted', path);
- return true;
- }
- reportProperty(ses.severities.SAFE_SPEC_VIOLATION,
- 'Bounced back', path);
- } else if (deleted === false) {
- reportProperty(ses.severities.SAFE_SPEC_VIOLATION,
- 'Strict delete returned false rather than throwing', path);
- } else if (err instanceof TypeError) {
- // This is the normal abnormal case, so leave it to the next
- // section to emit a diagnostic.
- //
- // reportProperty(ses.severities.SAFE_SPEC_VIOLATION,
- // 'Cannot be deleted', path);
- } else {
- reportProperty(ses.severities.NEW_SYMPTOM,
- 'Delete failed with' + err, path);
- }
-
- try {
- defProp(base, name, {
- get: poison,
- set: poison,
- enumerable: false,
- configurable: false
- });
- } catch (cantPoisonErr) {
- try {
- // Perhaps it's writable non-configurable, in which case we
- // should still be able to freeze it in a harmless state.
- var value = gopd(base, name).value;
- defProp(base, name, {
- // If it's a primitive value, like IE10's non-standard,
- // non-deletable, but harmless RegExp.prototype.options,
- // then we allow it to retain its value.
- value: value === Object(value) ? void 0 : value,
- writable: false,
- configurable: false
- });
- } catch (cantFreezeHarmless) {
- reportProperty(ses.severities.NOT_ISOLATED,
- 'Cannot be poisoned', path);
- return false;
- }
- }
- var desc2 = gopd(base, name);
- if (desc2.get === poison &&
- desc2.set === poison &&
- !desc2.configurable) {
- try {
- var dummy2 = base[name];
- } catch (expectedErr) {
- if (expectedErr instanceof TypeError) {
- reportProperty(ses.severities.SAFE,
- 'Successfully poisoned', path);
- return true;
- }
- }
- } else if (desc2.value !== Object(desc2.value2) && // is primitive
- !desc2.writable &&
- !desc2.configurable) {
- var diagnostic = 'Frozen harmless';
- if (name === 'caller' || name === 'arguments') {
- diagnostic = name + ' ' + diagnostic;
- }
- reportProperty(ses.severities.SAFE,
- diagnostic , path);
- return false;
- }
- reportProperty(ses.severities.NEW_SYMPTOM,
- 'Failed to be poisoned', path);
- return false;
- }
-
/**
* Removes all non-whitelisted properties found by recursively and
* reflectively walking own property chains.

removeProperties: delete more unused code from the original es-lab version