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:
parent
aa6d6bb188
commit
bb43511573
1 changed files with 16 additions and 8 deletions
24
README.rdoc
24
README.rdoc
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue