Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: JScript Panel (Read 285519 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: JScript Panel

Reply #175
@vince_57

The jscript/interface api files exist only to provide auto-complete functionality when typing in the configuration window. You should ignore them.



As for javascript language support, yes we are stuck several generations behind what current javascript developers are working with. We are stuck with JScript 5.8/Javascript 1.5. This is basically IE8 levels of support. While the JScript9 option in the configuration window can provide slightly faster performance, there are no language improvements or changes.

While we don't have functions like alert or console.log, we do have alternatives. We can output message to the foobar2000 Console using fb.trace(message);. If you really wanted to, you can use this little snippet to have console.log available...

Code: [Select]
var console = {
log: function (msg) {
fb.trace(msg);
}
};

console.log("Hello world!");
console.log(2 * 5);

You can display popup windows using this bit of code...

Code: [Select]
fb.ShowPopupMessage("hello");
//code here will execute immediately even with the popup window still open

If you want the behaviour to more like alert, you can do this:

Code: [Select]
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.popup("hello", 0); //0 is the code for displaying just an OK button
//code here won't execute until the window is dismissed.

There is no problem with making web requests and working with JSON. I do this a fair bit myself such as using the musicbrainz API like this...

http://i.imgur.com/pu2wL2W.png

Of course when it comes to displaying text in the panel itself, this is only possible using the gdiDrawText or DrawString functions which are C++ but we can pass text, fonts, colours, etc via our script.

Do you plan to bring that function back?

No.

Re: JScript Panel

Reply #176
We are stuck with JScript 5.8/Javascript 1.5. This is basically IE8 levels of support.
I think, I might be able to add full JScript9 support to JScriptPanel by wrapping all the JSRT API calls into WSH style calls. This will come at the cost of losing support of Windows versions below Windows 7 though. But we will have much more up-to-date JScript =)

Re: JScript Panel

Reply #177
hi, how to access installation path for import? so far, I only notice %fb2k_profile_path% and also %fb2k_component_path%.


Re: JScript Panel

Reply #179
docs\preprocessors.txt

Using %fb2k_path% really isn't advisable though. %fb2k_profile_path% already points at the program folder when using foobar2000 in portable mode and you shouldn't be placing user files inside program files\foobar2000 if using standard mode.

Re: JScript Panel

Reply #180
@marc2003: there is actually a simpler way to enable JScript9 (though probably only features from old Chakra engine(i.e. ECMA5 and not ECMA6) are available):

When using cls id for JScript9 you also must change JS language version to a higher value (it might not available on windows lower than Windows 7)

foo_jscript_panel\host.cpp:
ScriptHost::InitScriptEngineByName
Line 892: scriptLangVersion.lVal = SCRIPTLANGUAGEVERSION_5_8;

SCRIPTLANGUAGEVERSION_5_8 (which is 2) should be replaced by 3

Tested with Date.now() and String.prototype.trim() methods, that are not available in the ECMA3 and consequently in the current JScriptPanel build.

Getting ECMA6 will be much harder, because it requires to either rebase whole JScriptPanel on JSRT or make a WSH wrapper around JSRT (which will be slower than the former). Both are feasible, but since ECMA6 (i.e. new Chakra engine) is available only on Windows 10, I don't think I'll bother with it for now, because my main PC is Windows 7 =)

PS: I've not yet tested on Windows 7 though, but it should work, since old Chakra(ECMA5) is available via jscript9.dll, which is supplied with IE11, which is available on Win7. New Chakra engine (ECMA6) is Win10 exclusive, because the corresponding chakra.dll is supplied only with Edge.

Re: JScript Panel

Reply #181
Assuming that all works out, that's a really nice find. Thanks. I'll do some testing later/tomorrow.

I'm using windows 8.1 myself and have no interest in windows 10.

More Basic Question

Reply #182
@marc2003
Please don't do anything that would break JScript Panel on Windows7 (I use Win7Pro).
Since you didn't reply to my questions with "1)You are in way over your head & should stop asking questions"  :( , I have some more newbie questions.
1) Is it correct to think of JScript Panel as an SDK for foobar and Windows? That is, in addition to supporting javascript/jscript statements, JScript Panel has it's own APIs which allow me to interface to the foobar2000 SDK API's and the Windows SDK API's.
2)Thanks for clarification on the purpose of the .api files. Should I be using Interfaces.txt as my reference to all available JScript Panel APIs (similar to the Windows API Index at https://msdn.microsoft.com/en-us/library/ff818516(v=vs.85).aspx) ?
3)I did not really understand your discussion with TheQwertiest about JScript9, but it seems like the answer to the question "Where is the ECMA Script engine used by JScript panel?" is that the Script engine is built into JScript Panel & does not depend on any external engine (web browser). ?

The WScript.Shell "object" (?) is cool. I found some info at TechNet, and used WshShell.run to kick off another application from within JScript Panel!

Re: JScript Panel

Reply #183
@TheQwertiest, it works on Vista with IE9 so that's an added bonus. And no code changes are required if it's not supported. I tested Vista with IE7 and that works as expected without the extra goodies.

@vince_57, no I won't be breaking windows 7.

1) pretty much
2) yes, interfaces.txt and callbacks.txt are the most important files in the docs folder
3) until now, the underlying browser didn't really matter except the minimum requirement for working with the native JSON object was IE8. With the upcoming changes, IE9 or later will be required to use the newer ES5 features. like function.prototype.bind and array.prototype.map. I'll list more when I publish the updated component.

Re: JScript Panel

Reply #184
it works on Vista with IE9 so that's an added bonus. And no code changes are required if it's not supported. I tested Vista with IE7 and that works as expected without the extra goodies.
That's good to hear!
Does anyone still uses Win Vista nowadays? =)

Btw, changing JS version to 3 via SetProperty only makes sense, when ScriptEngine is set to JScript9, otherwise it won't do anything (i.e. it won't enable ES5).
So, I think moving SetProperty under if (wcscmp(engineName, L"JScript9") == 0) might be a good idea.

And if I may, a few suggestions to consider:
1. Removing fallback to JScript in InitScriptEngineByName and returning error instead. So the component users won't think that JScript9 is enabled, while it is actually not.
2. Adding additional comboboxes to ScriptEngine dialog: smth like JScript9 (ES3 + json) and JScript9 (ES5).
3. Adding IE version detection, so ScriptEngine dialog could show only available ScriptEngines (JScript9 (ES5) and JScript for IE >= 9, JScript9 (ES3 + json) and JScript for lower versions).

If you want, I can make a PR for those.

Re: JScript Panel

Reply #185
I've already made the changes. The combo box is gone and JScript9+ES5 will be default for everyone if it's available. This is probably going to be 99.99% of users.

I've renamed the function because it doesn't take an "engineName" parameter any more.

https://github.com/19379/foo-jscript-panel/blob/a39c3d56d23a93f80fccbfbebb97f9e309509234/foo_jscript_panel/host.cpp#L846

As I mentioned already, the fallback works fine on Vista with IE7 (JScript 5.7) even with your change.

edit: you will get full credit for this on the releases page and in the changelog.

Re: JScript Panel

Reply #186
I've already made the changes. The combo box is gone and JScript9+ES5 will be default for everyone if it's available. This is probably going to be 99.99% of users.

I've renamed the function because it doesn't take an "engineName" parameter any more.

https://github.com/19379/foo-jscript-panel/blob/a39c3d56d23a93f80fccbfbebb97f9e309509234/foo_jscript_panel/host.cpp#L846

As I mentioned already, the fallback works fine on Vista with IE7 (JScript 5.7) even with your change.
Great minds think alike 8)

edit: you will get full credit for this on the releases page and in the changelog.
Thanks! Glad to be of help =)


Re: JScript Panel

Reply #188
What I did was the complete opposite of what you said!!  :o
Yeah, I should stop replying before waking up completely... By the time I noticed the incongruity of my reply, it was too late to edit my post -_-""

Callbacks.txt Basic Questions

Reply #189
Spent most of the day reading about Windows User Interface, Messages , & Message Queues.
I used your fb.ShowPopupMessage in most of the various callbacks defined in callbacks.txt, like:
Code: [Select]
function on_mouse_lbtn_down()
{ fb.ShowPopupMessage ("Code invoked when mouse left button is pressed: See function on_mouse_lbtn_down");}

function on_volume_change()
{   fb.ShowPopupMessage("Code Invoked When Volume Changes: See function on_volume_change", "Volume Changed", 1);}
to test what I think was going on (When I did this for function on_paint() I locked up foobar with a never-ending display of popups  :o )
I have some "sanity" test questions I would appreciate help with:
Using the specific JScript Panel callback of  function on_mouse_lbtn_down(x, y, mask) {}:
1) Is this callback the JScript Panel equivalent of the Windows message WM_LBUTTONDOWN?
2) Are the x,y values the same as the "lparam" parameter after being processed by GET_X_LPARAM and GET_Y_LPARAM?
3) Is the mask value the same as the "wParam" parameter, and is that what is being defined in Flags.txt in the section "// Mask for mouse callbacks"
4) The Windows MSDN docs. describes a bunch of coding that a Windows program needs to do for WM_LBUTTONDOWN.
Is JScript Panel taking care of all this coding under the covers, and providing the (much) gentler/kinder "on_mouse_lbtn_down"?
Here is what MSDN says happens when the left mouse button is pressed:
    The operating system places a WM_LBUTTONDOWN message on the message queue.
    Your program calls the GetMessage function.
    GetMessage pulls the WM_LBUTTONDOWN message from the queue and fills in the MSG structure.
    Your program calls the TranslateMessage and DispatchMessage functions.
    Inside DispatchMessage, the operating system calls your window procedure.
    Your window procedure can either respond to the message or ignore it.

Assuming I understand, I have a greater appreciation  :) for what your code is doing to make these callbacks user friendly  (I don't need to write code for a message queue, no code for translate/dispatch message, no code to separate out the x,y values, etc.)

Re: JScript Panel

Reply #190
Code: [Select]
v1.2.0 Beta 1
ADD: If your computer has IE9 or later installed, newer ECMAScript5 features
     are now available. Many thanks to TheQwertiest for discovering how to do this.
CHG: The "JScript engine" option has been removed from the "Configuration" window.
     JScript9 is always used if available but will fall back if not.
ADD: utils.version reports the component version. See docs\interfaces.txt.
FIX: A previous window.RepaintRect bug with JScript9 reported by Wilb has now been fixed.

https://github.com/19379/foo-jscript-panel/releases

Forcing JScript9 may reveal previously unknown bugs - that's why this is a beta! Please report any problems.


Re: JScript Panel

Reply #192
Forcing JScript9 may reveal previously unknown bugs - that's why this is a beta! Please report any problems.
With my scripts the only changes I've noticed are stricter rules on Java Script: some implicitly declared variables have their visibility scope reduced, which resulted in errors; calls to named IIFE started to work inconsistently, i.e. sometimes calling IIFE may result in Undefined function error. Both are considered bad practices though =)

I could not find any meaningful difference performance-wise with ES3 Jscript9, probably because Script Engine language version only limits available keywords.

PS: And it seems that, despite all the other ES5 features being implemented, Strict Mode (i.e. "use strict" ) is still not supported by the engine =(

Re: JScript Panel

Reply #193
For those you who have a string.prototype.trim "polyfill" in your own scripts, you may wish to check and use the native version if it's present...

Code: [Select]
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}

If you know you're using IE9 or later everywhere, you could remove it entirely.

Here's some of the other ES5 stuff available...

https://msdn.microsoft.com/library/ff974378.aspx#_ecmascript


Re: JScript Panel

Reply #195
Argh, that would be crazy Falstaff's coding style   :D

Code: [Select]
if (something) {

}; else { // <--this semi-colon is the problem

}

Thanks for spotting. I guess testing all included scripts would have been a wise idea.

Re: JScript Panel

Reply #196
Argh, that would be crazy Falstaff's coding style  :D

Code: [Select]
if (something) {

}; else { // <--this semi-colon is the problem

}

Thanks for spotting. I guess testing all included scripts would have been a wise idea.

And

Code: [Select]
  try {
                 }; catch(e) {          
                };

Re: JScript Panel

Reply #197
All fixed. Changes will be uploaded soon.

 

Re: JScript Panel

Reply #198
@marc2003 From your suggestion I realized the bug occurs only during playing, so I tracked every settings related to playing.
Through dozens of test sessions I tried to find the exact triggers to the bug.

1. Install foobar2000 and jscript panel plugin. (Columns UI not required)
2. Leave a jscript panel and delete everything else.
3. Configure the panel
font = gdi.Font("Segoe UI", 12);
function on_paint(gr){
   gr.GdiDrawText("井美空  -  TVアニメ「キルラキル」ED", font, 0, 0, 0, window.Width, window.Height, 0);
}
4. Rename the foobar2000 window title by setting the title format or forcing with an external tool: 沢
5. Repeatedly minimze and restore the foobar2000 window.

The original window title from the Eole skin was:
沢井美空  -  TVアニメ「キルラキル」EDテーマ -「ごめんね、いいコじゃいられない。」  -  01 : ごめんね、いいコじゃいられない。  -  2013
If the above steps don't work, use this for the GDI text and the window title. It's more likely for Windows 10 to freeze. Also the font size should be 11 or 12. FYI, I used Windows 10 Enterprise x64 build 14393.576 Korean.

A workaround for now is just to fix the foobar2000 window title. I set the title format just "foobar2000"

Re: JScript Panel

Reply #199
Well like I said, I don't have windows 10 so can't investigate myself. At least you have a workaround.

@zeremy I've updated the component on github with a fixed jsplaylist. The version hasn't been bumped because there are no component changes.

I checked and Falstaff/Br3tt's JS Smooth scripts on deviantart have the same issue. Users of those should avoid this component for now.