Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bugs 16866/16876, added test for 16890 ( still need to fix thou…

…gh ), added config.w32 and some patches from hoshino

git-svn-id: https://ookoo.org/svn/pecl-spidermonkey@54 a25dae62-eead-11dd-be30-d70757e1f724
  • Loading branch information...
commit 1cb07965de9e5ef2794f2c6e9ad798d8576421a5 1 parent 411a4fe
BombStrike authored
21 config.w32
View
@@ -0,0 +1,21 @@
+// config.w32 by hoshino at labs dot cybozu dot co dot jp ( http://developer.cybozu.co.jp/oss/2010/01/spidermonkey-ph.html )
+// $Id$
+// $Revision$
+// vim:ft=javascript
+
+ARG_WITH("spidermonkey", "spidermonkey support", "no");
+
+if (PHP_SPIDERMONKEY != "no") {
+ if (CHECK_LIB("js32.lib", "spidermonkey", PHP_SPIDERMONKEY) &&
+ CHECK_HEADER_ADD_INCLUDE("jsapi.h", "CFLAGS_SPIDERMONKEY", PHP_SPIDERMONKEY + "\\include\\js")) {
+
+ EXTENSION("spidermonkey", "spidermonkey.c spidermonkey_context.c spidermonkey_external.c spidermonkey_streams.c");
+
+ AC_DEFINE("HAVE_SPIDERMONKEY", 1, "Have SpiderMonkey library");
+ ADD_FLAG("CFLAGS_SPIDERMONKEY", "/D XP_WIN /D WIN32");
+
+ } else {
+ WARNING("spidermonkey not enabled; libraries and headers not found");
+ }
+
+}
4 package.xml
View
@@ -12,9 +12,9 @@
<email>crobin@php.net</email>
<active>yes</active>
</lead>
- <date>2009-03-13</date>
+ <date>2010-02-21</date>
<version>
- <release>0.1.2</release><api>0.1.2</api>
+ <release>0.1.4</release><api>0.1.4</api>
</version>
<stability>
<release>beta</release><api>beta</api>
18 spidermonkey.c
View
@@ -189,6 +189,7 @@ static zend_object_value php_jscontext_object_new(zend_class_entry *class_type T
*/
PHP_MINIT_FUNCTION(spidermonkey)
{
+ zend_class_entry ce;
/* CONSTANTS */
@@ -225,8 +226,6 @@ PHP_MINIT_FUNCTION(spidermonkey)
/* here we set handlers to zero, meaning that we have no handlers set */
memcpy(&jscontext_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
- zend_class_entry ce;
-
/* init JSContext class */
INIT_CLASS_ENTRY(ce, PHP_SPIDERMONKEY_JSC_NAME, php_spidermonkey_jsc_functions);
/* this function will be called when the object is created by php */
@@ -291,9 +290,17 @@ void jsval_to_zval(zval *return_value, JSContext *ctx, jsval *jval TSRMLS_DC)
str = JSVAL_TO_STRING(rval);
if (str != NULL)
{
- /* then we retrieve the pointer to the string */
- char *txt = JS_GetStringBytes(str);
- RETVAL_STRING(txt, strlen(txt));
+ /* check string length and return an empty string if the
+ js string is empty (bug 16876) */
+ if (JS_GetStringLength(str)) {
+ /* then we retrieve the pointer to the string */
+ char *txt = JS_GetStringBytes(str);
+ RETVAL_STRINGL(txt, strlen(txt), 1);
+ }
+ else
+ {
+ RETVAL_EMPTY_STRING();
+ }
}
else
{
@@ -396,6 +403,7 @@ void zval_to_jsval(zval *val, JSContext *ctx, jsval *jval TSRMLS_DC)
zend_function *fptr;
php_jscontext_object *intern;
php_jsobject_ref *jsref;
+ php_stream *stream;
if (val == NULL) {
*jval = JSVAL_NULL;
9 spidermonkey_context.c
View
@@ -121,7 +121,7 @@ PHP_METHOD(JSContext, assign)
}
/* }}} */
-/* {{{ proto public mixed JSContext::evaluateScript(string $script)
+/* {{{ proto public mixed JSContext::evaluateScript(string $script [, string $script_name ])
Evaluate script and return the last global object in scope to PHP.
Objects are not returned for now. Any global variable declared in
this script will be usable in any following call to evaluateScript
@@ -129,19 +129,20 @@ PHP_METHOD(JSContext, assign)
PHP_METHOD(JSContext, evaluateScript)
{
char *script;
- int script_len;
+ char *script_name = NULL;
+ int script_len, script_name_len = 0;
php_jscontext_object *intern;
jsval rval;
/* retrieve script */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
- "s", &script, &script_len) == FAILURE) {
+ "s|s", &script, &script_len, &script_name, &script_name_len) == FAILURE) {
RETURN_FALSE;
}
intern = (php_jscontext_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
- if (JS_EvaluateScript(intern->ct, intern->obj, script, script_len, NULL, 0, &rval) == JS_TRUE)
+ if (JS_EvaluateScript(intern->ct, intern->obj, script, script_len, script_name, 0, &rval) == JS_TRUE)
{
if (rval != 0)
{
4 spidermonkey_external.c
View
@@ -286,11 +286,11 @@ JSBool JS_PropertyGetterPHP(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
if (jsref->obj != NULL && Z_TYPE_P(jsref->obj) == IS_OBJECT) {
JSString *str;
char *prop_name;
+ zval *val = NULL;
str = JS_ValueToString(cx, id);
prop_name = JS_GetStringBytes(str);
-
- zval *val = NULL;
+
val = zend_read_property(Z_OBJCE_P(jsref->obj), jsref->obj, prop_name, strlen(prop_name), 1 TSRMLS_CC);
if (val != EG(uninitialized_zval_ptr)) {
29 tests/bug16866.phpt
View
@@ -0,0 +1,29 @@
+--TEST--
+Regression test for bug 16866 ( Returning empty string from static function causes segmentation fault )
+--FILE--
+<?php
+$app = new App();
+$app->run();
+
+class App {
+ public function run () {
+ $context = new JSContext();
+ $context->registerClass( 'TimeObject' );
+ echo $context->evaluateScript( 'var t = new TimeObject();
+t.getTime();' );
+ }
+
+ static function getString() {
+ return ''; // <-- empty string causes seg fault
+ //return ' '; // <-- a space won't cause seg fault
+ }
+}
+
+class TimeObject {
+ public function getTime () {
+ return App::getString();
+ }
+}
+?>
+--EXPECTF--
+
22 tests/bug16876.phpt
View
@@ -0,0 +1,22 @@
+--TEST--
+Regression test for bug 16876 ( Empty string as a parameter causes segfault )
+--FILE--
+<?php
+class myClass
+{
+ public function test( $str )
+ {
+ //any code
+ echo 'TestWrite';
+ }
+}
+
+$myclass = new myClass();
+
+$js = new JSContext();
+$js->assign("myclass", $myclass);
+
+$js->evaluateScript( 'myclass.test("")' );
+?>
+--EXPECTF--
+TestWrite
41 tests/bug16890.phpt
View
@@ -0,0 +1,41 @@
+--TEST--
+Regression test for bug 16890 ( Variable is cleaned while being used in JS )
+--FILE--
+<?php
+
+function test($arr) {
+ var_dump($arr);
+}
+
+$ctx = new JSContext();
+$ctx->registerFunction('test');
+
+$js = <<<JS
+arr = [1, null, 0, 'str'];
+test(arr);
+test(arr);
+JS;
+
+$ctx->evaluateScript($js);
+?>
+--EXPECTF--
+object(stdClass)#2 (4) {
+ ["0"]=>
+ int(1)
+ ["1"]=>
+ NULL
+ ["2"]=>
+ int(0)
+ ["3"]=>
+ string(3) "str"
+}
+object(stdClass)#2 (4) {
+ ["0"]=>
+ int(1)
+ ["1"]=>
+ NULL
+ ["2"]=>
+ int(0)
+ ["3"]=>
+ string(3) "str"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.