microsoft / Chakra-Samples

Repository for Chakra JavaScript engine related samples.
MIT License
216 stars 84 forks source link

host object creation with/without new operator #13

Closed SrinivasGourarum closed 8 years ago

SrinivasGourarum commented 8 years ago

How to differentiate between an object that is created using "new" and the one without it? I have defined a host object and in the callback (JavaScriptNativeFunction ) for this object's creation, the value for the argument "bool isConstructCall" is always coming as "true" irrespective of the object being created with new or without it.

I want the object to be created only when it is created using the new operator.

liminzhu commented 8 years ago

isConstructCall should indicate whether the 'new' operator is used. We're investigating this issue. Thanks!

liminzhu commented 8 years ago

It turns out that the marshaling was wrong for isConstructCall in JavaScriptNativeFunction. If you change the type of isConstructCall from bool to [MarshalAs(UnmanagedType.U1)] bool, it would behave as expected (see the fix commit).

Sorry about the issue and thanks for finding it :+1:.

SrinivasGourarum commented 8 years ago

Thank you for the timely fix. It is working as expected :)