Skip to content

JScript to SpiderMonkey migration guide

TheQwertiest edited this page Nov 19, 2018 · 5 revisions

It is rather simple to migrate your script from foo_jscript_panel to foo_spider_monkey_panel: you only need to perform all the steps listed below.
Most of these can be automated by using Find & Replace command in your favourite text editor.

Replace old headers:

Before

// ==PREPROCESSOR==
// @name "MyScript"
// @author "Me"
// @version "1.2.3"
// @import "%fb2k_path%\path\to\script1.js"
// @import "%fb2k_path%\path\to\script2.js"
// @feature "dragdrop"
// ==/PREPROCESSOR==
After

window.DefinePanel('MyScript', {author: 'Me', version: '1.2.3', features: {drag_n_drop: true} });
include(fb.FoobarPath + 'path\\to\\script1.js');
include(fb.FoobarPath + 'path\\to\\script2.js');

Remove .toArray() and .Dispose() methods:

Before

var artists = tfo.EvalWithMetadbs(handle_list).toArray();
var artist = artists[0];
After

var artists = tfo.EvalWithMetadbs(handle_list);
var artist = artists[0];

Replace FbMetadbHandleList.Item(i) calls with FbMetadbHandleList[i]:

Before

var items = plman.GetPlaylistItems(plman.ActivePlaylist);
var item = items.Item(0);
After

var items = plman.GetPlaylistItems(plman.ActivePlaylist);
var item = items[0];

Replace plman.PlaylistRecyclerManager with plman.PlaylistRecycler; replace calls to it's properties: Name>GetName, Content>GetContent:

Before

var playlist_name = plman.PlaylistRecyclerManager.Name(i);
var playlist_content = plman.PlaylistRecyclerManager.Content(i);
After

var playlist_name = plman.PlaylistRecycler.GetName(i);
var playlist_content = plman.PlaylistRecycler.GetContent(i);

Add window.ID argument to fb.DoDragDrop:

Before

fb.DoDragDrop(cur_playlist_selection, g_drop_effect.copy);
After

fb.DoDragDrop(window.ID, cur_playlist_selection, g_drop_effect.copy);

If there are errors about unknown methods or properties, make sure that corresponding methods and properties have the valid case:

Before

Console.Log('Log message');
var items = plman.getPlaylistItems(plman.activePlaylist);
After

console.log('Log message');
var items = plman.GetPlaylistItems(plman.ActivePlaylist);

Some methods have more rigorous error checks, so you'll have to pass the valid arguments:

Before

menu.CheckMenuRadioItem(StartIndex, StartIndex, StartIndex + (checked ? 0 : 1)); ///< out of bounds error
After

if (checked) {
    menu.CheckMenuRadioItem(StartIndex, StartIndex, StartIndex);
}
You can’t perform that action at this time.