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

ForIn的上下文有问题 #3

Open
axetroy opened this issue Mar 4, 2018 · 1 comment
Open

ForIn的上下文有问题 #3

axetroy opened this issue Mar 4, 2018 · 1 comment

Comments

@axetroy
Copy link

axetroy commented Mar 4, 2018

scope.$declar(kind, name, value)

这里不应该是设置父级的作用域。

应该是设置for循环里的新作用域new_scope

亲测, 下面这个例子跑不痛。

import test from "ava";
import * as fs from "fs";

import vm from "../src/vm";

test("ForInStatement-1", t => {
  const sandbox: any = vm.createContext({});

  const obj: any = vm.runInContext(
    `
const obj = {
  1: false,
  2: false
};

for (let attr in obj) {
  obj[attr] = true;
}

module.exports = obj;
  `,
    sandbox
  );

  t.true(obj[1]);
  t.true(obj[2]);
});

attr应该是 0、1,但实际上,永远是1,因为for循环里面的作用域没有attr变量。

只有父级作用域有attr,而且attr=1

@bramblex
Copy link
Owner

bramblex commented Mar 5, 2018

嗯,这是个 bug ……

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

No branches or pull requests

2 participants