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

OS#14115684: Function-in-block semantics don't work for defer parse #4673

Merged
merged 1 commit into from
Feb 13, 2018

Conversation

boingoing
Copy link
Contributor

In below code repro, we do not create var decl binding for foo inside the nest function in defer-parse mode. Due to this, we leave the reference to foo in nest on the pid ref stack and bind it to the formal foo parameter from the test function. This leads us to think formal foo is captured and try to put it into a scope slot. However, formal foo is not actually captured so no scope slot is allocated. When we actually generate bytecode for test, we hit a fail fast.

function test(foo) {
    function nest() {
        {
            function foo() {
                console.log('pass');
            }
        }
        foo();
    }
    nest();
}
test(()=>console.log('fail'));

Fix is to create the var binding for foo at the function declaration for foo even in defer-parse mode.

Fixes:
https://microsoft.visualstudio.com/web/wi.aspx?id=14115684

In below code repro, we do not create var decl binding for `foo` inside the `nest` function in defer-parse mode. Due to this, we leave the reference to `foo` in `nest` on the pid ref stack and bind it to the formal `foo` parameter from the `test` function. This leads us to think formal `foo` is captured and try to put it into a scope slot. However, formal `foo` is not actually captured so no scope slot is allocated. When we actually generate bytecode for `test`, we hit a fail fast.

```js
function test(foo) {
    function nest() {
        {
            function foo() {
                console.log('pass');
            }
        }
        foo();
    }
    nest();
}
test(()=>console.log('fail'));
```

Fix is to create the var binding for `foo` at the function declaration for `foo` even in defer-parse mode.

Fixes:
https://microsoft.visualstudio.com/web/wi.aspx?id=14115684
@boingoing
Copy link
Contributor Author

@dotnet-bot test OSX static_osx_osx_debug please

@boingoing
Copy link
Contributor Author

Thanks, Paul.

@chakrabot chakrabot merged commit c3d4e4d into chakra-core:release/1.8 Feb 13, 2018
chakrabot pushed a commit that referenced this pull request Feb 13, 2018
…'t work for defer parse

Merge pull request #4673 from boingoing:DeferFunctionInBlock

In below code repro, we do not create var decl binding for `foo` inside the `nest` function in defer-parse mode. Due to this, we leave the reference to `foo` in `nest` on the pid ref stack and bind it to the formal `foo` parameter from the `test` function. This leads us to think formal `foo` is captured and try to put it into a scope slot. However, formal `foo` is not actually captured so no scope slot is allocated. When we actually generate bytecode for `test`, we hit a fail fast.

```js
function test(foo) {
    function nest() {
        {
            function foo() {
                console.log('pass');
            }
        }
        foo();
    }
    nest();
}
test(()=>console.log('fail'));
```

Fix is to create the var binding for `foo` at the function declaration for `foo` even in defer-parse mode.

Fixes:
https://microsoft.visualstudio.com/web/wi.aspx?id=14115684
chakrabot pushed a commit that referenced this pull request Feb 13, 2018
…antics don't work for defer parse

Merge pull request #4673 from boingoing:DeferFunctionInBlock

In below code repro, we do not create var decl binding for `foo` inside the `nest` function in defer-parse mode. Due to this, we leave the reference to `foo` in `nest` on the pid ref stack and bind it to the formal `foo` parameter from the `test` function. This leads us to think formal `foo` is captured and try to put it into a scope slot. However, formal `foo` is not actually captured so no scope slot is allocated. When we actually generate bytecode for `test`, we hit a fail fast.

```js
function test(foo) {
    function nest() {
        {
            function foo() {
                console.log('pass');
            }
        }
        foo();
    }
    nest();
}
test(()=>console.log('fail'));
```

Fix is to create the var binding for `foo` at the function declaration for `foo` even in defer-parse mode.

Fixes:
https://microsoft.visualstudio.com/web/wi.aspx?id=14115684
chakrabot pushed a commit that referenced this pull request Feb 13, 2018
…-in-block semantics don't work for defer parse

Merge pull request #4673 from boingoing:DeferFunctionInBlock

In below code repro, we do not create var decl binding for `foo` inside the `nest` function in defer-parse mode. Due to this, we leave the reference to `foo` in `nest` on the pid ref stack and bind it to the formal `foo` parameter from the `test` function. This leads us to think formal `foo` is captured and try to put it into a scope slot. However, formal `foo` is not actually captured so no scope slot is allocated. When we actually generate bytecode for `test`, we hit a fail fast.

```js
function test(foo) {
    function nest() {
        {
            function foo() {
                console.log('pass');
            }
        }
        foo();
    }
    nest();
}
test(()=>console.log('fail'));
```

Fix is to create the var binding for `foo` at the function declaration for `foo` even in defer-parse mode.

Fixes:
https://microsoft.visualstudio.com/web/wi.aspx?id=14115684
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.

3 participants