#
# 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.
#

#
# Typemap for PerlConnect
#

TYPEMAP
# These types have direct equivalents implemented as Perl packages
JSRuntime *      RUNTIME
JSContext *      CONTEXT
jsval            jsval
# This is an auxilary type. Object serves as a wrapper for it
JSObject *       OBJECT


OUTPUT
jsval
    {
        JSContext *cx = getContext();
        JSVALToSV(cx, JS_GetGlobalObject(cx), $var, &$arg);
    }

OBJECT
    sv_setref_pv($arg, "JS::Object", (void*)$var);

CONTEXT
    sv_setref_pv($arg, "JS::Context", (void*)$var);

RUNTIME
    sv_setref_pv($arg, "JS::Runtime", (void*)$var);

#JS_OBJECT
#    sv_setref_pv($arg, "JSObject", (void*)$var);

INPUT
jsval
    {
        JSContext *cx = getContext();
        SVToJSVAL(cx, JS_GetGlobalObject(cx), newRV($arg), &$var);
    }

OBJECT
    if(sv_isa($arg, \"JS::Object\"))
        $var = ($type)SvIV((SV*)SvRV($arg));
    else{
        warn(\"${Package}::$func_name() -- $var is not a blessed JS::Object reference\");
        XSRETURN_UNDEF;
    }

CONTEXT
    if(sv_isa($arg, \"JS::Context\"))
        $var = ($type)SvIV((SV*)SvRV($arg));
    else{
        warn(\"${Package}::$func_name() -- $var is not a blessed JS::Context reference\");
        XSRETURN_UNDEF;
    }

RUNTIME
    if(sv_isa($arg, \"JS::Runtime\"))
        $var = ($type)SvIV((SV*)SvRV($arg));
    else{
        warn(\"${Package}::$func_name() -- $var is not a blessed JS::Runtime reference\");
        XSRETURN_UNDEF;
    }
