11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst vm = require('vm'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// https://github.com/nodejs/node/issues/10223 81cb0ef41Sopenharmony_ciconst ctx = vm.createContext(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Define x with writable = false. 111cb0ef41Sopenharmony_civm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx); 121cb0ef41Sopenharmony_ciassert.strictEqual(ctx.x, 42); 131cb0ef41Sopenharmony_ciassert.strictEqual(vm.runInContext('x', ctx), 42); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_civm.runInContext('x = 0', ctx); // Does not throw but x... 161cb0ef41Sopenharmony_ciassert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered. 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciassert.throws(() => vm.runInContext('"use strict"; x = 0', ctx), 191cb0ef41Sopenharmony_ci /Cannot assign to read only property 'x'/); 201cb0ef41Sopenharmony_ciassert.strictEqual(vm.runInContext('x', ctx), 42); 21