1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00
elinks/src/ecmascript/spidermonkey/util.h

81 lines
1.7 KiB
C
Raw Normal View History

#ifndef EL__ECMASCRIPT_SPIDERMONKEY_UTIL_H
#define EL__ECMASCRIPT_SPIDERMONKEY_UTIL_H
#include "ecmascript/spidermonkey-shared.h"
#include "util/memory.h"
static void string_to_jsval(JSContext *ctx, jsval *vp, unsigned char *string);
static void astring_to_jsval(JSContext *ctx, jsval *vp, unsigned char *string);
static void int_to_jsval(JSContext *ctx, jsval *vp, int number);
static void object_to_jsval(JSContext *ctx, jsval *vp, JSObject *object);
static void boolean_to_jsval(JSContext *ctx, jsval *vp, int boolean);
static int jsval_to_boolean(JSContext *ctx, jsval *vp);
/** Inline functions */
static inline void
string_to_jsval(JSContext *ctx, jsval *vp, unsigned char *string)
{
if (!string) {
*vp = JSVAL_NULL;
} else {
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(ctx, string));
}
}
static inline void
astring_to_jsval(JSContext *ctx, jsval *vp, unsigned char *string)
{
string_to_jsval(ctx, vp, string);
mem_free_if(string);
}
static inline void
int_to_jsval(JSContext *ctx, jsval *vp, int number)
{
*vp = INT_TO_JSVAL(number);
}
static inline void
object_to_jsval(JSContext *ctx, jsval *vp, JSObject *object)
{
*vp = OBJECT_TO_JSVAL(object);
}
static inline void
boolean_to_jsval(JSContext *ctx, jsval *vp, int boolean)
{
*vp = BOOLEAN_TO_JSVAL(boolean);
}
static inline int
jsval_to_boolean(JSContext *ctx, jsval *vp)
{
jsval val;
if (JS_ConvertValue(ctx, *vp, JSTYPE_BOOLEAN, &val) == JS_FALSE) {
return JS_FALSE;
}
return JSVAL_TO_BOOLEAN(val);
}
SMJS: add session object Add session_class, which defines a JSObject wrapper for struct session. Add location_array_class, which defines a JSObject wrapper for struct ses_history. The "history" member of struct session is a struct ses_history, which is a linked list of struct location. Add a pointer from struct session to the session_class object and the location_array object. Add smjs_get_session_object to return a session_class JSObject wrapper for a given struct session. Add smjs_get_session_location_array_object to return a location_array_class JSObject wrapper for a given struct session. Add "session" property to the "elinks" object, which uses smjs_get_session_object to get a JSObject wrapper for smjs_ses. Add smjs_location_array_get_property, which allows indexing a location_array object using a positive number for history forward or a negative number for history backward. Add session_props, session_get_property, session_set_property, session_funcs, smjs_session_goto_url (which implements the "goto" method), and smjs_init_session_interface for session_class. Add session_construct, which creates a new tab and returns the JSObject session_class wrapper. Add session_finalize and smjs_location_array_finalize, which clear the pointers between struct session and the JSObject wrappers in question. Add smjs_detach_session_object, which clears the pointers between a given struct session and the corresponding JSObject wrappers. In destroy_session, call smjs_detach_session_object. Add jsval_to_object helper in ecmascript/spidermonkey/util.h; jsval_to_object is used in smjs_session_goto_url. Modify delayed_goto_uri_frame to allow the target to be NULL. smjs_session_goto_url needs this modification.
2011-11-13 02:12:08 -05:00
static inline JSObject *
jsval_to_object(JSContext *ctx, jsval *vp)
{
jsval val;
if (JS_ConvertValue(ctx, *vp, JSTYPE_OBJECT, &val) == JS_FALSE) {
return NULL;
}
return JSVAL_TO_OBJECT(val);
}
#endif