[gjs] Fix processing of versioning defaults



commit b7c45e5cf364e618afb1018e189ba0ab0ac0dd8b
Author: Colin Walters <walters verbum org>
Date:   Mon Dec 20 15:18:12 2010 -0500

    Fix processing of versioning defaults
    
    Previously, the buffer scanning like
    gjs_context_scan_buffer_for_js_version returned "default" if there was
    no found version; but that isn't what we want yet since it implies web
    JS.
    
    Fix this by returning "NULL" to mean "I don't know".  Then the only
    thing that knows the default JS version is context.c.

 gjs/console.c            |    3 ++-
 gjs/context.c            |   19 +++++++++++--------
 test/js/testJSDefault.js |    1 +
 3 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/gjs/console.c b/gjs/console.c
index 7c2553e..1d0b10f 100644
--- a/gjs/console.c
+++ b/gjs/console.c
@@ -94,7 +94,8 @@ main(int argc, char **argv)
     /* If user explicitly specifies a version, use it */
     if (js_version != NULL)
         source_js_version = js_version;
-    js_context = g_object_new(GJS_TYPE_CONTEXT, "search-path", include_path, "js-version", source_js_version, NULL);
+    js_context = g_object_new(GJS_TYPE_CONTEXT, "search-path", include_path,
+                              "js-version", source_js_version, NULL);
 
     /* prepare command line arguments */
     if (!gjs_context_define_string_array(js_context, "ARGV",
diff --git a/gjs/context.c b/gjs/context.c
index 80c1538..218139f 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -708,7 +708,10 @@ gjs_context_set_property (GObject      *object,
         break;
     case PROP_JS_VERSION:
         g_free(js_context->jsversion_string);
-        js_context->jsversion_string = g_value_dup_string(value);
+        if (g_value_get_string (value) == NULL)
+            js_context->jsversion_string = g_strdup(_GJS_JS_VERSION_DEFAULT);
+        else
+            js_context->jsversion_string = g_value_dup_string(value);
         break;
 
     default:
@@ -733,7 +736,7 @@ gjs_context_set_property (GObject      *object,
  * <literal>// application/javascript;version=1.8</literal>
  *
  * Returns: A string suitable for use as the GjsContext::version property.
- *   If the version is unknown or invalid, "default" will be returned.
+ *   If the version is unknown or invalid, %NULL will be returned.
  */
 const char *
 gjs_context_scan_buffer_for_js_version (const char *buffer,
@@ -748,13 +751,13 @@ gjs_context_scan_buffer_for_js_version (const char *buffer,
 
     substr = g_strstr_len(buffer, maxbytes, prefix);
     if (!substr)
-        return "default";
+        return NULL;
 
     remaining_bytes = maxbytes - ((substr - buffer) + strlen (prefix));
     /* 20 should give us enough space for all the valid JS version strings; anyways
      * it's really a bug if we're close to the limit anyways. */
     if (remaining_bytes < (gssize)sizeof(buf)-1)
-        return "default";
+        return NULL;
 
     buf[sizeof(buf)-1] = '\0';
     strncpy(buf, substr + strlen (prefix), sizeof(buf)-1);
@@ -767,7 +770,7 @@ gjs_context_scan_buffer_for_js_version (const char *buffer,
 
     ver = JS_StringToVersion(buf);
     if (ver == JSVERSION_UNKNOWN)
-        return "default";
+        return NULL;
     return JS_VersionToString(ver);
 }
 
@@ -785,18 +788,18 @@ gjs_context_scan_file_for_js_version (const char *file_path)
 {
     char *utf8_buf;
     guint8 buf[1024];
-    const char *version = "default";
+    const char *version = NULL;
     gssize len;
     FILE *f;
 
     f = fopen(file_path, "r");
     if (!f)
-        return "default";
+        return NULL;
 
     len = fread(buf, 1, sizeof(buf)-1, f);
     fclose(f);
     if (len < 0)
-        return "default";
+        return NULL;
     buf[len] = '\0';
 
     utf8_buf = _gjs_g_utf8_make_valid((const char*)buf);
diff --git a/test/js/testJSDefault.js b/test/js/testJSDefault.js
index 8231e0f..93e3ee3 100644
--- a/test/js/testJSDefault.js
+++ b/test/js/testJSDefault.js
@@ -1,5 +1,6 @@
 // Test that we *don't* get SpiderMonkey extensions; see
 // testJS1_8.js.
+// application/javascript;version=ECMAv3
 
 var GLib = imports.gi.GLib;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]