From 67f8c4d8ed2706c52ff18accce549e9c7082a035 Mon Sep 17 00:00:00 2001 From: Toni Date: Fri, 13 Nov 2015 11:34:01 -0500 Subject: [PATCH] Add argument to control whether NamespaceResolver attempts to pair mangled constructors --- resurrect.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/resurrect.js b/resurrect.js index 31fdc42..34103e3 100644 --- a/resurrect.js +++ b/resurrect.js @@ -136,9 +136,11 @@ Resurrect.prototype.Error.prototype.name = 'ResurrectError'; * Resolves prototypes through the properties on an object and * constructor names. * @param {Object} scope + * @param {boolean} resolveMangled * @constructor */ -Resurrect.NamespaceResolver = function(scope) { +Resurrect.NamespaceResolver = function(scope, resolveMangled) { + this.resolveMangled = resolveMangled || false; this.scope = scope; }; @@ -177,6 +179,13 @@ Resurrect.NamespaceResolver.prototype.getName = function(object) { } else if (constructor === 'Object' || constructor === 'Array') { return null; } else { + if (this.resolveMangled) { + for (var prop in this.scope) { + if (this.scope.hasOwnProperty(prop) && this.scope[prop] === object.constructor) { + return prop; + } + } + } return constructor; } };