Skip to content

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

Merged
chakrabot merged 1 commit into
chakra-core:release/1.8from
boingoing:DeferFunctionInBlock
Feb 13, 2018
Merged

chakrabot merged 1 commit into
chakra-core:release/1.8from
boingoing:DeferFunctionInBlock

Conversation

@boingoing

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@dotnet-bot test OSX static_osx_osx_debug please

@boingoing

Copy link
Copy Markdown
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