From 5fa728d4849d589aeae9b19325cca10bbbde9406 Mon Sep 17 00:00:00 2001 From: krmbn0576 Date: Sun, 19 Aug 2018 19:29:48 +0900 Subject: [PATCH 1/2] Fix JsonEx cannot parse Object.create(null) --- js/rpg_core/JsonEx.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/js/rpg_core/JsonEx.js b/js/rpg_core/JsonEx.js index 389e92a2..a6d551bb 100644 --- a/js/rpg_core/JsonEx.js +++ b/js/rpg_core/JsonEx.js @@ -131,7 +131,7 @@ JsonEx._encode = function(value, circular, depth) { value['@'] = constructorName; } for (var key in value) { - if (value.hasOwnProperty(key) && !key.match(/^@./)) { + if ((!value.hasOwnProperty || value.hasOwnProperty(key)) && !key.match(/^@./)) { if(value[key] && typeof value[key] === 'object'){ if(value[key]['@c']){ circular.push([key, value, value[key]]); @@ -173,14 +173,16 @@ JsonEx._decode = function(value, circular, registry) { if (type === '[object Object]' || type === '[object Array]') { registry[value['@c']] = value; - if (value['@']) { + if (value['@'] === 'NoPrototype') { + value = this._resetPrototype(value, null); + } else if (value['@']) { var constructor = window[value['@']]; if (constructor) { value = this._resetPrototype(value, constructor.prototype); } } for (var key in value) { - if (value.hasOwnProperty(key)) { + if (!value.hasOwnProperty || value.hasOwnProperty(key)) { if(value[key] && value[key]['@a']){ //object is array wrapper var body = value[key]['@a']; @@ -206,6 +208,9 @@ JsonEx._decode = function(value, circular, registry) { * @private */ JsonEx._getConstructorName = function(value) { + if (!value.constructor) { + return 'NoPrototype'; + } var name = value.constructor.name; if (name === undefined) { var func = /^\s*function\s*([A-Za-z0-9_$]*)/; From 4a1a08f45e5212fe7616bb1de6105297e9bd0b01 Mon Sep 17 00:00:00 2001 From: krmbn0576 Date: Wed, 22 Aug 2018 02:56:55 +0900 Subject: [PATCH 2/2] use null instead of NoPrototype --- js/rpg_core/JsonEx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/rpg_core/JsonEx.js b/js/rpg_core/JsonEx.js index a6d551bb..e80b2306 100644 --- a/js/rpg_core/JsonEx.js +++ b/js/rpg_core/JsonEx.js @@ -173,7 +173,7 @@ JsonEx._decode = function(value, circular, registry) { if (type === '[object Object]' || type === '[object Array]') { registry[value['@c']] = value; - if (value['@'] === 'NoPrototype') { + if (value['@'] === null) { value = this._resetPrototype(value, null); } else if (value['@']) { var constructor = window[value['@']]; @@ -209,7 +209,7 @@ JsonEx._decode = function(value, circular, registry) { */ JsonEx._getConstructorName = function(value) { if (!value.constructor) { - return 'NoPrototype'; + return null; } var name = value.constructor.name; if (name === undefined) {