UNPKG

@powerlang/egg-js

Version:

A Smalltalk VM that runs on top of JavaScript

127 lines (104 loc) 2.17 kB
import SExpression from './SExpression.js'; let SCascadeMessage = class extends SExpression { constructor() { super(); this._selector = nil; this.__arguments = nil; this._cascade = nil; this._cache = nil; } static decodeUsing_(aTreecodeDecoder) { return aTreecodeDecoder.decodeCascadeMessage(); } acceptVisitor_(visitor) { return visitor.visitCascadeMessage_(this); } argumentCount() { return this.__arguments.size(); } arguments() { return this.__arguments; } arguments_(aCollection) { this.__arguments = aCollection; return this; } cache_when_(anSCompiledMethod, type) { if (nil === this._cache) { return this._cache = Array.with_with_(type, anSCompiledMethod) } ; this._cache = this._cache._comma(Array.with_with_(type, anSCompiledMethod)); return this; } cacheUndermessage_(aBlockClosure) { this._cache = aBlockClosure; return this; } cachedUndermessage() { let _retval; _retval = nil; if (this._cache.isBlock()) { _retval = this._cache } ; return _retval; } cascade() { return this._cascade; } cascade_(anSCascade) { this._cascade = anSCascade; return this; } flushCache() { this._cache = nil; return this; } isCascadeMessage() { return true; } methodFor_(requiredType) { let type, _retval; const _home = {}; try { if (nil === this._cache) { return nil } ; (1).to_by_do_(this._cache.size(), 2, (i) => { type = this._cache.at_(i); _retval = nil; if (type._equalEqual(requiredType)) { throw [_home, this._cache.at_((i+1))] } ; return _retval }); return nil; } catch(e) { if (e[0] == _home) return e[1]; else throw(e); } } receiver() { return this._cascade.receiver(); } registerCacheWith_(runtime) { if (nil === this._cache) { runtime.registerCache_for_(this, this._selector) } ; return this; } selector() { return this._selector; } selector_(aSymbol) { this._selector = aSymbol; return this; } } export default SCascadeMessage