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

Make all the readonly attributes in Device Capabilities valid. #2355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is right. I think it's enough for this PR's target. Can you verify it if you only change this one point?

};
};

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)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halton , I found it failed at this line createConstClone(data) for listener. It should be wrong. I try hard to understand the EventTargetPrototype's structure but can not understand totally. I can not find where the real recieved data is. Try to add createConstClone in line 190, 230 or 245 and all are failed. Could you please have a look at this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@legendlee1314 Do you still work on this? I think this point doesn't need to change. Just keep the old design.

};

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