зеркало из https://github.com/mozilla/pjs.git
Context typemapping changed
This commit is contained in:
Родитель
e3ff9d6708
Коммит
c880a69b75
|
@ -118,10 +118,24 @@ sub new #7/31/98 3:39PM
|
||||||
{
|
{
|
||||||
warn "JS::Context::new\n" if $DEBUG;
|
warn "JS::Context::new\n" if $DEBUG;
|
||||||
my($class, $rt, $stacksize) = @_;
|
my($class, $rt, $stacksize) = @_;
|
||||||
my $this = JS::Runtime::NewContext($rt, $stacksize);
|
$class = ref $class || $class;
|
||||||
return $this;
|
my $cx = JS::Runtime::NewContext($rt, $stacksize);
|
||||||
|
my $self = {
|
||||||
|
_handle => $cx,
|
||||||
|
_name => ("name_" . int (rand 1000)),
|
||||||
|
};
|
||||||
|
$self->{_handle};
|
||||||
|
bless $self, $class;
|
||||||
|
return $self;
|
||||||
} ##new
|
} ##new
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
sub exec {
|
||||||
|
my ($self, $script) = @_;
|
||||||
|
$self->exec_($script);
|
||||||
|
}
|
||||||
|
|
||||||
sub DESTROY #7/31/98 4:54PM
|
sub DESTROY #7/31/98 4:54PM
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -136,23 +150,22 @@ sub DESTROY #7/31/98 4:54PM
|
||||||
package JS::Script;
|
package JS::Script;
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, $code, $name, $rt, $cx) = @_;
|
my ($class, $cx, $code, $name) = @_;
|
||||||
$class = ref $class || $class;
|
$class = ref $class || $class;
|
||||||
my $self = {};
|
my $self = {};
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
$self->{_rt} = $rt;
|
$self->{_script} = $self->compileScript($cx, $code, $name);
|
||||||
my $wcx = $cx or $rt->createContext(8192);
|
$self->{_root} = $self->rootScript($cx, $name);
|
||||||
$self->{_script} = $wcx->compileScript($code, $name);
|
$self->{_cx} = $cx; #!!! dangerous
|
||||||
undef $wcx unless $cx;
|
$self->{_name} = $name;
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub DESTROY {
|
sub DESTROY {
|
||||||
my ($self, $cx) = @_;
|
my $self = shift;
|
||||||
my $wcx = $cx or $self->{_rt}->createContext(8192);
|
print "---> script destroy\n";
|
||||||
$wcx->destroyScript($self);
|
my $cx = $self->{_cx};
|
||||||
undef $self->{_rt};
|
$self->destroyScript($cx);
|
||||||
undef $wcx unless $cx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
|
@ -77,6 +77,14 @@ checkError(JSContext *cx)
|
||||||
return JS_TRUE;
|
return JS_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clearException(JSContext *cx)
|
||||||
|
{
|
||||||
|
if (JS_IsExceptionPending(cx)) {
|
||||||
|
JS_ClearPendingException(cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
/* calback stub */
|
/* calback stub */
|
||||||
|
|
||||||
|
@ -109,6 +117,7 @@ typedef struct PerlCallbackItem PerlCallbackItem;
|
||||||
struct PerlObjectItem {
|
struct PerlObjectItem {
|
||||||
char * name;
|
char * name;
|
||||||
SV* pObject;
|
SV* pObject;
|
||||||
|
//JSObject *jsStub;
|
||||||
JSObject *jsObject;
|
JSObject *jsObject;
|
||||||
JSClass *jsClass;
|
JSClass *jsClass;
|
||||||
struct PerlCallbackItem* vector;
|
struct PerlCallbackItem* vector;
|
||||||
|
@ -284,7 +293,7 @@ PCB_FreeObjectItem(PerlObjectItem *object) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PCB_FreeContextItem(JSContext * cx) {
|
PCB_FreeContextItem(JSContext *cx) {
|
||||||
JSContextItem *cxitem, *aux;
|
JSContextItem *cxitem, *aux;
|
||||||
PerlObjectItem *objitem, *next;
|
PerlObjectItem *objitem, *next;
|
||||||
|
|
||||||
|
@ -456,6 +465,10 @@ PCB_SetProperty(JSContext *cx, JSObject *obj, jsval name, jsval *rval) {
|
||||||
/* JSClass pointer is disposed by
|
/* JSClass pointer is disposed by
|
||||||
JS engine during context cleanup _PH_
|
JS engine during context cleanup _PH_
|
||||||
*/
|
*/
|
||||||
|
void
|
||||||
|
PCB_FinalizeStub(JSContext *cx, JSObject *obj) {
|
||||||
|
}
|
||||||
|
|
||||||
static JSClass*
|
static JSClass*
|
||||||
PCB_NewStdJSClass(char *name) {
|
PCB_NewStdJSClass(char *name) {
|
||||||
JSClass *class;
|
JSClass *class;
|
||||||
|
@ -470,7 +483,8 @@ PCB_NewStdJSClass(char *name) {
|
||||||
class->enumerate = JS_EnumerateStub;
|
class->enumerate = JS_EnumerateStub;
|
||||||
class->resolve = JS_ResolveStub;
|
class->resolve = JS_ResolveStub;
|
||||||
class->convert = JS_ConvertStub;
|
class->convert = JS_ConvertStub;
|
||||||
class->finalize = JS_FinalizeStub;
|
//class->finalize = JS_FinalizeStub;
|
||||||
|
class->finalize = PCB_FinalizeStub;
|
||||||
return(class);
|
return(class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +608,7 @@ JS_DestroyRuntime(rt)
|
||||||
# package JS::Runtime
|
# package JS::Runtime
|
||||||
MODULE = JS PACKAGE = JS::Runtime PREFIX = JS_
|
MODULE = JS PACKAGE = JS::Runtime PREFIX = JS_
|
||||||
|
|
||||||
JSContext *
|
int
|
||||||
JS_NewContext(rt, stacksize)
|
JS_NewContext(rt, stacksize)
|
||||||
JSRuntime *rt
|
JSRuntime *rt
|
||||||
int stacksize
|
int stacksize
|
||||||
|
@ -613,8 +627,9 @@ JS_NewContext(rt, stacksize)
|
||||||
/* __PH__ set the error reporter */
|
/* __PH__ set the error reporter */
|
||||||
JS_SetErrorReporter(cx, PCB_ErrorReporter);
|
JS_SetErrorReporter(cx, PCB_ErrorReporter);
|
||||||
obj = JS_NewObject(cx, &global_class, NULL, NULL);
|
obj = JS_NewObject(cx, &global_class, NULL, NULL);
|
||||||
|
JS_SetGlobalObject(cx, obj);
|
||||||
JS_InitStandardClasses(cx, obj);
|
JS_InitStandardClasses(cx, obj);
|
||||||
RETVAL = cx;
|
RETVAL = (int)cx;
|
||||||
}
|
}
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
@ -631,6 +646,7 @@ JS_DestroyContext(cx)
|
||||||
JS_ClearPendingException(cx);
|
JS_ClearPendingException(cx);
|
||||||
}
|
}
|
||||||
JS_SetErrorReporter(cx, NULL);
|
JS_SetErrorReporter(cx, NULL);
|
||||||
|
JS_GC(cx); //important
|
||||||
JS_DestroyContext(cx);
|
JS_DestroyContext(cx);
|
||||||
PCB_FreeContextItem(cx);
|
PCB_FreeContextItem(cx);
|
||||||
}
|
}
|
||||||
|
@ -658,72 +674,50 @@ JS_eval(cx, bytes, ...)
|
||||||
cxitem = PCB_FindContextItem(cx);
|
cxitem = PCB_FindContextItem(cx);
|
||||||
if (!cxitem || cxitem->dieFromErrors)
|
if (!cxitem || cxitem->dieFromErrors)
|
||||||
croak("JS script evaluation failed");
|
croak("JS script evaluation failed");
|
||||||
|
|
||||||
|
clearException(cx);
|
||||||
XSRETURN_UNDEF;
|
XSRETURN_UNDEF;
|
||||||
}
|
}
|
||||||
RETVAL = rval;
|
RETVAL = rval;
|
||||||
}
|
}
|
||||||
|
clearException(cx);
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
|
|
||||||
JSScript *
|
|
||||||
JS_compileScript(cx, bytes, ...)
|
|
||||||
JSContext *cx
|
|
||||||
char *bytes
|
|
||||||
PREINIT:
|
|
||||||
JSContextItem *cxitem;
|
|
||||||
char *filename = NULL;
|
|
||||||
JSObject *scrobj;
|
|
||||||
CODE:
|
|
||||||
{
|
|
||||||
if (items > 2) { filename = SvPV(ST(2), PL_na); };
|
|
||||||
/* Call on the global object */
|
|
||||||
if(!(RETVAL = JS_CompileScript(cx, JS_GetGlobalObject(cx),
|
|
||||||
bytes, strlen(bytes),
|
|
||||||
filename ? filename : "Perl",
|
|
||||||
0)))
|
|
||||||
{
|
|
||||||
cxitem = PCB_FindContextItem(cx);
|
|
||||||
if (!cxitem || cxitem->dieFromErrors)
|
|
||||||
croak("JS script compilation failed");
|
|
||||||
XSRETURN_UNDEF;
|
|
||||||
}
|
|
||||||
//scrobj = JS_NewScriptObject(cx, RETVAL);
|
|
||||||
//JS_AddRoot(cx, &scrobj);
|
|
||||||
}
|
|
||||||
OUTPUT:
|
|
||||||
RETVAL
|
|
||||||
|
|
||||||
jsval
|
jsval
|
||||||
JS_exec(cx, script)
|
JS_exec_(cx, script)
|
||||||
JSContext *cx
|
JSContext *cx
|
||||||
JSScript *script
|
SV *script
|
||||||
PREINIT:
|
PREINIT:
|
||||||
JSContextItem *cxitem;
|
JSContextItem *cxitem;
|
||||||
char *filename = NULL;
|
JSScript *handle;
|
||||||
CODE:
|
CODE:
|
||||||
{
|
{
|
||||||
jsval rval;
|
jsval rval;
|
||||||
|
handle = (JSScript*)SvIV(*hv_fetch((HV*)SvRV(script), "_script", 7, 0));
|
||||||
/* Call on the global object */
|
/* Call on the global object */
|
||||||
if(!JS_ExecuteScript(cx, JS_GetGlobalObject(cx),
|
if(!JS_ExecuteScript(cx, JS_GetGlobalObject(cx),
|
||||||
script, &rval)) {
|
handle, &rval)) {
|
||||||
cxitem = PCB_FindContextItem(cx);
|
cxitem = PCB_FindContextItem(cx);
|
||||||
if (!cxitem || cxitem->dieFromErrors)
|
if (!cxitem || cxitem->dieFromErrors)
|
||||||
croak("JS script evaluation failed");
|
croak("JS script evaluation failed");
|
||||||
|
|
||||||
|
clearException(cx);
|
||||||
XSRETURN_UNDEF;
|
XSRETURN_UNDEF;
|
||||||
}
|
}
|
||||||
|
clearException(cx);
|
||||||
RETVAL = rval;
|
RETVAL = rval;
|
||||||
//RETVAL = 1;
|
|
||||||
}
|
}
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
void
|
#void
|
||||||
JS_destroyScript(cx, script)
|
#JS_destroyScript(cx, script)
|
||||||
JSContext *cx
|
# JSContext *cx
|
||||||
JSScript *script
|
# JSScript *script
|
||||||
CODE:
|
# CODE:
|
||||||
JS_DestroyScript(cx, script);
|
# JS_DestroyScript(cx, script);
|
||||||
|
|
||||||
# __PH__
|
# __PH__
|
||||||
void
|
void
|
||||||
|
@ -808,7 +802,14 @@ JS_createObject(cx, object, name, methods)
|
||||||
}
|
}
|
||||||
/* create js object in given context */
|
/* create js object in given context */
|
||||||
object_class = PCB_NewStdJSClass(name);
|
object_class = PCB_NewStdJSClass(name);
|
||||||
jso = JS_NewObject(cx, object_class, NULL, 0);
|
//jso = JS_NewObject(cx, object_class, NULL, 0);
|
||||||
|
|
||||||
|
jso = JS_DefineObject(cx, JS_GetGlobalObject(cx), name,
|
||||||
|
object_class, NULL,
|
||||||
|
JSPROP_ENUMERATE | JSPROP_READONLY |
|
||||||
|
JSPROP_PERMANENT);
|
||||||
|
|
||||||
|
|
||||||
if (!jso) croak("Unable create JS object");
|
if (!jso) croak("Unable create JS object");
|
||||||
/* create callback info */
|
/* create callback info */
|
||||||
po = PCB_AddObject(name, object, cx, jso, object_class);
|
po = PCB_AddObject(name, object, cx, jso, object_class);
|
||||||
|
@ -826,17 +827,6 @@ JS_createObject(cx, object, name, methods)
|
||||||
croak("Unable create JS function");
|
croak("Unable create JS function");
|
||||||
pcbitem = pcbitem->next;
|
pcbitem = pcbitem->next;
|
||||||
}
|
}
|
||||||
/* for (i = 0; i < po->count; i++) {
|
|
||||||
if (! JS_DefineFunction(cx, jso,
|
|
||||||
po->vector[i]->name,
|
|
||||||
PCB_UniversalStub,
|
|
||||||
0,0))
|
|
||||||
croak("Unable create JS function\n");
|
|
||||||
} */
|
|
||||||
po->jsObject = JS_InitClass(cx, JS_GetGlobalObject(cx), jso,
|
|
||||||
object_class, 0, 0,
|
|
||||||
NULL, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
# __PH__END
|
# __PH__END
|
||||||
|
|
||||||
|
@ -995,4 +985,61 @@ JS_EXISTS(obj, key)
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
RETVAL
|
RETVAL
|
||||||
|
|
||||||
|
#script
|
||||||
|
MODULE = JS PACKAGE = JS::Script PREFIX = JS_
|
||||||
|
|
||||||
|
int
|
||||||
|
JS_compileScript(object, cx, bytes, ...)
|
||||||
|
SV *object
|
||||||
|
JSContext *cx
|
||||||
|
char *bytes
|
||||||
|
PREINIT:
|
||||||
|
JSContextItem *cxitem;
|
||||||
|
char *filename = NULL;
|
||||||
|
CODE:
|
||||||
|
{
|
||||||
|
if (items > 2) { filename = SvPV(ST(2), PL_na); };
|
||||||
|
/* Call on the global object */
|
||||||
|
if(!(RETVAL = (int)JS_CompileScript(cx, JS_GetGlobalObject(cx),
|
||||||
|
bytes, strlen(bytes),
|
||||||
|
filename ? filename : "Perl",
|
||||||
|
0)))
|
||||||
|
{
|
||||||
|
cxitem = PCB_FindContextItem(cx);
|
||||||
|
if (!cxitem || cxitem->dieFromErrors)
|
||||||
|
croak("JS script compilation failed");
|
||||||
|
XSRETURN_UNDEF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OUTPUT:
|
||||||
|
RETVAL
|
||||||
|
|
||||||
|
int
|
||||||
|
JS_rootScript(object, cx, name)
|
||||||
|
SV *object
|
||||||
|
JSContext *cx
|
||||||
|
char *name
|
||||||
|
PREINIT:
|
||||||
|
JSObject **scrobj;
|
||||||
|
JSScript *handle;
|
||||||
|
CODE:
|
||||||
|
handle = (JSScript*)SvIV(*hv_fetch((HV*)SvRV(object), "_script", 7, 0));
|
||||||
|
scrobj = malloc(sizeof(JSObject*));
|
||||||
|
*scrobj = JS_NewScriptObject(cx, handle);
|
||||||
|
JS_AddNamedRoot(cx, scrobj, name);
|
||||||
|
RETVAL = (int)scrobj;
|
||||||
|
OUTPUT:
|
||||||
|
RETVAL
|
||||||
|
|
||||||
|
void
|
||||||
|
JS_destroyScript(object, cx)
|
||||||
|
SV *object
|
||||||
|
JSContext *cx
|
||||||
|
PREINIT:
|
||||||
|
JSObject **scrobj;
|
||||||
|
JSScript *handle;
|
||||||
|
CODE:
|
||||||
|
handle = (JSScript*)SvIV(*hv_fetch((HV*)SvRV(object), "_script", 7, 0));
|
||||||
|
scrobj = (JSObject**)SvIV(*hv_fetch((HV*)SvRV(object), "_root", 5, 0));
|
||||||
|
JS_RemoveRoot(cx, scrobj);
|
||||||
|
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
use ExtUtils::MakeMaker;
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use Getopt::Std;
|
|
||||||
|
|
||||||
my (%foo, $jsdir, $inc, $libpath);
|
|
||||||
|
|
||||||
#m - build under mozilla tree
|
|
||||||
#d - specifies js build directory (with include/ and lib/ directories)
|
|
||||||
#c - build under charlie tree
|
|
||||||
getopts('mcd:', \%foo);
|
|
||||||
|
|
||||||
$jsdir = $foo{d};
|
|
||||||
|
|
||||||
$foo{'m'} = 1 unless $foo{c} || $foo{d}; #mozilla tree is the default
|
|
||||||
|
|
||||||
if ($foo{c}) {
|
|
||||||
$inc = "-I$ENV{CHARLIE_HOME}/include";
|
|
||||||
$libpath = "-L$ENV{CHARLIE_HOME}/lib";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($jsdir) {
|
|
||||||
$inc = "-I$jsdir/include";
|
|
||||||
$libpath = "-L$jsdir/lib -ljs";
|
|
||||||
}
|
|
||||||
|
|
||||||
my $tmpmk = <<'eof';
|
|
||||||
DEPTH=..
|
|
||||||
include ../config.mk
|
|
||||||
|
|
||||||
all:
|
|
||||||
@echo '$(OBJDIR)'
|
|
||||||
eof
|
|
||||||
|
|
||||||
if ($foo{'m'}) {
|
|
||||||
if ($^O eq "MSWin32") {
|
|
||||||
$inc = "-I.. -I../Debug"; #I'm not sure
|
|
||||||
$libpath = "-L../Debug";
|
|
||||||
} else { #suppose unix, never Mac, gmake
|
|
||||||
open FOO, ">tempmakefile";
|
|
||||||
print FOO $tmpmk;
|
|
||||||
close FOO;
|
|
||||||
my $objdir = `gmake -f tempmakefile`;
|
|
||||||
unlink "tempmakefile";
|
|
||||||
$inc = "-I.. -I../$objdir";
|
|
||||||
$libpath = "-L../$objdir";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
my %extras = ();
|
|
||||||
my $define;
|
|
||||||
|
|
||||||
if ($^O eq "MSWin32") {
|
|
||||||
$define = "-DXP_PC";
|
|
||||||
} else {
|
|
||||||
$define = '-DXP_UNIX';
|
|
||||||
}
|
|
||||||
$extras{OBJECT} = '$(BASEEXT)$(OBJ_EXT) jsperl.obj';
|
|
||||||
|
|
||||||
|
|
||||||
print "+++> $libpath\n";
|
|
||||||
|
|
||||||
WriteMakefile(NAME => 'JS',
|
|
||||||
DEFINE => $define,
|
|
||||||
INC => $inc,
|
|
||||||
LIBS => "$libpath -ljs",
|
|
||||||
VERSION_FROM => 'JS.pm',
|
|
||||||
%extras,);
|
|
||||||
|
|
||||||
__END__
|
|
|
@ -56,8 +56,8 @@ jsval
|
||||||
OBJECT
|
OBJECT
|
||||||
sv_setref_pv($arg, "JS::Object", (void*)$var);
|
sv_setref_pv($arg, "JS::Object", (void*)$var);
|
||||||
|
|
||||||
CONTEXT
|
#CONTEXT
|
||||||
sv_setref_pv($arg, "JS::Context", (void*)$var);
|
# sv_setref_pv($arg, "JS::Context", (void*)$var);
|
||||||
|
|
||||||
SCRIPT
|
SCRIPT
|
||||||
sv_setref_pv($arg, "JS::Script", (void*)$var);
|
sv_setref_pv($arg, "JS::Script", (void*)$var);
|
||||||
|
@ -83,9 +83,17 @@ OBJECT
|
||||||
XSRETURN_UNDEF;
|
XSRETURN_UNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#CONTEXT
|
||||||
|
# if(sv_isa($arg, \"JS::Context\"))
|
||||||
|
# $var = ($type)SvIV((SV*)SvRV($arg));
|
||||||
|
# else{
|
||||||
|
# warn(\"${Package}::$func_name() -- $var is not a blessed JS::Context reference\");
|
||||||
|
# XSRETURN_UNDEF;
|
||||||
|
# }
|
||||||
|
|
||||||
CONTEXT
|
CONTEXT
|
||||||
if(sv_isa($arg, \"JS::Context\"))
|
if(sv_isa($arg, \"JS::Context\"))
|
||||||
$var = ($type)SvIV((SV*)SvRV($arg));
|
$var = ($type)SvIV(*hv_fetch((HV*)SvRV($arg), \"_handle\", 7, 0));
|
||||||
else{
|
else{
|
||||||
warn(\"${Package}::$func_name() -- $var is not a blessed JS::Context reference\");
|
warn(\"${Package}::$func_name() -- $var is not a blessed JS::Context reference\");
|
||||||
XSRETURN_UNDEF;
|
XSRETURN_UNDEF;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче