[gjs] Bug 560048 - Use JS_SetPropertyAttributes to seal imports
- From: Owen Taylor <otaylor src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gjs] Bug 560048 - Use JS_SetPropertyAttributes to seal imports
- Date: Mon, 24 Aug 2009 20:39:40 +0000 (UTC)
commit e63e2dfd4e8c0a806476d82e977c931a4fb4bbf5
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Sun Nov 9 13:21:16 2008 -0500
Bug 560048 - Use JS_SetPropertyAttributes to seal imports
Instead of defining the module object property again to make it
permanent, use JS_[Get/Set]PropertyAttributes.
gjs/importer.c | 41 ++++++++++++++++++++++++++++-------------
1 files changed, 28 insertions(+), 13 deletions(-)
---
diff --git a/gjs/importer.c b/gjs/importer.c
index 787ee46..d0b0361 100644
--- a/gjs/importer.c
+++ b/gjs/importer.c
@@ -149,23 +149,36 @@ define_import(JSContext *context,
return JS_TRUE;
}
-/* Just like define_import, but makes the setting permament.
+/* Make the property we set in define_import permament;
* we do this after the import succesfully completes.
*/
-static void
-seal_import(JSContext *context,
+static JSBool
+seal_import(JSContext *context,
JSObject *obj,
- JSObject *module_obj,
const char *name)
{
- if (!JS_DefineProperty(context, obj,
- name, OBJECT_TO_JSVAL(module_obj),
- NULL, NULL,
- GJS_MODULE_PROP_FLAGS)) {
+ JSBool found;
+ uintN attrs;
+
+ if (!JS_GetPropertyAttributes(context, obj, name,
+ &attrs, &found) || !found) {
+ gjs_debug(GJS_DEBUG_IMPORTER,
+ "Failed to get attributes to seal '%s' in importer",
+ name);
+ return JS_FALSE;
+ }
+
+ attrs |= JSPROP_PERMANENT;
+
+ if (!JS_SetPropertyAttributes(context, obj, name,
+ attrs, &found) || !found) {
gjs_debug(GJS_DEBUG_IMPORTER,
- "Failed to permanently define '%s' in importer",
+ "Failed to set attributes to seal '%s' in importer",
name);
+ return JS_FALSE;
}
+
+ return JS_TRUE;
}
/* An import failed. Delete the property pointing to the import
@@ -237,13 +250,14 @@ import_native_file(JSContext *context,
if (!finish_import(context, name))
goto out;
+ if (!seal_import(context, obj, name))
+ goto out;
+
retval = JS_TRUE;
out:
if (!retval)
cancel_import(context, obj, name);
- else if (!(flags & GJS_NATIVE_SUPPLIES_MODULE_OBJ))
- seal_import(context, obj, module_obj, name);
return retval;
}
@@ -437,13 +451,14 @@ import_file(JSContext *context,
if (!finish_import(context, name))
goto out;
+ if (!seal_import(context, obj, name))
+ goto out;
+
retval = JS_TRUE;
out:
if (!retval)
cancel_import(context, obj, name);
- else
- seal_import(context, obj, module_obj, name);
return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]