Chakracore: Question: Getting the prototype of the caller of "super"?

Created on 4 Mar 2017  路  1Comment  路  Source: chakra-core/ChakraCore

I'm writing a binding generator for C++ <-> ChakraCore. Right now, I'm struggling to support extending native classes from JS-defined classes like so:

class JavascriptChildClass extends NativeSuperClass {
  constructor() {
    super();
  }

  TestChildMethod() {
    console.log("Oops!");
  }
}

However, when I return the object generated from NativeSuperClass's native constructor, I have to call JsSetPrototype on it in order to properly bind the native class to its JS prototype.

I'd like to attach the prototype of "JavascriptChildClass" instead. Right now, I can't find any way to do that, and so the methods on the child class are lost, i.e., TestChildMethod can't be called.

I can't figure out any way to get JavascriptChildClass's prototype from a native context in order to properly set it when "super" is called. It doesn't seem to be, "callee.prototype", "callee.__proto__", or "arguments[0].__proto__", or anything returned from JsGetPrototype on either callee or arguments[0].

Any ideas? Am I doing this completely incorrectly?

Question

>All comments

I managed to figure this out.

The "arguments[0]" object (this) passed in is actually the function that represents the class (JavascriptChildClass constructor in this case, somewhat unintuitively, but maybe only because I'm not super experienced with Javascript), so the "prototype" property on arguments[0] ("this" object) is what I'm looking for here.

Closing and hopefully this knowledge might help someone else in the future :)

note to anyone who encounters this issue in the future and finds this: this is true, the thumbs down are from my dickhead friends

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tommyZZM picture tommyZZM  路  5Comments

rajatd picture rajatd  路  6Comments

Kureev picture Kureev  路  5Comments

aneeshdk picture aneeshdk  路  4Comments

basdl picture basdl  路  3Comments