aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/Message.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-04-23 17:15:40 +0000
committerMaximilian Krambach <[email protected]>2018-04-23 17:15:40 +0000
commit727340b295f25e04cb595022ba143cda48364697 (patch)
tree81d54f26c2dfcdd324382119486b6681a529aed2 /lang/js/src/Message.js
parentjs: Key handling stubs, Error handling, refactoring (diff)
downloadgpgme-727340b295f25e04cb595022ba143cda48364697.tar.gz
gpgme-727340b295f25e04cb595022ba143cda48364697.zip
js: don't allow message operation changes
-- Once an operation is changed, their set of allowed/required parameters will change. So we shouldn't set/change the operation later.
Diffstat (limited to 'lang/js/src/Message.js')
-rw-r--r--lang/js/src/Message.js42
1 files changed, 20 insertions, 22 deletions
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js
index 6a93b6f4..f5e21e00 100644
--- a/lang/js/src/Message.js
+++ b/lang/js/src/Message.js
@@ -23,28 +23,7 @@ export class GPGME_Message {
//TODO getter
constructor(operation){
- if (operation){
- this.operation(operation);
- }
- }
-
- /**
- * Defines the operation this message will have
- * @param {String} operation Must be defined in permittedOperations
- * TODO: move to constructor?
- */
- set operation (operation){
- if (!operation || typeof(operation) !== 'string'){
- return new GPGMEJS_Error('WRONGPARAM');
- }
- if (operation in permittedOperations){
- if (!this._msg){
- this._msg = {};
- }
- this._msg.op = operation;
- } else {
- return new GPGMEJS_Error('WRONG_OP');
- }
+ setOperation(this, operation);
}
get operation(){
@@ -110,4 +89,23 @@ export class GPGME_Message {
}
}
+}
+
+/**
+ * Defines the operation this message will have
+ * @param {String} operation Must be defined in permittedOperations
+ * TODO: move to constructor?
+ */
+function setOperation (scope, operation){
+ if (!operation || typeof(operation) !== 'string'){
+ return new GPGMEJS_Error('WRONGTYPE');
+ }
+ if (permittedOperations.hasOwnProperty(operation)){
+ if (!scope._msg){
+ scope._msg = {};
+ }
+ scope._msg.op = operation;
+ } else {
+ return new GPGMEJS_Error('WRONG_OP');
+ }
} \ No newline at end of file