<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BombStrike's blog &#187; api</title>
	<atom:link href="http://www.bombstrike.org/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bombstrike.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 07 Mar 2010 22:44:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Current status and API of spidermonkey</title>
		<link>http://www.bombstrike.org/2009/02/current-status-and-api-of-spidermonkey/</link>
		<comments>http://www.bombstrike.org/2009/02/current-status-and-api-of-spidermonkey/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 20:10:38 +0000</pubDate>
		<dc:creator>Christophe Robin</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[spidermonkey]]></category>

		<guid isPermaLink="false">http://www.bombstrike.org/?p=73</guid>
		<description><![CDATA[Spidermonkey had many features and changes done this week, so let&#8217;s look at what it can actually do, and what it can&#8217;t.
Features

Execute Javascript ( well, of course it does   )
Register PHP functions to use in Javascript
Assign PHP values in Javascript
Register Classes in Javascript, allowing the user to instanciate them.

Just with those functionalities, you [...]]]></description>
			<content:encoded><![CDATA[<p>Spidermonkey had many features and changes done this week, so let&#8217;s look at what it can actually do, and what it can&#8217;t.</p>
<p><strong>Features</strong></p>
<ol>
<li>Execute Javascript ( well, of course it does <img src='http://www.bombstrike.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  )</li>
<li>Register PHP functions to use in Javascript</li>
<li>Assign PHP values in Javascript</li>
<li>Register Classes in Javascript, allowing the user to instanciate them.</li>
</ol>
<p>Just with those functionalities, you can already do a great deal of things with JS, and extend it really easily.</p>
<p><strong>Conversion</strong></p>
<p>When working with each others, Javascript convert is types to Zval ( PHP native type ) and vice-versa. Most types are successfully converted, but there are some exceptions:</p>
<ul>
<li>Javascript arrays are converted to stdClass due to the fact that they are stored as Objects by Spidermonkey.</li>
<li>Javascript closures are not yet supported, but because PHP 5.3 support closures too, it should be done soon.</li>
<li>Javascript regexp are not supported either, because there are no equivalents on the PHP side. In the end they&#8217;ll be converted to string.</li>
</ul>
<p>Streams resources will soon have a prototype added by default with functions like read(), getline(), write(), etc&#8230;<br />
Objects extending the Iterator abstract will also have a forEach function defined.</p>
<p><strong>API</strong></p>
<p>Here is the API:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:560px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> JSContext <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* evaluate javascript source code<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @param string $script &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A string containing the javascript source code<br />
&nbsp; &nbsp; &nbsp;* @return mixed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The last value in the global scope is returned to PHP<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> mixed &nbsp;evaluateScript<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$script</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* register a function for use in javascript<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @param callback $callback &nbsp; &nbsp; &nbsp; &nbsp; A valid callback that will be called<br />
&nbsp; &nbsp; &nbsp;* @param string &nbsp; $name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The name under which the function will appear in Javascript,<br />
&nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mandatory for closures and recommanded for array($obj, 'function')<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> void &nbsp; registerFunction<span style="color: #009900;">&#40;</span>callback <span style="color: #000088;">$callback</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* register a class for use in javascript so that it can be instancied using &quot;new&quot;<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @param callback $class_name &nbsp; &nbsp; &nbsp; A valid class to export<br />
&nbsp; &nbsp; &nbsp;* @param string &nbsp; $exported_name &nbsp; &nbsp;The name under which the class will appear<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> void &nbsp; registerClass<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$class_name</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> string <span style="color: #000088;">$exported_name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* register a variable for use in javascript<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @param string &nbsp; $name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The name of the variable in Javascript<br />
&nbsp; &nbsp; &nbsp;* @param mixed &nbsp; &nbsp;$value &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Value for the variable, objects &nbsp;and resources<br />
&nbsp; &nbsp; &nbsp;* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; are passed by reference<br />
&nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> void &nbsp; assign<span style="color: #009900;">&#40;</span>string <span style="color: #000088;">$name</span><span style="color: #339933;">,</span> mixed <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* those function allow you to play with the version the engine is running<br />
&nbsp; &nbsp; &nbsp;* it's not totally compatible and most versions will not be loaded by<br />
&nbsp; &nbsp; &nbsp;* the engine, you can still have a try with the constants defined above */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> mixed &nbsp;setVersion<span style="color: #009900;">&#40;</span>long <span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> long &nbsp; getVersion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> string getVersionString<span style="color: #009900;">&#40;</span>long <span style="color: #000088;">$version</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>This is the current status at revision 38. Next revisions will be aimed at bug correction and error management. If you have any ideas for features, feel free to comments this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombstrike.org/2009/02/current-status-and-api-of-spidermonkey/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
