Skip to content

Instantly share code, notes, and snippets.

@AnnaMag
Created December 28, 2016 21:25
Show Gist options
  • Save AnnaMag/f676154dc5e4e8c5b952fe1318013c31 to your computer and use it in GitHub Desktop.
Save AnnaMag/f676154dc5e4e8c5b952fe1318013c31 to your computer and use it in GitHub Desktop.
Test for changes in the Node.js's Copy Properties (accessor property check)
'use strict';
require('../common');
const vm = require('vm');
const assert = require('assert');
var x = { value : 13};
Object.defineProperty(x, 'p0', {value : 12});
Object.defineProperty(x, 'p1', {
set : function(value) { this.value = value; },
get : function() { return this.value; },
});
const context = vm.createContext(x);
const code = `y = Object.getOwnPropertyDescriptor(this, 'p1');
var c=3;
Object.getOwnPropertyNames(y)
`;
const res = vm.runInContext(code, context);
console.log(res) // {value, y, c} included, {p0, p1} absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment