microsoft / Chakra-Samples

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

property access callback #7

Closed SrinivasGourarum closed 8 years ago

SrinivasGourarum commented 8 years ago

A couple of queries:

  1. Is it possible to get callback whenever a property is accessed on an object even if the property is not defined on the object? This will help with lazy initialization and also with memory issues. The property accessed if valid, will be added as a property to the object in the c# code.
  2. Can the API "JsCreateExternalObject( _Inopt void data, _Inopt JsFinalizeCallback finalizeCallback, Out JsValueRef object );"
    hold a c# object as the "data"? Currently we are holding a int as data which maps to our c# object.
liminzhu commented 8 years ago
  1. Proxy (a new feature in ECMAScript 2015) should be able to solve this problem nicely.
  2. Yes you can hold c# object as data, but remember to put a hold on the object otherwise it may get garbage collected.
SrinivasGourarum commented 8 years ago

Thanks for the reply,

I understand we can create proxy in javascript code but is there a way to create it programatically? I did not find the key word "proxy" in the javascript reference(https://msdn.microsoft.com/en-us/library/dn249536(v=vs.94).aspx )

liminzhu commented 8 years ago

Thanks for clarifying :). Unfortunately as for now there is no API that directly creates proxies. A kind of hacky way I guess is to have a script that creates a proxy you want and then run it with JsRunScript, which returns the resulting proxy object to C# environment.