Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit a1d7f4a

Browse files
scuxiayiqiankygx-legend
authored andcommitted
Make all the readonly attributes in Device Capabilities valid.
Bug=XWALK-2162
1 parent 28d0e0f commit a1d7f4a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

sysapps/common/common_api.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ var v8tools;
99

1010
var unique_id = 0;
1111

12+
function addConstProperty(obj, propertyKey, propertyValue) {
13+
Object.defineProperty(obj, propertyKey, {
14+
configurable: false,
15+
writable: false,
16+
value: propertyValue
17+
});
18+
}
19+
20+
function createConstClone(obj) {
21+
var const_obj = {};
22+
for (var key in obj) {
23+
if (Array.isArray(obj[key])) {
24+
var obj_array = obj[key];
25+
var const_obj_array = [];
26+
for (var i = 0; i < obj_array.length; ++i) {
27+
var const_sub_obj = {};
28+
for (var sub_key in obj_array[i]) {
29+
addConstProperty(const_sub_obj, sub_key, obj_array[i][sub_key]);
30+
}
31+
const_obj_array.push(const_sub_obj);
32+
}
33+
addConstProperty(const_obj, key, const_obj_array);
34+
} else {
35+
addConstProperty(const_obj, key, obj[key]);
36+
}
37+
}
38+
return const_obj;
39+
}
40+
1241
function getUniqueId() {
1342
return (unique_id++).toString();
1443
}
@@ -18,7 +47,7 @@ function wrapPromiseAsCallback(promise) {
1847
if (error)
1948
promise.reject(error);
2049
else
21-
promise.fulfill(data);
50+
promise.fulfill(createConstClone(data));
2251
};
2352
};
2453

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

207236
for (var i in listeners)
208-
listeners[i](new this._event_synthesizers[type](type, data));
237+
listeners[i](new this._event_synthesizers[type](type,
238+
createConstClone(data)));
209239
};
210240

211241
// We need a reference to the calling object because

0 commit comments

Comments
 (0)