[Notification] Fix non nullable attributes
authorRicardo de Almeida Gonzaga <ricardo.gonzaga@intel.com>
Thu, 21 Nov 2013 13:40:47 +0000 (11:40 -0200)
committerRicardo de Almeida Gonzaga <ricardo.gonzaga@intel.com>
Fri, 22 Nov 2013 15:48:13 +0000 (13:48 -0200)
Now its not possible to set non nullable attributes to null

notification/notification_api.js

index 1d335b6..3042838 100644 (file)
@@ -131,6 +131,17 @@ function defineReadOnlyProperty(object, key, value) {
   });
 }
 
+function defineNonNullableProperty(object, key) {
+  Object.defineProperty(object, key, {
+    get: function(k) {
+      return this[k];
+    }.bind(object, key + '_'),
+    set: function(k, NewValue) {
+      if (NewValue != null)
+        this[k] = NewValue;
+    }.bind(object, key + '_') });
+}
+
 tizen.NotificationDetailInfo = function(mainText, subText) {
   // FIXME(cmarcelo): This is a best effort that covers the common
   // cases. Investigate whether we can implement a primitive natively to give us
@@ -146,7 +157,7 @@ tizen.StatusNotification = function(statusType, title, dict) {
   if (!this || this.constructor != tizen.StatusNotification)
     throw new TypeError;
 
-  this.title = title;
+  this.title_ = title;
 
   defineReadOnlyProperty(this, 'id', undefined);
   defineReadOnlyProperty(this, 'postedTime', undefined);
@@ -162,20 +173,26 @@ tizen.StatusNotification = function(statusType, title, dict) {
   this.content = dict.content || null;
   this.iconPath = dict.iconPath || null;
   this.soundPath = dict.soundPath || null;
-  this.vibration = Boolean(dict.vibration);
+  this.vibration_ = Boolean(dict.vibration);
   this.appControl = dict.appControl || null;
   this.appId = dict.appId !== undefined ? dict.appId : null;
-  this.progressType = dict.progressType || 'PERCENTAGE';
+  this.progressType_ = dict.progressType || 'PERCENTAGE';
   this.progressValue = dict.progressValue !== undefined ? dict.progressValue : null;
   this.number = dict.number || null;
   this.subIconPath = dict.subIconPath || null;
   // FIXME(cmarcelo): enforce maximum of 2 elements in the array.
   this.detailInfo = dict.detailInfo || [];
   this.ledColor = dict.ledColor || null;
-  this.ledOnPeriod = dict.ledOnPeriod || 0;
-  this.ledOffPeriod = dict.ledOffPeriod || 0;
+  this.ledOnPeriod_ = dict.ledOnPeriod || 0;
+  this.ledOffPeriod_ = dict.ledOffPeriod || 0;
   this.backgroundImagePath = dict.backgroundImagePath || null;
   this.thumbnails = dict.thumbnails || [];
+
+  defineNonNullableProperty(this, 'title');
+  defineNonNullableProperty(this, 'vibration');
+  defineNonNullableProperty(this, 'progressType');
+  defineNonNullableProperty(this, 'ledOnPeriod');
+  defineNonNullableProperty(this, 'ledOffPeriod');
 };
 
 exports.post = function(notification) {