Permalink
Browse files

Started working on spidermonkey 1.8.5 support (doesn't works yet)

  • Loading branch information...
1 parent 32ac46b commit fd6c53286a0dce9e655d3868003be8cbf87e7ca4 @christopherobin committed Aug 18, 2011
Showing with 191 additions and 9 deletions.
  1. +10 −6 config.m4
  2. +17 −0 php_spidermonkey.h
  3. +34 −2 spidermonkey.c
  4. +83 −1 spidermonkey_external.c
  5. +47 −0 spidermonkey_streams.c
View
16 config.m4
@@ -28,11 +28,15 @@ AC_DEFUN([PHP_SPIDERMONKEY_CHECK_VERSION],[
PHP_ARG_WITH(spidermonkey, whether to enable spidermonkey support,
[ --with-spidermonkey[=DIR] Enable spidermonkey support])
-
+
if test "$PHP_SPIDERMONKEY" != "no"; then
for i in $PHP_SPIDERMONKEY /usr/local /usr; do
- for j in js mozjs; do
- test -f $i/include/$j/jsapi.h && SPIDERMONKEY_BASEDIR=$i && SPIDERMONKEY_INCDIR=$i/include/$j && SPIDERMONKEY_LIBNAME=$j && break
+ for j in js mozjs mozjs185; do
+ test -f $i/include/$j/jsapi.h && SPIDERMONKEY_BASEDIR=$i && SPIDERMONKEY_INCDIR=$i/include/$j && break
+ done
+ # test for the libname independantely
+ for j in js mozjs mozjs185; do
+ test -f $i/lib/lib$j.so && SPIDERMONKEY_LIBNAME=$j && break
done
test -f $i/include/$j/jsapi.h && break
done
@@ -44,9 +48,9 @@ if test "$PHP_SPIDERMONKEY" != "no"; then
PHP_SPIDERMONKEY_CHECK_VERSION
PHP_ADD_LIBRARY_WITH_PATH($SPIDERMONKEY_LIBNAME, $SPIDERMONKEY_BASEDIR/$PHP_LIBDIR, SPIDERMONKEY_SHARED_LIBADD)
- PHP_ADD_INCLUDE($SPIDERMONKEY_INCDIR)
+ PHP_ADD_INCLUDE($SPIDERMONKEY_INCDIR)
PHP_SUBST(SPIDERMONKEY_SHARED_LIBADD)
-
- PHP_NEW_EXTENSION(spidermonkey, spidermonkey.c spidermonkey_context.c spidermonkey_external.c spidermonkey_streams.c, $ext_shared)
+
+ PHP_NEW_EXTENSION(spidermonkey, spidermonkey.c spidermonkey_context.c spidermonkey_external.c spidermonkey_streams.c, $ext_shared)
fi
View
17 php_spidermonkey.h
@@ -126,6 +126,7 @@ PHP_METHOD(JSContext, getVersionString);
* PHP. You need to declare them in the global_functions
* struct in JSContext's constructor
*/
+ #if JS_VERSION < 185
JSBool generic_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool generic_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
/* streams */
@@ -134,14 +135,30 @@ JSBool js_stream_getline(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
JSBool js_stream_seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool js_stream_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool js_stream_tell(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
+#else
+JSBool generic_call(JSContext *cx, uintN argc, jsval *vp);
+JSBool generic_constructor(JSContext *cx, uintN argc, jsval *vp);
+/* streams */
+JSBool js_stream_read(JSContext *cx, uintN argc, jsval *vp);
+JSBool js_stream_getline(JSContext *cx, uintN argc, jsval *vp);
+JSBool js_stream_seek(JSContext *cx, uintN argc, jsval *vp);
+JSBool js_stream_write(JSContext *cx, uintN argc, jsval *vp);
+JSBool js_stream_tell(JSContext *cx, uintN argc, jsval *vp);
+#endif
/* }}} */
/* Methods used/exported in JS */
void reportError(JSContext *cx, const char *message, JSErrorReport *report);
void JS_FinalizePHP(JSContext *cx, JSObject *obj);
+#if JS_VERSION < 185
JSBool JS_ResolvePHP(JSContext *cx, JSObject *obj, jsval id);
JSBool JS_PropertySetterPHP(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
JSBool JS_PropertyGetterPHP(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
+#else
+JSBool JS_ResolvePHP(JSContext *cx, JSObject *obj, jsid id);
+JSBool JS_PropertySetterPHP(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp);
+JSBool JS_PropertyGetterPHP(JSContext *cx, JSObject *obj, jsid id, jsval *vp);
+#endif
/* Define the entry point symbol
* Zend will use when loading this module
View
36 spidermonkey.c
@@ -134,14 +134,22 @@ static zend_object_value php_jscontext_object_new_ex(zend_class_entry *class_typ
intern->script_class.convert = JS_ConvertStub;
/* Optionally non-null members start here. */
+#if JS_VERSION < 185
intern->script_class.getObjectOps = 0;
+#else
+ intern->script_class.reserved0 = 0;
+#endif
intern->script_class.checkAccess = 0;
intern->script_class.call = 0;
intern->script_class.construct = 0;
intern->script_class.xdrObject = 0;
intern->script_class.hasInstance = 0;
intern->script_class.mark = 0;
+#if JS_VERSION < 185
intern->script_class.reserveSlots = 0;
+#else
+ intern->script_class.reserved1 = 0;
+#endif
/* says that our script runs in global scope */
JS_SetOptions(intern->ct, JSOPTION_VAROBJFIX);
@@ -150,7 +158,11 @@ static zend_object_value php_jscontext_object_new_ex(zend_class_entry *class_typ
JS_SetErrorReporter(intern->ct, reportError);
/* create global object for execution */
+#if JS_VERSION < 185
intern->obj = JS_NewObject(intern->ct, &intern->script_class, NULL, NULL);
+#else
+ intern->obj = JS_NewGlobalObject(intern->ct, &intern->script_class);
+#endif
/* store pointer to HashTable */
JS_SetPrivate(intern->ct, intern->obj, intern->jsref);
@@ -267,7 +279,11 @@ void _jsval_to_zval(zval *return_value, JSContext *ctx, jsval *jval, php_jsparen
}
else if (JSVAL_IS_DOUBLE(rval))
{
+#if JS_VERSION < 185
RETVAL_DOUBLE(*JSVAL_TO_DOUBLE(rval));
+#else
+ RETVAL_DOUBLE(JSVAL_TO_DOUBLE(rval));
+#endif
}
else if (JSVAL_IS_INT(rval))
{
@@ -276,16 +292,24 @@ void _jsval_to_zval(zval *return_value, JSContext *ctx, jsval *jval, php_jsparen
else if (JSVAL_IS_STRING(rval))
{
JSString *str;
+ int len;
/* first we convert the jsval to a JSString */
str = JSVAL_TO_STRING(rval);
if (str != NULL)
{
/* check string length and return an empty string if the
js string is empty (bug 16876) */
- if (JS_GetStringLength(str)) {
+ if ((len = JS_GetStringLength(str)) > 0) {
/* then we retrieve the pointer to the string */
+#if JS_VERSION < 185
char *txt = JS_GetStringBytes(str);
- RETVAL_STRINGL(txt, strlen(txt), 1);
+ RETVAL_STRINGL(txt, len, 1);
+#else
+ /* because version 1.8.5 supports unicode, we must encode strings */
+ char *txt = JS_EncodeString(ctx, str);
+ REVAL_STRING(txt, strlen(txt), 1);
+ JS_Free(txt);
+#endif
}
else
{
@@ -369,7 +393,12 @@ void _jsval_to_zval(zval *return_value, JSContext *ctx, jsval *jval, php_jsparen
str = JS_ValueToString(ctx, val);
/* Retrieve property name */
+#if JS_VERSION < 185
name = JS_GetStringBytes(str);
+#else
+ /* because version 1.8.5 supports unicode, we must encode strings */
+ name = JS_EncodeString(ctx, str);
+#endif
/* Try to read property */
if (JS_GetProperty(ctx, obj, name, &item_val) == JS_TRUE)
@@ -385,6 +414,9 @@ void _jsval_to_zval(zval *return_value, JSContext *ctx, jsval *jval, php_jsparen
/* Destroy pointer to zval */
zval_ptr_dtor(&fval);
}
+#if JS_VERSION >= 185
+ JS_Free(name);
+#endif
}
}
View
84 spidermonkey_external.c
@@ -44,7 +44,11 @@ void php_jsobject_set_property(JSContext *ctx, JSObject *obj, char *property_nam
}
/* all function calls are mapped through this unique function */
+#if JS_VERSION < 185
JSBool generic_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+#else
+JSBool generic_call(JSContext *cx, uintN argc, jsval *vp)
+#endif
{
TSRMLS_FETCH();
JSFunction *func;
@@ -55,11 +59,21 @@ JSBool generic_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
php_jscontext_object *intern;
php_jsobject_ref *jsref;
int i;
+#if JS_VERSION >= 185
+ JSObject *obj = JS_THIS_OBJECT(cx, vp);
+ jsval *argv = JS_ARGV(cx,vp);
+ jsval *rval = &JS_RVAL(cx,vp);
+#endif
/* first retrieve function name */
func = JS_ValueToFunction(cx, ((argv)[-2]));
jfunc_name = JS_GetFunctionId(func);
+#if JS_VERSION < 185
func_name = JS_GetStringBytes(jfunc_name);
+#else
+ /* because version 1.8.5 supports unicode, we must encode strings */
+ func_name = JS_EncodeString(cx, jfunc_name);
+#endif
intern = (php_jscontext_object*)JS_GetContextPrivate(cx);
@@ -73,6 +87,11 @@ JSBool generic_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Failed to retrieve function callback", 0 TSRMLS_CC);
}
+ /* free function name */
+#if JS_VERSION >= 185
+ JS_Free(func_name);
+#endif
+
/* ready parameters */
params = emalloc(argc * sizeof(zval**));
for (i = 0; i < argc; i++)
@@ -114,7 +133,11 @@ JSBool generic_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
}
/* this native is used for class constructors */
+#if JS_VERSION < 185
JSBool generic_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+#else
+JSBool generic_constructor(JSContext *cx, uintN argc, jsval *vp)
+#endif
{
TSRMLS_FETCH();
JSFunction *class;
@@ -123,26 +146,45 @@ JSBool generic_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
zval ***params, *retval_ptr;
zend_class_entry *ce, **pce;
zval *cobj;
+#if JS_VERSION >= 185
+ JSObject *obj = JS_THIS_OBJECT(cx, vp);
+ jsval *argv = JS_ARGV(cx,vp);
+ jsval *rval = &JS_RVAL(cx,vp);
+#endif
php_jscontext_object *intern;
int i;
+#if JS_VERSION < 185
if (!JS_IsConstructing(cx))
+#else
+ if (!JS_IsConstructing(cx, vp))
+#endif
{
return JS_FALSE;
}
/* first retrieve class name */
class = JS_ValueToFunction(cx, ((argv)[-2]));
jclass_name = JS_GetFunctionId(class);
+#if JS_VERSION < 185
class_name = JS_GetStringBytes(jclass_name);
+#else
+ /* because version 1.8.5 supports unicode, we must encode strings */
+ class_name = JS_EncodeString(cx, jclass_name);
+#endif
intern = (php_jscontext_object*)JS_GetContextPrivate(cx);
/* search for class entry */
if (zend_hash_find(intern->ec_ht, class_name, strlen(class_name), (void**)&pce) == FAILURE) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Failed to retrieve function callback", 0 TSRMLS_CC);
}
+
+ /* free class name */
+#if JS_VERSION >= 185
+ JS_Free(class_name);
+#endif
/* retrieve pointer to ce */
ce = *pce;
@@ -156,7 +198,12 @@ JSBool generic_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
zend_fcall_info_cache fcc;
if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
+#if JS_VERSION < 185
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Access to non-public constructor of class %s", class_name);
+#else
+ /* we can't use spidermonkey's class_name pointer because it's not managed by it */
+ zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Access to non-public constructor");
+#endif
}
object_init_ex(cobj, ce);
@@ -236,14 +283,21 @@ JSBool generic_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
return JS_TRUE;
}
-
+#if JS_VERSION < 185
JSBool JS_ResolvePHP(JSContext *cx, JSObject *obj, jsval id)
+#else
+JSBool JS_ResolvePHP(JSContext *cx, JSObject *obj, jsid id)
+#endif
{
/* always return true, as PHP doesn't use any resolver */
return JS_TRUE;
}
+#if JS_VERSION < 185
JSBool JS_PropertySetterPHP(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+#else
+JSBool JS_PropertySetterPHP(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
+#endif
{
TSRMLS_FETCH();
php_jsobject_ref *jsref;
@@ -260,20 +314,34 @@ JSBool JS_PropertySetterPHP(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
zval *val;
str = JS_ValueToString(cx, id);
+#if JS_VERSION < 185
prop_name = JS_GetStringBytes(str);
+#else
+ /* because version 1.8.5 supports unicode, we must encode strings */
+ prop_name = JS_EncodeString(cx, str);
+#endif
MAKE_STD_ZVAL(val);
jsval_to_zval(val, cx, vp);
zend_update_property(Z_OBJCE_P(jsref->obj), jsref->obj, prop_name, strlen(prop_name), val TSRMLS_CC);
zval_ptr_dtor(&val);
+
+ /* free prop name */
+#if JS_VERSION >= 185
+ JS_Free(prop_name);
+#endif
}
}
return JS_TRUE;
}
+#if JS_VERSION < 185
JSBool JS_PropertyGetterPHP(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+#else
+JSBool JS_PropertyGetterPHP(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
+#endif
{
TSRMLS_FETCH();
php_jsobject_ref *jsref;
@@ -290,17 +358,31 @@ JSBool JS_PropertyGetterPHP(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
JSBool has_property;
str = JS_ValueToString(cx, id);
+#if JS_VERSION < 185
prop_name = JS_GetStringBytes(str);
+#else
+ /* because version 1.8.5 supports unicode, we must encode strings */
+ prop_name = JS_EncodeString(cx, str);
+#endif
has_property = JS_FALSE;
if (JS_HasProperty(cx, obj, prop_name, &has_property) && (has_property == JS_TRUE)) {
if (JS_LookupProperty(cx, obj, prop_name, vp) == JS_TRUE) {
+ /* free prop name */
+#if JS_VERSION >= 185
+ JS_Free(prop_name);
+#endif
return JS_TRUE;
}
}
val = zend_read_property(Z_OBJCE_P(jsref->obj), jsref->obj, prop_name, strlen(prop_name), 1 TSRMLS_CC);
+ /* free prop name */
+#if JS_VERSION >= 185
+ JS_Free(prop_name);
+#endif
+
if (val != EG(uninitialized_zval_ptr)) {
zval_add_ref(&val);
zval_to_jsval(val, cx, vp TSRMLS_CC);
View
47 spidermonkey_streams.c
@@ -22,12 +22,22 @@
#include "php_spidermonkey.h"
/* this native is used for read from streams */
+
+#if JS_VERSION < 185
JSBool js_stream_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+#else
+JSBool js_stream_read(JSContext *cx, uintN argc, jsval *vp)
+#endif
{
TSRMLS_FETCH();
php_jscontext_object *intern;
php_jsobject_ref *jsref;
php_stream *stream = NULL;
+#if JS_VERSION >= 185
+ JSObject *obj = JS_THIS_OBJECT(cx, vp);
+ jsval *argv = JS_ARGV(cx,vp);
+ jsval *rval = &JS_RVAL(cx,vp);
+#endif
intern = (php_jscontext_object*)JS_GetContextPrivate(cx);
jsref = (php_jsobject_ref*)JS_GetInstancePrivate(cx, obj, &intern->script_class, NULL);
@@ -76,12 +86,22 @@ JSBool js_stream_read(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
}
/* this native is used to retrieve a line from a stream */
+#if JS_VERSION < 185
JSBool js_stream_getline(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+#else
+JSBool js_stream_getline(JSContext *cx, uintN argc, jsval *vp)
+#endif
{
TSRMLS_FETCH();
php_jscontext_object *intern;
php_jsobject_ref *jsref;
php_stream *stream = NULL;
+#if JS_VERSION >= 185
+ JSObject *obj = JS_THIS_OBJECT(cx, vp);
+ jsval *argv = JS_ARGV(cx,vp);
+ jsval *rval = &JS_RVAL(cx,vp);
+#endif
+
intern = (php_jscontext_object*)JS_GetContextPrivate(cx);
jsref = (php_jsobject_ref*)JS_GetInstancePrivate(cx, obj, &intern->script_class, NULL);
@@ -130,12 +150,21 @@ JSBool js_stream_getline(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
}
/* this native is used to seek in a stream */
+#if JS_VERSION < 185
JSBool js_stream_seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+#else
+JSBool js_stream_seek(JSContext *cx, uintN argc, jsval *vp)
+#endif
{
TSRMLS_FETCH();
php_jscontext_object *intern;
php_jsobject_ref *jsref;
php_stream *stream = NULL;
+#if JS_VERSION >= 185
+ JSObject *obj = JS_THIS_OBJECT(cx, vp);
+ jsval *argv = JS_ARGV(cx,vp);
+ jsval *rval = &JS_RVAL(cx,vp);
+#endif
intern = (php_jscontext_object*)JS_GetContextPrivate(cx);
jsref = (php_jsobject_ref*)JS_GetInstancePrivate(cx, obj, &intern->script_class, NULL);
@@ -172,12 +201,21 @@ JSBool js_stream_seek(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
}
/* this native is used for writing to a stream */
+#if JS_VERSION < 185
JSBool js_stream_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+#else
+JSBool js_stream_write(JSContext *cx, uintN argc, jsval *vp)
+#endif
{
TSRMLS_FETCH();
php_jscontext_object *intern;
php_jsobject_ref *jsref;
php_stream *stream = NULL;
+#if JS_VERSION >= 185
+ JSObject *obj = JS_THIS_OBJECT(cx, vp);
+ jsval *argv = JS_ARGV(cx,vp);
+ jsval *rval = &JS_RVAL(cx,vp);
+#endif
intern = (php_jscontext_object*)JS_GetContextPrivate(cx);
jsref = (php_jsobject_ref*)JS_GetInstancePrivate(cx, obj, &intern->script_class, NULL);
@@ -220,12 +258,21 @@ JSBool js_stream_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
}
/* this native is used for telling the position in the file */
+#if JS_VERSION < 185
JSBool js_stream_tell(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+#else
+JSBool js_stream_tell(JSContext *cx, uintN argc, jsval *vp)
+#endif
{
TSRMLS_FETCH();
php_jscontext_object *intern;
php_jsobject_ref *jsref;
php_stream *stream = NULL;
+#if JS_VERSION >= 185
+ JSObject *obj = JS_THIS_OBJECT(cx, vp);
+ jsval *argv = JS_ARGV(cx,vp);
+ jsval *rval = &JS_RVAL(cx,vp);
+#endif
intern = (php_jscontext_object*)JS_GetContextPrivate(cx);
jsref = (php_jsobject_ref*)JS_GetInstancePrivate(cx, obj, &intern->script_class, NULL);

0 comments on commit fd6c532

Please sign in to comment.