r9784 - in helma-ng/trunk/modules: core helma/storage
[email protected] Fri, 15 May 2009 11:44:27 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090515094427.C704A3D0D6@mia> |
Author: hannes
Date: 2009-05-15 11:44:27 +0200 (Fri, 15 May 2009)
New Revision: 9784
Added:
helma-ng/trunk/modules/core/json.js
Removed:
helma-ng/trunk/modules/core/JSON.js
helma-ng/trunk/modules/core/json2.js
Modified:
helma-ng/trunk/modules/helma/storage/filestore.js
helma-ng/trunk/modules/helma/storage/memstore.js
Log:
Unify JSON support: remove core/JSON, rename core/json2 to core/json, and use Object.defineProperty to define toJSON() in the String, Date, Number, and Boolean prototypes.
The reason for this is that Object.protoype.toJSON() in core/JSON clashed with the methods in strings, dates, numbers, and booleans set by core/json2, and it seems stupid to provide two ways of doing the same thing anyway.
Details at http://dev.helma.org/trac/helma/changeset/9784
Deleted: helma-ng/trunk/modules/core/JSON.js
Copied: helma-ng/trunk/modules/core/json.js (from rev 9783, helma-ng/trunk/modules/core/json2.js)
Deleted: helma-ng/trunk/modules/core/json2.js
Modified: helma-ng/trunk/modules/helma/storage/filestore.js
===================================================================
--- helma-ng/trunk/modules/helma/storage/filestore.js 2009-05-15 08:45:46 UTC (rev 9783)
+++ helma-ng/trunk/modules/helma/storage/filestore.js 2009-05-15 09:44:27 UTC (rev 9784)
@@ -1,6 +1,6 @@
require('core/object');
require('core/array');
-require('core/JSON');
+include('core/json');
include('helma/file');
include('helma/functional');
@@ -189,7 +189,7 @@
log.debug("Storing object: " + object.toSource());
tempfile.open({ append: true });
- tempfile.write(entity.toJSON());
+ tempfile.write(JSON.stringify(entity));
tempfile.close();
txn.updateResource({ file: file, tempfile: tempfile });
};
@@ -205,7 +205,7 @@
}
var content = file.readAll();
- var entity = content.parseJSON();
+ var entity = JSON.parse(content);
Object.defineProperty(entity, "_key", {
value: [type, file.getName()]
});
Modified: helma-ng/trunk/modules/helma/storage/memstore.js
===================================================================
--- helma-ng/trunk/modules/helma/storage/memstore.js 2009-05-15 08:45:46 UTC (rev 9783)
+++ helma-ng/trunk/modules/helma/storage/memstore.js 2009-05-15 09:44:27 UTC (rev 9784)
@@ -1,6 +1,6 @@
require('core/object');
require('core/array');
-require('core/JSON');
+include('core/json');
include('helma/functional');
export("Storable");
@@ -164,7 +164,7 @@
if (!dir) {
data[type] = dir = {};
}
- dir[id] = entity.toJSON();
+ dir[id] = JSON.stringify(entity);
};
this.load = function(type, id) {
@@ -172,7 +172,7 @@
if (!dir || !dir[id]) {
return null;
}
- var entity = dir[id].parseJSON();
+ var entity = JSON.parse(dir[id]);
Object.defineProperty(entity, "_key", {
value: [type, id]
});