jerryscript-project / iotjs

Platform for Internet of Things with JavaScript http://www.iotjs.net
Other
2.59k stars 438 forks source link

Make sure JObjectWrap never could be created as local variable. #135

Closed ILyoan closed 9 years ago

ILyoan commented 9 years ago

Instance of JObjectWrap never be created as local variable.

Constructor of JObjectWrap set native pointer for javascript object so that when the object was reclaimed by garbage collector, the wrapper will also be reclaimed. If wrapper was created as local variable, this may lead double free.

And first of all, JObjectWrap was designed to be used for holding javascript object throughout asynchronous program execution, not just for local time span. JObject would just be fine for handling local javascript object.

Preventing creating instance of JObjectWrap by moving constructor into private section and exposing static method for creating wrapper at heap space is an option.

ILyoan commented 9 years ago

No objection? Then I'll do this after HTTP and GPIO landed.

chunseoklee commented 9 years ago

No objection. I am in.

ILyoan commented 9 years ago

I could not found the effective way to prevent it. Guide not to create an instance of JObjectWrap as local variable. (https://github.com/Samsung/iotjs/wiki/Inside%20IoT.js#jobjectwrap)

Close as won't fix.