listView columns.AutoSize() not working in eval() code

I'm stumped once again ^^
While working with a detached GUI in a JScript button, I can't seem to get a ListView's column's AutoSize to work.

var dlg = DOpus.Dlg();
dlg.template = "RenameGUI";
dlg.detach = true;

dlg.Show();

dlg.Control("fileList").AddItem("test");
log(dlg.Control("fileList").columns); // <- recognizes Control.columns as an object
dlg.Control("fileList").columns.InsertColumn("Toast", 1);
log("works so far");
dlg.Control("fileList").columns.AutoSize(); // <- throws 0x8000ffff

Throws

A method was called unexpectedly (0x8000ffff)

And I know I'm using .AutoSize() in another script.
What on earth is going on here? O.o

Edit:

This only seems to reproduce in an eval().
Because I'm using a wrapper function that allows me to write the actual script I want without having to manually set up everything (declare standard variables, set up checks, functions and extensions, etc), my scripts run through a custom command that evals the script source reading it from a file.

Here I've created a button script that illustrates the issue: Toggle asEval to trigger the error.

var tab;
function OnClick(data)
{
	tab = data.func.sourcetab;
	var asEval = false; // <- toggle to switch between eval and direct interpretation
	if(asEval){
		eval("var dlg = DOpus.Dlg();\
		dlg.window = tab;\
		dlg.template = 'RenameGUI';\
		dlg.detach = true;\
		\
		dlg.Show();\
		\
		dlg.Control('fileList').AddItem('test');\
		dlg.Control('fileList').columns.InsertColumn('Toast', 1);\
		DOpus.Output('works so far');\
		dlg.Control('fileList').columns.AutoSize();\
		while (true) {\
			var Msg = dlg.GetMsg();\
			if(Msg.result !== false){\
			}\
			else{\
				break;\
			}\
		}");
	}else{
	//////////////// VS //////////////////////
		var dlg = DOpus.Dlg();
		dlg.window = tab;
		dlg.template = 'RenameGUI';
		dlg.detach = true;
		
		dlg.Show();
		
		dlg.Control('fileList').AddItem('test');
		dlg.Control('fileList').columns.InsertColumn('Toast', 1);
		DOpus.Output('works so far');
		dlg.Control('fileList').columns.AutoSize();
		DOpus.Output('success');
		while (true) {
			var Msg = dlg.GetMsg();
			if(Msg.result !== false){
			}
			else{
				break;
			}
		}
	}
}

GUI:

<resources>
	<resource name="RenameGUI" type="dialog">
		<dialog fontsize="8" height="252" lang="" resize="yes" width="690">
			<control height="174" name="fileList" nosel="yes" resize="wh" type="listview" viewmode="details" width="678" x="6" y="54">
				<columns>
					<item text="Old Name" />
					<item text="New Name" />
				</columns>
			</control>
			<control close="1" default="yes" height="14" name="bOK" resize="xy" title="OK" type="button" width="50" x="636" y="234" />
		</dialog>
	</resource>
</resources>

I've done a bunch of scripting within eval()s, but this is the first time I've noticed something not working within one that would without.
What gives? O.o
It's especially strange since columns.InsertColumn works, and everything before it.

(Yes, I know, eval is evil, but until DOpus allows users to write and conveniently use function libraries and wrappers for button scripts, it's just too useful not to use)

I don't think using eval is a good idea at all here. It isn't going to run in the correct context.

Meaning?
Everything else works fine (all my other scripts do, too), and it looks like it's evaluated in place.
Sure, it's unsafe and messy and nobody should ever use eval and should burn at the stakes for doing so, that's a given.
But if InsertColumn() works, why doesn't AutoSize()?
If y'all don't want to check up on this, is there maybe a way for me to look at some intermediate language a script is compiled to?

Opus doesn't know you are using eval, and just handles requests that come from the Windows Scripting API. If using eval itself is breaking things then it must be running the JSCode, or sending the requests, in a context where it's either on a different thread or missing the objects/references of the original calling context. I don't know which, as I didn't implement JScript.

My advice is to not use eval, for lots of reasons in addition to this. Whatever usefulness it provides cannot be worth the extra complexity it causes. It's also going to make your scripts much slower.

(It's also possible the problem isn't eval but something else, of course. I'm assuming it's eval because of what you've said, but haven't verified that myself, as I'd already advise against using eval.)

There are ways to do libraries with Windows Scripting if you need that:

Not that I know of, unless Windows Scripting provides something for that.

Thank you for your feedback.
Yes, I've seen the WSC approach, but it looked very cumbersome, didn't seem like it enabled prototype extension, required scoping within an object and didn't provide ways to set up common variables.
That left me thinking, "if I need to copy/paste that much stuff for every new script I set up, I might as well not use it".
Also, the eval route allowed me to use my code editor of choice for button scripts directly.
But I'll give it a try now. It's a shame about the concessions I'll have to make :frowning:

The only way AutoSize() should throw that error is if it's being called as if it were a property and not a method. Maybe eval() is misinterpreting the syntax because there are no arguments and using the wrong calling convention (in which case this would be a bug in eval() that I don't think you could do anything about).