prepack icon indicating copy to clipboard operation
prepack copied to clipboard

"Empty" Values Behave Strangely with getOwnPropertyDescriptor

Open sebmarkbage opened this issue 6 years ago • 1 comments

  var c = __abstract('boolean', 'c');
  var x = {foo:1};
  if (c) x.bar = 2;
  result2 = Object.getOwnPropertyDescriptor(x, 'bar');
  
  var y = __abstract({foo:1}, 'y');
  __makeSimple(y);
  if (c) y.bar = 2;
  result4 = Object.getOwnPropertyDescriptor(y, 'bar');
  var _$1 = this;

  var __empty = {};
  var _0 = {
    value: void 0,
    writable: true,
    enumerable: true,
    configurable: true
  };
  var _4 = c;
  if (_4) _0.value = 2;else delete _0.value;
  _$1.result2 = _0;

  if (_4) {
    y.bar = 2;
  }

  var _$0 = _4 ? 2 : __empty;

  _$1.result4 = {
    value: _$0,
    writable: true,
    enumerable: true,
    configurable: true
  };

It effectively leaks when it doesn't go through a getter. In the first case it is as if the property on the descriptor is missing, not the descriptor itself. In the second case, it actually leaks the placeholder value.

sebmarkbage avatar Aug 02 '18 23:08 sebmarkbage

I think this case is especially bad because you don't even need to use getOwnPropertyDescriptor for this one:

  var c = __abstract('boolean', 'c');
  var y = __abstract({foo:1}, 'y');
  __makeSimple(y);
  if (c) y.bar = 2;
  result = y.bar ? 'truthy' : 'falsy';

->

  var _$1 = this;

  var __empty = {};
  var _0 = c;

  if (_0) {
    y.bar = 2;
  }

  var _$0 = _0 ? 2 : __empty; // This turns into two truthy values. The second one should be `undefined`.

  _$1.result = _$0 ? "truthy" : "falsy";

sebmarkbage avatar Aug 02 '18 23:08 sebmarkbage