bugfix... (took so long because of motivation issues)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-01-03 15:49:56 +03:00
parent 9c9622e999
commit 5a9d977c4e
3 changed files with 71 additions and 65 deletions

View File

@ -114,50 +114,50 @@ class B extends A {
## Contents ## Contents
- [object.js](#objectjs) - [object.js](#objectjs)
- [Contents](#contents) - [Contents](#contents)
- [Installation](#installation) - [Installation](#installation)
- [Basic usage](#basic-usage) - [Basic usage](#basic-usage)
- [Inheritance](#inheritance) - [Inheritance](#inheritance)
- [Callable instances](#callable-instances) - [Callable instances](#callable-instances)
- [Mix-ins](#mix-ins) - [Mix-ins](#mix-ins)
- [Advanced usage](#advanced-usage) - [Advanced usage](#advanced-usage)
- [Low level constructor](#low-level-constructor) - [Low level constructor](#low-level-constructor)
- [Extending the constructor](#extending-the-constructor) - [Extending the constructor](#extending-the-constructor)
- [Inheriting from native constructor objects](#inheriting-from-native-constructor-objects) - [Inheriting from native constructor objects](#inheriting-from-native-constructor-objects)
- [Extending native `.constructor(..)`](#extending-native-constructor) - [Extending native `.constructor(..)`](#extending-native-constructor)
- [Special methods](#special-methods) - [Special methods](#special-methods)
- [`<object>.__new__(..)`](#object__new__) - [`<object>.__new__(..)`](#object__new__)
- [`<object>.__init__(..)`](#object__init__) - [`<object>.__init__(..)`](#object__init__)
- [`<object>.__call__(..)`](#object__call__) - [`<object>.__call__(..)`](#object__call__)
- [Components](#components) - [Components](#components)
- [`STOP` / `STOP(..)`](#stop--stop) - [`STOP` / `STOP(..)`](#stop--stop)
- [`sources(..)`](#sources) - [`sources(..)`](#sources)
- [`values(..)`](#values) - [`values(..)`](#values)
- [`parent(..)`](#parent) - [`parent(..)`](#parent)
- [`parentProperty(..)`](#parentproperty) - [`parentProperty(..)`](#parentproperty)
- [`parentCall(..)`](#parentcall) - [`parentCall(..)`](#parentcall)
- [`parentOf(..)` / `childOf(..)` / `related(..)`](#parentof--childof--related) - [`parentOf(..)` / `childOf(..)` / `related(..)`](#parentof--childof--related)
- [`RawInstance(..)`](#rawinstance) - [`RawInstance(..)`](#rawinstance)
- [`Constructor(..)` / `C(..)`](#constructor--c) - [`Constructor(..)` / `C(..)`](#constructor--c)
- [`mixin(..)`](#mixin) - [`mixin(..)`](#mixin)
- [`mixins(..)`](#mixins) - [`mixins(..)`](#mixins)
- [`hasMixin(..)`](#hasmixin) - [`hasMixin(..)`](#hasmixin)
- [`mixout(..)`](#mixout) - [`mixout(..)`](#mixout)
- [`mixinFlat(..)`](#mixinflat) - [`mixinFlat(..)`](#mixinflat)
- [`Mixin(..)`](#mixin-1) - [`Mixin(..)`](#mixin-1)
- [`<mixin>(..)`](#mixin-2) - [`<mixin>(..)`](#mixin-2)
- [`<mixin>.mode`](#mixinmode) - [`<mixin>.mode`](#mixinmode)
- [`<mixin>.mixout(..)`](#mixinmixout) - [`<mixin>.mixout(..)`](#mixinmixout)
- [`<mixin>.isMixed(..)`](#mixinismixed) - [`<mixin>.isMixed(..)`](#mixinismixed)
- [Utilities](#utilities) - [Utilities](#utilities)
- [`normalizeIndent(..)` / `normalizeTextIndent(..)` / `doc` / `text`](#normalizeindent--normalizetextindent--doc--text) - [`normalizeIndent(..)` / `normalizeTextIndent(..)` / `doc` / `text`](#normalizeindent--normalizetextindent--doc--text)
- [`deepKeys(..)`](#deepkeys) - [`deepKeys(..)`](#deepkeys)
- [`match(..)`](#match) - [`match(..)`](#match)
- [`matchPartial(..)`](#matchpartial) - [`matchPartial(..)`](#matchpartial)
- [Limitations](#limitations) - [Limitations](#limitations)
- [Can not mix unrelated native types](#can-not-mix-unrelated-native-types) - [Can not mix unrelated native types](#can-not-mix-unrelated-native-types)
- [More](#more) - [More](#more)
- [License](#license) - [License](#license)
## Installation ## Installation
@ -571,7 +571,7 @@ sources(<object>, <name>, <callback>)
``` ```
``` ```
callback(<source>) callback(<source>, <index>)
-> STOP -> STOP
-> STOP(<value>) -> STOP(<value>)
-> undefined -> undefined
@ -619,7 +619,7 @@ values(<object>, <name>, <callback>)
``` ```
``` ```
callback(<value>, <source>) callback(<value>, <source>, <index>)
-> STOP -> STOP
-> undefined -> undefined
-> <value> -> <value>

View File

@ -329,7 +329,7 @@ BOOTSTRAP(function(){
// -> list // -> list
// //
// //
// callback(obj) // callback(obj, i)
// -> STOP // -> STOP
// -> STOP(value) // -> STOP(value)
// -> .. // -> ..
@ -366,6 +366,7 @@ function(obj, name, callback){
callback = name callback = name
name = undefined name = undefined
} }
var i = 0
var o var o
var res = [] var res = []
while(obj != null){ while(obj != null){
@ -375,7 +376,7 @@ function(obj, name, callback){
|| (name == '__call__' && typeof(obj) == 'function')){ || (name == '__call__' && typeof(obj) == 'function')){
// handle callback... // handle callback...
o = callback o = callback
&& callback(obj) && callback(obj, i++)
// manage results... // manage results...
res.push( res.push(
(o === undefined || o === module.STOP) ? (o === undefined || o === module.STOP) ?
@ -435,9 +436,9 @@ function(obj, name, callback, props){
: obj[name] } : obj[name] }
// wrap the callback if given... // wrap the callback if given...
var c = typeof(callback) == 'function' var c = typeof(callback) == 'function'
&& function(obj){ && function(obj, i){
var val = _get(obj, name) var val = _get(obj, name)
var res = callback(val, obj) var res = callback(val, obj, i)
return res === module.STOP ? return res === module.STOP ?
// wrap the expected stop result if the user did not do it... // wrap the expected stop result if the user did not do it...
module.STOP(val) module.STOP(val)
@ -514,12 +515,12 @@ function(obj, name, callback, props){
// and to the method after the match. // and to the method after the match.
// NOTE: this is super(..) replacement, usable in any context without // NOTE: this is super(..) replacement, usable in any context without
// restriction -- super(..) is restricted to class methods only... // restriction -- super(..) is restricted to class methods only...
// // NOTE: contrary to sources(..) in the .__call__ case, this will skip
// XXX BUG: the two flows with parent(proto.__call__, ..) and // the base callable instance, this will make both the following
// parent(proto, '__call__', ..) yeild different results... // cases identical:
// ...this appears to affect only the .__call__(..) method... // parent(C.prototype.__call__, obj)
// the problem seems to be that we are getting the first non-match // and:
// when we want the first match after current... // parent(C.prototype, '__call__')
var parent = var parent =
module.parent = module.parent =
function(proto, name){ function(proto, name){
@ -535,15 +536,21 @@ function(proto, name){
throw new Error('parent(..): need a method with non-empty .name') } throw new Error('parent(..): need a method with non-empty .name') }
// get first matching source... // get first matching source...
proto = sources(that, name, proto = sources(that, name,
function(obj){ function(obj, i){
return obj[name] === proto // NOTE: the .hasOwnProperty(..) test is here so as
// to skip the base callable when searching for
// .__call__ that is returned as a special case
// by sourcei(..) and this should have no effect
// or other cases...
// NOTE: this will only skip the root callable...
return (i > 0 || obj.hasOwnProperty(name))
&& obj[name] === proto
&& module.STOP }) && module.STOP })
.pop() } .pop() }
// get first source... // get first source...
var c = 0
var res = sources(proto, name, var res = sources(proto, name,
function(obj){ function(obj, i){
return c++ == 1 return i == 1
&& module.STOP }) && module.STOP })
.pop() .pop()
return !res ? return !res ?
@ -564,10 +571,9 @@ var parentProperty =
module.parentProperty = module.parentProperty =
function(proto, name){ function(proto, name){
// get second source... // get second source...
var c = 0
var res = sources(proto, name, var res = sources(proto, name,
function(obj){ function(obj, i){
return c++ == 1 return i == 1
&& module.STOP }) && module.STOP })
.pop() .pop()
return res ? return res ?

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-object", "name": "ig-object",
"version": "5.4.15", "version": "5.4.16",
"description": "", "description": "",
"main": "object.js", "main": "object.js",
"scripts": { "scripts": {