From bed2eed2de75fbd3f6b0d5cc9f0225b0b5ccf2f3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 4 Aug 2022 16:05:32 +0300 Subject: [PATCH] reworked the .name handling back -- neither chrome nor ff show the correct name otherwise... Signed-off-by: Alex A. Naanou --- object.js | 35 ++++++++++++++--------------------- package.json | 2 +- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/object.js b/object.js index 1806716..5181362 100755 --- a/object.js +++ b/object.js @@ -217,7 +217,11 @@ function(obj){ // NOTE: we just created func(..) so no need to sanitize it, the // only potential vector of atack (AFAIK) here is name and // that is checked above... - Object.defineProperty(func, 'name', {value: name}) + func = eval('('+ + func + .toString() + .replace(/function\(/, `function ${name}(`) +')') + //Object.defineProperty(func, 'name', {value: name}) /* XXX NAME... //func.name = name func.name != name @@ -916,28 +920,15 @@ function Constructor(name, a, b, c){ obj.__init__ instanceof Function && obj.__init__(...arguments) return obj } - - // constructor naming... + // rename the consructor... // NOTE: we are not using: // Object.defineProperty(_constructor, 'name', { value: name }) - // because this does not affect the name displayed by the Chrome - // DevTools. FF does not seem to care about either version of code... - Object.defineProperty(_constructor, 'name', {value: name}) - /* XXX NAME... - //_constructor.name = name - // just in case the browser/node refuses to change the name, we'll make - // them a different offer ;) - // NOTE: it is not possible to abstract this eval(..) into something - // like renameFunction(..) as reconstructing the function will - // lose it's closure that we depend on here... - // NOTE: this eval(..) should not be a risk as its inputs are - // static and never infuenced by external inputs... - _constructor.name != name - && (_constructor = eval('('+ - _constructor - .toString() - .replace(/Constructor/g, name) +')')) - //*/ + // because this does not affect the name displayed by the DevTools. + _constructor = eval('('+ + _constructor + .toString() + .replace(/Constructor/g, name) +')') + // set .toString(..)... // NOTE: this test is here to enable mixinFlat(..) to overwrite // .toString(..) below... @@ -1309,6 +1300,8 @@ Constructor('Mixin', { // NOTE: we do not need to configure this any more, .defineProperty(..) // merges the descriptor into the original keeping any values not // explicitly overwritten... + // XXX is this effective??? + // ...will this show up in DevTools??? Object.defineProperty(this, 'name', { value: name }) // create/merge .data... this.data = this.constructor.mixinFlat({}, diff --git a/package.json b/package.json index d28b25b..1601f33 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "6.1.2", + "version": "6.1.4", "description": "", "main": "object.js", "scripts": {