{"id":15605982,"url":"https://github.com/kares/dienashorner","last_synced_at":"2025-04-27T12:09:24.616Z","repository":{"id":65828194,"uuid":"53928797","full_name":"kares/dienashorner","owner":"kares","description":"Ein Next-Generation-JavaScript-Engine für die J(Ruby)VM","archived":false,"fork":false,"pushed_at":"2018-03-07T14:47:54.000Z","size":454,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T12:09:20.462Z","etag":null,"topics":["execjs","nashorn","rhino"],"latest_commit_sha":null,"homepage":"https://blogs.oracle.com/nashorn/","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kares.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-15T08:51:11.000Z","updated_at":"2022-08-16T15:13:00.000Z","dependencies_parsed_at":"2023-02-12T19:40:12.503Z","dependency_job_id":null,"html_url":"https://github.com/kares/dienashorner","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/kares%2Fdienashorner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kares%2Fdienashorner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kares%2Fdienashorner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kares%2Fdienashorner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kares","download_url":"https://codeload.github.com/kares/dienashorner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251134767,"owners_count":21541383,"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":["execjs","nashorn","rhino"],"created_at":"2024-10-03T04:20:32.419Z","updated_at":"2025-04-27T12:09:24.598Z","avatar_url":"https://github.com/kares.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dia nashorner\n\nEmbed the ~~Mozilla Rhino~~ [Nashorn][0] JavaScript interpreter into Ruby.\n\nNashorn JavaScript engine is part of [OpenJDK][4] (since 8u40), try `jjs -v`.\n\n\n### Requirements\n\nJava (Open/Oracle JRE) **\u003e= 8**\n\n`jruby -S gem install dienashorner` # make sure you have JRuby \u003e= 1.7.x\n\n\n### Features\n\n* Evaluate JavaScript bits from the Ruby side\n* Embed Ruby objects into the JavaScript world\n\n```ruby\nrequire 'nashorn'\n```\n\n* evaluate some simple JavaScript\n```ruby\nNashorn.eval 'true + 100' #=\u003e 101\nNashorn.eval_js '\"4\" + 2' #=\u003e \"42\"\n```\n\n```ruby\ninclude Nashorn\neval_js \"'1' + '' * 2\" #=\u003e \"10\"\n```\n\n* if you need more control, use a `Context`\n```ruby\nNashorn::Context.open do |js|\n  js['foo'] = \"bar\"\n  js.eval('foo') # =\u003e \"bar\"\nend\n```\n\n* evaluate a Ruby function from JavaScript\n```ruby\nNashorn::Context.open do |js|\n  js['say'] = lambda { |word, times| word * times }\n  js.eval(\"say('Szia', 3) + '!'\") #=\u003e SziaSziaSzia!\nend\n```\n\n* embed a Ruby object into your JavaScript environment\n```ruby\nclass MyMath\n  def plus(a, b); a + b + 1 end\nend\n\nNashorn::Context.open do |js|\n  js[\"math\"] = MyMath.new\n  js.eval(\"math.plus(20, 21)\") #=\u003e 42\nend\n```\n\n* make a Ruby object a JavaScript (global) environment\n```ruby\nmath = MyMath.new\nNashorn::Context.open(:with =\u003e math) do |js|\n  js.eval(\"plus(20, 21)\") #=\u003e 42\nend\n```\n\n\n### Context Options\n\nMostly the same as with **`jjs`** e.g. `Nashorn::Context.open(:strict =\u003e true)`.\n\n\n### Loading .js\n\n```ruby\n  File.open('___.js') { |file| eval_js file }\n```\n\n```ruby\n  Nashorn::Context.open { |js| js.load('___.js') }\n```\n\n\n### Configurable Ruby access\n\nPorted over from [Rhino](https://github.com/cowboyd/therubyrhino#configurable-ruby-access)\n\n\u003c!--\nBy default accessing Ruby objects from JavaScript is compatible with *therubyracer*:\nhttps://github.com/cowboyd/therubyracer/wiki/Accessing-Ruby-Objects-From-JavaScript\n\nThus you end-up calling arbitrary no-arg methods as if they were JavaScript properties,\nsince instance accessors (properties) and methods (functions) are indistinguishable :\n\n```ruby\nNashorn::Context.open do |context|\n  context['Time'] = Time\n  context.eval('Time.now')\nend\n```\n\nHowever, you can customize this behavior and there's another access implementation\nthat attempts to mirror only attributes as properties as close as possible:\n```ruby\nclass Foo\n  attr_accessor :bar\n\n  def initialize\n    @bar = \"bar\"\n  end\n\n  def check_bar\n    bar == \"bar\"\n  end\nend\n\nRhino::Ruby::Scriptable.access = :attribute\nRhino::Context.open do |context|\n  context['Foo'] = Foo\n  context.eval('var foo = new Foo()')\n  context.eval('foo.bar') # get property using reader\n  context.eval('foo.bar = null') # set property using writer\n  context.eval('foo.check_bar()') # called like a function\nend\n```\n\nIf you happen to come up with your own access strategy, just set it directly :\n```ruby\nRhino::Ruby::Scriptable.access = FooApp::BarAccess.instance\n```\n--\u003e\n\n\n### Rhino Compatibility\n\nNashorn was inspired (and crafted) from Rhino a.k.a **therubyrhino** JRuby gem.\nFar from being a drop-in replacement although there's `require 'nashorn/rhino'`.\n\n\n### ExecJS\n\ndienashorner gem ships with an [ExecJS][3] compatible runtime, its best to load it\n(`require 'nashorn/execjs/load'`) before ExecJS's auto-detection takes place :\n```ruby\ngem 'execjs', require: false\ngem 'dienashorner', platform: :jruby, require: [ 'nashorn/execjs/load', 'execjs' ]\n```\n\nwhen auto-detection is not used, set the runtime manually :\n```ruby\nrequire 'execjs/module'\nrequire 'nashorn/execjs/load'\nExecJS.runtime = ExecJS::NashornRuntime.new\n```\n\n\n### Less.rb\n\n[Less.rb](https://github.com/cowboyd/less.rb) seems to be working (with hacks),\nfor now you will need to :`require 'nashorn/rhino/less'` before `require 'less'`.\n\n\n## Copyright\n\nCopyright (c) 2017 Karol Bucek. Apache License v2 (see LICENSE for details).\n\n[0]: http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html\n[3]: https://github.com/rails/execjs\n[4]: http://openjdk.java.net/projects/nashorn/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkares%2Fdienashorner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkares%2Fdienashorner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkares%2Fdienashorner/lists"}