From 1954d27be86b8e4eb801ca6ddcb670f8cfb149f5 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Mon, 20 Aug 2018 12:12:43 +0200 Subject: js: revert changes to class read/write restriction -- * undoes 94ee0988d4eaac27785de6efb7c19ca9976e1e9c and e16a87e83910ebb6bfdc4148369165f121f0997e. I do not fully understand why my approach was bad, but I am not in a position to argue. This revert was requested to me after a review, and I'm doing it in the assumption that more experienced people know better than me. * unittests: Also changed some outdated tests that stopped working since 754e799d35fd62d7a979452f44342934659908c7 (as GPGME_Key is not exported, one cannot check for instanceof in the tests anymore) --- lang/js/src/Errors.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lang/js/src/Errors.js') diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js index b22eca73..2a35bc5e 100644 --- a/lang/js/src/Errors.js +++ b/lang/js/src/Errors.js @@ -123,7 +123,7 @@ const err_list = { export function gpgme_error(code = 'GENERIC_ERROR', info){ if (err_list.hasOwnProperty(code)){ if (err_list[code].type === 'error'){ - return Object.freeze(new GPGME_Error(code)); + return new GPGME_Error(code); } if (err_list[code].type === 'warning'){ // eslint-disable-next-line no-console @@ -131,10 +131,10 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ } return null; } else if (code === 'GNUPG_ERROR'){ - return Object.freeze(new GPGME_Error(code, info)); + return new GPGME_Error(code, info); } else { - return Object.freeze(new GPGME_Error('GENERIC_ERROR')); + return new GPGME_Error('GENERIC_ERROR'); } } @@ -148,6 +148,7 @@ export function gpgme_error(code = 'GENERIC_ERROR', info){ */ class GPGME_Error extends Error{ constructor(code = 'GENERIC_ERROR', msg=''){ + if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){ super(msg); } else if (err_list.hasOwnProperty(code)){ @@ -159,12 +160,10 @@ class GPGME_Error extends Error{ } else { super(err_list['GENERIC_ERROR'].msg); } - this.getCode = function(){ - return code; - }; + this._code = code; } get code(){ - return this.getCode(); + return this._code; } } \ No newline at end of file -- cgit v1.2.3