11cb0ef41Sopenharmony_ciimport '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport assert from 'assert';
31cb0ef41Sopenharmony_ciimport { syncBuiltinESMExports } from 'module';
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciimport fs, { readFile, readFileSync } from 'fs';
61cb0ef41Sopenharmony_ciimport events, { defaultMaxListeners } from 'events';
71cb0ef41Sopenharmony_ciimport util from 'util';
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst readFileDescriptor = Reflect.getOwnPropertyDescriptor(fs, 'readFile');
101cb0ef41Sopenharmony_ciconst readFileSyncDescriptor =
111cb0ef41Sopenharmony_ci  Reflect.getOwnPropertyDescriptor(fs, 'readFileSync');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst s = Symbol();
141cb0ef41Sopenharmony_ciconst fn = () => s;
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciReflect.deleteProperty(fs, 'readFile');
171cb0ef41Sopenharmony_cisyncBuiltinESMExports();
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciassert.deepStrictEqual([fs.readFile, readFile], [undefined, undefined]);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cifs.readFile = fn;
221cb0ef41Sopenharmony_cisyncBuiltinESMExports();
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciassert.deepStrictEqual([fs.readFile(), readFile()], [s, s]);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciReflect.defineProperty(fs, 'readFile', {
271cb0ef41Sopenharmony_ci  value: fn,
281cb0ef41Sopenharmony_ci  configurable: true,
291cb0ef41Sopenharmony_ci  writable: true,
301cb0ef41Sopenharmony_ci});
311cb0ef41Sopenharmony_cisyncBuiltinESMExports();
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciassert.deepStrictEqual([fs.readFile(), readFile()], [s, s]);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciReflect.deleteProperty(fs, 'readFile');
361cb0ef41Sopenharmony_cisyncBuiltinESMExports();
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciassert.deepStrictEqual([fs.readFile, readFile], [undefined, undefined]);
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cilet count = 0;
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ciReflect.defineProperty(fs, 'readFile', {
431cb0ef41Sopenharmony_ci  get() { return count; },
441cb0ef41Sopenharmony_ci  configurable: true,
451cb0ef41Sopenharmony_ci});
461cb0ef41Sopenharmony_cisyncBuiltinESMExports();
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciassert.deepStrictEqual([readFile, fs.readFile], [0, 0]);
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_cicount++;
511cb0ef41Sopenharmony_cisyncBuiltinESMExports();
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciassert.deepStrictEqual([fs.readFile, readFile], [1, 1]);
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_cilet otherValue;
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ciReflect.defineProperty(fs, 'readFile', { // eslint-disable-line accessor-pairs
581cb0ef41Sopenharmony_ci  set(value) {
591cb0ef41Sopenharmony_ci    Reflect.deleteProperty(fs, 'readFile');
601cb0ef41Sopenharmony_ci    otherValue = value;
611cb0ef41Sopenharmony_ci  },
621cb0ef41Sopenharmony_ci  configurable: true,
631cb0ef41Sopenharmony_ci});
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ciReflect.defineProperty(fs, 'readFileSync', {
661cb0ef41Sopenharmony_ci  get() {
671cb0ef41Sopenharmony_ci    return otherValue;
681cb0ef41Sopenharmony_ci  },
691cb0ef41Sopenharmony_ci  configurable: true,
701cb0ef41Sopenharmony_ci});
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_cifs.readFile = 2;
731cb0ef41Sopenharmony_cisyncBuiltinESMExports();
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ciassert.deepStrictEqual([readFile, readFileSync], [undefined, 2]);
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ciReflect.defineProperty(fs, 'readFile', readFileDescriptor);
781cb0ef41Sopenharmony_ciReflect.defineProperty(fs, 'readFileSync', readFileSyncDescriptor);
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ciconst originDefaultMaxListeners = events.defaultMaxListeners;
811cb0ef41Sopenharmony_ciconst utilProto = util.__proto__; // eslint-disable-line no-proto
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_cicount = 0;
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ciReflect.defineProperty(Function.prototype, 'defaultMaxListeners', {
861cb0ef41Sopenharmony_ci  configurable: true,
871cb0ef41Sopenharmony_ci  enumerable: true,
881cb0ef41Sopenharmony_ci  get: function() { return ++count; },
891cb0ef41Sopenharmony_ci  set: function(v) {
901cb0ef41Sopenharmony_ci    Reflect.defineProperty(this, 'defaultMaxListeners', {
911cb0ef41Sopenharmony_ci      configurable: true,
921cb0ef41Sopenharmony_ci      enumerable: true,
931cb0ef41Sopenharmony_ci      writable: true,
941cb0ef41Sopenharmony_ci      value: v,
951cb0ef41Sopenharmony_ci    });
961cb0ef41Sopenharmony_ci  },
971cb0ef41Sopenharmony_ci});
981cb0ef41Sopenharmony_cisyncBuiltinESMExports();
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ciassert.strictEqual(defaultMaxListeners, originDefaultMaxListeners);
1011cb0ef41Sopenharmony_ciassert.strictEqual(events.defaultMaxListeners, originDefaultMaxListeners);
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_cievents.defaultMaxListeners += 1;
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ciassert.strictEqual(events.defaultMaxListeners,
1061cb0ef41Sopenharmony_ci                   originDefaultMaxListeners + 1);
1071cb0ef41Sopenharmony_ci
1081cb0ef41Sopenharmony_cisyncBuiltinESMExports();
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ciassert.strictEqual(defaultMaxListeners, originDefaultMaxListeners + 1);
1111cb0ef41Sopenharmony_ciassert.strictEqual(Function.prototype.defaultMaxListeners, 1);
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ciFunction.prototype.defaultMaxListeners = 'foo';
1141cb0ef41Sopenharmony_cisyncBuiltinESMExports();
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_ciassert.strictEqual(Function.prototype.defaultMaxListeners, 'foo');
1171cb0ef41Sopenharmony_ciassert.strictEqual(events.defaultMaxListeners, originDefaultMaxListeners + 1);
1181cb0ef41Sopenharmony_ciassert.strictEqual(defaultMaxListeners, originDefaultMaxListeners + 1);
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_cicount = 0;
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ciconst p = {
1231cb0ef41Sopenharmony_ci  get foo() { return ++count; },
1241cb0ef41Sopenharmony_ci  set foo(v) {
1251cb0ef41Sopenharmony_ci    Reflect.defineProperty(this, 'foo', {
1261cb0ef41Sopenharmony_ci      configurable: true,
1271cb0ef41Sopenharmony_ci      enumerable: true,
1281cb0ef41Sopenharmony_ci      writable: true,
1291cb0ef41Sopenharmony_ci      value: v,
1301cb0ef41Sopenharmony_ci    });
1311cb0ef41Sopenharmony_ci  },
1321cb0ef41Sopenharmony_ci};
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ciutil.__proto__ = p; // eslint-disable-line no-proto
1351cb0ef41Sopenharmony_cisyncBuiltinESMExports();
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ciassert.strictEqual(util.foo, 1);
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ciutil.foo = 'bar';
1401cb0ef41Sopenharmony_cisyncBuiltinESMExports();
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_ciassert.strictEqual(count, 1);
1431cb0ef41Sopenharmony_ciassert.strictEqual(util.foo, 'bar');
1441cb0ef41Sopenharmony_ciassert.strictEqual(p.foo, 2);
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_cip.foo = 'foo';
1471cb0ef41Sopenharmony_cisyncBuiltinESMExports();
1481cb0ef41Sopenharmony_ci
1491cb0ef41Sopenharmony_ciassert.strictEqual(p.foo, 'foo');
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_cievents.defaultMaxListeners = originDefaultMaxListeners;
1521cb0ef41Sopenharmony_ciutil.__proto__ = utilProto; // eslint-disable-line no-proto
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ciReflect.deleteProperty(util, 'foo');
1551cb0ef41Sopenharmony_ciReflect.deleteProperty(Function.prototype, 'defaultMaxListeners');
1561cb0ef41Sopenharmony_cisyncBuiltinESMExports();
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ciassert.throws(
1591cb0ef41Sopenharmony_ci  () => Object.defineProperty(events, 'defaultMaxListeners', { value: 3 }),
1601cb0ef41Sopenharmony_ci  /TypeError: Cannot redefine/
1611cb0ef41Sopenharmony_ci);
162