ExtendScript: 'Undefined is not an object' error everywhere? - object

So I just checked out some ExtendScript code I wrote a few weeks back to finish the After Effects script I was working on.
I tried to compile, and now I get these 'Undefined is not an object' errors at various points in my code.
I won't post the full script now. Don't think that'd help the situation. Just why are these errors happening at all anyway? I didn't have them when I wrote the script, and now that I open it back up they're there. I really don't get it.
Anyway, let's take a look at e.g. this part of my code:
var projectCompNames = new Array ();
var projectCompObjects = new Array ();
var scriptPath = ((new File($.fileName)).parent).toString();
var i;
// get a list of all compositions in the project and write them into an array
for (i = 1; i <= app.project.numItems; i++) {
if (app.project.item(i) instanceof CompItem) {
projectCompNames.push(app.project.item(i).name);
projectCompObjects.push(app.project.item(i));
}
}
So as the comment suggests, this gets all the compositions in the project and writes them into an array. Worked fine when I worked on the script, now it doesn't.
This part:
app.project.numItems
Apparently produces the error 'Undefined is not object.' because if I change the code to this:
for (i = 1; i <= 5; i++) {
if (app.project.item(i) instanceof CompItem) {
projectCompNames.push(app.project.item(i).name);
projectCompObjects.push(app.project.item(i));
}
}
The error is gone. In the first line. Same error in the second line. Then I can fix it by using some random integers for the if condition and the error continues to be there. In any line of my code. All over it. I'm quite desperate here. No idea where this is coming from. Is there something wrong with the compiler? Should I reinstall the ExtendScript Toolkit? I mean, this is really odd.
If anyone knows why this is happening, I'd much appreciate the help. If I don't figure this out, I'm going to have to start over again with the script. I can't possibly debug that error at like 50 different places in my code, especially because it's so random.
Edit: Because I started the ExtendScript Editor individually and not from AE I had to link the editor to AE myself. I just didn't do that. If you launch it from the AE UI it does that automatically.
This is what I'm talking about. It was the only reason the compiler was freaking out. Quite obvious when all After Effects specific variables and functions weren't loaded.

Related

Update Terminal Output Node.js

I've been working on some problems on projecteuler.net, and am programming functions and algorithms to solve these problems in mostly JavaScript (ran in the Node.js environment).
In many of these problems I am going through many thousand different numbers, and I would like to show (in the terminal output) which number it is currently on. I don't want it to just keep writing new lines, but just update the existing line... Is there a way to do this in JavaScript? Possibly with the help of any Node modules?
I know there is a way to clear the console, and so I could just have it clear it and then write the number again, but that would also clear the previous output that I still want to show...
Thanks in advance!
May be this suffices?
import readline from 'readline';
function clearLine() {
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 0);
}
let counter = 0;
setInterval(() => {
clearLine();
process.stdout.write(String(counter++));
}, 1000);

HWND handle being returned via FindWindowW differs from top-level parent

I'm trying to create a utility that will selectively hide and show windows based on pre-assigned hotkeys and I'm working with the Windows API code.
I use a FindWindowW call to get a handle to a window as a test (in my case, a window with the text "Calculator - Calculator", which matched an open calculator window) and use that handle in a ShowWindow function.
Code below:
var user32path = 'C:\\Windows\\System32\\user32.dll';
function TEXT(text){
return new Buffer(text, 'ucs2').toString('binary');
}
var user32 = new FFI.Library(user32path, {
'FindWindowW': ['int', ['string', 'string']],
'ShowWindow': ['int', ['int', 'int']],
'ShowWindowAsync': ['int', ['int', 'int']],
'FindWindowExW': ['int', ['int', 'int', 'string', 'string']],
'BringWindowToTop': ['int', ['int']],
'GetActiveWindow': ['int', ['int']]
var handle = user32.FindWindowW(null,TEXT("Calculator ‎- Calculator"));
user32.ShowWindow(
handle, 'SW_Hide');
//associatedWindowHandle is a manually-created variable with the Spy++ variable.
//The Spy++ doesn't match and I'm not sure why.
user32.ShowWindowAsync(activeHandle, 'SW_Hide');
var pruneLength = Object.keys(prunedData).length;
for (let i = 0; i < pruneLength-1; i++){
if (Object.entries(prunedData)[i][1] === hotkey){
for(let j = 1; j <= prunedData.assocWindows.length; j++){
let associatedWindow = Object.entries(prunedData)[i+1][j].toString();
let associatedWindowHandle = parseInt(associatedWindow);
user32.ShowWindowAsync(associatedWindowHandle, 'SW_Hide');
user32.BringWindowToTop(associatedWindowHandle[i+1][j]);
}
}
}
2 main issues:
When I try hiding and/or minimizing the open calculator window, I can't seem to show it again when clicking on it. the preview image disappers and I notice a "Process Broker" is thrown.
I can't seem to actually find the window handle given with tools like Spy++, which makes it somewhat hard to debug to see if I need to grab a different handle. The parent-level calculator window's handle doesn't seem to match, and I verified that it was the same tool.
I'd also like to be pointed to some decent resources to help self-educate on this so I can better troubleshoot this in the future.
Many thanks!
Firstly, I'd echo Hans Passant's remarks that you're probably better off not trying to so this with a UWP app like Calculator, but then again these apps are not going to go away so perhaps you might want to try anyway.
The shell doesn't appear to appreciate you trying to hide a UWP app (Win32 apps work fine though, go figure). As you have observed, it's icon remains visible in the toolbar but behaves strangely while the window is hidden. So, short version, don't do that.
Instead, try this:
PostMessage (hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
Then things work a lot better, although the user can still undo all your good work by reopening the window of course.
As for Spy++, I have no trouble locating the top-level window of a UWP app using the 'Finder tool' (Menu -> Search -> Find Window). You just have to walk a couple of levels up the window hierarchy afterwards until you get to the one you really want.
Spy++ seems not to be able to log messages being sent to such a window however, see (shameless plug): Why can't Spy++ see messages sent to UWP apps?. I plan to look into this a bit more when I have time.
Finally, what do you mean by 'a "Process Broker" is thrown' please? I don't understand that comment. There's something called RuntimeBroker, which shows up in Process Explorer and appears to be connected with UWP apps in some way, but I don't know if that's what you mean and and I don't know anything about it even if you did.

Limit Execution Time in Node

I am working on a node-based MUD game and I would like to limit the amount of time any one command can execute before it gets killed (e.g. 1000ms). I found a module called Tripwire which seems promising but it does not appear to be actively maintained. Tripwire does work as advertised. It manages to force an exception if someone creates an endless loop, but it does not support any resumption of the original script thread.
I am looking for either:
(1) A similar but actively maintained Node module that can interrupt and resume the original event thread, or,
(2) A working example of V8's Isolate::IsExecutionTerminating + Isolate::CancelTerminateExecution (I forked Tripwire but I haven't done any meaningful C++ in a long time and am now just beating my head against the wall).
I have only been able to find test cases so far (which is at least something). I am really hoping that someone has already tackled this, though.
Test cases:
https://chromium.googlesource.com/v8/v8/+/ad55afcb459dafda1cf48e676985717fd7eae786/test/cctest/test-thread-termination.cc
I know this is a bit vague.
I ended up instrumenting the script by passing it through acorn and generating my own final script. I am hoping that the sandbox is locked down to prevent users from escaping it. Example of "compiled" output:
createPermissions(expr) {
let __mec = __bfc(this || GameMaster, 'public', 'createPermissions', __FILE__, false); try { let parts = expr.split('/');
for (let i = 0; i < parts.length; i++) {
__ala(); let foo = parts.slice(0, i).join('/');
} } finally { __efc(__mec, 'createPermissions'); }
}
This new "language" supports public, protected, package, and private variables/methods (by maintaining its own internal call stack, execution context, etc). The directives are "reserved words" (e.g. __bfc=begin function call, __ala=assert loop alarm).
Thanks #jfriend00 for the suggestion.
For those who are curious: Transpiler Module

SVG fill animation cycle broken

i am looking to simply animate two fill colors of an SVG. ping pong, loop, however you want to call it. the pieces work on their own, but put together into a recursive function to form the loop breaks it.
here's what i have (using jQuery):
$(document).ready( function() {
var items = $('.st1');
items.css('fill', '#ff3600');
bl-colorCycle();
function bl-colorCycle() {
console.log('color cycle called');
items.animate({fill: '#00ffcc'}, 5000, 'linear', bl-colorCycle);
}
});
for some reason, this throws this error:
SyntaxError: missing ( before formal parameters
what the heck am i missing? i've torn this apart several times and for the life of me, i cannot spot where the hell the missing '(' is! i've read all that i can find here, and found nothing that helps in this scenario. i've even tried putting the function call at the very end, just to see if some weird web-voodoo was at play...bupkiss. :(
i'm hoping someone out there has sharper eyes... :P
TIA.
WR!
Hyphen ("-") is not a legal identifier character. Try underscore ("_") instead. Ie. bl_colorCycle().

Swift UIWebView Optional is nil

In the below example, infoScroller is a UIWebView and println(HTMLDescription) prints a lovely string of HTML. However, the attempt to loadHTMLString gets the runtime error: fatal error: Can't unwrap Optional.None
if let HTMLDescription = self.myData?.content? {
println(HTMLDescription)
infoScroller.loadHTMLString(HTMLDescription, baseURL: nil)
}
I've tried every combination of ! and ? in both the assignment and use of the string but I get this same error every time, though the variable never fails to print out perfectly to the console.
There is another value that I set using the same method and it works fine. Both are strings, but the other one is more simple in that HTMLDescription is multiline and the working one is not.
Edit: The discussion in the comments prompted me to check the infoScroller and it's description as printed in the console is: (#sil_weak UIWebView!) infoScroller =
I'm thinking that's the issue, but I'm not sure what it means or how to fix it.
Edit 2: This has to be the issue. println(infoScroller.description) yields the exact same error.
Got it! This question put me on the path. I was trying to load the content before the view was fully loaded. Moved loadHTMLString() into viewDidLoad(). Stupid simple.

Resources