1
0
Fork 0
mirror of https://github.com/rubyjs/therubyrhino synced 2023-03-27 23:21:34 -04:00

update readme doc for init_standard_objects api

This commit is contained in:
Charles Lowell 2009-10-06 09:18:13 -05:00
parent aa6d6bb188
commit bb43511573

View file

@ -18,7 +18,7 @@ Embed the Mozilla Rhino Javascript interpreter into Ruby
1. Our shark's in the Javascript!
include Rhino
# evaluate some simple javascript
Rhino::Context.open do |context|
@ -26,16 +26,24 @@ Embed the Mozilla Rhino Javascript interpreter into Ruby
end
# evaluate a ruby function from javascript
include Rhino
Rhino::Context.open do |context|
context.standard do |scope|
scope.put("say", scope, function {|word, times| word * times})
context.evaljs("say("Hello", 3)") #=> HelloHelloHello
end
scope = context.init_standard_objects
scope["say"] = function {|word, times| word * times}
context.evaljs("say("Hello", 3)") #=> HelloHelloHello
end
# Configure your embedding setup
Rhino::Context.open do |context|
# Make your standard objects (Object, String, etc...) immutable
scope = context.init_standard_objects(:sealed => true)
context.evaljs("Object.prototype.toString = function() {}") # this is an error!
#Turn on Java integration from javascript (probably a bad idea)
scope = context.init_standard_objects(:java => true)
context.evaljs("java.lang.System.exit()") #it's dangerous!
end
== REQUIREMENTS:
* JRuby >= 1.3.0