From 5a9d977c4e9427e237bfd99b9b5ded4c7c583de3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 3 Jan 2021 15:49:56 +0300 Subject: [PATCH] bugfix... (took so long because of motivation issues) Signed-off-by: Alex A. Naanou --- README.md | 92 ++++++++++++++++++++++++++-------------------------- object.js | 42 ++++++++++++++---------- package.json | 2 +- 3 files changed, 71 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 00a6e61..c5cd7cd 100755 --- a/README.md +++ b/README.md @@ -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) - - [`.__new__(..)`](#object__new__) - - [`.__init__(..)`](#object__init__) - - [`.__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-2) - - [`.mode`](#mixinmode) - - [`.mixout(..)`](#mixinmixout) - - [`.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) + - [`.__new__(..)`](#object__new__) + - [`.__init__(..)`](#object__init__) + - [`.__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-2) + - [`.mode`](#mixinmode) + - [`.mixout(..)`](#mixinmixout) + - [`.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(, , ) ``` ``` -callback() +callback(, ) -> STOP -> STOP() -> undefined @@ -619,7 +619,7 @@ values(, , ) ``` ``` -callback(, ) +callback(, , ) -> STOP -> undefined -> diff --git a/object.js b/object.js index d3edc2d..e972000 100755 --- a/object.js +++ b/object.js @@ -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 ? diff --git a/package.json b/package.json index f9049ea..87e6ca5 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "5.4.15", + "version": "5.4.16", "description": "", "main": "object.js", "scripts": {