Search code examples
javascriptfunctionembednamingspidermonkey

Test for functions names in javascript script (SpiderMonkey engine)


I am embeding SpiderMonkey (mozila javascript) interpreter/engine in my C/C++ application. i programatically loading a javascript script and want to test (from my C/C++ code) if a certain function exist/defined in this script.

is there a way to do that ? maybe a way to list all functions in a given script ?

Tnx, Vertilka


Solution

  • As far as I know, this, by default, refers to the global scope. So you can:

    (function() {
        var globals = this;
        for (var i in globals) {
            if (typeof globals[i] == 'function') {
                // a function named i is defined.
            }
        }
    })();