From 78529b667b84619b43a585b7622696b1ff75595d Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 14 Nov 2020 19:13:53 +0300 Subject: [PATCH] found a bug... Signed-off-by: Alex A. Naanou --- object.js | 17 ++++++++++++++++- test.js | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/object.js b/object.js index 66731d7..f76daa2 100755 --- a/object.js +++ b/object.js @@ -352,6 +352,20 @@ function(obj, name, callback){ // // // NOTE: for more docs on the callback(..) see sources(..) +// +// XXX BUG: passing a callback here breaks the return value at the STOP... +// essentially this is a question of how can we return STOP and the +// value to be returned at the same time??? +// ...ways to go: +// - store the last return from callback(..) and if it's STOP +// patch the last value (HACK-ish) +// - skip the last value... +// ...this will complicate the logic quite a bit as the user +// will need to STOP after the last position... +// - return STOP(value) or [STOP, value] +// ...requires the user not to forget... +// - ignore the callback return value... +// ...this seems the most uniform, but this can break things... var values = module.values = function(obj, name, callback, props){ @@ -374,7 +388,8 @@ function(obj, name, callback, props){ return callback(_get(obj, name), obj) } return c ? // NOTE: we do not need to handle the callback return values as - // this is fully done in sources(..) + // this is fully done by c(..) in sources(..) + // XXX BUG: if this stops the last value will be the obj and not the prop... sources(obj, name, c) : sources(obj, name) .map(function(obj){ diff --git a/test.js b/test.js index ce0bc67..0e73f06 100755 --- a/test.js +++ b/test.js @@ -651,6 +651,30 @@ var cases = test.Cases({ assert(object.parent({}) === {}.__proto__, 'basic proto') assert.error('.parent(..) of anonymous function', function(){ object.parent(function(){}, {}) }) + + // object.values(..) + var obj = Object.create({x: 123}) + obj.x = 321 + + assert.array( + object.values(obj, 'x', true) + .map(function(e){ return e.value }), + // XXX essert ignores the order here -- this should fail... + [123, 321], '.values(.., true) ') + + // XXX BUG: this returns the object and not the value... + console.log('>>>>>', object.values(obj, 'x', function(){ return object.STOP })) + // XXX BUG: this returns the object and not the prop descriptor... + console.log('>>>>>', object.values(obj, 'x', function(){ return object.STOP }, true)) + + assert( + object.values(obj, 'x', function(){ return object.STOP })[0] == 321, + // XXX essert ignores the order here -- this should fail... + '.values(.., func) ') + assert( + object.values(obj, 'x', function(){ return object.STOP }, true)[0].value == 321, + // XXX essert ignores the order here -- this should fail... + '.values(.., func, true) ') }, deepKeys: function(assert){ var a = {