Skip to content

Commit 76fdfef

Browse files
authored
Merge pull request rpgtkoolmv#174 from rpgtkoolmv/fix_noprototype
Fix JsonEx cannot parse Object.create(null)
2 parents 69db961 + 4a1a08f commit 76fdfef

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

js/rpg_core/JsonEx.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ JsonEx._encode = function(value, circular, depth) {
131131
value['@'] = constructorName;
132132
}
133133
for (var key in value) {
134-
if (value.hasOwnProperty(key) && !key.match(/^@./)) {
134+
if ((!value.hasOwnProperty || value.hasOwnProperty(key)) && !key.match(/^@./)) {
135135
if(value[key] && typeof value[key] === 'object'){
136136
if(value[key]['@c']){
137137
circular.push([key, value, value[key]]);
@@ -173,14 +173,16 @@ JsonEx._decode = function(value, circular, registry) {
173173
if (type === '[object Object]' || type === '[object Array]') {
174174
registry[value['@c']] = value;
175175

176-
if (value['@']) {
176+
if (value['@'] === null) {
177+
value = this._resetPrototype(value, null);
178+
} else if (value['@']) {
177179
var constructor = window[value['@']];
178180
if (constructor) {
179181
value = this._resetPrototype(value, constructor.prototype);
180182
}
181183
}
182184
for (var key in value) {
183-
if (value.hasOwnProperty(key)) {
185+
if (!value.hasOwnProperty || value.hasOwnProperty(key)) {
184186
if(value[key] && value[key]['@a']){
185187
//object is array wrapper
186188
var body = value[key]['@a'];
@@ -206,6 +208,9 @@ JsonEx._decode = function(value, circular, registry) {
206208
* @private
207209
*/
208210
JsonEx._getConstructorName = function(value) {
211+
if (!value.constructor) {
212+
return null;
213+
}
209214
var name = value.constructor.name;
210215
if (name === undefined) {
211216
var func = /^\s*function\s*([A-Za-z0-9_$]*)/;

0 commit comments

Comments
 (0)