Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

vm.Script inheritance error #555

Open

Description

@jdalton

In node-chakracore 10.1.0 the following throws

class S extends vm.Script {}
for (const n of Reflect.ownKeys(vm.Script.prototype)) S.prototype[n] = vm.Script.prototype[n]
Object.setPrototypeOf(S.prototype, null)
new S('1+2').runInThisContext() // throws

It does not throw in Node 10.x in v8

Activity

  1. MSLaguana commented on Jun 23, 2018

    @MSLaguana
    Contributor

    This is somewhat interesting; the native code checks that the script object (the new S in rhis case) is an instance of ContextifyScript. For us, we do that via the javascript semantics of instanceof, and due to your manipulations of the prototype that instanceof check fails (in both v8 and chakracore) but v8's native implementation of ContextifyScript::HasInstance uses different internal behaviors to do with function templates to determine that the object was originally related to ContextifyScript.

  2. MSLaguana commented on Jun 25, 2018

    @MSLaguana
    Contributor

    @jdalton do you have a scenario where you wanted to do something like this and expected it to work?

    I did check the other case, where you take a non-vm.Script object and set its prototype to vm.Script.prototype, and that ends up erroring out with "Illegal Invocation" in both v8 and chakra. I think that the requirement from native code here is just that we can get access to the wrapped native object that is created as part of ContextifyScript (which is the superclass of vm.Script), but I don't believe that with chakra/chakrashim we can currently tell how an object was constructed.

  3. jdalton commented on Jun 25, 2018

    @jdalton
    MemberAuthor

    I ran into some code working in node-V8 and not in node-chakracore. The workaround was to set the prototype to that of the ContextifyScript prototype instead of null.

  4. MSLaguana commented on Jun 25, 2018

    @MSLaguana
    Contributor

    I'm curious what the intent of the code was; why was the code removing the prototype?

  5. jdalton commented on Jun 25, 2018

    @jdalton
    MemberAuthor

    Creating a "safe" reference to the vm module here the safe() helper will null the prototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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