From b9da833bb5598afb2092a1a15d97b04042137a39 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Wed, 3 Jun 2026 17:14:08 -0700 Subject: [PATCH] better callAccessor + optimize "__allowGetSet" --- hscript/CustomClass.hx | 4 ++-- hscript/CustomClassHandler.hx | 4 ++-- hscript/Property.hx | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hscript/CustomClass.hx b/hscript/CustomClass.hx index e629551..d06b4b4 100644 --- a/hscript/CustomClass.hx +++ b/hscript/CustomClass.hx @@ -177,7 +177,7 @@ class CustomClass implements IHScriptCustomClassBehaviour { prop.__allowSetGet = this.__allowSetGet; prop.__callingProperty = true; var r = prop.callGetter(); - prop.__allowSetGet = null; + prop.__allowSetGet = true; return r; } return f; @@ -190,7 +190,7 @@ class CustomClass implements IHScriptCustomClassBehaviour { prop.__allowSetGet = this.__allowSetGet; prop.__callingProperty = true; var r = prop.callSetter(val); - prop.__allowSetGet = null; + prop.__allowSetGet = true; return r; } __interp.variables.set(name, val); diff --git a/hscript/CustomClassHandler.hx b/hscript/CustomClassHandler.hx index 4bb2191..fa1fdbb 100644 --- a/hscript/CustomClassHandler.hx +++ b/hscript/CustomClassHandler.hx @@ -99,7 +99,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip prop.__allowSetGet = this.__allowSetGet; prop.__callingProperty = true; var r = prop.callGetter(); - prop.__allowSetGet = null; + prop.__allowSetGet = true; return r; } return f; @@ -112,7 +112,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip prop.__allowSetGet = this.__allowSetGet; prop.__callingProperty = true; var r = prop.callSetter(val); - prop.__allowSetGet = null; + prop.__allowSetGet = true; return r; } __interp.variables.set(name, val); diff --git a/hscript/Property.hx b/hscript/Property.hx index cead3d1..3a7ae0c 100644 --- a/hscript/Property.hx +++ b/hscript/Property.hx @@ -87,8 +87,7 @@ class Property { var __allowReadAccess:Bool = false; var __allowWriteAccess:Bool = false; // Internal flag to gain access if the field is accessed with @:bypassAccessor - // TODO: check if it's necessary to use a nullable Bool - var __allowSetGet:Null = null; + var __allowSetGet:Bool = true; /** * Internal Flag to check if the get/set function hasn't been called directly. @@ -104,7 +103,7 @@ class Property { var fName:String = getterFunc; if(!__callingProperty) __allowReadAccess = true; - if (!__allowReadAccess && (__allowSetGet != null && __allowSetGet || !interp.isBypassAccessor)) { + if (!__allowReadAccess && (__allowSetGet || !interp.isBypassAccessor)) { if (varExists(fName)) { return callAccessor(fName); } else @@ -132,9 +131,9 @@ class Property { var fName:String = setterFunc; if(!__callingProperty) __allowWriteAccess = true; - if (!__allowWriteAccess && (__allowSetGet != null && __allowSetGet || !interp.isBypassAccessor)) { + if (!__allowWriteAccess && (__allowSetGet || !interp.isBypassAccessor)) { if (varExists(fName)) - return callAccessor(fName, [val], true); + return callAccessor(fName, val); else interp.error(ECustom('Method $fName required by property $name is missing')); } else { @@ -154,14 +153,15 @@ class Property { return r = val; } - private function callAccessor(f:String, ?args:Array, isWrite:Bool = false):Dynamic { + private function callAccessor(f:String, ?value:Dynamic):Dynamic { var fn = isStatic ? interp.staticVariables.get(f) : interp.variables.get(f); var rt:Dynamic = null; + var isWrite:Bool = value != null; if (fn != null && Reflect.isFunction(fn)) { if (isWrite) __allowWriteAccess = true; else __allowReadAccess = true; - rt = UnsafeReflect.callMethodUnsafe(null, fn, args == null ? [] : args); + rt = UnsafeReflect.callMethodUnsafe(null, fn, isWrite ? [value] : []); if (isWrite) __allowWriteAccess = false; else __allowReadAccess = false; @@ -176,7 +176,7 @@ class Property { return rt; } - private function varExists(n:String) { + private inline function varExists(n:String) { return isStatic ? interp.staticVariables.exists(n) : interp.variables.exists(n); } }