Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proxy-less env support #171

Closed
wants to merge 6 commits into from
Closed

Conversation

NoemiRozpara
Copy link

Description

Commit picked from https://github.com/bassarisse/v8n/ and applied to the most recent version of the library. Provides IE11 support.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (please, feel free to specify what kind of change it is)

Checklist:

  • I have created my branch from a recent version of master
  • The code is clean and easy to understand
  • I have written tests to guarantee that everything is working properly
  • I have made corresponding changes to the documentation
  • I have added changes to the Unreleased section of the CHANGELOG

Copy link
Collaborator

@sbarfurth sbarfurth left a comment

Choose a reason for hiding this comment

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

Please take a look at my comments. There is a lot of repetition in the fix and I wonder if that could be mitigated to an extent.

.gitignore Outdated Show resolved Hide resolved
src/v8n.js Outdated Show resolved Hide resolved
src/v8n.js Outdated Show resolved Hide resolved
src/v8n.js Outdated Show resolved Hide resolved
@NoemiRozpara
Copy link
Author

Please take a look at my comments. There is a lot of repetition in the fix and I wonder if that could be mitigated to an extent.

Thank you a lot for your review! Will be happy to work on that today or tomorrow :)

Copy link
Collaborator

@sbarfurth sbarfurth left a comment

Choose a reason for hiding this comment

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

Thanks for implementing feedback. Code needs to be a bit more concise now, but this is already close.

src/v8n.js Outdated
return newContext._applyRule(availableRules[prop], prop)(...args);
};
});
const buildRuleSet = ruleSet =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

To avoid side effects this should accept the context as a parameter and return it. This is currently modifying a variable in place and is not very readable.

Also: Does this name make sense? This adds a rule set to the context and not only builds it. Just as a side note.

src/v8n.js Outdated
});
const buildRuleSet = ruleSet =>
Object.keys(ruleSet).forEach(prop => {
context[prop] = (...args) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is this variable from? Should be a function argument for buildRuleSet.

src/v8n.js Outdated
};
});
buildRuleSet(availableRules);
buildRuleSet(customRules);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This changes context but that's not readable.

@NoemiRozpara
Copy link
Author

@brfrth I'm not sure if that's what you meant or I missed something, waiting for the further feedback

@sbarfurth
Copy link
Collaborator

I’ll read over this a little later. Thanks for the work.

src/v8n.js Show resolved Hide resolved
src/v8n.js Outdated
return newContext._applyRule(ruleSet[prop], prop)(...args);
};
});

buildRuleSet(availableRules);
buildRuleSet(customRules);
addRuleSet(availableRules, context);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The returned, changed context should be reassigned here. otherwise the context variable is changed below and it's not clear where. So it should be clearly reassigned.

@sbarfurth sbarfurth added this to the v1.4.0 milestone May 12, 2020
@NoemiRozpara
Copy link
Author

@brfrth 57249c9 is possibly redundant, but I thought you might want to keep this for the sake of clarity. If not - feel free to revert :) And about this one 6a34e9a I didn't have better idea for the variable names, so let me know if you think of anything better

@NoemiRozpara
Copy link
Author

@brfrth did you have a moment to take a look?

@ev-akarel
Copy link

@NoemiRozpara I've tested this PR using JINT (ES5.1 spec only implementation for .Net). It throws an error that targetContext in addRuleSet is undefined during execution. Works fine with the shim in original fork by @bassarisse ported to latest though. I haven't had time to step through it (because it's not the easiest thing to do with JINT), but wanted to let you know, since it could potentially affect other ES5.1 interpreters.

When I have a second to get into it a bit more I'll try and find the issue. Also, thank you!

@sbarfurth
Copy link
Collaborator

@NoemiRozpara Sorry for taking so long. The reassignment looks fine now.

The error that @ev-akarel mentioned would need to be looked at though. I can't remove the merge block until it is.

@ev-akarel
Copy link

@NoemiRozpara @brfrth
Finally had a chance to look at it and found the issue. The addRuleSet method isn't returning anything, so the subsequent context variables were undefined. Just have it return the targetContext and all's well.

E.g.

  const addRuleSet = (ruleSet, targetContext) => {
    Object.keys(ruleSet).forEach(prop => {
      targetContext[prop] = (...args) => {
        const newContext = proxyContextEs5(targetContext._clone());
        const contextWithRuleApplied = newContext._applyRule(
          ruleSet[prop],
          prop
        )(...args);
        return contextWithRuleApplied;
      };
    });
    return targetContext;
  };

One last question: Does proxylessContext make more sense than proxyContextEs5? Since it covers environments without the Proxy object.

@sbarfurth
Copy link
Collaborator

Closing this due to the lack of activity from @NoemiRozpara. Please feel free to comment here if you merge the changes @ev-akarel suggested.

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

Successfully merging this pull request may close these issues.

None yet

4 participants