- changed status to invalid
No longer possible to return nil object from Delphi side
Issue #34
invalid
After 508af9c it is no longer possible to return a nil object reference from Delphi side.
Test case
Script
var MyObject := SomeFunctionReturningAnObject; // Causes assertion failure
Delphi side
procedure TDataModuleBlah.dwsUnitBlahFunctionsSomeFunctionReturningAnObjectEval(Info: TProgramInfo; ExtObject: TObject);
begin
Info.ResultAsVariant := Unassigned; // Return a nil object reference to script
end;
The problem is with TProgramExpr.EvalAsScriptObj
:
// EvalAsScriptObj
//
procedure TProgramExpr.EvalAsScriptObj(exec : TdwsExecution; var Result : IScriptObj);
var
buf : Variant;
begin
EvalAsVariant(exec, buf);
Assert(VarType(buf)=varUnknown);
Result:=(IUnknown(TVarData(buf).VUnknown) as IScriptObj);
end;
The ASSERT should read:
Assert((VarType(buf)=varEmpty) or (VarType(buf)=varUnknown));
Comments (2)
-
repo owner -
reporter Got it. Thanks.
- Log in to comment
This was an error: Unassigned is distinct from a nil object (and both nil and Unassigned are distinct from Null)
To return a nil you should pass either an IUnknown(nil) or IScriptObj(nil)