Re: Proxy objects and collection
On Tue, Sep 2, 2014 at 1:07 PM, Daurnimator q...@daurnimator.com wrote: I'm the maintainer of lua.vm.js[1], which allows Lua code to run in the browser. I've managed to construct a simple and robust cross-language bridge, so that Lua code can interact with Javascript objects. When the Lua no longer references the Javascript object, its garbage collector notifies me (via the __gc metamethod[2]). At this point, I drop the reference to the JS object, and the JS garbage collector can collect it if needed. However, currently, exposing a Lua function or object to Javascript does not have the same ability; there is no way (that I know of) to know when Javascript no longer needs your object. Example use case: A Lua script wishes to have a Lua function called on an interval: `timerid = window:setInterval(function() window.console:log(ping) end)` Later, it wishes to clear the timer: `window:clearInterval(timerid)` This will stop the function from being called, but I have no way to notify Lua that the function can be collected. If the JS function contains the only strong reference to the Lua function, then when the JS function is collected, the Lua function will be collected too. Why isn't that sufficient? Does the Lua runtime keep a list of all functions or something? What for? -j ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Set#toString and Map#toString
Neither `Set` nor `Map` have `toString` methods defined on the prototype. This can lead to somewhat surprising behavior for interactive users (this is node with`es6-shim`): ```js s = new Set(['a']) {} m = new Map([['a','b']]) {} s.toString() '[object Object]' m.toString() '[object Object]' ``` Eventually node's `util.inspect` (and the various browser analogs) will presumably learn about `Map` and `Set`. But the latest Chrome beta still reports: ```js s = new Set(['a']) Set {} s.has('a') true ``` Since the potential for confusion with an empty object is clear, might it make sense to define `Set#toString` and `Map#toString` methods in ES6? I'm thinking that: ```js Set.prototype.toString = function() { return Array.from(this).toString(); } ``` Not sure about `Map#toString`, but the equivalent definition: ```js Map.prototype.toString = function() { return Array.from(this).toString(); } ``` gives somewhat confusing results. Eg: ```js (new Map([['k1','v1'],['k2','v2']])).toString() 'k1,v1,k2,v2' ``` What do y'all think? --scott ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Set#toString and Map#toString
ES6 defines `Map.prototype[Symbol.toStringTag]` and `Set.prototype[Symbol.toStringTag]` such that the ES6 version of Object.prototype.toString will produce [object Map] and [object Set] respectively when applied to Map or Set instances Allen On Sep 4, 2014, at 2:51 PM, C. Scott Ananian wrote: Neither `Set` nor `Map` have `toString` methods defined on the prototype. This can lead to somewhat surprising behavior for interactive users (this is node with`es6-shim`): ```js s = new Set(['a']) {} m = new Map([['a','b']]) {} s.toString() '[object Object]' m.toString() '[object Object]' ``` Eventually node's `util.inspect` (and the various browser analogs) will presumably learn about `Map` and `Set`. But the latest Chrome beta still reports: ```js s = new Set(['a']) Set {} s.has('a') true ``` Since the potential for confusion with an empty object is clear, might it make sense to define `Set#toString` and `Map#toString` methods in ES6? I'm thinking that: ```js Set.prototype.toString = function() { return Array.from(this).toString(); } ``` Not sure about `Map#toString`, but the equivalent definition: ```js Map.prototype.toString = function() { return Array.from(this).toString(); } ``` gives somewhat confusing results. Eg: ```js (new Map([['k1','v1'],['k2','v2']])).toString() 'k1,v1,k2,v2' ``` What do y'all think? --scott ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Set#toString and Map#toString
On 9/4/14, 5:51 PM, C. Scott Ananian wrote: s.toString() '[object Object]' Per spec this should be [object Set]. Both V8 and SpiderMonkey get this right, fwiw. m.toString() '[object Object]' Again, should be [object Map]. Eventually node's `util.inspect` (and the various browser analogs) will presumably learn about `Map` and `Set`. But the latest Chrome beta still reports: ```js s = new Set(['a']) Set {} Firefox reports: Set [ a ] -Boris ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss