Add test262 to repair-legacy-accessors
ADD
packages/repair-legacy-accessors/.prettierrc.json
+{
+ "trailingComma": "all",
+ "singleQuote": true
+}

RENAME
packages/repair-legacy-accessors/LICENSE
packages/repair-legacy-accessors/LICENSE-tc39
MODIFY
packages/repair-legacy-accessors/package.json
packages/repair-legacy-accessors/package.json
"scripts": {
"lint": "eslint '**/*.js'",
"lint-fix": "eslint --fix '**/*.js'",
- "test": "tap --no-esm --no-coverage --reporter specy 'test/**/*.test.js'"
+ "test": "tap --no-esm --no-coverage --reporter specy 'test/**/*.test.js'",
+ "test262": "tap --no-esm --no-coverage --reporter specy test262/test262-run.js"
},
"devDependencies": {
"babel-eslint": "^10.0.3",

MODIFY
packages/repair-legacy-accessors/src/main.js
packages/repair-legacy-accessors/src/main.js
@@ -19,7 +19,7 @@ export default function repairLegacyAccessors() {
try {
// Verify that the method is not callable.
// eslint-disable-next-line no-restricted-properties, no-underscore-dangle
- (0, Object.prototype.__lookupGetter__)("x");
+ (0, Object.prototype.__lookupGetter__)('x');
} catch (ignore) {
// Throws, no need to patch.
return;
@@ -30,7 +30,7 @@ export default function repairLegacyAccessors() {
defineProperties,
getOwnPropertyDescriptor,
getPrototypeOf,
- prototype: objectPrototype
+ prototype: objectPrototype,
} = Object;
// On some platforms, the implementation of these functions act as
@@ -47,14 +47,14 @@ export default function repairLegacyAccessors() {
}
function asPropertyName(obj) {
- if (typeof obj === "symbol") {
+ if (typeof obj === 'symbol') {
return obj;
}
return `${obj}`;
}
function aFunction(obj, accessor) {
- if (typeof obj !== "function") {
+ if (typeof obj !== 'function') {
throw TypeError(`invalid ${accessor} usage`);
}
return obj;
@@ -65,21 +65,21 @@ export default function repairLegacyAccessors() {
value: function __defineGetter__(prop, func) {
const O = toObject(this);
defineProperty(O, prop, {
- get: aFunction(func, "getter"),
+ get: aFunction(func, 'getter'),
enumerable: true,
- configurable: true
+ configurable: true,
});
- }
+ },
},
__defineSetter__: {
value: function __defineSetter__(prop, func) {
const O = toObject(this);
defineProperty(O, prop, {
- set: aFunction(func, "setter"),
+ set: aFunction(func, 'setter'),
enumerable: true,
- configurable: true
+ configurable: true,
});
- }
+ },
},
__lookupGetter__: {
value: function __lookupGetter__(prop) {
@@ -91,7 +91,7 @@ export default function repairLegacyAccessors() {
O = getPrototypeOf(O);
}
return desc && desc.get;
- }
+ },
},
__lookupSetter__: {
value: function __lookupSetter__(prop) {
@@ -103,7 +103,7 @@ export default function repairLegacyAccessors() {
O = getPrototypeOf(O);
}
return desc && desc.set;
- }
- }
+ },
+ },
});
}

MODIFY
packages/repair-legacy-accessors/test/repairLegacyAccessors.test.js
packages/repair-legacy-accessors/test/repairLegacyAccessors.test.js
-import tap from "tap";
-import sinon from "sinon";
-import repairLegacyAccessors from "../src/main.js";
+import tap from 'tap';
+import sinon from 'sinon';
+import repairLegacyAccessors from '../src/main.js';
+import stubLegacyAccessors from './stubLegacyAccessors.js';
const { test } = tap;
/* eslint-disable no-restricted-properties, no-underscore-dangle, func-names */
-function sandboxLegacyAccessors() {
- sinon.stub(Object.prototype, "__defineGetter__").callsFake(() => {});
- sinon.stub(Object.prototype, "__defineSetter__").callsFake(() => {});
- sinon.stub(Object.prototype, "__lookupGetter__").callsFake(() => {});
- sinon.stub(Object.prototype, "__lookupSetter__").callsFake(() => {});
-}
-
-test("sandboxLegacyAccessors - restore", t => {
- t.plan(8);
-
- const descs = Object.getOwnPropertyDescriptors(Object.prototype);
-
- sandboxLegacyAccessors();
-
- t.notEqual(descs.__defineGetter__.value, Object.prototype.__defineGetter__);
- t.notEqual(descs.__defineSetter__.value, Object.prototype.__defineSetter__);
- t.notEqual(descs.__lookupGetter__.value, Object.prototype.__lookupGetter__);
- t.notEqual(descs.__lookupSetter__.value, Object.prototype.__lookupSetter__);
-
- sinon.restore();
-
- t.equal(descs.__defineGetter__.value, Object.prototype.__defineGetter__);
- t.equal(descs.__defineSetter__.value, Object.prototype.__defineSetter__);
- t.equal(descs.__lookupGetter__.value, Object.prototype.__lookupGetter__);
- t.equal(descs.__lookupSetter__.value, Object.prototype.__lookupSetter__);
-});
-
-test("repairAccessors - no multiple fix", t => {
+test('repairAccessors - no multiple fix', t => {
t.plan(1);
- sandboxLegacyAccessors();
+ stubLegacyAccessors(sinon);
repairLegacyAccessors();
const original = Object.prototype.__lookupGetter__;
@@ -48,10 +22,10 @@ test("repairAccessors - no multiple fix", t => {
sinon.restore();
});
-test("repairAccessors - force", specs => {
+test('repairAccessors - force', specs => {
specs.plan(4);
- sandboxLegacyAccessors();
+ stubLegacyAccessors(sinon);
repairLegacyAccessors();
const {
@@ -60,185 +34,185 @@ test("repairAccessors - force", specs => {
__defineGetter__,
__defineSetter__,
__lookupGetter__,
- __lookupSetter__
- }
+ __lookupSetter__,
+ },
} = Object;
- specs.test("Object#__defineGetter__", t => {
+ specs.test('Object#__defineGetter__', t => {
t.plan(9);
- t.equal(typeof __defineGetter__, "function");
+ t.equal(typeof __defineGetter__, 'function');
t.equal(__defineGetter__.length, 2);
- t.equal(__defineGetter__.name, "__defineGetter__");
+ t.equal(__defineGetter__.name, '__defineGetter__');
const object = {};
t.equal(
- object.__defineGetter__("key", () => 42),
+ object.__defineGetter__('key', () => 42),
undefined,
- "void"
+ 'void',
);
- t.equal(object.key, 42, "works");
+ t.equal(object.key, 42, 'works');
- object.__defineSetter__("key", function() {
+ object.__defineSetter__('key', function() {
this.foo = 43;
});
object.key = 44;
- t.ok(object.key === 42 && object.foo === 43, "works with setter");
+ t.ok(object.key === 42 && object.foo === 43, 'works with setter');
t.throws(
- () => object.__defineSetter__("foo", undefined),
+ () => object.__defineSetter__('foo', undefined),
TypeError,
- "Throws on not function`"
+ 'Throws on not function`',
);
t.throws(
() => __defineGetter__.call(null, 1, () => {}),
TypeError,
- "Throws on null as `this`"
+ 'Throws on null as `this`',
);
t.throws(
() => __defineGetter__.call(undefined, 1, () => {}),
TypeError,
- "Throws on undefined as `this`"
+ 'Throws on undefined as `this`',
);
});
- specs.test("Object#__defineSetter__", t => {
+ specs.test('Object#__defineSetter__', t => {
t.plan(9);
- t.equal(typeof __defineSetter__, "function");
+ t.equal(typeof __defineSetter__, 'function');
t.equal(__defineSetter__.length, 2);
- t.equal(__defineSetter__.name, "__defineSetter__");
+ t.equal(__defineSetter__.name, '__defineSetter__');
const object = {};
t.equal(
- object.__defineSetter__("key", function() {
+ object.__defineSetter__('key', function() {
this.foo = 43;
}),
undefined,
- "void"
+ 'void',
);
object.key = 44;
- t.equal(object.foo, 43, "works");
+ t.equal(object.foo, 43, 'works');
- object.__defineSetter__("key", function() {
+ object.__defineSetter__('key', function() {
this.foo = 43;
});
- object.__defineGetter__("key", () => 42);
+ object.__defineGetter__('key', () => 42);
object.key = 44;
- t.ok(object.key === 42 && object.foo === 43, "works with getter");
+ t.ok(object.key === 42 && object.foo === 43, 'works with getter');
t.throws(
- () => object.__defineSetter__("foo", undefined),
+ () => object.__defineSetter__('foo', undefined),
TypeError,
- "Throws on not function`"
+ 'Throws on not function`',
);
t.throws(
() => __defineSetter__.call(null, 1, () => {}),
TypeError,
- "Throws on null as `this`"
+ 'Throws on null as `this`',
);
t.throws(
() => __defineSetter__.call(undefined, 1, () => {}),
TypeError,
- "Throws on undefined as `this`"
+ 'Throws on undefined as `this`',
);
});
- specs.test("Object#__lookupGetter__", t => {
+ specs.test('Object#__lookupGetter__', t => {
t.plan(14);
- t.equal(typeof __lookupGetter__, "function");
+ t.equal(typeof __lookupGetter__, 'function');
t.equal(__lookupGetter__.length, 1);
- t.equal(__lookupGetter__.name, "__lookupGetter__");
+ t.equal(__lookupGetter__.name, '__lookupGetter__');
// assert.looksNative(__lookupGetter__);
t.equal(
- Object.getOwnPropertyDescriptor(Object.prototype, "__lookupGetter__")
+ Object.getOwnPropertyDescriptor(Object.prototype, '__lookupGetter__')
.enumerable,
- false
+ false,
);
- t.equal({}.__lookupGetter__("key"), undefined, "empty object");
- t.equal({ key: 42 }.__lookupGetter__("key"), undefined, "data descriptor");
+ t.equal({}.__lookupGetter__('key'), undefined, 'empty object');
+ t.equal({ key: 42 }.__lookupGetter__('key'), undefined, 'data descriptor');
const obj1 = {};
function setter1() {}
- obj1.__defineGetter__("key", setter1);
+ obj1.__defineGetter__('key', setter1);
- t.equal(obj1.__lookupGetter__("key"), setter1, "own getter");
- t.equal(create(obj1).__lookupGetter__("key"), setter1, "proto getter");
- t.equal(create(obj1).__lookupGetter__("foo"), undefined, "empty proto");
+ t.equal(obj1.__lookupGetter__('key'), setter1, 'own getter');
+ t.equal(create(obj1).__lookupGetter__('key'), setter1, 'proto getter');
+ t.equal(create(obj1).__lookupGetter__('foo'), undefined, 'empty proto');
const obj2 = {};
function setter2() {}
- const symbol2 = Symbol("key");
+ const symbol2 = Symbol('key');
obj2.__defineGetter__(symbol2, setter2);
- t.equal(obj2.__lookupGetter__(symbol2), setter2, "own getter");
- t.equal(create(obj2).__lookupGetter__(symbol2), setter2, "proto getter");
+ t.equal(obj2.__lookupGetter__(symbol2), setter2, 'own getter');
+ t.equal(create(obj2).__lookupGetter__(symbol2), setter2, 'proto getter');
t.equal(
- create(obj2).__lookupGetter__(Symbol("foo")),
+ create(obj2).__lookupGetter__(Symbol('foo')),
undefined,
- "empty proto"
+ 'empty proto',
);
t.throws(
() => __lookupGetter__.call(null, 1, () => {}),
TypeError,
- "Throws on null as `this`"
+ 'Throws on null as `this`',
);
t.throws(
() => __lookupGetter__.call(undefined, 1, () => {}),
TypeError,
- "Throws on undefined as `this`"
+ 'Throws on undefined as `this`',
);
});
- specs.test("Object#__lookupSetter__", t => {
+ specs.test('Object#__lookupSetter__', t => {
t.plan(14);
- t.equal(typeof __lookupSetter__, "function");
+ t.equal(typeof __lookupSetter__, 'function');
t.equal(__lookupSetter__.length, 1);
- t.equal(__lookupSetter__.name, "__lookupSetter__");
+ t.equal(__lookupSetter__.name, '__lookupSetter__');
// assert.looksNative(__lookupSetter__);
t.equal(
- Object.getOwnPropertyDescriptor(Object.prototype, "__lookupSetter__")
+ Object.getOwnPropertyDescriptor(Object.prototype, '__lookupSetter__')
.enumerable,
- false
+ false,
);
- t.equal({}.__lookupSetter__("key"), undefined, "empty object");
- t.equal({ key: 42 }.__lookupSetter__("key"), undefined, "data descriptor");
+ t.equal({}.__lookupSetter__('key'), undefined, 'empty object');
+ t.equal({ key: 42 }.__lookupSetter__('key'), undefined, 'data descriptor');
const obj1 = {};
function setter1() {}
- obj1.__defineSetter__("key", setter1);
+ obj1.__defineSetter__('key', setter1);
- t.equal(obj1.__lookupSetter__("key"), setter1, "own getter");
- t.equal(create(obj1).__lookupSetter__("key"), setter1, "proto getter");
- t.equal(create(obj1).__lookupSetter__("foo"), undefined, "empty proto");
+ t.equal(obj1.__lookupSetter__('key'), setter1, 'own getter');
+ t.equal(create(obj1).__lookupSetter__('key'), setter1, 'proto getter');
+ t.equal(create(obj1).__lookupSetter__('foo'), undefined, 'empty proto');
const obj2 = {};
function setter2() {}
- const symbol2 = Symbol("key");
+ const symbol2 = Symbol('key');
obj2.__defineSetter__(symbol2, setter2);
- t.equal(obj2.__lookupSetter__(symbol2), setter2, "own getter");
- t.equal(create(obj2).__lookupSetter__(symbol2), setter2, "proto getter");
+ t.equal(obj2.__lookupSetter__(symbol2), setter2, 'own getter');
+ t.equal(create(obj2).__lookupSetter__(symbol2), setter2, 'proto getter');
t.equal(
- create(obj2).__lookupSetter__(Symbol("foo")),
+ create(obj2).__lookupSetter__(Symbol('foo')),
undefined,
- "empty proto"
+ 'empty proto',
);
t.throws(
() => __lookupSetter__.call(null, 1, () => {}),
TypeError,
- "Throws on null as `this`"
+ 'Throws on null as `this`',
);
t.throws(
() => __lookupSetter__.call(undefined, 1, () => {}),
TypeError,
- "Throws on undefined as `this`"
+ 'Throws on undefined as `this`',
);
});

ADD
packages/repair-legacy-accessors/test/stubLegacyAccessors.js
+export default function stubLegacyAccessors(sinon) {
+ sinon.stub(Object.prototype, '__defineGetter__').callsFake(() => {});
+ sinon.stub(Object.prototype, '__defineSetter__').callsFake(() => {});
+ sinon.stub(Object.prototype, '__lookupGetter__').callsFake(() => {});
+ sinon.stub(Object.prototype, '__lookupSetter__').callsFake(() => {});
+}

ADD
packages/repair-legacy-accessors/test/stubLegacyAccessors.test.js
+import tap from 'tap';
+import sinon from 'sinon';
+import stubLegacyAccessors from './stubLegacyAccessors.js';
+
+const { test } = tap;
+
+/* eslint-disable no-restricted-properties, no-underscore-dangle */
+
+test('stubLegacyAccessors - restore', t => {
+ t.plan(8);
+
+ const descs = Object.getOwnPropertyDescriptors(Object.prototype);
+
+ stubLegacyAccessors(sinon);
+
+ t.notEqual(descs.__defineGetter__.value, Object.prototype.__defineGetter__);
+ t.notEqual(descs.__defineSetter__.value, Object.prototype.__defineSetter__);
+ t.notEqual(descs.__lookupGetter__.value, Object.prototype.__lookupGetter__);
+ t.notEqual(descs.__lookupSetter__.value, Object.prototype.__lookupSetter__);
+
+ sinon.restore();
+
+ t.equal(descs.__defineGetter__.value, Object.prototype.__defineGetter__);
+ t.equal(descs.__defineSetter__.value, Object.prototype.__defineSetter__);
+ t.equal(descs.__lookupGetter__.value, Object.prototype.__lookupGetter__);
+ t.equal(descs.__lookupSetter__.value, Object.prototype.__lookupSetter__);
+});
+
+/* eslint-enable no-restricted-properties, no-underscore-dangle */

ADD
packages/repair-legacy-accessors/test262/test262-run.js
+// eslint-disable-next-line import/no-extraneous-dependencies
+import test262Runner from '@agoric/test262-runner';
+import repairLegacyAccessors from '../src/main.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}`);
+ },
+});

DELETE
packages/tame-global-date-object/.eslintignore
-/dist/

Add test262 to repair-legacy-accessors