Skip to content

Commit

Permalink
use a WeakMap when possible in the WebIDL cache. Helps kripken/ammo.j…
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Nov 18, 2019
1 parent 1abc0c7 commit 21c7ffa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tools/webidl_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def build_constructor(name):
return [r'''{name}.prototype = Object.create({implementing}.prototype);
{name}.prototype.constructor = {name};
{name}.prototype.__class__ = {name};
{name}.__cache__ = {{}};
// If WeakMaps are supported, use them. This prevents the cache from rooting
// objects and keeping them alive forever.
{name}.__cache__ = typeof WeakMap !== 'undefined' ? new WeakMap() : {{}};
Module['{name}'] = {name};
'''.format(name=name, implementing=implementing_name)]

Expand Down

0 comments on commit 21c7ffa

Please sign in to comment.