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

View File

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

View File

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