OSSP CVS Repository

ossp - Check-in [5635]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 5635
Date: 2006-Aug-03 15:19:20 (local)
2006-Aug-03 13:19:20 (UTC)
User:rse
Branch:
Comment: Add optional Dynamic Shared Object (DSO) support (see src/jsdso.[ch]). This comes in two flavors:

1. Provide two public C API functions... JSBool JS_DSOLoad (JSContext *cx, int *id, const char *filename); JSBool JS_DSOUnload (JSContext *cx, int id); ...as an ultra-thin wrapper around the POSIX dlopen(3) API. It especially mimics the BSD RTLD behaviour of calling pre-defined functions (mandatory "js_DSO_load" and optional "js_DSO_unload") inside the DSO after/before the dlopen/dlclose calls. This allows the DSOs to perform their init/shutdown actions.

2. Provide a small JavaScript global object "DSO" which binds the two public DSO C API functions into the JavaScript language as "DSO.load" and "DSO.unload". The "DSO" object can be created by the friend C API function js_InitDSOClass(). This function is used by the command-linne interface "js" by default.

As a result the OSSP Mozilla JavaScript engine is now able to dynamically load C extensions similar to what other programming languages provide since a longer time.

Tickets:
Inspections:
Files:
ossp-pkg/js/ChangeLog      1.28 -> 1.29     23 inserted, 0 deleted
ossp-pkg/js/Makefile.in      1.26 -> 1.27     1 inserted, 0 deleted
ossp-pkg/js/configure.ac      1.18 -> 1.19     13 inserted, 0 deleted
ossp-pkg/js/devtool.conf      1.9 -> 1.10     1 inserted, 0 deleted
ossp-pkg/js/src/js.c      1.6 -> 1.7     7 inserted, 0 deleted
ossp-pkg/js/src/jsapi.c      1.12 -> 1.13     10 inserted, 0 deleted
ossp-pkg/js/src/jsatom.c      1.2 -> 1.3     8 inserted, 0 deleted
ossp-pkg/js/src/jsatom.h      -> 1.2     3 inserted, 0 deleted
ossp-pkg/js/src/jsdso.c      added-> 1.1
ossp-pkg/js/src/jsdso.h      added-> 1.1

ossp-pkg/js/ChangeLog 1.28 -> 1.29

--- ChangeLog    2006/08/03 12:41:27     1.28
+++ ChangeLog    2006/08/03 13:19:20     1.29
@@ -13,6 +13,29 @@
 
   Changes between 1.6.20060731 and 1.6.200608xx (2006-07-31 to 2006-08-xx)
 
+   o Add optional Dynamic Shared Object (DSO) support (see src/jsdso.[ch]).
+     This comes in two flavors:
+
+     1. Provide two public C API functions...
+        JSBool JS_DSOLoad   (JSContext *cx, int *id, const char *filename);
+        JSBool JS_DSOUnload (JSContext *cx, int  id);
+        ...as an ultra-thin wrapper around the POSIX dlopen(3) API. It
+        especially mimics the BSD RTLD behaviour of calling pre-defined
+        functions (mandatory "js_DSO_load" and optional "js_DSO_unload")
+        inside the DSO after/before the dlopen/dlclose calls. This
+        allows the DSOs to perform their init/shutdown actions.
+
+     2. Provide a small JavaScript global object "DSO" which binds
+        the two public DSO C API functions into the JavaScript language
+        as "DSO.load" and "DSO.unload". The "DSO" object can be created
+        by the friend C API function js_InitDSOClass(). This function is
+        used by the command-linne interface "js" by default.
+
+     As a result the OSSP Mozilla JavaScript engine is now able to
+     dynamically load C extensions similar to what other programming
+     languages provide since a longer time.
+     [Ralf S. Engelschall <rse@engelschall.com>]
+
    o Be more clean and replace weak "#if JS_HAS_FILE_OBJECT" constructs
      with the stronger "#if defined(JS_HAS_FILE_OBJECT) && (JS_HAS_FILE_OBJECT - 0)"
      as the JS_HAS_FILE_OBJECT can be not defined at all (in contrast to


ossp-pkg/js/Makefile.in 1.26 -> 1.27

--- Makefile.in  2006/07/31 18:09:45     1.26
+++ Makefile.in  2006/08/03 13:19:20     1.27
@@ -95,6 +95,7 @@
                src/jsxdrapi.lo             \
                src/jsxml.lo                \
                src/prmjtime.lo             \
+               src/jsdso.lo                \
                src/fdlibm/e_acos.lo        \
                src/fdlibm/e_asin.lo        \
                src/fdlibm/e_atan2.lo       \


ossp-pkg/js/configure.ac 1.18 -> 1.19

--- configure.ac 2006/08/03 12:41:27     1.18
+++ configure.ac 2006/08/03 13:19:20     1.19
@@ -138,6 +138,19 @@
     CPPFLAGS="$CPPFLAGS -DJS_HAS_FILE_OBJECT"
 fi
 
+dnl #   configure option --with-dso
+AC_ARG_WITH([dso],
+        AS_HELP_STRING([--with-dso], [build without DSO object (allows run-time process extending)]),
+        [ac_cv_with_dso=$withval], [ac_cv_with_dso=no])
+AC_CACHE_CHECK([whether to build with the DSO object], [ac_cv_with_dso], [ac_cv_with_dso=no])
+if test ".$ac_cv_with_dso" = ".yes"; then
+    AC_CHECK_LIB(dl, dlopen)
+    AC_CHECK_HEADER(dlfcn.h, , AC_ERROR([dlopen(3) header <dlfcn.h> required]))
+    AC_CHECK_FUNCS(dlopen dlclose dlerror, , AC_ERROR([dlopen(3) API functions dlopen/dlclose/dlerror required]))
+    CPPFLAGS="$CPPFLAGS -DJS_HAS_DSO_OBJECT"
+    CLI_LDFLAGS="$CLI_LDFLAGS -export-dynamic"
+fi
+
 AC_SUBST(CLI_CFLAGS)
 AC_SUBST(CLI_CPPFLAGS)
 AC_SUBST(CLI_LDFLAGS)


ossp-pkg/js/devtool.conf 1.9 -> 1.10

--- devtool.conf 2006/07/31 17:44:29     1.9
+++ devtool.conf 2006/08/03 13:19:20     1.10
@@ -18,6 +18,7 @@
         --with-editline=/usr/opkg/lib \
         --with-perl=/usr/opkg/bin/perl \
         --with-file \
+        --with-dso \
         --disable-shared \
         "$@"
 


ossp-pkg/js/src/js.c 1.6 -> 1.7

--- js.c 2006/08/03 12:41:28     1.6
+++ js.c 2006/08/03 13:19:20     1.7
@@ -67,6 +67,9 @@
 #if defined(JS_HAS_FILE_OBJECT) && (JS_HAS_FILE_OBJECT - 0) /* OSSP BUGFIX */
 #include "jsfile.h"
 #endif
+#if defined(JS_HAS_DSO_OBJECT) && (JS_HAS_DSO_OBJECT -0)
+#include "jsdso.h"
+#endif
 #endif
 
 #ifdef PERLCONNECT
@@ -2537,6 +2540,10 @@
     if (!js_InitFileClass(cx, glob))
         return 1;
 #endif
+#if defined(JS_HAS_DSO_OBJECT) && (JS_HAS_DSO_OBJECT - 0)
+    if (!js_InitDSOClass(cx, glob))
+        return 1;
+#endif
 #endif
 #endif
     if (!JS_DefineFunctions(cx, glob, shell_functions))


ossp-pkg/js/src/jsapi.c 1.12 -> 1.13

--- jsapi.c      2006/08/03 12:41:28     1.12
+++ jsapi.c      2006/08/03 13:19:20     1.13
@@ -82,6 +82,10 @@
 #include "jsfile.h"
 #endif
 
+#if defined(OSSP) && defined(JS_HAS_DSO_OBJECT) && (JS_HAS_DSO_OBJECT - 0)
+#include "jsdso.h"
+#endif
+
 #if JS_HAS_XML_SUPPORT
 #include "jsxml.h"
 #endif
@@ -1215,6 +1219,9 @@
 #if defined(JS_HAS_FILE_OBJECT) && (JS_HAS_FILE_OBJECT - 0) /* OSSP BUGFIX */
            js_InitFileClass(cx, obj) &&
 #endif
+#if defined(JS_HAS_DSO_OBJECT) && (JS_HAS_DSO_OBJECT - 0)
+           js_InitDSOClass(cx, obj) &&
+#endif
 #endif
            js_InitDateClass(cx, obj);
 }
@@ -1258,6 +1265,9 @@
 #if defined(JS_HAS_FILE_OBJECT) && (JS_HAS_FILE_OBJECT - 0) /* OSSP BUGFIX */
     {js_InitFileClass,              ATOM_OFFSET(File)},
 #endif
+#if defined(JS_HAS_DSO_OBJECT) && (JS_HAS_DSO_OBJECT - 0)
+    {js_InitDSOClass,               ATOM_OFFSET(DSO)},
+#endif
     {NULL,                          0}
 };
 


ossp-pkg/js/src/jsatom.c 1.2 -> 1.3

--- jsatom.c     2006/07/24 19:53:01     1.2
+++ jsatom.c     2006/08/03 13:19:20     1.3
@@ -144,6 +144,10 @@
 const char js_xml_str[]             = "xml";
 #endif
 
+#if defined(OSSP) && defined(JS_HAS_DSO_OBJECT) && (JS_HAS_DSO_OBJECT - 0)
+const char js_DSO_str[]             = "DSO";
+#endif
+
 #ifdef NARCISSUS
 const char js_call_str[]             = "__call__";
 const char js_construct_str[]        = "__construct__";
@@ -363,6 +367,10 @@
     FROB(tagcAtom,                js_tagc_str);
     FROB(xmlAtom,                 js_xml_str);
 #endif
+    
+#if defined(OSSP) && defined(JS_HAS_DSO_OBJECT) && (JS_HAS_DSO_OBJECT - 0)
+    FROB(DSOAtom,                 js_DSO_str);
+#endif
 
 #ifdef NARCISSUS
     FROB(callAtom,                js_call_str);


ossp-pkg/js/src/jsatom.h -> 1.2

*** /dev/null    Sat Nov 23 01:42:00 2024
--- -    Sat Nov 23 01:42:05 2024
***************
*** 0 ****
--- 1,471 ----
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+  *
+  * ***** 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 of 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 ***** */
+ 
+ #ifndef jsatom_h___
+ #define jsatom_h___
+ /*
+  * JS atom table.
+  */
+ #include <stddef.h>
+ #include "jstypes.h"
+ #include "jshash.h" /* Added by JSIFY */
+ #include "jsapi.h"
+ #include "jsprvtd.h"
+ #include "jspubtd.h"
+ 
+ #ifdef JS_THREADSAFE
+ #include "jslock.h"
+ #endif
+ 
+ JS_BEGIN_EXTERN_C
+ 
+ #define ATOM_PINNED     0x01            /* atom is pinned against GC */
+ #define ATOM_INTERNED   0x02            /* pinned variant for JS_Intern* API */
+ #define ATOM_MARK       0x04            /* atom is reachable via GC */
+ #define ATOM_HIDDEN     0x08            /* atom is in special hidden subspace */
+ #define ATOM_NOCOPY     0x40            /* don't copy atom string bytes */
+ #define ATOM_TMPSTR     0x80            /* internal, to avoid extra string */
+ 
+ struct JSAtom {
+     JSHashEntry         entry;          /* key is jsval, value keyword info or
+                                            unhidden atom if ATOM_HIDDEN */
+     uint32              flags;          /* pinned, interned, and mark flags */
+     jsatomid            number;         /* atom serial number and hash code */
+ };
+ 
+ #define ATOM_KEY(atom)            ((jsval)(atom)->entry.key)
+ #define ATOM_IS_OBJECT(atom)      JSVAL_IS_OBJECT(ATOM_KEY(atom))
+ #define ATOM_TO_OBJECT(atom)      JSVAL_TO_OBJECT(ATOM_KEY(atom))
+ #define ATOM_IS_INT(atom)         JSVAL_IS_INT(ATOM_KEY(atom))
+ #define ATOM_TO_INT(atom)         JSVAL_TO_INT(ATOM_KEY(atom))
+ #define ATOM_IS_DOUBLE(atom)      JSVAL_IS_DOUBLE(ATOM_KEY(atom))
+ #define ATOM_TO_DOUBLE(atom)      JSVAL_TO_DOUBLE(ATOM_KEY(atom))
+ #define ATOM_IS_STRING(atom)      JSVAL_IS_STRING(ATOM_KEY(atom))
+ #define ATOM_TO_STRING(atom)      JSVAL_TO_STRING(ATOM_KEY(atom))
+ #define ATOM_IS_BOOLEAN(atom)     JSVAL_IS_BOOLEAN(ATOM_KEY(atom))
+ #define ATOM_TO_BOOLEAN(atom)     JSVAL_TO_BOOLEAN(ATOM_KEY(atom))
+ 
+ /*
+  * Return a printable, lossless char[] representation of a string-type atom.
+  * The lifetime of the result extends at least until the next GC activation,
+  * longer if cx's string newborn root is not overwritten.
+  */
+ extern JS_FRIEND_API(const char *)
+ js_AtomToPrintableString(JSContext *cx, JSAtom *atom);
+ 
+ #define ATOM_KEYWORD(atom)        ((struct keyword *)(atom)->entry.value)
+ #define ATOM_SET_KEYWORD(atom,kw) ((atom)->entry.value = (kw))
+ 
+ struct JSAtomListElement {
+     JSHashEntry         entry;
+ };
+ 
+ #define ALE_ATOM(ale)   ((JSAtom *) (ale)->entry.key)
+ #define ALE_INDEX(ale)  ((jsatomid) JS_PTR_TO_UINT32((ale)->entry.value))
+ #define ALE_JSOP(ale)   ((JSOp) (ale)->entry.value)
+ #define ALE_VALUE(ale)  ((jsval) (ale)->entry.value)
+ #define ALE_NEXT(ale)   ((JSAtomListElement *) (ale)->entry.next)
+ 
+ #define ALE_SET_ATOM(ale,atom)  ((ale)->entry.key = (const void *)(atom))
+ #define ALE_SET_INDEX(ale,index)((ale)->entry.value = JS_UINT32_TO_PTR(index))
+ #define ALE_SET_JSOP(ale,op)    ((ale)->entry.value = JS_UINT32_TO_PTR(op))
+ #define ALE_SET_VALUE(ale,val)  ((ale)->entry.value = (JSHashEntry *)(val))
+ #define ALE_SET_NEXT(ale,link)  ((ale)->entry.next = (JSHashEntry *)(link))
+ 
+ struct JSAtomList {
+     JSAtomListElement   *list;          /* literals indexed for mapping */
+     JSHashTable         *table;         /* hash table if list gets too long */
+     jsuint              count;          /* count of indexed literals */
+ };
+ 
+ #define ATOM_LIST_INIT(al)  ((al)->list = NULL, (al)->table = NULL,           \
+                              (al)->count = 0)
+ 
+ #define ATOM_LIST_SEARCH(_ale,_al,_atom)                                      \
+     JS_BEGIN_MACRO                                                            \
+         JSHashEntry **_hep;                                                   \
+         ATOM_LIST_LOOKUP(_ale, _hep, _al, _atom);                             \
+     JS_END_MACRO
+ 
+ #define ATOM_LIST_LOOKUP(_ale,_hep,_al,_atom)                                 \
+     JS_BEGIN_MACRO                                                            \
+         if ((_al)->table) {                                                   \
+             _hep = JS_HashTableRawLookup((_al)->table, _atom->number, _atom); \
+             _ale = *_hep ? (JSAtomListElement *) *_hep : NULL;                \
+         } else {                                                              \
+             JSAtomListElement **_alep = &(_al)->list;                         \
+             _hep = NULL;                                                      \
+             while ((_ale = *_alep) != NULL) {                                 \
+                 if (ALE_ATOM(_ale) == (_atom)) {                              \
+                     /* Hit, move atom's element to the front of the list. */  \
+                     *_alep = ALE_NEXT(_ale);                                  \
+                     ALE_SET_NEXT(_ale, (_al)->list);                          \
+                     (_al)->list = _ale;                                       \
+                     break;                                                    \
+                 }                                                             \
+                 _alep = (JSAtomListElement **)&_ale->entry.next;              \
+             }                                                                 \
+         }                                                                     \
+     JS_END_MACRO
+ 
+ struct JSAtomMap {
+     JSAtom              **vector;       /* array of ptrs to indexed atoms */
+     jsatomid            length;         /* count of (to-be-)indexed atoms */
+ };
+ 
+ struct JSAtomState {
+     JSRuntime           *runtime;       /* runtime that owns us */
+     JSHashTable         *table;         /* hash table containing all atoms */
+     jsatomid            number;         /* one beyond greatest atom number */
+     jsatomid            liveAtoms;      /* number of live atoms after last GC */
+ 
+     /* The rt->emptyString atom, see jsstr.c's js_InitRuntimeStringState. */
+     JSAtom              *emptyAtom;
+ 
+     /* Type names and value literals. */
+     JSAtom              *typeAtoms[JSTYPE_LIMIT];
+     JSAtom              *booleanAtoms[2];
+     JSAtom              *nullAtom;
+ 
+     /* Various built-in or commonly-used atoms, pinned on first context. */
+     JSAtom              *ArgumentsAtom;
+     JSAtom              *ArrayAtom;
+     JSAtom              *BooleanAtom;
+     JSAtom              *CallAtom;
+     JSAtom              *DateAtom;
+     JSAtom              *ErrorAtom;
+     JSAtom              *FunctionAtom;
+     JSAtom              *MathAtom;
+     JSAtom              *NamespaceAtom;
+     JSAtom              *NumberAtom;
+     JSAtom              *ObjectAtom;
+     JSAtom              *QNameAtom;
+     JSAtom              *RegExpAtom;
+     JSAtom              *ScriptAtom;
+     JSAtom              *StringAtom;
+     JSAtom              *XMLAtom;
+     JSAtom              *FileAtom;
+     JSAtom              *anonymousAtom;
+     JSAtom              *argumentsAtom;
+     JSAtom              *arityAtom;
+     JSAtom              *calleeAtom;
+     JSAtom              *callerAtom;
+     JSAtom              *classPrototypeAtom;
+     JSAtom              *constructorAtom;
+     JSAtom              *countAtom;
+     JSAtom              *eachAtom;
+     JSAtom              *etagoAtom;
+     JSAtom              *evalAtom;
+     JSAtom              *getAtom;
+     JSAtom              *getterAtom;
+     JSAtom              *indexAtom;
+     JSAtom              *inputAtom;
+     JSAtom              *lengthAtom;
+     JSAtom              *nameAtom;
+     JSAtom              *namespaceAtom;
+     JSAtom              *noSuchMethodAtom;
+     JSAtom              *parentAtom;
+     JSAtom              *protoAtom;
+     JSAtom              *ptagcAtom;
+     JSAtom              *qualifierAtom;
+     JSAtom              *setAtom;
+     JSAtom              *setterAtom;
+     JSAtom              *spaceAtom;
+     JSAtom              *stagoAtom;
+     JSAtom              *starAtom;
+     JSAtom              *starQualifierAtom;
+     JSAtom              *tagcAtom;
+     JSAtom              *toLocaleStringAtom;
+     JSAtom              *toSourceAtom;
+     JSAtom              *toStringAtom;
+     JSAtom              *valueOfAtom;
+     JSAtom              *xmlAtom;
+ #ifdef OSSP
+     JSAtom              *DSOAtom;
+ #endif
+ 
+     /* Less frequently used atoms, pinned lazily by JS_ResolveStandardClass. */
+     struct {
+         JSAtom          *AnyNameAtom;
+         JSAtom          *AttributeNameAtom;
+         JSAtom          *EvalErrorAtom;
+         JSAtom          *InfinityAtom;
+         JSAtom          *InternalErrorAtom;
+         JSAtom          *NaNAtom;
+         JSAtom          *RangeErrorAtom;
+         JSAtom          *ReferenceErrorAtom;
+         JSAtom          *SyntaxErrorAtom;
+         JSAtom          *TypeErrorAtom;
+         JSAtom          *URIErrorAtom;
+         JSAtom          *XMLListAtom;
+         JSAtom          *decodeURIAtom;
+         JSAtom          *decodeURIComponentAtom;
+         JSAtom          *defineGetterAtom;
+         JSAtom          *defineSetterAtom;
+         JSAtom          *encodeURIAtom;
+         JSAtom          *encodeURIComponentAtom;
+         JSAtom          *escapeAtom;
+         JSAtom          *functionNamespaceURIAtom;
+         JSAtom          *hasOwnPropertyAtom;
+         JSAtom          *isFiniteAtom;
+         JSAtom          *isNaNAtom;
+         JSAtom          *isPrototypeOfAtom;
+         JSAtom          *isXMLNameAtom;
+         JSAtom          *lookupGetterAtom;
+         JSAtom          *lookupSetterAtom;
+         JSAtom          *parseFloatAtom;
+         JSAtom          *parseIntAtom;
+         JSAtom          *propertyIsEnumerableAtom;
+         JSAtom          *unescapeAtom;
+         JSAtom          *unevalAtom;
+         JSAtom          *unwatchAtom;
+         JSAtom          *watchAtom;
+     } lazy;
+ 
+ #ifdef JS_THREADSAFE
+     JSThinLock          lock;
+     volatile uint32     tablegen;
+ #endif
+ #ifdef NARCISSUS
+     JSAtom              *callAtom;
+     JSAtom              *constructAtom;
+     JSAtom              *hasInstanceAtom;
+     JSAtom              *ExecutionContextAtom;
+     JSAtom              *currentAtom;
+ #endif
+ };
+ 
+ /* Well-known predefined strings and their atoms. */
+ extern const char   *js_type_str[];
+ extern const char   *js_boolean_str[];
+ 
+ extern const char   js_Arguments_str[];
+ extern const char   js_Array_str[];
+ extern const char   js_Boolean_str[];
+ extern const char   js_Call_str[];
+ extern const char   js_Date_str[];
+ extern const char   js_Function_str[];
+ extern const char   js_Math_str[];
+ extern const char   js_Namespace_str[];
+ extern const char   js_Number_str[];
+ extern const char   js_Object_str[];
+ extern const char   js_QName_str[];
+ extern const char   js_RegExp_str[];
+ extern const char   js_Script_str[];
+ extern const char   js_String_str[];
+ extern const char   js_XML_str[];
+ extern const char   js_File_str[];
+ extern const char   js_anonymous_str[];
+ extern const char   js_arguments_str[];
+ extern const char   js_arity_str[];
+ extern const char   js_callee_str[];
+ extern const char   js_caller_str[];
+ extern const char   js_class_prototype_str[];
+ extern const char   js_constructor_str[];
+ extern const char   js_count_str[];
+ extern const char   js_etago_str[];
+ extern const char   js_each_str[];
+ extern const char   js_eval_str[];
+ extern const char   js_getter_str[];
+ extern const char   js_get_str[];
+ extern const char   js_index_str[];
+ extern const char   js_input_str[];
+ extern const char   js_length_str[];
+ extern const char   js_name_str[];
+ extern const char   js_namespace_str[];
+ extern const char   js_noSuchMethod_str[];
+ extern const char   js_object_str[];
+ extern const char   js_parent_str[];
+ extern const char   js_private_str[];
+ extern const char   js_proto_str[];
+ extern const char   js_ptagc_str[];
+ extern const char   js_qualifier_str[];
+ extern const char   js_setter_str[];
+ extern const char   js_set_str[];
+ extern const char   js_space_str[];
+ extern const char   js_stago_str[];
+ extern const char   js_star_str[];
+ extern const char   js_starQualifier_str[];
+ extern const char   js_tagc_str[];
+ extern const char   js_toSource_str[];
+ extern const char   js_toString_str[];
+ extern const char   js_toLocaleString_str[];
+ extern const char   js_valueOf_str[];
+ extern const char   js_xml_str[];
+ 
+ #ifdef NARCISSUS
+ extern const char   js_call_str[];
+ extern const char   js_construct_str[];
+ extern const char   js_hasInstance_str[];
+ extern const char   js_ExecutionContext_str[];
+ extern const char   js_current_str[];
+ #endif
+ 
+ /*
+  * Initialize atom state.  Return true on success, false with an out of
+  * memory error report on failure.
+  */
+ extern JSBool
+ js_InitAtomState(JSContext *cx, JSAtomState *state);
+ 
+ /*
+  * Free and clear atom state (except for any interned string atoms).
+  */
+ extern void
+ js_FreeAtomState(JSContext *cx, JSAtomState *state);
+ 
+ /*
+  * Interned strings are atoms that live until state's runtime is destroyed.
+  * This function frees all interned string atoms, and then frees and clears
+  * state's members (just as js_FreeAtomState does), unless there aren't any
+  * interned strings in state -- in which case state must be "free" already.
+  *
+  * NB: js_FreeAtomState is called for each "last" context being destroyed in
+  * a runtime, where there may yet be another context created in the runtime;
+  * whereas js_FinishAtomState is called from JS_DestroyRuntime, when we know
+  * that no more contexts will be created.  Thus we minimize garbage during
+  * context-free episodes on a runtime, while preserving atoms created by the
+  * JS_Intern*String APIs for the life of the runtime.
+  */
+ extern void
+ js_FinishAtomState(JSAtomState *state);
+ 
+ /*
+  * Atom garbage collection hooks.
+  */
+ typedef void
+ (*JSGCThingMarker)(void *thing, void *data);
+ 
+ extern void
+ js_MarkAtomState(JSAtomState *state, uintN gcflags, JSGCThingMarker mark,
+                  void *data);
+ 
+ extern void
+ js_SweepAtomState(JSAtomState *state);
+ 
+ extern JSBool
+ js_InitPinnedAtoms(JSContext *cx, JSAtomState *state);
+ 
+ extern void
+ js_UnpinPinnedAtoms(JSAtomState *state);
+ 
+ /*
+  * Find or create the atom for an object.  If we create a new atom, give it the
+  * type indicated in flags.  Return 0 on failure to allocate memory.
+  */
+ extern JSAtom *
+ js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags);
+ 
+ /*
+  * Find or create the atom for a Boolean value.  If we create a new atom, give
+  * it the type indicated in flags.  Return 0 on failure to allocate memory.
+  */
+ extern JSAtom *
+ js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags);
+ 
+ /*
+  * Find or create the atom for an integer value.  If we create a new atom, give
+  * it the type indicated in flags.  Return 0 on failure to allocate memory.
+  */
+ extern JSAtom *
+ js_AtomizeInt(JSContext *cx, jsint i, uintN flags);
+ 
+ /*
+  * Find or create the atom for a double value.  If we create a new atom, give
+  * it the type indicated in flags.  Return 0 on failure to allocate memory.
+  */
+ extern JSAtom *
+ js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags);
+ 
+ /*
+  * Find or create the atom for a string.  If we create a new atom, give it the
+  * type indicated in flags.  Return 0 on failure to allocate memory.
+  */
+ extern JSAtom *
+ js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
+ 
+ extern JS_FRIEND_API(JSAtom *)
+ js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags);
+ 
+ extern JS_FRIEND_API(JSAtom *)
+ js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags);
+ 
+ /*
+  * This variant handles all value tag types.
+  */
+ extern JSAtom *
+ js_AtomizeValue(JSContext *cx, jsval value, uintN flags);
+ 
+ /*
+  * Convert v to an atomized string.
+  */
+ extern JSAtom *
+ js_ValueToStringAtom(JSContext *cx, jsval v);
+ 
+ /*
+  * Assign atom an index and insert it on al.
+  */
+ extern JSAtomListElement *
+ js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al);
+ 
+ /*
+  * Get the atom with index i from map.
+  */
+ extern JS_FRIEND_API(JSAtom *)
+ js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i);
+ 
+ /*
+  * For all unmapped atoms recorded in al, add a mapping from the atom's index
+  * to its address.  The GC must not run until all indexed atoms in atomLists
+  * have been mapped by scripts connected to live objects (Function and Script
+  * class objects have scripts as/in their private data -- the GC knows about
+  * these two classes).
+  */
+ extern JS_FRIEND_API(JSBool)
+ js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al);
+ 
+ /*
+  * Free map->vector and clear map.
+  */
+ extern JS_FRIEND_API(void)
+ js_FreeAtomMap(JSContext *cx, JSAtomMap *map);
+ 
+ JS_END_EXTERN_C
+ 
+ #endif /* jsatom_h___ */


ossp-pkg/js/src/jsdso.c -> 1.1

*** /dev/null    Sat Nov 23 01:42:00 2024
--- -    Sat Nov 23 01:42:05 2024
***************
*** 0 ****
--- 1,247 ----
+ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+  *
+  * ***** 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.
+  *
+  * Contributor(s):
+  *
+  * Alternatively, the contents of this file may be used under the terms of
+  * either of 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 ***** */
+ 
+ /* ATTENTION: This is an OSSP js extension to the Mozilla JavaScript engine.
+    It was implemented by Ralf S. Engelschall <rse@engelschall.com> for OSSP. */
+ 
+ #if defined(OSSP) && defined(JS_HAS_DSO_OBJECT) && JS_HAS_DSO_OBJECT
+ 
+ /* own headers (part 1/2) */
+ #include "jsstddef.h"
+ 
+ /* system headers */
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <dlfcn.h>
+ 
+ /* own headers (part 2/2) */
+ #include "jstypes.h"
+ #include "jsapi.h"
+ #include "jsatom.h"
+ #include "jscntxt.h"
+ #include "jsconfig.h"
+ #include "jsobj.h"
+ #include "jsdso.h"
+ 
+ /* process local storage of DSO handles */
+ static void *dso_handle[10000];
+ 
+ /* type of the DSO load/unload functions */
+ typedef JSBool (*dso_func_t)(JSContext *cx);
+ 
+ /* ISO-C type coersion trick */
+ typedef union { void *vp; dso_func_t fp; } dso_func_ptr_t;
+ 
+ /* public C API function: DSO loading */
+ JS_PUBLIC_API(JSBool)
+ JS_DSOLoad(JSContext *cx, int *idp, const char *filename)
+ {
+     int id;
+     void *handle;
+     dso_func_ptr_t func;
+     JSBool rc;
+ 
+     /* determine next free DSO handle slot */
+     for (id = 0; dso_handle[id] != NULL && id < sizeof(dso_handle)/sizeof(dso_handle[0]); id++)
+         ;
+     if (id == sizeof(dso_handle)/sizeof(dso_handle[0])) {
+         JS_ReportError(cx, "no more free DSO handle slots available");
+         return JS_FALSE;
+     }
+ 
+     /* load DSO into process */
+     if ((handle = dlopen(filename, RTLD_NOW)) == NULL) {
+         JS_ReportError(cx, "unable to load DSO \"%s\": %s", filename, dlerror());
+         return JS_FALSE;
+     }
+ 
+     /* resolve "js_DSO_load" function, call it and insist on a true return */
+     if ((func.vp = dlsym(handle, "js_DSO_load")) == NULL) {
+         JS_ReportError(cx, "unable to resolve symbol \"js_DSO_load\" in DSO \"%s\"", filename);
+         dlclose(handle);
+         return JS_FALSE;
+     }
+     rc = func.fp(cx);
+     if (!rc) {
+         JS_ReportError(cx, "function \"js_DSO_load\" in DSO \"%s\" returned error", filename);
+         dlclose(handle);
+         return JS_FALSE;
+     }
+ 
+     /* store DSO handle into process local storage */
+     dso_handle[id] = handle;
+ 
+     /* return DSO id to caller */
+     if (idp != NULL)
+         *idp = id;
+ 
+     return JS_TRUE;
+ }
+ 
+ /* public C API function: DSO unloading */
+ JS_PUBLIC_API(JSBool)
+ JS_DSOUnload(JSContext *cx, int id)
+ {
+     int idx;
+     void *handle;
+     dso_func_ptr_t func;
+     JSBool rc;
+ 
+     /* sanity check DSO id */
+     if (id < 0 || id >= sizeof(dso_handle)/sizeof(dso_handle[0])) {
+         JS_ReportError(cx, "invalid argument: DSO id #%d out of range", id);
+         return JS_FALSE;
+     }
+ 
+     /* determine DSO handle */
+     if ((handle = dso_handle[id]) == NULL) {
+         JS_ReportError(cx, "invalid argument: DSO id #%d currently unused", id);
+         return JS_FALSE;
+     }
+ 
+     /* resolve "js_DSO_unload" function and (if available only)
+        call it and insist on a true return */
+     if ((func.vp = dlsym(handle, "js_DSO_unload")) != NULL) {
+         rc = func.fp(cx);
+         if (!rc) {
+             JS_ReportError(cx, "function \"js_DSO_unload\" in DSO with id #%d returned error", idx);
+             return JS_FALSE;
+         }
+     }
+ 
+     /* unload DSO from process */
+     dlclose(handle);
+ 
+     /* free DSO handle slot */
+     dso_handle[id] = NULL;
+ 
+     return JS_TRUE;
+ }
+ 
+ /* global JavaScript language DSO object method: id = DSO.load("filename.so") */
+ static JSBool dso_load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+ {
+     JSString *filename;
+     char *c_filename;
+     int id;
+ 
+     /* usage sanity checks */
+     if (argc == 0) {
+         JS_ReportError(cx, "usage: id = DSO.load(filename)");
+         return JS_FALSE;
+     }
+     if (argc != 1) {
+         JS_ReportError(cx, "invalid number of arguments: %d received, %d expected", argc, 1);
+         return JS_FALSE;
+     }
+ 
+     /* determine filename */
+     if ((filename = js_ValueToString(cx, argv[0])) == NULL) {
+         JS_ReportError(cx, "invalid argument");
+         return JS_FALSE;
+     }
+     if ((c_filename = JS_GetStringBytes(filename)) == NULL) {
+         JS_ReportError(cx, "invalid argument");
+         return JS_FALSE;
+     }
+ 
+     /* load DSO */
+     if (!JS_DSOLoad(cx, &id, c_filename))
+         return JS_FALSE;
+ 
+     /* return DSO handle id */
+     *rval = INT_TO_JSVAL(id);
+ 
+     return JS_TRUE;
+ }
+ 
+ /* global JavaScript language DSO object method: DSO.unload(id) */
+ static JSBool dso_unload(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+ {
+     int id;
+     JSBool rc;
+ 
+     /* usage sanity checks */
+     if (argc == 0) {
+         JS_ReportError(cx, "usage: DSO.unload(id)");
+         return JS_FALSE;
+     }
+     if (argc != 1) {
+         JS_ReportError(cx, "invalid number of arguments: %d received, %d expected", argc, 1);
+         return JS_FALSE;
+     }
+ 
+     /* determine DSO id */
+     id = JSVAL_TO_INT(argv[0]);
+ 
+     /* unload DSO */
+     if (!JS_DSOUnload(cx, id))
+         return JS_FALSE;
+ 
+     return JS_TRUE;
+ }
+ 
+ /* JavaScript DSO class method definitions */
+ static JSFunctionSpec dso_methods[] = {
+     { "load",   dso_load,   1, 0, 0 },
+     { "unload", dso_unload, 1, 0, 0 },
+     { NULL,     NULL,       0, 0, 0 }
+ };
+ 
+ /* JavaScript DSO class definition */
+ static JSClass dso_class = {
+     "DSO",
+     0,
+     JS_PropertyStub,
+     JS_PropertyStub,
+     JS_PropertyStub,
+     JS_PropertyStub,
+     JS_EnumerateStub,
+     JS_ResolveStub,
+     JS_ConvertStub,
+     JS_FinalizeStub,
+     JSCLASS_NO_OPTIONAL_MEMBERS
+ };
+ 
+ /* JavaScript DSO class global initializer */
+ JSObject *js_InitDSOClass(JSContext *cx, JSObject *obj)
+ {
+     JSObject *DSO;
+ 
+     if ((DSO = JS_DefineObject(cx, obj, "DSO", &dso_class, NULL, 0)) == NULL)
+         return NULL;
+     if (!JS_DefineFunctions(cx, DSO, dso_methods))
+         return NULL;
+     return DSO;
+ }
+ 
+ #endif /* JS_HAS_DSO_OBJECT */
+ 


ossp-pkg/js/src/jsdso.h -> 1.1

*** /dev/null    Sat Nov 23 01:42:00 2024
--- -    Sat Nov 23 01:42:05 2024
***************
*** 0 ****
--- 1,51 ----
+ /* ***** 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.
+  *
+  * Contributor(s):
+  *
+  * Alternatively, the contents of this file may be used under the terms of
+  * either of 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 ***** */
+ 
+ /* ATTENTION: This is an OSSP js extension to the Mozilla JavaScript engine.
+    It was implemented by Ralf S. Engelschall <rse@engelschall.com> for OSSP. */
+ 
+ #ifndef jsdso_h___
+ #define jsdso_h___
+ 
+ #if defined(OSSP) && defined(JS_HAS_DSO_OBJECT) && JS_HAS_DSO_OBJECT
+ 
+ JS_BEGIN_EXTERN_C
+ 
+ /* public API */
+ extern JSBool    JS_DSOLoad      (JSContext *cx, int *id, const char *filename);
+ extern JSBool    JS_DSOUnload    (JSContext *cx, int  id);
+ 
+ /* friend API */
+ extern JSObject *js_InitDSOClass (JSContext *cx, JSObject *obj);
+ 
+ JS_END_EXTERN_C
+ 
+ #endif
+ 
+ #endif /* jsdso_h___ */

CVSTrac 2.0.1