gjs r106 - trunk/gjs
- From: otaylor svn gnome org
- To: svn-commits-list gnome org
- Subject: gjs r106 - trunk/gjs
- Date: Tue, 18 Nov 2008 12:31:33 +0000 (UTC)
Author: otaylor
Date: Tue Nov 18 12:31:33 2008
New Revision: 106
URL: http://svn.gnome.org/viewvc/gjs?rev=106&view=rev
Log:
Fix priv_from_js_with_typecheck() for dynamic types
For the dynamic case, priv_from_js_with_typecheck() can't call
JS_InstanceOf(), since the dynamic class isn't an instance of the
static class. Instead do the checks in gjs_get_instance_private_dynamic(),
but don't raise exceptions.
http://bugzilla.gnome.org/show_bug.cgi?id=561203
Modified:
trunk/gjs/jsapi-util.c
trunk/gjs/jsapi-util.h
Modified: trunk/gjs/jsapi-util.c
==============================================================================
--- trunk/gjs/jsapi-util.c (original)
+++ trunk/gjs/jsapi-util.c Tue Nov 18 12:31:33 2008
@@ -432,6 +432,38 @@
return JS_GetInstancePrivate(context, obj, obj_class, argv);
}
+void*
+gjs_get_instance_private_dynamic_with_typecheck(JSContext *context,
+ JSObject *obj,
+ JSClass *static_clasp,
+ jsval *argv)
+{
+ RuntimeData *rd;
+ JSClass *obj_class;
+
+ if (static_clasp->name != NULL) {
+ g_warning("Dynamic class should not have a name in the JSClass struct");
+ return NULL;
+ }
+
+ obj_class = JS_GetClass(context, obj);
+ g_assert(obj_class != NULL);
+
+ rd = get_data_from_context(context);
+ g_assert(rd != NULL);
+
+ /* Check that it's safe to cast to DynamicJSClass */
+ if (g_hash_table_lookup(rd->dynamic_classes, obj_class) == NULL) {
+ return NULL;
+ }
+
+ if (static_clasp != ((DynamicJSClass*) obj_class)->static_class) {
+ return NULL;
+ }
+
+ return JS_GetInstancePrivate(context, obj, obj_class, argv);
+}
+
JSObject*
gjs_construct_object_dynamic(JSContext *context,
JSObject *proto,
Modified: trunk/gjs/jsapi-util.h
==============================================================================
--- trunk/gjs/jsapi-util.h (original)
+++ trunk/gjs/jsapi-util.h Tue Nov 18 12:31:33 2008
@@ -78,11 +78,13 @@
JSObject *object, \
type **out) \
{\
+ type *result; \
if (!out) \
return JS_FALSE; \
- if (!JS_InstanceOf(context, object, &class, NULL)) \
+ result = gjs_get_instance_private_dynamic_with_typecheck(context, object, &class, NULL); \
+ if (result == NULL) \
return JS_FALSE; \
- *out = gjs_get_instance_private_dynamic(context, object, &class, NULL); \
+ *out = result; \
return JS_TRUE; \
}\
static type*\
@@ -126,14 +128,16 @@
JSPropertySpec *static_ps,
JSFunctionSpec *static_fs);
gboolean gjs_check_constructing (JSContext *context);
-void* gjs_get_instance_private_dynamic (JSContext *context,
- JSObject *obj,
- JSClass *static_clasp,
- jsval *argv);
-void* gjs_get_instance_private_dynamic (JSContext *context,
- JSObject *obj,
- JSClass *static_clasp,
- jsval *argv);
+
+void* gjs_get_instance_private_dynamic (JSContext *context,
+ JSObject *obj,
+ JSClass *static_clasp,
+ jsval *argv);
+void* gjs_get_instance_private_dynamic_with_typecheck (JSContext *context,
+ JSObject *obj,
+ JSClass *static_clasp,
+ jsval *argv);
+
JSObject* gjs_construct_object_dynamic (JSContext *context,
JSObject *proto,
uintN argc,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]