From 4479d98d4f4747f3df4e075dda734fb3ea6d7401 Mon Sep 17 00:00:00 2001 From: Ricardo de Almeida Gonzaga Date: Thu, 21 Nov 2013 11:40:47 -0200 Subject: [PATCH] [Notification] Fix non nullable attributes Now its not possible to set non nullable attributes to null --- notification/notification_api.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/notification/notification_api.js b/notification/notification_api.js index 1d335b6..3042838 100644 --- a/notification/notification_api.js +++ b/notification/notification_api.js @@ -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) { -- 2.7.4