Skip to content

Add "Context" constructor #7

Closed
Closed
@pluma

Description

@pluma

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions