found a bug...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-11-14 19:13:53 +03:00
parent 5a4b999382
commit 78529b667b
2 changed files with 40 additions and 1 deletions

View File

@ -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){

24
test.js
View File

@ -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 = {