diff options
Diffstat (limited to 'js/src/Ice/Exception.js')
-rw-r--r-- | js/src/Ice/Exception.js | 164 |
1 files changed, 72 insertions, 92 deletions
diff --git a/js/src/Ice/Exception.js b/js/src/Ice/Exception.js index 3b21ad75662..973c4ff7436 100644 --- a/js/src/Ice/Exception.js +++ b/js/src/Ice/Exception.js @@ -7,10 +7,9 @@ // // ********************************************************************** -var Ice = require("../Ice/Class").Ice; -var Class = Ice.Class; +const Ice = require("../Ice/ModuleRegistry").Ice; -var toString = function(key, object, objectTable, ident) +const toString = function(key, object, objectTable, ident) { ident += " "; if(object === null) @@ -35,8 +34,8 @@ var toString = function(key, object, objectTable, ident) } objectTable.push(object); - var s = "\n" + ident + key + ":"; - for(var k in object) + let s = "\n" + ident + key + ":"; + for(let k in object) { if(key.indexOf("_") === 0) { @@ -55,19 +54,23 @@ var toString = function(key, object, objectTable, ident) // // Ice.Exception // -var Exception = Class(Error, { - __init__: function(cause) +class Exception extends Error +{ + constructor(cause) { + super(); if(cause) { this.ice_cause = cause; } - }, - ice_name: function() + } + + ice_name() { return "Ice::Exception"; - }, - toString: function() + } + + toString() { // // We have a guard here to prevent being re-entered. With some browsers (IE), accessing @@ -80,8 +83,8 @@ var Exception = Class(Error, { } this._inToStringAlready = true; - var s = this.ice_name(); - for(var key in this) + let s = this.ice_name(); + for(let key in this) { if(key != "_inToStringAlready") { @@ -96,94 +99,96 @@ var Exception = Class(Error, { this._inToStringAlready = false; return s; } -}); - -Exception.captureStackTrace = function(object) -{ - var stack = new Error().stack; - // - // In IE 10 and greater the stack will be filled once the Error is throw - // we don't need to do anything. - // - if(stack !== undefined) + + static captureStackTrace(object) { - Object.defineProperty(object, "stack", { - get: function(){ - return stack; - } - }); + const stack = new Error().stack; + // + // In IE 10 and greater the stack will be filled once the Error is throw + // we don't need to do anything. + // + if(stack !== undefined) + { + Object.defineProperty(object, "stack", { + get: function() + { + return stack; + } + }); + } } -}; +} Ice.Exception = Exception; // // Ice.LocalException // -var LocalException = Class(Exception, { - __init__: function(cause) +class LocalException extends Exception +{ + constructor(cause) { - Exception.call(this, cause); + super(cause); Exception.captureStackTrace(this); - }, - ice_name: function() + } + + ice_name() { return "Ice::LocalException"; } -}); +} Ice.LocalException = LocalException; -var Slice = Ice.Slice; -Slice.defineLocalException = function(constructor, base, name) -{ - var ex = constructor; - ex.prototype = new base(); - ex.prototype.constructor = ex; - ex.prototype.ice_name = function() - { - return name; - }; - return ex; -}; +const Slice = Ice.Slice; // // Ice.UserException // -var UserException = Class(Exception, { - __init__: function(cause) +class UserException extends Exception +{ + constructor(cause) { - Exception.call(this, cause); + super(cause); Exception.captureStackTrace(this); - }, - ice_name: function() + } + + ice_name() { return "Ice::UserException"; - }, - __write: function(os) + } + + __write(os) { os.startException(null); __writeImpl(this, os, this.__mostDerivedType()); os.endException(); - }, - __read: function(is) + } + + __read(is) { is.startException(); __readImpl(this, is, this.__mostDerivedType()); is.endException(false); - }, - __usesClasses: function() + } + + __usesClasses() { return false; } -}); + + __mostDerivedType() + { + return Ice.UserException; + } +} Ice.UserException = UserException; // // Private methods // -var __writeImpl = function(obj, os, type) +const __writeImpl = function(obj, os, type) { // // The __writeImpl method is a recursive method that goes down the @@ -205,7 +210,7 @@ var __writeImpl = function(obj, os, type) __writeImpl(obj, os, type.__parent); }; -var __readImpl = function(obj, is, type) +const __readImpl = function(obj, is, type) { // // The __readImpl method is a recursive method that goes down the @@ -227,7 +232,7 @@ var __readImpl = function(obj, is, type) __readImpl(obj, is, type.__parent); }; -var __writePreserved = function(os) +const __writePreserved = function(os) { // // For Slice exceptions which are marked "preserved", the implementation of this method @@ -238,7 +243,7 @@ var __writePreserved = function(os) os.endException(); }; -var __readPreserved = function(is) +const __readPreserved = function(is) { // // For Slice exceptions which are marked "preserved", the implementation of this method @@ -249,35 +254,10 @@ var __readPreserved = function(is) this.__slicedData = is.endException(true); }; -Slice.defineUserException = function(constructor, base, name, writeImpl, readImpl, preserved, usesClasses) +Slice.PreservedUserException = function(ex) { - var ex = constructor; - ex.__parent = base; - ex.prototype = new base(); - ex.__id = "::" + name; - ex.prototype.ice_name = function() - { - return name; - }; - - ex.prototype.constructor = ex; - ex.prototype.__mostDerivedType = function() { return ex; }; - if(preserved) - { - ex.prototype.__write = __writePreserved; - ex.prototype.__read = __readPreserved; - } - ex.prototype.__writeMemberImpl = writeImpl; - ex.prototype.__readMemberImpl = readImpl; - - if(usesClasses) - { - ex.prototype.__usesClasses = function() - { - return true; - }; - } - - return ex; + ex.prototype.__write = __writePreserved; + ex.prototype.__read = __readPreserved; }; + module.exports.Ice = Ice; |