blob: 4829267c5704de78ed8ab075c70f05b4fc3ef871 [file] [log] [blame]
/*
* 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 nextId = 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 = next()
// 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
//-----------------------------------------------------------------------------
function next
var result = nextId
nextId += 1
return result