Skip to content

Commit

Permalink
Make all the readonly attributes in Device Capabilities valid.
Browse files Browse the repository at this point in the history
Bug=XWALK-2162
  • Loading branch information
scuxiayiqian authored and legendlee1314 committed Aug 27, 2014
1 parent 98522ef commit 8aeaf52
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions sysapps/common/common_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ var v8tools;

var unique_id = 0;

function addConstProperty(obj, propertyKey, propertyValue) {
Object.defineProperty(obj, propertyKey, {
configurable: false,
writable: false,
value: propertyValue
});
}

function createConstClone(obj) {
var const_obj = {};
for (var key in obj) {
if (Array.isArray(obj[key])) {
var obj_array = obj[key];
var const_obj_array = [];
for (var i = 0; i < obj_array.length; ++i) {
var const_sub_obj = {};
for (var sub_key in obj_array[i]) {
addConstProperty(const_sub_obj, sub_key, obj_array[i][sub_key]);
}
const_obj_array.push(const_sub_obj);
}
addConstProperty(const_obj, key, const_obj_array);
} else {
addConstProperty(const_obj, key, obj[key]);
}
}
return const_obj;
}

function getUniqueId() {
return (unique_id++).toString();
}
Expand All @@ -18,7 +47,7 @@ function wrapPromiseAsCallback(promise) {
if (error)
promise.reject(error);
else
promise.fulfill(data);
promise.fulfill(createConstClone(data));
};
};

Expand Down Expand Up @@ -205,7 +234,8 @@ var EventTargetPrototype = function() {
var listeners = this._event_listeners[type];

for (var i in listeners)
listeners[i](new this._event_synthesizers[type](type, data));
listeners[i](new this._event_synthesizers[type](type,
createConstClone(data)));
};

// We need a reference to the calling object because
Expand Down

0 comments on commit 8aeaf52

Please sign in to comment.