summaryrefslogtreecommitdiff
path: root/js/src/Ice/EnumBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/Ice/EnumBase.js')
-rw-r--r--js/src/Ice/EnumBase.js256
1 files changed, 125 insertions, 131 deletions
diff --git a/js/src/Ice/EnumBase.js b/js/src/Ice/EnumBase.js
index a387219e81c..5ec900be310 100644
--- a/js/src/Ice/EnumBase.js
+++ b/js/src/Ice/EnumBase.js
@@ -7,157 +7,151 @@
//
// **********************************************************************
-(function(global){
- require("Ice/Class");
-
- var Slice = global.Slice || {};
- var Ice = global.Ice || {};
- //
- // Ice.EnumBase
- //
- var EnumBase = Ice.Class({
- __init__: function(name, value)
- {
- this._name = name;
- this._value = value;
- },
- equals: function(rhs)
- {
- if(this === rhs)
- {
- return true;
- }
-
- var proto = Object.getPrototypeOf(this);
- if(!(rhs instanceof proto.constructor))
- {
- return false;
- }
+var Ice = require("../Ice/Class").Ice;
- return this._value == rhs._value;
- },
- hashCode: function()
- {
- return this._value;
- },
- toString: function()
+//
+// Ice.EnumBase
+//
+var EnumBase = Ice.Class({
+ __init__: function(name, value)
+ {
+ this._name = name;
+ this._value = value;
+ },
+ equals: function(rhs)
+ {
+ if(this === rhs)
{
- return this._name;
+ return true;
}
- });
- var prototype = EnumBase.prototype;
+ var proto = Object.getPrototypeOf(this);
+ if(!(rhs instanceof proto.constructor))
+ {
+ return false;
+ }
- Object.defineProperty(prototype, 'name', {
- enumerable: true,
- get: function() { return this._name; }
- });
+ return this._value == rhs._value;
+ },
+ hashCode: function()
+ {
+ return this._value;
+ },
+ toString: function()
+ {
+ return this._name;
+ }
+});
+Ice.EnumBase = EnumBase;
- Object.defineProperty(prototype, 'value', {
- enumerable: true,
- get: function() { return this._value; }
- });
+var prototype = EnumBase.prototype;
- var EnumHelper = Ice.Class({
- __init__: function(enumType)
- {
- this._enumType = enumType;
- },
- write: function(os, v)
- {
- this._enumType.__write(os, v);
- },
- writeOpt: function(os, tag, v)
- {
- this._enumType.__writeOpt(os, tag, v);
- },
- read: function(is)
- {
- return this._enumType.__read(is);
- },
- readOpt: function(is, tag)
- {
- return this._enumType.__readOpt(is, tag);
- }
- });
+Object.defineProperty(prototype, 'name', {
+ enumerable: true,
+ get: function() { return this._name; }
+});
- Ice.EnumHelper = EnumHelper;
+Object.defineProperty(prototype, 'value', {
+ enumerable: true,
+ get: function() { return this._value; }
+});
- var write = function(os, v)
+var EnumHelper = Ice.Class({
+ __init__: function(enumType)
{
- os.writeEnum(v);
- };
- var writeOpt = function(os, tag, v)
+ this._enumType = enumType;
+ },
+ write: function(os, v)
{
- os.writeOptValue(tag, Ice.OptionalFormat.Size, Ice.BasicStream.prototype.writeEnum, v);
- };
-
- Slice.defineEnum = function(enumerators)
+ this._enumType.__write(os, v);
+ },
+ writeOpt: function(os, tag, v)
{
- var type = function(n, v)
- {
- EnumBase.call(this, n, v);
- };
+ this._enumType.__writeOpt(os, tag, v);
+ },
+ read: function(is)
+ {
+ return this._enumType.__read(is);
+ },
+ readOpt: function(is, tag)
+ {
+ return this._enumType.__readOpt(is, tag);
+ }
+});
+
+Ice.EnumHelper = EnumHelper;
+
+var write = function(os, v)
+{
+ os.writeEnum(v);
+};
+var writeOpt = function(os, tag, v)
+{
+ os.writeOptValue(tag, Ice.OptionalFormat.Size, Ice.BasicStream.prototype.writeEnum, v);
+};
+
+var Slice = Ice.Slice;
+Slice.defineEnum = function(enumerators)
+{
+ var type = function(n, v)
+ {
+ EnumBase.call(this, n, v);
+ };
- type.prototype = new EnumBase();
- type.prototype.constructor = type;
+ type.prototype = new EnumBase();
+ type.prototype.constructor = type;
- var enums = [];
- var maxValue = 0;
- for(var e in enumerators)
+ var enums = [];
+ var maxValue = 0;
+ for(var e in enumerators)
+ {
+ var value = enumerators[e];
+ var enumerator = new type(e, value);
+ enums[value] = enumerator;
+ Object.defineProperty(type, e, {
+ enumerable: true,
+ value: enumerator
+ });
+ if(value > maxValue)
{
- var value = enumerators[e];
- var enumerator = new type(e, value);
- enums[value] = enumerator;
- Object.defineProperty(type, e, {
- enumerable: true,
- value: enumerator
- });
- if(value > maxValue)
- {
- maxValue = value;
- }
+ maxValue = value;
}
+ }
- Object.defineProperty(type, "minWireSize", {
- get: function(){ return 1; }
- });
+ Object.defineProperty(type, "minWireSize", {
+ get: function(){ return 1; }
+ });
- type.__write = write;
- type.__read = function(is)
- {
- return is.readEnum(type);
- };
- type.__writeOpt = writeOpt;
- type.__readOpt = function(is, tag)
- {
- return is.readOptEnum(tag, type);
- };
-
- type.__helper = new EnumHelper(type);
-
- Object.defineProperty(type, 'valueOf', {
- value: function(v) {
- if(v === undefined)
- {
- return type;
- }
- return enums[v]; }
- });
+ type.__write = write;
+ type.__read = function(is)
+ {
+ return is.readEnum(type);
+ };
+ type.__writeOpt = writeOpt;
+ type.__readOpt = function(is, tag)
+ {
+ return is.readOptEnum(tag, type);
+ };
- Object.defineProperty(type, 'maxValue', {
- value: maxValue
- });
+ type.__helper = new EnumHelper(type);
- Object.defineProperty(type.prototype, 'maxValue', {
- value: maxValue
- });
+ Object.defineProperty(type, 'valueOf', {
+ value: function(v) {
+ if(v === undefined)
+ {
+ return type;
+ }
+ return enums[v]; }
+ });
- return type;
- };
+ Object.defineProperty(type, 'maxValue', {
+ value: maxValue
+ });
- Ice.EnumBase = EnumBase;
+ Object.defineProperty(type.prototype, 'maxValue', {
+ value: maxValue
+ });
- global.Slice = Slice;
- global.Ice = Ice;
-}(typeof (global) === "undefined" ? window : global));
+ return type;
+};
+module.exports.Ice = Ice;