diff options
Diffstat (limited to 'javascript')
-rw-r--r-- | javascript/jsapi.h | 80 | ||||
-rw-r--r-- | javascript/jsapi/htmldocument.bnd | 49 |
2 files changed, 82 insertions, 47 deletions
diff --git a/javascript/jsapi.h b/javascript/jsapi.h index ca672e108..8b7fe51eb 100644 --- a/javascript/jsapi.h +++ b/javascript/jsapi.h @@ -35,30 +35,26 @@ #include <string.h> -/* *CAUTION* these macros introduce and use jsapi_this and jsapi_rval - * parameters, native function code should not conflict with these - */ # ifndef JSVERSION_LATEST # define JSVERSION_LATEST JS_VERSION # endif -/* five parameter jsapi native call */ -#define JSAPI_NATIVE(name, cx, argc, vp) \ - jsapi_native_##name(cx, JSObject *jsapi_this, argc, vp, jsval *jsapi_rval) -/* five parameter function descriptor with no JS_FS macro */ -#define JSAPI_FS(name, nargs, flags) \ - { #name, jsapi_native_##name, nargs, flags, 0 } -/* function descriptor end */ -#define JSAPI_FS_END { NULL, NULL, 0, 0, 0 } +/* *CAUTION* these native function macros introduce and use jsapi_this + * and jsapi_rval variables, native function code should not conflict + * with these + */ -/* return value */ +/* native function definition with five parameters */ +#define JSAPI_NATIVE(name, cx, argc, vp) \ + jsapi_native_##name(cx, JSObject *jsapi_this, argc, vp, jsval *jsapi_rval) + +/* native function return value */ #define JSAPI_RVAL(cx, vp) (jsapi_rval) -/* return value setter */ +/* native function return value setter with no JS_SET_RVAL */ #define JSAPI_SET_RVAL(cx, vp, v) (*jsapi_rval = (v)) -#define JS_SET_RVAL(cx, vp, v) (*(vp) = (v)) /* arguments */ #define JSAPI_ARGV(cx, vp) (vp) @@ -66,27 +62,47 @@ /* check if a jsval is an object */ #define JSAPI_JSVAL_IS_OBJECT(v) JSVAL_IS_OBJECT(v) -/* The object instance in a native call */ -/* "this" JSObject getter */ -JSObject * js_ComputeThis(JSContext *cx, JSObject *thisp, void *argv); -#define JSAPI_THIS_OBJECT(cx, vp) \ - js_ComputeThis(cx, JSVAL_TO_OBJECT(vp[-1]), vp) +/* native function specifier with five parameters and no JS_FS macro */ +#define JSAPI_FS(name, nargs, flags) \ + { #name, jsapi_native_##name, nargs, flags, 0 } -/* proprty native calls */ +/* native function specifier list end */ +#define JSAPI_FS_END { NULL, NULL, 0, 0, 0 } + + + + +/* native proprty definition */ #define JSAPI_PROPERTYGET(name, cx, obj, vp) \ jsapi_property_##name##_get(cx, obj, jsval id, vp) #define JSAPI_PROPERTYSET(name, cx, obj, vp) \ jsapi_property_##name##_set(cx, obj, jsval id, vp) -/* property specifier */ +/* native property getter return value */ +#define JS_SET_RVAL(cx, vp, v) (*(vp) = (v)) + +/* native property specifier */ #define JSAPI_PS(name, tinyid, flags) \ { #name , tinyid , flags , jsapi_property_##name##_get , jsapi_property_##name##_set } +/* native property specifier with no setter */ #define JSAPI_PS_RO(name, tinyid, flags) \ { #name , tinyid , flags | JSPROP_READONLY, jsapi_property_##name##_get , NULL } +/* native property specifier list end */ #define JSAPI_PS_END { NULL, 0, 0, NULL, NULL } +#define JS_StrictPropertyStub JS_PropertyStub + + + + +/* The object instance in a native call */ +/* "this" JSObject getter */ +JSObject * js_ComputeThis(JSContext *cx, JSObject *thisp, void *argv); +#define JSAPI_THIS_OBJECT(cx, vp) \ + js_ComputeThis(cx, JSVAL_TO_OBJECT(vp[-1]), vp) + static inline JSObject * JS_NewCompartmentAndGlobalObject(JSContext *cx, JSClass *jsclass, @@ -100,7 +116,6 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, return global; } -#define JS_StrictPropertyStub JS_PropertyStub #define JSString_to_char(injsstring, outchar, outlen) \ outchar = JS_GetStringBytes(injsstring); \ @@ -111,7 +126,9 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_CLASS_NO_INTERNAL_MEMBERS NULL -/* GC marking */ +/* Garbage Collector */ + +/* macros for GC marking */ #define JSAPI_JSCLASS_MARK_IS_TRACE 0 #define JSAPI_JSCLASS_MARKOP(x) (x) @@ -122,7 +139,10 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_GCMARK(thing) JS_MarkGCThing(cx, thing, "object", arg) +/* Macros for manipulating GC root */ +#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj) +#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj) #elif JS_VERSION == 180 @@ -199,13 +219,15 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_CLASS_NO_INTERNAL_MEMBERS NULL +/* Garbage Collector */ + /* GC marking */ #ifdef JSCLASS_MARK_IS_TRACE -/* mark requires casting */ +/* mark function pointer requires casting */ #define JSAPI_JSCLASS_MARK_IS_TRACE JSCLASS_MARK_IS_TRACE #define JSAPI_JSCLASS_MARKOP(x) ((JSMarkOp)x) #else -/* mark does not require casting */ +/* mark function pointer does not require casting */ #define JSAPI_JSCLASS_MARK_IS_TRACE 0 #define JSAPI_JSCLASS_MARKOP(x) (x) #endif @@ -216,6 +238,10 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_GCMARK(thing) JS_CallTracer(trc, thing, JSTRACE_OBJECT); +/* Macros for manipulating GC root */ +#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddRoot(cx, obj) +#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveRoot(cx, obj) + #else /* #if JS_VERSION == 180 */ @@ -305,6 +331,10 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx, #define JSAPI_GCMARK(thing) JS_CallTracer(trc, thing, JSTRACE_OBJECT); +/* Macros for manipulating GC root */ +#define JSAPI_ADD_OBJECT_ROOT(cx, obj) JS_AddObjectRoot(cx, obj) +#define JSAPI_REMOVE_OBJECT_ROOT(cx, obj) JS_RemoveObjectRoot(cx, obj) + #endif #define JSLOG(args...) LOG((args)) diff --git a/javascript/jsapi/htmldocument.bnd b/javascript/jsapi/htmldocument.bnd index 80a30bb4e..7ca49489c 100644 --- a/javascript/jsapi/htmldocument.bnd +++ b/javascript/jsapi/htmldocument.bnd @@ -181,19 +181,22 @@ operation createTextNode %{ dom_exception exc; dom_text *text; - JSLOG("Creating text node for string \"%s\"", data); - exc = dom_string_create((unsigned char*)data, data_len, &data_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } + if (data != NULL) { - exc = dom_document_create_text_node(private->node, data_dom, &text); - dom_string_unref(data_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } + JSLOG("Creating text node for string \"%s\"", data); + exc = dom_string_create((unsigned char*)data, data_len, &data_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } - jsret = jsapi_new_Text(cx, NULL, NULL, text, private->htmlc); + exc = dom_document_create_text_node(private->node, data_dom, &text); + dom_string_unref(data_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } + + jsret = jsapi_new_Text(cx, NULL, NULL, text, private->htmlc); + } JSLOG("returning jsobject %p",jsret); @@ -205,19 +208,21 @@ operation createElement %{ dom_exception exc; dom_element *element; - JSLOG("Creating text node for string \"%s\"", localName); - exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } + if (localName != NULL) { + JSLOG("Creating text node for string \"%s\"", localName); + exc = dom_string_create((unsigned char*)localName, localName_len, &localName_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } - exc = dom_document_create_element(private->node, localName_dom, &element); - dom_string_unref(localName_dom); - if (exc != DOM_NO_ERR) { - return JS_FALSE; - } + exc = dom_document_create_element(private->node, localName_dom, &element); + dom_string_unref(localName_dom); + if (exc != DOM_NO_ERR) { + return JS_FALSE; + } - jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); + jsret = jsapi_new_HTMLElement(cx, NULL, NULL, element, private->htmlc); + } JSLOG("returning jsobject %p",jsret); |