From 9dbc1968376f936264ca185898b4b1ab4118b057 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Tue, 5 Aug 2014 11:55:34 -0700 Subject: [PATCH 1/2] make ClassNotFoundException a subclass of Error --- classes.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/classes.js b/classes.js index 7abc9e57..48034314 100644 --- a/classes.js +++ b/classes.js @@ -13,8 +13,12 @@ var Classes = function() { } } -Classes.ClassNotFoundException = function() { -} +Classes.ClassNotFoundException = function(message) { + this.message = message; +}; +Classes.ClassNotFoundException.prototype = new Error(); +Classes.ClassNotFoundException.prototype.name = "ClassNotFoundException"; +Classes.ClassNotFoundException.prototype.constructor = Classes.ClassNotFoundException; Classes.prototype.addPath = function(name, data) { if (name.substr(-4) === ".jar") { @@ -63,7 +67,7 @@ Classes.prototype.loadClassFile = function(fileName) { console.info("loading " + fileName + " ..."); var bytes = this.loadFile(fileName); if (!bytes) - throw new (Classes.ClassNotFoundException)(); + throw new (Classes.ClassNotFoundException)(fileName); var self = this; var classInfo = this.loadClassBytes(bytes); if (classInfo.superClassName) From a798f311167be8b451f173dd04c7f24e4743251f Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Tue, 5 Aug 2014 12:15:13 -0700 Subject: [PATCH 2/2] use Object.create to clarify intent --- classes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes.js b/classes.js index 48034314..31a13a16 100644 --- a/classes.js +++ b/classes.js @@ -16,7 +16,7 @@ var Classes = function() { Classes.ClassNotFoundException = function(message) { this.message = message; }; -Classes.ClassNotFoundException.prototype = new Error(); +Classes.ClassNotFoundException.prototype = Object.create(Error.prototype); Classes.ClassNotFoundException.prototype.name = "ClassNotFoundException"; Classes.ClassNotFoundException.prototype.constructor = Classes.ClassNotFoundException;