diff --git a/mozilla/js/src/perlconnect/JS.def b/mozilla/js/src/perlconnect/JS.def new file mode 100644 index 00000000000..8e079e8defc --- /dev/null +++ b/mozilla/js/src/perlconnect/JS.def @@ -0,0 +1,6 @@ +LIBRARY "JS" +DESCRIPTION "JS library for Perl <-> JS communications" +CODE LOADONCALL +DATA LOADONCALL NONSHARED MULTIPLE +EXPORTS + boot_JS diff --git a/mozilla/js/src/perlconnect/JS.dsp b/mozilla/js/src/perlconnect/JS.dsp new file mode 100644 index 00000000000..fcd1e61d4f5 --- /dev/null +++ b/mozilla/js/src/perlconnect/JS.dsp @@ -0,0 +1,98 @@ +# Microsoft Developer Studio Project File - Name="JS" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=JS - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "JS.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "JS.mak" CFG="JS - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "JS - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "JS - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "JS - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 + +!ELSEIF "$(CFG)" == "JS - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "d:\opc\ns\js\ref" /I "$(PERL_SRC)" /I "$(PERL_SRC)\win32" /I "$(PERL_SRC)\win32\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# SUBTRACT CPP /Gy +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 js32.lib PerlConnect.lib perl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"c:\perl\lib\auto\JS\JS.dll" /pdbtype:sept /libpath:"..\Debug" /libpath:"$(PERL_SRC)" + +!ENDIF + +# Begin Target + +# Name "JS - Win32 Release" +# Name "JS - Win32 Debug" +# Begin Source File + +SOURCE=.\JS.c +# End Source File +# Begin Source File + +SOURCE=.\JS.def +# End Source File +# End Target +# End Project diff --git a/mozilla/js/src/perlconnect/JS.pm b/mozilla/js/src/perlconnect/JS.pm new file mode 100644 index 00000000000..ab60bf508fa --- /dev/null +++ b/mozilla/js/src/perlconnect/JS.pm @@ -0,0 +1,241 @@ +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +# +# PerlConnect support package. +# + +############################################################################ +# PerlConnect support package. 8/3/98 2:50PM +# See README.html and JS.xs for information about this module. +############################################################################ + +package JS; +require Exporter; +require DynaLoader; +@ISA = qw(Exporter DynaLoader); +@EXPORT_OK = qw(perl_eval perl_resolve perl_call $js $ver); +$VERSION = '0.02'; + +# version string for the interpreter +$ver = "[Perl Interpreter: Version $] compiled under $^O]\n"; +$DEBUG = undef; + +############################################################################ +# TODO: This will be added +############################################################################ +sub AUTOLOAD #7/28/98 8:24PM +{ + print "\nJS::AUTOLOAD: $AUTOLOAD, not implemented yet\n" if $DEBUG; +} ##AUTOLOAD + +############################################################################ +# Evaluates the parameter and returns the return result of eval() as a +# reference +############################################################################ +sub perl_eval #7/15/98 5:13PM +{ + my($stmt) = shift; + package main; + my(@_js) = eval($stmt); + package JS; + my($_js) = (scalar(@_js)==1)?$_js[0]:\@_js; + undef $js; + $js = (ref $_js) ? $_js: \$_js; + print "Failure in perl_call!" unless ref $js; +} ##perl_eval + +############################################################################ +# Calls the procesure passed as the first parameter and passes the rest of +# the arguments to it. The return result is converted to a reference as +# before +############################################################################ +sub perl_call #7/21/98 2:16PM +{ + my($proc) = shift; + my($_js); + + $proc =~ s/main:://g; + #print "Calling $proc\n"; + package main; + my(@_js) = &$proc(@_); + package JS; + #print "here: ", @_js, "\n"; + $_js = (scalar(@_js)==1)?$_js[0]:\@_js; + undef $js; + $js = (ref $_js) ? $_js: \$_js; + #print ref $js; + print "Failure in perl_call!" unless ref $js; +} ##perl_call + +############################################################################ +# Takes the first parameter and tries to retrieve this variable +############################################################################ +sub perl_resolve #7/22/98 10:08AM +{ + my($name) = shift; + my(@parts) = split('::', $name); + my($last_part) = pop(@parts); + + # variable lookup -- variables must start with $, @, or % + if($last_part =~ /^([\$\@\%])(.+)/){ + my($resolved_name) = "$1".join('::', @parts)."::$2"; + package main; + my(@_js) = eval($resolved_name); + package JS; + my($_js) = (scalar(@_js)==1)?$_js[0]:\@_js; + undef $js; + $js = (ref $_js) ? $_js: \$_js; + }else{ + $name =~ s/main:://g; + # if this function exists + # function -- set $js to 1 to indicate this + if(eval "return defined(&main::$name)"){ + print "function $name\n" if $DEBUG; + $js = 1; + # module + }else{ + print "must be a module\n" if $DEBUG; + $js=2; + return; + # defined module -- try to do an eval and check $@ to trap errors + # as a result, the module is automatically pre-use'd if it exists + $name =~ s/main:://g; + if(eval "use $name; return !(defined($@));"){ + $js = 2; + # o.w. this module is undefined + }else{ + $js = 3; + } + } + } +} ##perl_resolve + +############################################################################ +# Validates package name +############################################################################ +sub perl_validate_package #7/22/98 10:15AM +{ + print "perl_validate_package\n" if $DEBUG; + my($name) = shift; + print $name if $DEBUG; + $js = $name?1:undef; +} ##perl_validate_package + +# test procedure +sub c{ + print "da!\n" if wantarray; + print "Called!\n"; + return @_; +} + +############################################################################ +# Duplicates JS::Context::new is a way +############################################################################ +sub new #7/31/98 5:32PM +{ + print "JS::new" if $DEBUG; + my $rt = new JS::Runtime(10_000); + return $this = new JS::Context($rt, 1_024); +} ##new + +############################################################################ +# Uses DynaLoader to load JS support DLL, performs the initialization +############################################################################ +sub boot #7/31/98 5:28PM +{ + # this is to load the JS DLL at run-time + bootstrap JS $VERSION; + push @dl_library_path, $ENV{'LD_LIBRARY_PATH'}; +} ##boot + +############################################################################ +package JS::Runtime; +@EXPORT = qw($this); + +sub AUTOLOAD #7/28/98 8:24PM +{ + print "\nJS::Runtime::AUTOLOAD: $AUTOLOAD, not implemented yet\n" if $DEBUG; +} ##AUTOLOAD + +############################################################################ +# Constructor. Calls NewRuntime and saves the returned value in this +############################################################################ +sub new #7/31/98 3:39PM +{ + print "JS::Runtime::new\n" if $DEBUG; + my($class, $maxbytes) = @_; + $this = JS::NewRuntime(scalar($maxbytes)); + return $this; +} ##new + +############################################################################ +# Destructor for Runtimes +############################################################################ +sub DESTROY #7/31/98 4:54PM +{ + my $self = shift; + print "JS::Runtime::DESTROY\n" if $DEBUG; + JS::DestroyRuntime($self); + undef $this; +} ##DESTROY + +############################################################################ +package JS::Context; +@EXPORT = qw($this); + +sub AUTOLOAD #7/28/98 8:24PM +{ + print "\nJS::Context::AUTOLOAD: $AUTOLOAD, not implemented yet\n" if $DEBUG; +} ##AUTOLOAD + +############################################################################ +# Constructor. Calls NewContext and saves the returned value in this +############################################################################ +sub new #7/31/98 3:39PM +{ + print "JS::Context::new\n" if $DEBUG; + my($class, $rt, $stacksize) = @_; + $this = JS::Runtime::NewContext($rt, $stacksize); + return $this; +} ##new + +############################################################################ +# Destructor for Contexts +############################################################################ +sub DESTROY #7/31/98 4:54PM +{ + my $self = shift; + print "JS::Contexts::DESTROY\n" if $DEBUG; + JS::Runtime::DestroyContext($self); + undef $this; +} ##DESTROY + +############################################################################ + +package JS::Object; + +sub AUTOLOAD #7/28/98 8:24PM +{ + $_ = $AUTOLOAD; + $_ =~ s/.*://; + print "\nJS::Object::AUTOLOAD: $_, not implemented yet\n" if $DEBUG; +} ##AUTOLOAD + +&JS::boot(); + +1; diff --git a/mozilla/js/src/perlconnect/JS.xs b/mozilla/js/src/perlconnect/JS.xs new file mode 100644 index 00000000000..9113e3bc6e8 --- /dev/null +++ b/mozilla/js/src/perlconnect/JS.xs @@ -0,0 +1,224 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * PerlConnect. Provides means for OO Perl <==> JS communications + */ + +/* This is an program written in XSUB. You need to compile it using xsubpp */ +/* usually found in your perl\bin directory. On my machine I do it like this:*/ +/* perl c:\perl\lib\ExtUtils\xsubpp -typemap \ */ +/* c:\perl\lib\extutils\typemap -typemap typemap JS.xs > JS.c */ +/* See perlxs man page for details. */ +/* Don't edit the resulting C file directly. See README.html for more info */ +/* on PerlConnect in general */ + +#ifdef __cplusplus + extern "C"; { +#endif +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" +#ifdef __cplusplus + } +#endif + +#include "jsapi.h" +#include "jsperlpvt.h" + +static +JSClass global_class = { + "Global", 0, + JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub +}; + +/* Helper functions needed for most JS API routines */ +static JSRuntime * +getRuntime() +{ + return (JSRuntime *)SvIV((SV*)SvRV(perl_get_sv("JS::Runtime::rt", FALSE))); +} + +static JSContext * +getContext() +{ + return (JSContext *)SvIV((SV*)SvRV(perl_get_sv("JS::Context::this", FALSE))); +} + +/* + The following packages are defined below: + JS -- main container for all JS functionality + JS::Runtime -- wrapper around JSRuntime * + JS::Context -- wrapper around JSContext * + JS::Object -- wrapper around JSObject * + */ + +MODULE = JS PACKAGE = JS PREFIX = JS_ +PROTOTYPES: DISABLE + # package JS + + # Most of the functions below have names coinsiding with those of the + # corresponding JS API functions. Thus, they are not commented. +JSRuntime * +JS_NewRuntime(maxbytes) + int maxbytes + +void +JS_DestroyRuntime(rt) + JSRuntime *rt + CODE: + /* + Make sure that the reference count to the runtime is zero. + O.w. this sequence of commands will cause double-deallocation: + $rt = new JS::Runtime(10_000); + $rt1 = $rt; + [exit here] + So both $rt->DESTROY and $rt1->DESTROY will cause runtime destruction. + */ + if(SvREFCNT(ST(0))==0){ + JS_DestroyRuntime(rt); + } + + # package JS::Runtime +MODULE = JS PACKAGE = JS::Runtime PREFIX = JS_ + +JSContext * +JS_NewContext(rt, stacksize) + JSRuntime *rt + int stacksize + + CODE: + { + JSObject *obj; + jsval v; + /* Here we are creating the globals object ourselves. */ + JSContext *cx = JS_NewContext(rt, stacksize); + obj = JS_NewObject(cx, &global_class, NULL, NULL); + JS_InitStandardClasses(cx, obj); + RETVAL = cx; + } + OUTPUT: + RETVAL + +void +JS_DestroyContext(cx) + JSContext *cx + CODE: + /* See the comment about ref. count above */ + if(SvREFCNT(ST(0))==0){ + JS_DestroyContext(cx); + } + + + # package JS::Context +MODULE = JS PACKAGE = JS::Context PREFIX = JS_ + +jsval +JS_eval(cx, bytes) + JSContext *cx + char *bytes + + CODE: + { + jsval rval; + JSObject *obj; + /* Call on the global object */ + if(!JS_EvaluateScript(cx, JS_GetGlobalObject(cx), bytes, strlen(bytes), "Perl", 0, &rval)){ + croak("Perl eval failed"); + XSRETURN_UNDEF; + } + RETVAL = rval; + } + OUTPUT: + RETVAL + + # package JS::Object +MODULE = JS PACKAGE = JS::Object PREFIX = JS_ + + # + # The methods below get used when hash is tied. + # +JSObject * +JS_TIEHASH(class, obj) + char *class + JSObject *obj + CODE: + RETVAL = obj; + OUTPUT: + RETVAL + +jsval +JS_FETCH(obj, key) + JSObject *obj + char *key + PREINIT: + jsval rval; + CODE: + { + /*printf("in FETCH\n");*/ + JS_GetProperty(getContext(), obj, key, &rval); + RETVAL = rval; + } + OUTPUT: + RETVAL + +void +JS_STORE(obj, key, value) + JSObject *obj + char *key + jsval value + CODE: + { + /*printf("In STORE\n");*/ + JS_SetProperty(getContext(), obj, key, &value); + } + +void +JS_DELETE(obj, key) + JSObject *obj + char *key + CODE: + { + /*printf("In DELETE\n");*/ + JS_DeleteProperty(getContext(), obj, key); + } + +void +JS_CLEAR(obj) + JSObject *obj + CODE: + { + /*printf("In CLEAR\n");*/ + JS_ClearScope(getContext(), obj); + } + +int +JS_EXISTS(obj, key) + JSObject *obj + char *key + CODE: + { + jsval v; + + /*printf("In EXISTS\n");*/ + JS_LookupProperty(getContext(), obj, key, &v); + RETVAL = !JSVAL_IS_VOID(v); + } + OUTPUT: + RETVAL diff --git a/mozilla/js/src/perlconnect/PerlConnect.dsp b/mozilla/js/src/perlconnect/PerlConnect.dsp new file mode 100644 index 00000000000..6885bcf7927 --- /dev/null +++ b/mozilla/js/src/perlconnect/PerlConnect.dsp @@ -0,0 +1,104 @@ +# Microsoft Developer Studio Project File - Name="PerlConnect" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=PerlConnect - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "PerlConnect.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "PerlConnect.mak" CFG="PerlConnect - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "PerlConnect - Win32 Release" (based on\ + "Win32 (x86) Dynamic-Link Library") +!MESSAGE "PerlConnect - Win32 Debug" (based on\ + "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "PerlConnect - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 + +!ELSEIF "$(CFG)" == "PerlConnect - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "d:\opc\ns\js\ref" /I "$(PERL_SRC)" /I "$(PERL_SRC)\win32" /I "$(PERL_SRC)\win32\include" /I "." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "PERLCONNECT" /D "JSFILE" /D "XP_PC" /FR /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 js32.lib perl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /subsystem:windows /dll /pdb:none /debug /machine:I386 /out:"C:\DLLs\PerlConnect.dll" /implib:"PerlConnect.lib" /libpath:"d:\opc\ns\js\ref\Debug" /libpath:"$(PERL_SRC)" +# SUBTRACT LINK32 /verbose + +!ENDIF + +# Begin Target + +# Name "PerlConnect - Win32 Release" +# Name "PerlConnect - Win32 Debug" +# Begin Source File + +SOURCE=.\jsperl.c +# End Source File +# Begin Source File + +SOURCE=.\jsperl.h +# End Source File +# Begin Source File + +SOURCE=.\jsperlpvt.h +# End Source File +# End Target +# End Project diff --git a/mozilla/js/src/perlconnect/PerlConnect.dsw b/mozilla/js/src/perlconnect/PerlConnect.dsw new file mode 100644 index 00000000000..0f45a629454 --- /dev/null +++ b/mozilla/js/src/perlconnect/PerlConnect.dsw @@ -0,0 +1,59 @@ +Microsoft Developer Studio Workspace File, Format Version 5.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "JS"=.\JS.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name PerlConnect + End Project Dependency +}}} + +############################################################################### + +Project: "PerlConnect"=.\PerlConnect.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "PerlConnectShell"=.\PerlConnectShell.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name PerlConnect + End Project Dependency +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/mozilla/js/src/perlconnect/PerlConnectShell.dsp b/mozilla/js/src/perlconnect/PerlConnectShell.dsp new file mode 100644 index 00000000000..e93c37b1ccf --- /dev/null +++ b/mozilla/js/src/perlconnect/PerlConnectShell.dsp @@ -0,0 +1,90 @@ +# Microsoft Developer Studio Project File - Name="PerlConnectShell" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=PerlConnectShell - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "PerlConnectShell.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "PerlConnectShell.mak" CFG="PerlConnectShell - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "PerlConnectShell - Win32 Release" (based on\ + "Win32 (x86) Console Application") +!MESSAGE "PerlConnectShell - Win32 Debug" (based on\ + "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "PerlConnectShell - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "PerlConnectShell - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "D:\OPC\ns\js\ref" /I "D:\OPC\ns\js\ref\perlconnect" /I "$(PERL_SRC)" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "PERLCONNECT" /D "JSFILE" /D "_WIN32" /D "XP_PC" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 js32.lib PerlConnect.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"PerlConnectShell.exe" /pdbtype:sept /libpath:"d:\opc\ns\js\ref\Debug" /libpath:"d:\opc\perl_src" /libpath:"." + +!ENDIF + +# Begin Target + +# Name "PerlConnectShell - Win32 Release" +# Name "PerlConnectShell - Win32 Debug" +# Begin Source File + +SOURCE=..\js.c +# End Source File +# End Target +# End Project diff --git a/mozilla/js/src/perlconnect/README.html b/mozilla/js/src/perlconnect/README.html new file mode 100644 index 00000000000..edc74729aa3 --- /dev/null +++ b/mozilla/js/src/perlconnect/README.html @@ -0,0 +1,321 @@ + +
+ + + +p = new Perl('Sys::Hostname', 'Test::Harness')+In addition to creating an interpreter, this will also include the libraries +you pass to the Perl constructor, which is equivalent to use +Sys::Hostname; use Test::Harness. You can always include libraries +explicitly by using p.eval('use Sys::Hostname; use Test::Harness'). +There is also another way to do this: p.use('Sys::Hostname', 'Test::Harness'). +As you can see, TMTOWTDI. Natura lly, you will want to +look at the result of your function calls and eval statements. +Suppose, you do something like this: +
line = p.eval("'-' x 80")+Perl's eval returns the last statement evaluated, unless you explicitly +say return. So now line contains 80 dashes. You can do +similar things with non-scalar data types: +
p.use('Time::gmtime'); ++assigns a Perl array to t. You can print t, use the for/in +syntax to walk through it, compute its lenght, etc. You can read and assign +to individual elements using the standard syntax. However, PerlValues, +that is, the value we get from Perl, don't support all the standard operations, +for isntance, don't expect t.reverse() to work. Hashes can also +be returned from Perl: +
t = p.eval('Time::gmtime::gmtime') // returns +[49,0,4,24,6,98,5,204,0]
info=p.eval("{ver=>$], pid=>$$}")+Now you can look at individual hash keys like this: +
info["ver"] or info.pid+Suppose you want to use Perl to perform pattern-based string replacement. +Here's how you can do it from JavaScript: +
p.eval("\ ++and now +
sub perl_replace(){\ +
my($string, $find, $replace) += @_;\ +
eval(\"\\$string =~ +s/$find/$replace/g;\");\ +
return $string;\ +
}" +
);
p.perl_replace('Quick brown fox jumped over a lazy dog', +'dog', 'rhino')+produces what you'd expect. + +
You can use the same syntax to call procedures defined in modules other +than main. The example with gmtime can be rewritten like +this: +
p.use('Time::gmtime'); ++ You can reference variables exported by modules others than main +like this: +
t = p.Time.gmtime.gmtime() // returns [49,0,4,24,6,98,5,204,0]
a=p.Foo.$bar or a=p.Foo["$bar"] or ++Each of the stetements above returns a either an immediate JS value, for +scalar types, or a PerlValue for compound types. a.type contains +the type of the PerlValue in a. This may change because we +may end up separating Perl hashes and arrays into separate classes. +
a=p.Foo["@bar"]or a=p.Foo["%bar"]
use JS; ++and now you can do something like this: +
$js = new JS();
$js->eval(q/ ++//TODO: more features and examples +Object o = {}; ++/);
o.a = 'p'; +
o.b = 'q'; +
return o;
| Object | + +What it does | +
| Perl | + +Perl Interpreter Object. It's prototype type +is PerlModule, it corresponds to main::. Supports eval, +call, use. | +
| PerlModule | + +Implements JS-like syntax for Perl modules. Doesn't +export provide any methods. path property shown the name of the +Perl module the object represents. | +
| PerlValue | + +Represents a value returned from eval, +call, or obtained by using the subscript notation (p.Foo["@bar"]). +Its Perl type is stored in the type property. | +
| Package | + +What it contains | +
| JS | + +Doesn't not do anything in particular at this +point except defining a constuctor. So one can say $js = new +JS(), which will create a new runtime, add a context to it and return +that Context. JS also defines a bunch of private functions called from +C by PerlConnect. They are not exposed by default, but pushed onto @EXPORT_OK +array instead. | +
| JS::Runtime | + +Corresponds to JSRuntime* struct. Provides +a constructor and destructor. The destructor is invoked automatically, +so you don't have to worry about Runtime deallocation. Constructor syntax +is the following: $rt = new JS::Runtime(10_000), where +the parameter is the same number you pass to JS_NewRuntime. There +are many private functions created in JS.xs that are not exported +by default. | +
| JS::Context | + +Corresponds to JSContext* struct. Provides +a constructor and destructor. The destructor is invoked automatically, +so you don't have to worry about Context deallocation. Constructor syntax +is the following: $rt = new JS::Context($rt, 1_000), where +the parameter is the same number you pass to JS_NewContext. There +are many private functions created in JS.xs that are not exported +by default. | +
| JS::Object | + +Corresponds to JSObject* struct. There is not that much here +yet. This object is intended as a wrapper around the JSObject* stuct. +Support for tying hashes and possibly arrays with JS::Objects +is coming. | +
| [JS::Array] | + +I am not quite sure if this is needed. One might probably get away +with just JS::Object defined. If it's implemented, it will be +very much similar to JS::Object above. | +
All the modules above follow the convention of storing the variable +they return in the $this variable of the current class. So $JS::Context::this +will always be the last context created. Currently, this is where JS +API function that require contexts get it. +