Skip to content

Add "Context" constructor #7

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

Closed
pluma opened this issue Jan 18, 2014 · 0 comments
Closed

Add "Context" constructor #7

pluma opened this issue Jan 18, 2014 · 0 comments

Comments

@pluma
Copy link
Contributor

pluma commented Jan 18, 2014

Digging through the prototype chain of the result of node's vm.createContext reveals that objects returned by it are instances of Context, which seems to be a simple constructor function with a prototype that is a plain old object.

So to emulate node's behaviour, the following needs to be added:

function Context() {}
Context.prototype = {};
  • createContext should return a new Context rather than a new object. It should still perform a shallow copy.
  • runInContext should throw a TypeError if context is not an instance of Context (having the right prototype is not sufficient). The code that is currently in runInNewContext should be moved here.
  • runInNewContext should call runInContext with the context argument passed through createContext.

I can create a PR for this behaviour if you want.

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 a pull request may close this issue.

1 participant