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

js/encoding: ModuleV2 migration #2241

Merged
merged 1 commit into from
Nov 25, 2021
Merged

js/encoding: ModuleV2 migration #2241

merged 1 commit into from
Nov 25, 2021

Conversation

codebien
Copy link
Contributor

Migrated k6/encding to the modules.Module (aka modules.ModuleV2) interface.

@codebien codebien self-assigned this Nov 16, 2021
@CLAassistant
Copy link

CLAassistant commented Nov 16, 2021

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot requested review from inancgumus and na-- November 16, 2021 11:53
@codebien codebien added this to the v0.36.0 milestone Nov 16, 2021
@na-- na-- requested review from oleiade and yorugac and removed request for inancgumus November 22, 2021 14:56
mstoykov
mstoykov previously approved these changes Nov 22, 2021
Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM, I still (as in the other PRs) am not certain if we:

  • shouldn't stop exporting stuff that no longer need to be exported
  • just return map[string]interface{} instead of creating a goja.Object that is basically that.

yorugac
yorugac previously approved these changes Nov 23, 2021
@yorugac
Copy link
Contributor

yorugac commented Nov 23, 2021

Not sure about exports but regarding this:

  • just return map[string]interface{} instead of creating a goja.Object that is basically that.

I think it's a matter of readability too: goja.Object is a "clear" entity on its own, but map[string]interface{} could be anything.

@oleiade
Copy link
Member

oleiade commented Nov 23, 2021

I agree with @yorugac here. I also think explicit is better than implicit on the front of types.

oleiade
oleiade previously approved these changes Nov 23, 2021
Copy link
Member

@oleiade oleiade left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@codebien codebien dismissed stale reviews from oleiade, yorugac, and mstoykov via efbf2fc November 23, 2021 17:33
@codebien
Copy link
Contributor Author

I think it's a matter of readability too: goja.Object is a "clear" entity on its own, but map[string]interface{} could be anything.

This is true for the specific line, but I think that the map exported directly from the Exports method adds some important benefits, check the latest fixup:

  • We have removed the obj field from the instance, so the instance is the object and not a wrapper of another object. It should be clearer in terms of architecture.
  • Export method from Exports should be better in terms of readability instead of Export them from the NewInstanceModule.

Not visible from the fixup but from other PRs:

  • It's not required to add the mustExport method

@mstoykov
Copy link
Contributor

I think it's a matter of readability too: goja.Object is a "clear" entity on its own, but map[string]interface{} could be anything.

goja.Object can be anything ;) map[string]interface{} can only be a map ;).

So the argument for me goes the other direction in two different ways:

  1. goja.Object can truly be anything you can make it act as w/e you want which lets you w/e you want which also means that whoever reads this code now needs to actually look at whether you do something funky - which is what i went to look for, like I expected that it was goja.Object so that someone can't change an import, but that wasn't it we just made a goja.Object and then used it for the same thing that map is used for
  2. the way the map[string]interface{} can be written directly in the Export makes it IMO a lot easier to understand what it's doing and in case like this where there is nothing special it's the better option IMO

Around #2258 we might decided to make this all more ... robust and with more specific types, maybe having something like nodejs' module.syncBuiltinESMExports(), but given that this PR just moves from the old common.Bind to the new modules.Module based approach and in the old one this is map[string]interface{} if anything it's probably better to not more changes than necessary

yorugac
yorugac previously approved these changes Nov 25, 2021
@yorugac
Copy link
Contributor

yorugac commented Nov 25, 2021

For the sake of this discussion I just wanted to note the possibility of future renamings of those types but it seems @mstoykov already did that 🙂 I.e. there're pros and cons as mentioned and I also think this question should be revisited separately, like in #2258 as it simply has larger scope than this PR.

@codebien codebien merged commit 04bc2d2 into master Nov 25, 2021
@codebien codebien deleted the encoding-modulev2 branch November 25, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants