Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Add a name generator for __get_scope_binding_ functions #1978

Closed

Conversation

kwkit
Copy link

@kwkit kwkit commented May 16, 2018

Release Note: none

This uses a separate name generator for scope access functions.

This addresses #1084 and here is a sample output:

(function () {
  var __scope_0 = new Array(2);

  var __get_scope_binding_0 = function (__selector) {
    var __captured;

    switch (__selector) {
      case 0:
        __captured = [5];
        break;

      case 1:
        __captured = [3];
        break;

      default:
        throw new Error("Unknown scope selector");
    }

    __scope_0[__selector] = __captured;
    return __captured;
  };

  var _2 = function () {
    var __scope_3 = new Array(1);

    var __get_scope_binding_1 = function (__selector) {
      var __captured;

      switch (__selector) {
        case 0:
          __captured = [3];
          break;

        default:
          throw new Error("Unknown scope selector");
      }

      __scope_3[__selector] = __captured;
      return __captured;
    };

    var _3 = function () {
      var __captured__scope_1 = __scope_0[0] || __get_scope_binding_0(0);

      var __captured__scope_4 = __scope_3[0] || __get_scope_binding_1(0);

      --__captured__scope_1[0];
      return ++__captured__scope_4[0];
    };

    return _3;
  };

  var _0 = function () {
    return g();
  };

  var _1 = function () {
    var __captured__scope_1 = __scope_0[0] || __get_scope_binding_0(0);

    var __captured__scope_2 = __scope_0[1] || __get_scope_binding_0(1);

    --__captured__scope_1[0];
    return ++__captured__scope_2[0];
  };

  f = _2;
  g = _1;
  inspect = _0;
})();


this.referentializationState = new Map();
this._referentializedNameGenerator = referentializedNameGenerator;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be referenced anywhere or do anything. Just wanted to flag this out and make sure it really can be removed safely

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be a forgotten residue of earlier code that has been replaced.

Copy link
Contributor

@hermanventer hermanventer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but please add a test case that fails without this change and passes with it.


this.referentializationState = new Map();
this._referentializedNameGenerator = referentializedNameGenerator;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be a forgotten residue of earlier code that has been replaced.

this.realm = realm;
}

_options: SerializerOptions;
scopeNameGenerator: NameGenerator;
scopeBindingNameGenerator: NameGenerator;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefix "private" fields with an underscore.

Copy link
Contributor

@NTillmann NTillmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a cosmetic change, so I don't think we need to insist on a regression test case. Let's go ahead with it. Thanks a lot!

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NTillmann is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwkit is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants