better accessor bypass handling
This commit is contained in:
@@ -13,7 +13,6 @@ using Lambda;
|
||||
* @author Jamextreme140
|
||||
*/
|
||||
@:access(hscript.CustomClassHandler)
|
||||
@:access(hscript.Property)
|
||||
class CustomClass implements IHScriptCustomClassBehaviour {
|
||||
public var className(get, never):String;
|
||||
|
||||
@@ -174,10 +173,10 @@ class CustomClass implements IHScriptCustomClassBehaviour {
|
||||
var f = __interp.variables.get(name);
|
||||
if (f != null && allowProperty && f is Property) {
|
||||
var prop:Property = cast f;
|
||||
prop.__allowSetGet = this.__allowSetGet;
|
||||
//prop.__allowSetGet = this.__allowSetGet;
|
||||
prop.__callingProperty = true;
|
||||
var r = prop.callGetter();
|
||||
prop.__allowSetGet = true;
|
||||
var r = prop.get(!__allowSetGet);
|
||||
//prop.__allowSetGet = true;
|
||||
return r;
|
||||
}
|
||||
return f;
|
||||
@@ -187,10 +186,10 @@ class CustomClass implements IHScriptCustomClassBehaviour {
|
||||
var f = getField(name, false);
|
||||
if (f != null && f is Property) {
|
||||
var prop:Property = cast f;
|
||||
prop.__allowSetGet = this.__allowSetGet;
|
||||
//prop.__allowSetGet = this.__allowSetGet;
|
||||
prop.__callingProperty = true;
|
||||
var r = prop.callSetter(val);
|
||||
prop.__allowSetGet = true;
|
||||
var r = prop.set(val, !__allowSetGet);
|
||||
//prop.__allowSetGet = true;
|
||||
return r;
|
||||
}
|
||||
__interp.variables.set(name, val);
|
||||
|
||||
+16
-11
@@ -136,11 +136,16 @@ class Interp {
|
||||
|
||||
public var errorHandler:Error->Void;
|
||||
public var warnHandler:Error->Void;
|
||||
// TODO: set this callback as a Global Resolver
|
||||
/**
|
||||
* Custom Import resolver. It's called when an import couldn't be resolved.
|
||||
*/
|
||||
public var importFailedCallback:Array<String>->Null<String>->Bool;
|
||||
|
||||
public var customClasses:Map<String, CustomClassHandler>;
|
||||
public var variables:Map<String, Dynamic>;
|
||||
public var publicVariables:Map<String, Dynamic>;
|
||||
// TODO: maybe turn this completely static
|
||||
public var staticVariables:Map<String, Dynamic>;
|
||||
|
||||
// warning can be null
|
||||
@@ -297,7 +302,7 @@ class Interp {
|
||||
if (obj != null && obj is Property) {
|
||||
var prop:Property = cast obj;
|
||||
prop.__callingProperty = true;
|
||||
return prop.callSetter(v);
|
||||
return prop.set(v, isBypassAccessor);
|
||||
}
|
||||
varLocationCache.remove(id);
|
||||
setVar(id, v);
|
||||
@@ -305,7 +310,7 @@ class Interp {
|
||||
} else if (l.r is Property) {
|
||||
var prop:Property = cast l.r;
|
||||
prop.__callingProperty = true;
|
||||
return prop.callSetter(v);
|
||||
return prop.set(v, isBypassAccessor);
|
||||
} else {
|
||||
l.r = v;
|
||||
if (l.depth == 0) {
|
||||
@@ -380,7 +385,7 @@ class Interp {
|
||||
if (obj != null && obj is Property) {
|
||||
var prop:Property = cast obj;
|
||||
prop.__callingProperty = true;
|
||||
return prop.callSetter(v);
|
||||
return prop.set(v, isBypassAccessor);
|
||||
}
|
||||
varLocationCache.remove(id);
|
||||
setVar(id, v);
|
||||
@@ -391,7 +396,7 @@ class Interp {
|
||||
if (l.r is Property) {
|
||||
var prop:Property = cast l.r;
|
||||
prop.__callingProperty = true;
|
||||
return prop.callSetter(v);
|
||||
return prop.set(v, isBypassAccessor);
|
||||
}
|
||||
l.r = v;
|
||||
if (l.depth == 0) {
|
||||
@@ -436,18 +441,18 @@ class Interp {
|
||||
if (v is Property) {
|
||||
prop = cast v;
|
||||
prop.__callingProperty = true;
|
||||
v = prop.callGetter();
|
||||
v = prop.get(isBypassAccessor);
|
||||
}
|
||||
|
||||
if (prefix) {
|
||||
v += delta;
|
||||
if (prop != null)
|
||||
prop.callSetter(v);
|
||||
prop.set(v, isBypassAccessor);
|
||||
else
|
||||
l.r = v;
|
||||
} else {
|
||||
if (prop != null)
|
||||
prop.callSetter(v + delta);
|
||||
prop.set(v + delta, isBypassAccessor);
|
||||
else
|
||||
l.r = v + delta;
|
||||
}
|
||||
@@ -459,20 +464,20 @@ class Interp {
|
||||
if (v is Property) {
|
||||
prop = cast v;
|
||||
prop.__callingProperty = true;
|
||||
v = prop.callGetter();
|
||||
v = prop.get(isBypassAccessor);
|
||||
}
|
||||
|
||||
if (prefix) {
|
||||
v += delta;
|
||||
if (prop != null)
|
||||
prop.callSetter(v);
|
||||
prop.set(v, isBypassAccessor);
|
||||
else {
|
||||
varLocationCache.remove(id);
|
||||
setVar(id, v);
|
||||
}
|
||||
} else {
|
||||
if (prop != null)
|
||||
prop.callSetter(v + delta);
|
||||
prop.set(v + delta, isBypassAccessor);
|
||||
else {
|
||||
varLocationCache.remove(id);
|
||||
setVar(id, v + delta);
|
||||
@@ -615,7 +620,7 @@ class Interp {
|
||||
if(allowProperty && o != null && o is Property) {
|
||||
var prop:Property = cast o;
|
||||
prop.__callingProperty = true;
|
||||
return cast(o, Property).callGetter();
|
||||
return prop.get(isBypassAccessor);
|
||||
}
|
||||
else
|
||||
return o;
|
||||
|
||||
+19
-4
@@ -93,17 +93,32 @@ class Property {
|
||||
* Internal Flag to check if the get/set function hasn't been called directly.
|
||||
*/
|
||||
@:allow(hscript.Interp)
|
||||
@:allow(hscript.CustomClass)
|
||||
var __callingProperty:Bool = false;
|
||||
|
||||
final __isStatic:Bool = false;
|
||||
|
||||
public function callGetter():Dynamic {
|
||||
public function get(isBypassAccessor:Bool) {
|
||||
if(isBypassAccessor) __allowSetGet = false;
|
||||
var r:Dynamic = callGetter();
|
||||
if(isBypassAccessor) __allowSetGet = true;
|
||||
return r;
|
||||
}
|
||||
|
||||
public function set(value:Dynamic, isBypassAccessor:Bool) {
|
||||
if(isBypassAccessor) __allowSetGet = false;
|
||||
var r:Dynamic = callSetter(value);
|
||||
if(isBypassAccessor) __allowSetGet = true;
|
||||
return r;
|
||||
}
|
||||
|
||||
private function callGetter():Dynamic {
|
||||
switch (getter) {
|
||||
case AGet | ADynamic:
|
||||
var fName:String = getterFunc;
|
||||
if(!__callingProperty)
|
||||
__allowReadAccess = true;
|
||||
if (!__allowReadAccess && (__allowSetGet || !interp.isBypassAccessor)) {
|
||||
if (!__allowReadAccess && __allowSetGet) {
|
||||
if (varExists(fName)) {
|
||||
return callAccessor(fName);
|
||||
} else
|
||||
@@ -125,13 +140,13 @@ class Property {
|
||||
return r;
|
||||
}
|
||||
|
||||
public function callSetter(val:Dynamic):Dynamic {
|
||||
private function callSetter(val:Dynamic):Dynamic {
|
||||
switch (setter) {
|
||||
case ASet | ADynamic:
|
||||
var fName:String = setterFunc;
|
||||
if(!__callingProperty)
|
||||
__allowWriteAccess = true;
|
||||
if (!__allowWriteAccess && (__allowSetGet || !interp.isBypassAccessor)) {
|
||||
if (!__allowWriteAccess && __allowSetGet) {
|
||||
if (varExists(fName))
|
||||
return callAccessor(fName, val);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user