{"id":25999531,"url":"https://github.com/thomasbusch/perl-javascript-spidermonkey","last_synced_at":"2025-03-05T18:29:07.824Z","repository":{"id":56838530,"uuid":"143192879","full_name":"thomasbusch/perl-javascript-spidermonkey","owner":"thomasbusch","description":"Perl interface to the SpiderMonkey JavaScript Engine","archived":false,"fork":false,"pushed_at":"2018-08-07T09:40:36.000Z","size":123,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-19T02:07:08.577Z","etag":null,"topics":["javascript","perl","spidermonkey"],"latest_commit_sha":null,"homepage":"","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thomasbusch.png","metadata":{"files":{"readme":"README","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-01T18:23:07.000Z","updated_at":"2023-09-08T17:43:23.000Z","dependencies_parsed_at":"2022-09-12T10:20:13.484Z","dependency_job_id":null,"html_url":"https://github.com/thomasbusch/perl-javascript-spidermonkey","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasbusch%2Fperl-javascript-spidermonkey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasbusch%2Fperl-javascript-spidermonkey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasbusch%2Fperl-javascript-spidermonkey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thomasbusch%2Fperl-javascript-spidermonkey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thomasbusch","download_url":"https://codeload.github.com/thomasbusch/perl-javascript-spidermonkey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242078760,"owners_count":20068600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","perl","spidermonkey"],"created_at":"2025-03-05T18:29:06.508Z","updated_at":"2025-03-05T18:29:07.791Z","avatar_url":"https://github.com/thomasbusch.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"######################################################################\n    JavaScript::SpiderMonkey\n######################################################################\n\nNAME\n    JavaScript::SpiderMonkey - Perl interface to the JavaScript Engine\n\nSYNOPSIS\n        use JavaScript::SpiderMonkey;\n\n        my $js = JavaScript::SpiderMonkey-\u003enew();\n\n        $js-\u003einit();  # Initialize Runtime/Context\n\n                      # Define a perl callback for a new JavaScript function\n        $js-\u003efunction_set(\"print_to_perl\", sub { print \"@_\\n\"; });\n\n                      # Create a new (nested) object and a property\n        $js-\u003eproperty_by_path(\"document.location.href\");\n\n                      # Execute some code\n        my $rc = $js-\u003eeval(q!\n            document.location.href = append(\"http://\", \"www.aol.com\");\n\n            print_to_perl(\"URL is \", document.location.href);\n\n            function append(first, second) {\n                 return first + second;\n            }\n        !);\n\n            # Get the value of a property set in JS\n        my $url = $js-\u003eproperty_get(\"document.location.href\");\n\n        $js-\u003edestroy();\n\nINSTALL\n    JavaScript::SpiderMonkey requires Mozilla's readily compiled\n    SpiderMonkey 1.6 distribution or better. Please check \"SpiderMonkey\n    Installation\".\n\nDESCRIPTION\n    JavaScript::SpiderMonkey is a Perl Interface to the SpiderMonkey\n    JavaScript Engine. It is different from Claes Jacobsson's\n    \"JavaScript.pm\" in that it offers two different levels of access:\n\n    [1] A 1:1 mapping of the SpiderMonkey API to Perl\n\n    [2] A more Perl-like API\n\n    This document describes [2], for [1], please check \"SpiderMonkey.xs\".\n\n  new()\n    \"$js = JavaScript::SpiderMonkey-\u003enew()\" creates a new object to work\n    with. To initialize the JS runtime, call \"$js-\u003einit()\" afterwards.\n\n  $js-\u003edestroy()\n    \"$js-\u003edestroy()\" destroys the current runtime and frees up all memory.\n\n  $js-\u003einit()\n    \"$js-\u003einit()\" initializes the SpiderMonkey engine by creating a context,\n    default classes and objects and adding an error reporter.\n\n  $js-\u003earray_by_path($name)\n    Creates an object of type *Array* in the JS runtime:\n\n        $js-\u003earray_by_path(\"document.form\");\n\n    will first create an object with the name \"document\" (unless it exists\n    already) and then define a property named \"form\" to it, which is an\n    object of type *Array*. Therefore, in the JS code, you're going to be\n    able define things like\n\n        document.form[0] = \"value\";\n\n  $js-\u003efunction_set($name, $funcref, [$obj])\n    Binds a Perl function provided as a coderef ($funcref) to a newly\n    created JS function named $name in JS land. It's a real function\n    (therefore bound to the global object) if $obj is omitted. However, if\n    $obj is ref to a JS object (retrieved via \"$js-\u003eobject_by_path($path)\"\n    or the like), the function will be a *method* of the specified object.\n\n        $js-\u003efunction_set(\"write\", sub { print @_ });\n            # write(\"hello\"); // In JS land\n\n        $obj = $j-\u003eobject_by_path(\"navigator\");\n        $js-\u003efunction_set(\"write\", sub { print @_ }, $obj);\n            # navigator.write(\"hello\"); // In JS land\n\n  $js-\u003earray_set_element($obj, $idx, $val)\n    Sets the element of the array $obj at index position $idx to the value\n    $val. $obj is a reference to an object of type array (retrieved via\n    \"$js-\u003eobject_by_path($path)\" or the like).\n\n  $js-\u003earray_set_element_as_object($obj, $idx, $elobj)\n    Sets the element of the array $obj at index position $idx to the object\n    $elobj (both $obj and $elobj have been retrieved via\n    \"$js-\u003eobject_by_path($path)\" or the like).\n\n  $js-\u003earray_get_element($obj, $idx)\n    Gets the value of of the element at index $idx of the object of type\n    Array $obj.\n\n  $js-\u003eproperty_by_path($path, $value, [$getter], [$setter])\n    Sets the specified property of an object in $path to the value $value.\n    $path is the full name of the property, including the object(s) in JS\n    land it belongs to:\n\n        $js-E\u003cgt\u003eproperty_by_path(\"document.location.href\", \"abc\");\n\n    This first creates the object \"document\" (if it doesn't exist already),\n    then the object \"document.location\", then attaches the property \"href\"\n    to it and sets it to \"abc\".\n\n    $getter and $setter are coderefs that will be called by the JavaScript\n    engine when the respective property's value is requested or set:\n\n        sub getter {\n            my($property_path, $value) = @_;\n            print \"$property_path has value $value\\n\";\n        }\n\n        sub setter {\n            my($property_path, $value) = @_;\n            print \"$property_path set to value $value\\n\";\n        }\n\n        $js-E\u003cgt\u003eproperty_by_path(\"document.location.href\", \"abc\",\n                                  \\\u0026getter, \\\u0026setter);\n\n    If you leave out $getter and $setter, there's going to be no callbacks\n    triggerd while the properity is set or queried. If you just want to\n    specify a $setter, but no $getter, set the $getter to \"undef\".\n\n  $js-\u003eobject_by_path($path, [$newobj])\n    Get a pointer to an object with the path specified. Create it if it's\n    not there yet. If $newobj is provided, the ref is used to bind the\n    existing object to the name in $path.\n\n  $js-\u003eproperty_get($path)\n    Fetch the property specified by the $path.\n\n        my $val = $js-\u003eproperty_get(\"document.location.href\");\n\n  $js-\u003eeval($code)\n    Runs the specified piece of \u003c$code\u003e in the JS engine. Afterwards,\n    property values of objects previously defined will be available via\n    \"$j-\u003eproperty_get($path)\" and the like.\n\n        my $rc = $js-\u003eeval(\"write('hello');\");\n\n    The method returns 1 on success or else if there was an error in JS\n    land. In case of an error, the JS error text will be available in $@.\n\nSpiderMonkey Installation\n    First, get the latest SpiderMonkey distribution from mozilla.org:\n    http://ftp.mozilla.org/pub/spidermonkey/releases/ shows which releases are\n    available. \"js-1.60.tar.gz\" has been proven to work.\n\n    Untar it at the same directory level as you just untarred the\n    \"JavaScript::SpiderMonkey\" distribution you're currently reading. So, if\n    you're currently in \"/my/path/JavaScript-SpiderMonkey-v.vv\", do this:\n\n        cp js-1.60.tar.gz /my/path\n        cd /my/path\n        tar zxfv js-1.60.tar.gz\n\n    Then, compile the SpiderMonkey distribution, if you're on Linux, just\n    use:\n\n        cd js/src\n        make -f Makefile.ref\n\n    It's important that the js and JavaScript-SpiderMonkey-v.vv directories\n    are at the same level:\n\n        [/my/path]$ ls\n        JavaScript-SpiderMonkey-v.vv\n        js\n        js-1.60.tar.gz\n        [/my/path]$\n\n    (Note that you *can* untar the SpiderMonkey distribution elsewhere, but,\n    if so, then you need to edit the setting of $JSLIBPATH in Makefile.PL).\n\n    Next, you need to copy the shared library file thus constructed (e.g.,\n    libjs.so or js32.dll) to an appropriate directory on your library path.\n    On Windows, this can also be the directory where the perl executable\n    lives. On Unix, this has been shown to work without copying, but this\n    way you need to keep the compiled binary in the \"js\" build directory\n    forever. Copying \"js/src/Your_OS_DBG.OBJ/libjs.so\" to \"/usr/local/lib\"\n    and making sure that \"/usr/local/lib\" is in your \"LD_LIBRARY_PATH\" seems\n    to be safest bet.\n\n    Now, build JavaScript::SpiderMonkey in the standard way:\n\n        cd JavaScript-SpiderMonkey-v.vv\n        perl Makefile.PL\n        make\n        make test\n        make install\n\nAUTHORS \n    Mike Schilli\n    Thomas Busch\n\nCOPYRIGHT AND LICENSE\n    Copyright (c) 2002-2005 Mike Schilli\n    Copyright (c) 2006-2018 Thomas Busch\n\n    This library is free software; you can redistribute it and/or modify it\n    under the same terms as Perl itself.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasbusch%2Fperl-javascript-spidermonkey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomasbusch%2Fperl-javascript-spidermonkey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomasbusch%2Fperl-javascript-spidermonkey/lists"}