Index: ossp-pkg/js/src/perlconnect/Makefile.ref RCS File: /v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/Makefile.ref,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/Makefile.ref,v' | diff -u - /dev/null -L'ossp-pkg/js/src/perlconnect/Makefile.ref' 2>/dev/null --- ossp-pkg/js/src/perlconnect/Makefile.ref +++ /dev/null 2025-04-08 01:37:11.000000000 +0200 @@ -1,152 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Mozilla Communicator client code, released -# March 31, 1998. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1999 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -# -# Makefile for the perlconnect extension to javascript. -# - -# -# Stolen with apologies to liveconnect. -# - -DEPTH = .. - -# -# XCFLAGS may be set in the environment or on the gmake command line -# -CC = cc - -CFLAGS += $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES) \ - -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DX86_LINUX \ - -DDEBUG -DDEBUG_livshits -Dbool=char -DHAS_BOOL -DGCC_OPT_BUG -D_XOPEN_SOURCE - -# -DJSFILE $(XCFLAGS)\ -# -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DX86_LINUX - - -LDFLAGS += -lm $(XLDFLAGS) - -# -# Ask perl what flags it was built with, so we can build js with similar flags -# and link properly. Viva gmake. -# -PERLCFLAGS := $(shell perl -MExtUtils::Embed -e ccopts) -PERLLDFLAGS := $(shell perl -MExtUtils::Embed -e ldopts) - -# perl erroneously reports compiler flag -rdynamic (interpreted by ld -# as -r) when it really meant -export-dynamic. -PERLLDFLAGS := $(subst -rdynamic,-export-dynamic,$(PERLLDFLAGS)) - -CFLAGS += $(PERLCFLAGS) -LDFLAGS += $(PERLLDFLAGS) - - -# For purify -PURE_CFLAGS = -DXP_UNIX $(OPTIMIZER) $(PURE_OS_CFLAGS) $(DEFINES) \ - $(INCLUDES) $(XCFLAGS) - -# -# perlconnect file lists -# -PC_HFILES = \ - jsperl.h \ - $(NULL) - -HFILES = $(PC_HFILES) - -PC_CFILES = \ - jsperl.c \ - JS.c \ - $(NULL) - -#JS.c: JS.xs typemap -# perl jsperlbuild.pl - -LIB_CFILES = $(PC_CFILES) - -PROG_FILE = js - -include $(DEPTH)/config.mk - -# uncomment this if we decide we need a local config dir... -#include config/$(OS_CONFIG).mk - -INCLUDES += -I. -I.. -I../$(OBJDIR) - -ifdef USE_MSVC -OTHER_LIBS += $(DEPTH)/fdlibm/$(OBJDIR)/fdlibm.lib -else -OTHER_LIBS += -L$(DEPTH)/fdlibm/$(OBJDIR) -lfdm -endif - -ifdef JS_THREADSAFE -ifdef USE_MSVC -OTHER_LIBS += $(DEPTH)/../../dist/$(OBJDIR)/lib/nspr3.lib -else -OTHER_LIBS += -L$(DEPTH)/../../dist/$(OBJDIR)/lib -lnspr3 -endif -endif - -ifdef USE_MSVC -LIBRARY = $(OBJDIR)/JS.lib -SHARED_LIBRARY = $(OBJDIR)/JS.dll -PROGRAM = $(OBJDIR)/jsperl.exe -else -LIBRARY = $(OBJDIR)/JS.a -SHARED_LIBRARY = $(OBJDIR)/JS.so -PROGRAM = $(OBJDIR)/jsperl -endif - -include $(DEPTH)/rules.mk - -ifdef USE_MSVC -$(OBJDIR)/$(PROG_FILE)_lc.obj: ../$(PROG_FILE).c - @$(MAKE_OBJDIR) - $(CC) -Fo$@ -c $(CFLAGS) -DPERLCONNECT ../$(PROG_FILE).c - -$(PROGRAM): $(OBJDIR)/$(PROG_FILE)_lc.obj $(LIBRARY) - link.exe -out:"$@" /pdb:"$(OBJDIR)/$(@F:.exe=.pdb)" $(EXE_LINK_FLAGS) ../$(OBJDIR)/js32.lib $? -else -$(OBJDIR)/$(PROG_FILE).o: ../$(PROG_FILE).c - @$(MAKE_OBJDIR) - $(CC) -o $@ -c $(CFLAGS) -DPERLCONNECT ../$(PROG_FILE).c - -$(PROGRAM): $(OBJDIR)/$(PROG_FILE).o - @$(MAKE_OBJDIR) - $(CC) -o $@ $(CFLAGS) $+ $(LIBRARY) ../$(OBJDIR)/libjs.a $(LDFLAGS) $(OTHER_LIBS) -endif Index: ossp-pkg/js/src/perlconnect/README.html RCS File: /v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/README.html,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/README.html,v' | diff -u - /dev/null -L'ossp-pkg/js/src/perlconnect/README.html' 2>/dev/null --- ossp-pkg/js/src/perlconnect/README.html +++ /dev/null 2025-04-08 01:37:11.000000000 +0200 @@ -1,345 +0,0 @@ - - - - - - - PerlConnect Documentation - - - - -
-

-PERLCONNECT  AND  JS.PM

- -
USER-LEVEL DOCUMENTATION -
Vladimir Livshits -
-
- -
    -
  1. -Update history
  2. - -
  3. -Overview
  4. - -
  5. -Features
  6. - -
  7. -Design
  8. - -
  9. -Installation
  10. - -
  11. -Current Limitations and Further Work
  12. -
- -

-Update History

- - - -

-Overview

-PerlConnect provides glue for the developer between JavaScript and Perl. -It currently consists of two parts, PerlConnect implemented in C and JS.pm, -a Perl module written using XSUBs. PerlConnect and JS.pm allow calling -Perl from JS and JS from Perl, respectively. Whenever possible, it is attempted -to achieve the maximum level of transparency for calling one language -from the other. This is done by converting values between the two languages, -creating wrappers around objects, and emulating the standard language syntax. -

-PerlConnect Features

-PerlConnect allows running a Perl interpreter concurrently with your JavaScript -embedding and executing Perl commands from JavaScript. You usually need -to create a Perl interpreter by doing something like this: -
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. -

Note: If the statements above fail on you saying something about -libraries not found in the search path, you need to make sure the modules -PerlConnect uses, JS.pm and PerlConnect.pm live in some directory accessible -from the search path. Search path can be set by adjusting the value of PERLLIB -and PERL5LIB environment variables. See  installation -for more details. -

Note: Despite the illusion p = new Perl(...) syntax might create, -there is actually only one version of the Perl interpreter running. I.e. -if you create two interpreters like this: -

p = new Perl; q = new Perl; -
p.eval("$a='ha-'x20");
-Now you'll see that q["$a"] will give you $a's value -from p. -

Naturally, 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'); -
t = p.eval('Time::gmtime::gmtime')    // returns -[49,0,4,24,6,98,5,204,0]
-assigns a Perl array to t. You can print t, use the for/in -syntax to walk through it, compute its length, 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 instance, don't expect t.reverse() to work. Hashes can also -be returned from Perl: -
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("\ -
    sub perl_replace(){\ -
        my($string, $find, $replace) -= @_;\ -
        eval(\"\\$string =~ -s/$find/$replace/g;\");\ -
        return $string;\ -
    }" -
);
-and now -
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'); -
t = p.Time.gmtime.gmtime()    // returns [49,0,4,24,6,98,5,204,0]
- You can reference variables exported by modules other than main -like this: -
a=p.Foo.$bar or a=p.Foo["$bar"] or -
a=p.Foo["@bar"]or a=p.Foo["%bar"]
-Each of the above statements return 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. -

-JS.pm Features

-JS.pm is much less tested then PerlConnect. You should be able to -do similar things from Perl. Just say -
use JS; -
$js = new JS();
-and now you can do something like this: -
$js->eval(q/ -
Object o = {}; -
o.a = 'p'; -
o.b = 'q'; -
return o;
-/);
-Note: Please see test.js and test.pl, test scripts that test and -demonstrate various features of PerlConnect and JS.pm, respectively. They -will help get you started. -

-PerlConnect Design

-PerlConnect is written in C. It uses both JavaScript and Perl APIs and -implements a mapping between the two. The following JavaScript objects -are implemented by PerlConnect: -
  -
- - - - - - - - - - - - - - - - - - - - - - - -
ObjectWhat it does
PerlPerl Interpreter Object. Its prototype type -is PerlModule, it corresponds to main::. Supports eval, -call, -use.
PerlModuleImplements JS-like syntax for Perl modules. Doesn't -export provide any methods. path property shows the name of the -Perl module the object represents.
PerlValueRepresents 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.
- -

See comments in the code, jsperl.c and JS.pm for more -info. -
Note:  PerlConnect heavily relies on PerlConnect.pm, which -does some background magic for it. PerlConnect.pm should not be -used. Use JS.pm instead. -

-JS.pm Design

-JSConnect is written using XSUBs, the language in which Perl extensions -are implemented. See the output of man perlxs/perlguts/perlembed/perlxstut  -for more details. The source files are JS.xs and typemap. -After processing them using the XSUBs compiler, xsubpp, the resulting -C file should be compiled into a DLL. See JS.xs for more details -on how to to run the XSUBS compiler. You will need a sufficiently recent -version of Perl to run JS.pm successfully. JS.pm provides bootstrapping -mechanism to load this DLL. -

The following Perl packages (objects) are implemented: -
  -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PackageWhat it contains
JSDoesn't do anything in particular at this -point except defining a constructor. 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::RuntimeCorresponds 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::ContextCorresponds 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::ObjectCorresponds to JSObject* struct. There is not that much here -yet. This object is intended as a wrapper around the JSObject* struct. -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. -

-PerlConnect Installation

-PerlConnect requires js/src and the Perl libraries and headers. -The only js/src file that must be included in jsapi.h in -the top level directory. You need to compile it together with Perl libraries. -Refer to the perlembed man page for more details. -
On WINNT: -
There are MSDEV Workspace and project files in the main PerlConnect -directory. There are three projects included in the PerlConnect workspace: -JS, PerlConnect and PerlConnectShell. You can use the latter to test PerlConnect. -You will probably need to adjust the library and include paths. Set PERL_SRC -environment variable to point to the directory where you unpacked and compiled -Perl sources. It is assumed that the directory structure is more or less -fixed, that is, you have PerlConnect in -js/src/perlconnect. PerlConnect -project produces PerlConnect.dll, you should make sure it and -perl.dll are in your path for PerlConnectShell to work. -

JS also builds a DLL, JS.dll which is supposed to reside where -Perl's DynaLoader can find it. On my machine I put it under c:\perl\lib\auto\JS\JS.dll. -You can also put it in c:\perl\lib\. You can probably adjust PERLLIB -to achieve the desired result. See Perl's DynaLoader documentation for -more info on how dynamic libraries are found. -

On UNIX: -
We are currently working on a UNIX makefile. Please contact -me for more details. -

-On the MAC:

-We never really thought of supporting the Mac. If anyone is really interested -in seeing Mac support, drop me a line. -

-Current Limitations and Further Work

- -
    -
  1. -Perl variables currently can't be assigned to, that is, p["$a"]=100 -doesn't do anything.
  2. - -
  3. -You can only have one interpreter running at a time. Despite the fact that -you can create multiple Perl objects on JavaScript, they all share the -same namespace. We can probably use Safe.pm to implement independent -namespaces.
  4. - -
  5. -Module name resolution reports an error only when you try to evaluate -the last element of the resolution chain. Here is what I mean: if you reference -p.Foo.Bar.Var and For or Bar don't exist, it -will only complain that p.Foo.Bar.Var is not a valid variable. Perl 5.005 -provides exists Foo::{Bar::} to check if Foo::Bar is a valid package.
  6. - -
  7. -Dynamic loading of the Perl interpreter only if it is required.
  8. - -
  9. -Recursive printing of Perl's arrays and hashes can be added. See Data::Dumper.pm
  10. - -
  11. -Full support for tied hashes and arrays in Perl
  12. - -
  13. -Calling JavaScript functions and accessing variables from Perl. JavaScript -calling syntax support using AUTOLOADing.
  14. - -
  15. -JS can be made a directory with Object.pm, Context.pm, -etc. in it. See how C or Tk are organized on CPAN
  16. - -
  17. -Distribution model for JS.pm. Perl provides something by default. See h2xs -man page, for example.
  18. -
- - - Index: ossp-pkg/js/src/perlconnect/bg.jpg RCS File: /v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/bg.jpg,v co -q -kk -p'1.2' '/v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/bg.jpg,v' | diff -u /dev/null - -L'ossp-pkg/js/src/perlconnect/bg.jpg' 2>/dev/null Binary files ossp-pkg/js/src/perlconnect/bg.jpg and - differ Index: ossp-pkg/js/src/perlconnect/jsperlbuild.pl RCS File: /v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/jsperlbuild.pl,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/jsperlbuild.pl,v' | diff -u - /dev/null -L'ossp-pkg/js/src/perlconnect/jsperlbuild.pl' 2>/dev/null --- ossp-pkg/js/src/perlconnect/jsperlbuild.pl +++ /dev/null 2025-04-08 01:37:11.000000000 +0200 @@ -1,81 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Mozilla Communicator client code, released -# March 31, 1998. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1999 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -# -# Helper perl script to abstract the location of xsubpp -# - -# Thanks to Dave Neuer for the original -# version of this file. Entered as NPL with his permission. - -use File::Find; -use Cwd; - -$notfound = 1; - -foreach(@INC){ - next if /^\.$/; - if(-e $_){ - find(\&find_ExtUtils, $_); - } -} - -if(-e $xsubpp && -e $typemap){ - $res = `perl $xsubpp -typemap $typemap -typemap typemap JS.xs > JS.c`; - if(-e "JS.c"){ - print "Successfuly built JS.c\n"; - exit(0); - } - else{ - die("Couldn't build JS.c: $res"); - } -} -else{ - die("Couldn't locate files neccessary for building JS.c"); -} - -sub find_ExtUtils{ - if($notfound){ - if($File::Find::dir =~ /ExtUtils/){ - my $path = cwd; - $xsubpp = $path . "/xsubpp"; - $typemap = $path . "/typemap"; - undef $notfound; - } - } -} Index: ossp-pkg/js/src/perlconnect/test.js RCS File: /v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/test.js,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/test.js,v' | diff -u - /dev/null -L'ossp-pkg/js/src/perlconnect/test.js' 2>/dev/null --- ossp-pkg/js/src/perlconnect/test.js +++ /dev/null 2025-04-08 01:37:11.000000000 +0200 @@ -1,73 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code, released - * March 31, 1998. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/******************************************************************************* -* PerlConnect test file. Some primitive testing in "silent mode" -- that is, -* you should be able to run -* perlconnectshell test.js -* without any error messages. See README.html for more info. -*******************************************************************************/ - -// Init -assert(p = new Perl('Sys::Hostname', 'Time::gmtime'), "Perl initialization failed"); -// Simple eval -assert(p.eval("'-' x 3") == '---', "Wrong value returned from eval"); - -assert(p.eval("undef()")==undefined, "Wrong value returned from eval"); -// Arrays -assert(a=p.eval("(1, 2, 3);"), "eval failed, 1"); -assert(a[1]==2, "Wrong value"); -assert(a.length==3, "Wrong length"); -// Hashes -assert(h=p.eval("{'one'=>1, 'two'=>2};"), "eval failed, 2"); -assert(h["two"]==2, "Wrong value"); -// Func. call -assert(p.eval("&hostname()") == p.call("hostname"), "Wrong value returned from eval or call"); -// Complex call -assert(b=p.Time.gmtime.gmtime(), "call failed"); -assert(b.length==9, "Wrong length") -// Variables -// Scalars -assert(p.eval("$a = 100; $b = 'abc';"), "eval failed, 3"); -assert(p.$a ==100, "Wrong variable value, 1"); -assert(p["$b"] == 'abc', "Wrong variable value, 2"); - -/* Auxilary function */ -function assert(cond, msg) -{ - cond || print("Error: " + msg+"\n"); -} // assert Index: ossp-pkg/js/src/perlconnect/test.pl RCS File: /v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/test.pl,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/js/src/perlconnect/Attic/test.pl,v' | diff -u - /dev/null -L'ossp-pkg/js/src/perlconnect/test.pl' 2>/dev/null --- ossp-pkg/js/src/perlconnect/test.pl +++ /dev/null 2025-04-08 01:37:11.000000000 +0200 @@ -1,244 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Mozilla Communicator client code, released -# March 31, 1998. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -# -# Test file for JS.pm -# - -############################################################ -# support packages for test script -############################################################ - -############################################################ -# Fotrik -package Father; - -sub old_meth { - return "Father::old_meth"; -} - - -############################################################ -# Synacek -package Son; -use vars qw( @ISA ); -@ISA = qw( Father ); - -sub new { - my $class = shift; - $class = ref $class || $class; - my $self = {}; - bless $self, $class; - return $self; -} - -sub new_meth { - return "Son::new_meth"; -} - -############################################################ -# Proxy -package Proxy; - -sub new { - my $class = shift; - $class = ref $class || $class; - my $self = { property => shift }; - bless $self, $class; - return $self; -} - -sub getObj { - my $ret = new Son(); - return $ret; -} - -sub getValue { - my $self = shift; - return $self->{ property }; -} - -sub getArray { - my $self = shift; - return [34, 35, 36, 37, 38]; -} - -sub getHash { - my $self = shift; - return { testkey1 => 'testvalue1', - testkey2 => 'testvalue2', - testkey3 => 'testvalue3', }; -} - -############################################################ -# main part of the test script -############################################################ - -package main; -use JS; - -BEGIN { - $| = 1; print "1..12\n"; -} - -END - { print "not ok 1\n" unless $loaded; } - -$loaded = 1; -print "ok 1\n"; - -use strict; #no typos, please - -my $rt = new JS(1_204 ** 2); -my $cx = $rt->createContext(8 * 1_024); - -my $jsval; -my $testc = 1; #testcounter -############################################################ -# the simplest test -$testc++; -$jsval = $cx->eval('6;'); -print $jsval == 6 ? "ok $testc\n" : "not ok $testc\n"; #2 - -############################################################ -#second very simple test -$testc++; -$jsval = $cx->eval('"hallo";'); -print $jsval eq "hallo" ? "ok $testc\n" : "not ok $testc\n"; #3 - -############################################################ -# third very simple test -$testc++; -$jsval = $cx->eval("1.23"); -print $jsval == 1.23 ? "ok $testc\n" : "not ok $testc\n"; #4 - -############################################################ -#undef is little bit tricky -$testc++; -$jsval = $cx->eval('undefined'); -print ! defined $jsval ? "ok $testc\n" : "not ok $testc\n"; #5 - -############################################################ -#can ve tie js objects? (generally to hash, Arrays to arrays too) -$testc++; -$jsval = $cx->eval('foo = new Object(); foo.prop = 11; foo;'); -my %hash; -#read js property -tie %hash, 'JS::Object', $jsval; -print $hash{prop} == 11 ? "ok $testc\n" : "not ok $testc\n"; #6 - -############################################################ -#set js propertry -$testc++; -$hash{prop2} = 2; -$jsval = $cx->eval('foo.prop2;'); -print $jsval == 2 ? "ok $testc\n" : "not ok $testc\n"; #7 - -############################################################ -#tie array -$testc++; -my @arr; -$jsval = $cx->eval('arr = new Array(); arr[0] = 0; arr[1] = 1; arr;'); -tie @arr, "JS::Object", $jsval; -print ((($#arr == 1) && ($arr[1] == 1)) ? "ok $testc\n" : "not ok $testc\n");#8 - -############################################################ -# object delegation test -$testc++; -$cx->createObject(new Proxy("init_value"), "perlobj", - { getObj => \&Proxy::getObj, - getValue => \&Proxy::getValue, - getArray => \&Proxy::getArray, - getHash => \&Proxy::getHash, - }); -$jsval = $cx->eval("perlobj.getValue()"); -print $jsval eq "init_value" ? "ok $testc\n" : "not ok $testc\n"; #9 - -############################################################ -# perl object returned to js -$testc++; -$jsval = $cx->eval("po = perlobj.getObj(); po.new_meth()"); -print $jsval eq "Son::new_meth" ? "ok $testc\n" : "not ok $testc\n"; #10 - -############################################################ -# and what about inherited methods? -$testc++; -$jsval = $cx->eval("po.old_meth()"); -print $jsval eq "Father::old_meth" ? "ok $testc\n" : "not ok $testc\n"; #11 - -############################################################ -# pass an array, check the element -$testc++; -$jsval = $cx->eval("parr = perlobj.getArray(); parr[2];"); -print $jsval == 36 ? "ok $testc\n" : "not ok $testc\n"; #12 - -############################################################ -# check the array length -$testc++; -$jsval = $cx->eval("parr.length"); -print $jsval == 5 ? "ok $testc\n" : "not ok $testc\n"; #13 - -############################################################ -# pass a hash, check the element -$testc++; -$jsval = $cx->eval("phash = perlobj.getHash(); phash.testkey1;"); -print $jsval eq 'testvalue1' ? "ok $testc\n" : "not ok $testc\n"; #14 - -############################################################ -# error test -$testc++; -my $line; -my $err; -sub js_ErrorReporter { - my ($msg, $file, $line, $linebuf, $token) = @_; - $err = "line $line $msg"; -} -$cx->setErrorReporter( \&js_ErrorReporter ); -$cx->eval("x = 2 + 4;\nx.method()\n"); -print $err =~ /^line 1/ ? "ok $testc\n" : "not ok $testc\n"; #15 - -############################################################ -# cleanup -# so far we have to undef context value, to make sure, -# it is disposed before runtime -undef $cx; -undef $rt; - -__END__ - -