| |
| /* |
| * weinre is available under *either* the terms of the modified BSD license *or* the |
| * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text. |
| * |
| * Copyright (c) 2011 IBM Corporation |
| */ |
| |
| //----------------------------------------------------------------------------- |
| class IDGenerator |
| |
| //----------------------------------------------------------------------------- |
| init |
| var nextIdValue = 1 |
| var idName = "__weinre__id" |
| |
| //----------------------------------------------------------------------------- |
| static method checkId(object) |
| return object[idName] |
| |
| //----------------------------------------------------------------------------- |
| static method getId(object, map) |
| var id = IDGenerator.checkId(object) |
| |
| if (!id) { |
| id = nextId() |
| |
| // note: |
| // attempted to use Object.defineProperty() to make |
| // the id property non-enumerable, etc, but doesn't |
| // work in JSC (TypeError), and still shows up in |
| // Web Inspector property views anyway. |
| object[idName] = id |
| } |
| |
| if (map) { |
| if (map[id] != object) { |
| map[id] = object |
| } |
| } |
| |
| return id |
| |
| //----------------------------------------------------------------------------- |
| static method next |
| return nextId() |
| |
| //----------------------------------------------------------------------------- |
| function nextId |
| var result = nextIdValue |
| nextIdValue += 1 |
| return result |
| |