gecko-dev/js/rhino/docs/faq.html

74 строки
3.2 KiB
HTML

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Norris Boyd">
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="KeyWords" content="Rhino, JavaScript, Java">
<title>Rhino FAQ</title>
</head>
<body bgcolor="#FFFFFF">
<script src="owner.js"></script>
<center>
<h1>
Frequently Asked Questions about Rhino</h1></center>
<script>document.write(owner());</script>
<br><script>
var d = new Date(document.lastModified);
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
document.write('<br>');
</script>
<center>
<hr WIDTH="100%"></center>
<p><b><font size=+2>Q</font>.</b> <i>How do I create a Java array from
JavaScript?</i>
<p><b><font size=+2>A.</font></b> You must use Java reflection. For instance,
to create an array of java.lang.String of length five, do
<blockquote><tt>var stringArray = java.lang.reflect.Array.newInstance(java.lang.String,
5);</tt></blockquote>
Then if you wish to assign the string "hi" to the first element, simply
execute <tt>stringArray[0] = "hi"</tt>.
<p>Creating arrays of primitive types is slightly different: you must use
the TYPE field. For example, creating an array of seven ints can be done
with the code
<blockquote><tt>var intArray = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE,
7);</tt></blockquote>
<p><br><b><font size=+2>Q</font>.</b> <i>When I try to execute a script
I get the exception </i><tt>Required security context missing</tt><i>.
What's going on?</i>
<p><b><font size=+2>A.</font></b> You've likely missed placing the <tt>Security.properties</tt>
file in your class path at <tt>org.mozilla.javascript.resources</tt>.
<p><b><font size=+2>Q</font>.</b> <i>Is it possible to make Rhino classes
serializable?</i>
<p><b><font size=+2>A.</font></b> A number of people have asked about making
Rhino data serializable. It certainly seems like it would be useful for
a variety of applications.
<p>The reason I haven't implemented Serializiable has been that java.lang.Class
is not Serializable, so any functions or scripts that have been compiled
to Java bytecodes can't be serialized. One Rhino embedder suggested that
we could get around this restriction by actually saving the bytecode in
a byte array and then having some mechanism for loading those bytes at
the destination. That would work, but is an extra mechanism beyond standard
serialization and imposes a significant space overhead on all users of
compiled scripts. I'm also curious as to whether that mechanism would be
any faster than simply recompiling from the script source, which would
be significantly smaller than the serialized form.
<p>It'd be great to have some solutions to the serialization problem, and
I'd certainly be happy to roll changes back into Rhino.
<p>Perhaps the best solution is to implement some serialization for Rhino's
interpretive mode and assume for Rhino's compiled mode that the class has
also been compiled on the receiving end (which is the assumption Java makes).
<br>&nbsp;
<h3>
<hr WIDTH="100%"><br>
<a href="index.html">back to top</a></h3>
</body>
</html>