Friday, November 19, 2010

JavaScript duplicated constants

Recently, I updated Tellurium IDE with changes from Tellurium Engine. After the merge, Tellurium IDE, the Firefox plugin, stopped working and it took me quick some time to figure out what happened. The cause was duplicated constants.

In Tellurium Engine, I defined the following constants

const ValueType = {
NUMBER: "number",
STRING: 'string',
BOOLEAN: 'boolean',
OBJECT: 'object',
VARIABLE: "var",
NIL: "nil"
};

const CommandType = {
HasUid: "hasUid",
NoUid: "noUid",
ACTION: "action",
ACCESSOR: "accessor",
DIRECT: "direct",
ASSERTION: "assertion"
};

const ReturnType = {
VOID: "void",
BOOLEAN: "boolean",
STRING: "string",
ARRAY: "Array",
NUMBER: "number",
OBJECT: "object"
};

While in Tellurium IDE, I had the same constants defined in a file workspace.js. Seems
Firefox detected the duplicates and quietly quitted loading the script file. Thus, the
object Workspace defined in workspace.js became undefined, which led to the misbehavior
of Tellurium IDE. Never expected this before. A good lesson to learn.

0 comments:

Post a Comment