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

Pass block info to extension methods #2102

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

cwillisf
Copy link
Contributor

@cwillisf cwillisf commented Apr 9, 2019

Resolves

This is a supporting change for the extensionification project.

Proposed Changes

Extension methods now receive a third argument which contains the section of the getInfo results which the extension provided for the block being executed.

Reason for Changes

Sometimes a single extension method needs to service several different instances of the same opcode. This can happen with variables or custom procedures, for example. This change allows the extension method to inspect the blockInfo for instance data, including arbitrary extension-specific properties if necessary.

Test Coverage

There is now a check check for correct blockInfo being passed into an extension method in test/integration/internal-extension.js.

Christopher Willis-Ford added 2 commits April 8, 2019 15:20
Sometimes a single extension method needs to service several different
instances of the same opcode. This can happen with variables or custom
procedures, for example. This change allows the extension method to
inspect the `blockInfo` for instance data, including arbitrary
extension-specific properties if necessary.
@cwillisf cwillisf added this to the April 2019 milestone Apr 9, 2019
@cwillisf cwillisf requested a review from kchadha April 9, 2019 01:01
}

blockInfo.func = blockInfo.func ? this._sanitizeID(blockInfo.func) : blockInfo.opcode;
if (blockInfo.opcode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for rearranging this conditional (from the previous structure of falsey check and early exit)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's kind of silly... but this isn't legal JavaScript:

default:
    if (!blockInfo.opcode) {
        throw new Error('Missing opcode for block');
    }
    const funcName = "stuff"; // it's not legal to make a new `const` here

You can do it if you introduce a new scope with {} which sort of naturally led me to the arrangement proposed here...

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmm okay. I think I'd prefer adding the new block of scope only because it's easier to read an early exit vs. keeping track of which block of code corresponds to which part of the if/else etc. Esp. since there are nested ifs involved here.

const serviceObject = dispatch.services[serviceName];
if (!serviceObject[funcName]) {
// The function might show up later as a dynamic property of the service object
log.warn(`Could not find extension block function called ${funcName}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this function exit after warning here? Below, the function RHS of the arrow function is just going to get bound to undefined(args, util, blockInfo) right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's looking up serviceObject[funcName] in the body of the (anonymous) function, it's possible that serviceObject[funcName] will become a valid function call between now and the first time it gets called. This could happen if the extension dynamically generates methods and monkey-patches itself, for example, especially if it needs to download some data first.

I don't expect this to be common but technically the way we make "remote" service calls doesn't even do this check at all, so I figured that if it's allowed there it should be allowed here. 🤷‍♂️

Copy link
Contributor

@kchadha kchadha left a comment

Choose a reason for hiding this comment

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

Some minor comments and questions, otherwise LG!

@kchadha kchadha assigned cwillisf and unassigned kchadha Apr 9, 2019
@cwillisf cwillisf force-pushed the pass-blockInfo-to-extension-methods branch from 228a2c3 to ab84dd0 Compare April 19, 2019 23:04
@BryceLTaylor BryceLTaylor modified the milestones: April 2019, Overdue Jul 13, 2020
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.

3 participants