assertEqual(0, counter, 'bundle should be empty');
}
+function TestCopyCtor() {
+ var src = new tizen.Bundle({
+ key1: 'value',
+ key2: ['value1', 'value2'],
+ });
+
+ var dest = new tizen.Bundle(src);
+
+ assertEqual(Object.keys(src.data).length, Object.keys(dest.data).length, "number of entries is different");
+ assertEqual(src.data.key1, dest.data.key1, "key1 entry has different value");
+ assertArrayEqual(src.data.key2, dest.data.key2, "key2 entry has different value");
+}
+
function TestJsonCtor() {
var json = {
key1: 'value',
var testcases = [
TestDefaultCtor,
TestJsonCtor,
+ TestCopyCtor,
TestSetter,
TestGetters,
TestTypeOf,
TestToJson,
TestToString
];
+
}
}
-exports.Bundle = function(json) {
+function Bundle(arg) {
xwalk.utils.validator.isConstructorCall(this, exports.Bundle);
this.data = {};
+ var json = {};
- if (xwalk.utils.type.isObject(json)) {
- forEachOwnProperty(
- json,
- function(key, value) {
- this.set(key, value);
- }.bind(this)
- );
+ // copy constructor
+ if (arg instanceof tizen.Bundle) {
+ // perform deep copy of the other bundle.
+ json = JSON.parse(arg.toString());
+ }
+ // json to bundle conversion
+ else if (xwalk.utils.type.isObject(json)) {
+ json = arg;
}
+
+ forEachOwnProperty(
+ json,
+ function(key, value) {
+ this.set(key, value);
+ }.bind(this)
+ );
};
+exports.Bundle = Bundle;
exports.Bundle.prototype.constructor = exports.Bundle;
exports.Bundle.prototype.set = function(key, value) {