[seed] Implement imports.Directory constructor
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Implement imports.Directory constructor
- Date: Tue, 21 Apr 2009 18:08:55 -0400 (EDT)
commit d04f6885c3ba19cc2aea20219cf55668192f3aec
Author: Robert Carr <racarr svn gnome org>
Date: Mon Apr 20 01:19:36 2009 -0400
Implement imports.Directory constructor
---
libseed/seed-importer.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index e1d995c..b6f1925 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -866,9 +866,44 @@ seed_importer_set_search_path(JSContextRef ctx,
}
+static JSObjectRef
+seed_importer_construct_dir (JSContextRef ctx,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef *exception)
+{
+ gchar *dir;
+
+ if (argumentCount != 1)
+ {
+ gchar *mes = g_strdup_printf("imports.Directory constructor expected 1 argument, got %d", argumentCount);
+
+ seed_make_exception (ctx, exception, "ArgumentError", mes);
+ g_free (mes);
+
+ return (JSObjectRef)JSValueMakeNull (ctx);
+ }
+ dir = seed_value_to_string (ctx, arguments[0], exception);
+ if (!g_file_test (dir, G_FILE_TEST_IS_DIR))
+ {
+ gchar * mes = g_strdup_printf("File: %s, is not a directory", dir);
+
+ seed_make_exception (ctx, exception, "ArgumentError", mes);
+ g_free (mes);
+ g_free (dir);
+
+ return (JSObjectRef)JSValueMakeNull (ctx);
+ }
+
+ return JSObjectMake (ctx, importer_dir_class, dir);
+}
+
void seed_initialize_importer(JSContextRef ctx,
JSObjectRef global)
{
+ JSObjectRef dir_constructor;
+
importer_class = JSClassCreate (&importer_class_def);
importer = JSObjectMake (ctx, importer_class, NULL);
@@ -884,5 +919,10 @@ void seed_initialize_importer(JSContextRef ctx,
gi_imports = g_hash_table_new (g_str_hash, g_str_equal);
file_imports = g_hash_table_new (g_str_hash, g_str_equal);
+ dir_constructor = JSObjectMakeConstructor (ctx, importer_dir_class,
+ seed_importer_construct_dir);
+ seed_object_set_property (ctx, importer, "Directory", dir_constructor);
+ JSValueProtect (ctx, dir_constructor);
+
seed_object_set_property (ctx, global, "imports", importer);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]