stdin, stdout and stderr File objects now automatically created globally by
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 1 Oct 2006 15:31:45 +0000 (15:31 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 1 Oct 2006 15:31:45 +0000 (15:31 +0000)
js_InitFileClass().

mmsoftware/js/classes/js_file.c

index b192621..e4b486b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: js_file.c,v 1.4 2006/09/26 12:40:54 mmondor Exp $ */
+/* $Id: js_file.c,v 1.5 2006/10/01 15:31:45 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -286,6 +286,53 @@ js_InitFileClass(JSContext *cx, JSObject *obj)
                }
        }
 
+       /* Create stdin, stdout, stderr File objects */
+       {
+               JSObject        *o;
+
+               if ((o = file_new(cx, stdin, 0)) != NULL) {
+                       if (!JS_DefineProperty(cx, obj, "stdin",
+                           OBJECT_TO_JSVAL(o), NULL, NULL,
+                           JSPROP_READONLY | JSPROP_PERMANENT)) {
+                               (void) fprintf(stderr,
+                                   "File: Error defining stdin property\n");
+                               return NULL;
+                       }
+               } else {
+                       (void) fprintf(stderr,
+                           "File: Error creating stdin object\n");
+                       return NULL;
+               }
+
+               if ((o = file_new(cx, stdout, 0)) != NULL) {
+                       if (!JS_DefineProperty(cx, obj, "stdout",
+                           OBJECT_TO_JSVAL(o), NULL, NULL,
+                           JSPROP_READONLY | JSPROP_PERMANENT)) {
+                               (void) fprintf(stderr,
+                                   "File: Error defining stdoutproperty\n");
+                               return NULL;
+                       }
+               } else {
+                       (void) fprintf(stderr,
+                           "File: Error creating stdout object\n");
+                       return NULL;
+               }
+
+               if ((o = file_new(cx, stderr, 0)) != NULL) {
+                       if (!JS_DefineProperty(cx, obj, "stderr",
+                           OBJECT_TO_JSVAL(o), NULL, NULL,
+                           JSPROP_READONLY | JSPROP_PERMANENT)) {
+                               (void) fprintf(stderr,
+                                   "File: Error defining stderr property\n");
+                               return NULL;
+                       }
+               } else {
+                       (void) fprintf(stderr,
+                           "File: Error creating stderr object\n");
+                       return NULL;
+               }
+       }
+
        return proto;
 }