Subject: | any attempt to use Javascript to in C++ mode with mozilla jsapi 1.8.5 ? |
Hi, I am trying JavaScript 1.16, out of the cpan box. but I am using
JS_VERSION 185 (from a debian distro)
it has become a bit troublesome.
I wonder if there is an attempt on the way to upgrade this package
JavaScript to the mozilla JS interface 1.8?
which happen to be in C++ now, and with some of the API being phased out!
a pre-work would start after applying those patches :
diff --git a/Makefile.PL b/Makefile.PL
index 4a332cf..6eb20f7 100755
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -177,7 +177,14 @@ END_OF_SOURCE
close $test_script;
my $exe = tmpnam();;
- my $cc = join(" ", $Config{cc}, @ccflags, "-o", $exe, "test_js.c",
"-I.", (map { "-I$_" } @incs), $libs, "-l${lib}" );
+
+#CPM110827
+# here need to compile with c++ in insing
/usr/include/mozjs/jsalloc.h,jsbit.h,jstl.h,..
+
+ my $cc = join(" ", $Config{'c++'} || 'c++', @ccflags
+ , "-o", $exe, "test_js.c"
+ , "-I.", (map { "-I$_" } @incs)
+ , $libs, "-l${lib}" );
qx($cc);
if ($?) {
print "Failed compiling test_js.c. ABORTING\n\n$cc\n";
@@ -226,6 +233,14 @@ WriteMakefile(
repository =>
"svn://svn.versed.se/public/Perl/modules/JavaScript"
}
},
+#CPM110827
+# here need to compile with c++ in insing
/usr/include/mozjs/jsalloc.h,jsbit.h,jstl.h,..
+ , 'CC' => "c++"
+ , 'XSOPT' => '-C++'
+# , 'XSOPT' => '-C++ -hiertype'
+ , 'TYPEMAPS' => ['perlobject.map' ]
+ , LD => 'c++'
+
);
sub get_paths {
Modified Makefile.old
then you would have many
...
+#ifdef __cplusplus
+extern "C" {
+#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
+#ifdef __cplusplus
+}
+#endif
...
diff --git a/JavaScript.xs b/JavaScript.xs
index f251296..65af495 100755
--- a/JavaScript.xs
+++ b/JavaScript.xs
@@ -1,11 +1,17 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
+#ifdef __cplusplus
+}
+#endif
#include "JavaScript.h"
-#ifndef FUN_OBJECT(fun)
-#define FUN_OBJECT(fun) (jsval)(fun->object)
+#ifndef FUN_OBJECT
+#define FUN_OBJECT(_fun_) (jsval)(_fun_->object)
#endif
typedef PJS_PerlArray * JavaScript__PerlArray;
@@ -103,7 +109,7 @@ jsr_init_perl_interrupt_handler(cb)
RETVAL = handler;
OUTPUT:
RETVAL
-
+
void
jsr_destroy_perl_interrupt_handler(handler)
PJS_TrapHandler *handler;
@@ -165,7 +171,7 @@ jsc_set_branch_handler(cx, handler)
}
cx->branch_handler = NULL;
- JS_SetBranchCallback(PJS_GetJSContext(cx), NULL);
+ JS_SetOperationCallback(PJS_GetJSContext(cx), NULL);
}
else if (SvROK(handler) && SvTYPE(SvRV(handler)) == SVt_PVCV) {
if (cx->branch_handler != NULL) {
@@ -173,7 +179,7 @@ jsc_set_branch_handler(cx, handler)
}
cx->branch_handler = SvREFCNT_inc(handler);
- JS_SetBranchCallback(PJS_GetJSContext(cx), PJS_branch_handler);
+ JS_SetOperationCallback(PJS_GetJSContext(cx),
(JSOperationCallback)PJS_branch_handler);
}
void
@@ -331,7 +337,7 @@ jsc_free_root(cx, root)
jsval *x;
CODE:
x = INT2PTR(jsval *, SvIV(root));
- JS_RemoveRoot(PJS_GetJSContext(cx), x);
+ JS_RemoveValueRoot(PJS_GetJSContext(cx), x);
jsval
jsc_call(cx, function, args)
@@ -350,7 +356,7 @@ jsc_call(cx, function, args)
tmp = SvIV((SV*)SvRV(PJS_call_perl_method("content",
function, NULL)));
func = INT2PTR(JSFunction *, tmp);
- if (PJS_call_javascript_function(cx, FUN_OBJECT(func),
args, &rval) == JS_FALSE) {
+ if (PJS_call_javascript_function(cx, (jsval)
FUN_OBJECT(func), args, &rval) == JS_FALSE) {
/* Exception was thrown */
XSRETURN_UNDEF;
}
@@ -381,12 +387,12 @@ jsc_call(cx, function, args)
RETVAL
SV *
-jsc_call_in_context( cx, afunc, args, rcx, class )
+jsc_call_in_context( cx, afunc, args, rcx, _class )
JavaScript::Context cx;
SV *afunc
SV *args;
SV *rcx;
- char *class;
+ char *_class;
PREINIT:
jsval rval;
jsval aval;
@@ -416,9 +422,9 @@ jsc_call_in_context( cx, afunc, args, rcx, class )
}
jsobj = JSVAL_TO_OBJECT(context);
- if (strlen(class) > 0) {
- if( JS_GetProperty(PJS_GetJSContext(cx),
JS_GetGlobalObject(PJS_GetJSContext(cx)), class, &aval) == JS_FALSE ) {
- croak("cannot get property %s",class);
+ if (strlen(_class) > 0) {
+ if( JS_GetProperty(PJS_GetJSContext(cx),
JS_GetGlobalObject(PJS_GetJSContext(cx)), _class, &aval) == JS_FALSE ) {
+ croak("cannot get property %s",_class);
Safefree(arg_list);
XSRETURN_UNDEF;
}
@@ -449,7 +455,7 @@ jsc_can(cx, func_name)
if (JS_GetProperty(PJS_GetJSContext(cx),
JS_GetGlobalObject(PJS_GetJSContext(cx)), func_name, &val)) {
if (JSVAL_IS_OBJECT(val)) {
JS_ValueToObject(PJS_GetJSContext(cx), val, &object);
- if (strcmp(OBJ_GET_CLASS(PJS_GetJSContext(cx),
object)->name, "Function") == 0 &&
+ if (strcmp(JS_GET_CLASS(PJS_GetJSContext(cx),
object)->name, "Function") == 0 &&
JS_ValueToFunction(PJS_GetJSContext(cx), val) !=
NULL) {
RETVAL = 1;
}
@@ -601,3 +607,4 @@ DESTROY(func)
JavaScript::PerlFunction func;
CODE:
PJS_DestroyFunction(func);
+
Modified JavaScript_Env.h
and so on...
I am using example of the JSPL package which seems to be more up for the
new stuff.
but is there already an attempt on the way from JavaScript 1.16?
CPM.