fix: kill obsolete repair-legacy-accessors
MODIFY
packages/ses/src/lockdown-shim.js
packages/ses/src/lockdown-shim.js
@@ -18,7 +18,6 @@ import makeHardener from '@agoric/make-hardener';
import { keys } from './commons.js';
import { makeIntrinsicsCollector } from './intrinsics.js';
import whitelistIntrinsics from './whitelist-intrinsics.js';
-import repairLegacyAccessors from './repair-legacy-accessors.js';
import tameFunctionConstructors from './tame-function-constructors.js';
import tameDateConstructor from './tame-date-constructor.js';
import tameMathObject from './tame-math-object.js';
@@ -231,9 +230,6 @@ export function repairIntrinsics(
// branded as honorary native functions.
whitelistIntrinsics(intrinsics, nativeBrander);
- // Repair problems with legacy accessors if necessary.
- repairLegacyAccessors();
-
// Initialize the powerful initial global, i.e., the global of the
// start compartment, from the intrinsics.
initGlobalObject(

DELETE
packages/ses/src/repair-legacy-accessors.js
-// Adapted from SES/Caja - Copyright (C) 2011 Google Inc.
-// https://github.com/google/caja/blob/master/src/com/google/caja/ses/startSES.js
-// https://github.com/google/caja/blob/master/src/com/google/caja/ses/repairES5.js
-import {
- defineProperty,
- defineProperties,
- getOwnPropertyDescriptor,
- getPrototypeOf,
- objectPrototype,
-} from './commons.js';
-
-/**
- * Replace the legacy accessors of Object to comply with strict mode
- * and ES2016 semantics, we do this by redefining them while in 'use strict'.
- *
- * todo: list the issues resolved
- *
- * This function can be used in two ways: (1) invoked directly to fix the primal
- * realm's Object.prototype, and (2) converted to a string to be executed
- * inside each new RootRealm to fix their Object.prototypes. Evaluation requires
- * the function to have no dependencies, so don't import anything from
- * the outside.
- */
-
-export default function repairLegacyAccessors() {
- try {
- // Verify that the method is not callable.
- // eslint-disable-next-line no-underscore-dangle
- (0, Object.prototype.__lookupGetter__)('x');
- } catch (ignore) {
- // Throws, no need to patch.
- return;
- }
-
- // On some platforms, the implementation of these functions act as
- // if they are in sloppy mode: if they're invoked badly, they will
- // expose the global object, so we need to repair these for
- // security. Thus it is our responsibility to fix this, and we need
- // to include repairAccessors. E.g. Chrome in 2016.
-
- function toObject(obj) {
- if (obj === undefined || obj === null) {
- throw new TypeError("can't convert undefined or null to object");
- }
- return Object(obj);
- }
-
- function asPropertyName(obj) {
- if (typeof obj === 'symbol') {
- return obj;
- }
- return `${obj}`;
- }
-
- function aFunction(obj, accessor) {
- if (typeof obj !== 'function') {
- throw TypeError(`invalid ${accessor} usage`);
- }
- return obj;
- }
-
- defineProperties(objectPrototype, {
- __defineGetter__: {
- value: function __defineGetter__(prop, func) {
- const O = toObject(this);
- defineProperty(O, prop, {
- get: aFunction(func, 'getter'),
- enumerable: true,
- configurable: true,
- });
- },
- },
- __defineSetter__: {
- value: function __defineSetter__(prop, func) {
- const O = toObject(this);
- defineProperty(O, prop, {
- set: aFunction(func, 'setter'),
- enumerable: true,
- configurable: true,
- });
- },
- },
- __lookupGetter__: {
- value: function __lookupGetter__(prop) {
- let O = toObject(this);
- prop = asPropertyName(prop);
- let desc;
- // eslint-disable-next-line no-cond-assign
- while (O && !(desc = getOwnPropertyDescriptor(O, prop))) {
- O = getPrototypeOf(O);
- }
- return desc && desc.get;
- },
- },
- __lookupSetter__: {
- value: function __lookupSetter__(prop) {
- let O = toObject(this);
- prop = asPropertyName(prop);
- let desc;
- // eslint-disable-next-line no-cond-assign
- while (O && !(desc = getOwnPropertyDescriptor(O, prop))) {
- O = getPrototypeOf(O);
- }
- return desc && desc.set;
- },
- },
- });
-}

DELETE
packages/ses/test262/repair-legacy-accessors.js
-import test262Runner from '@agoric/test262-runner';
-import repairLegacyAccessors from '../src/repair-legacy-accessors.js';
-
-test262Runner({
- testDirs: [
- 'test/annexB/built-ins/Object/prototype/__defineGetter__',
- 'test/annexB/built-ins/Object/prototype/__defineSetter__',
- 'test/annexB/built-ins/Object/prototype/__lookupGetter__',
- 'test/annexB/built-ins/Object/prototype/__lookupSetter__',
- ],
- excludePaths: [],
- excludeDescriptions: [],
- excludeFeatures: [
- 'cross-realm', // TODO: Evaluator does not create realms.
- ],
- excludeFlags: [
- 'noStrict', // TODO: Evaluator does not support sloppy mode.
- ],
- excludeErrors: [],
- sourceTextCorrections: [],
- captureGlobalObjectNames: ['Object'],
- async test(testInfo, harness) {
- repairLegacyAccessors();
- // eslint-disable-next-line no-eval
- (0, eval)(`${harness}\n${testInfo.contents}`);
- },
-});

fix: kill obsolete repair-legacy-accessors (#552)