Bug 381031: make JS1.8 the default for <xul:script>, and add a JSVERSION_LATEST #define to simplify future changes, patch by Nickolay Ponomarev <asqueella@gmail.com>, r+sr=brendan
authorgavin@gavinsharp.com
Thu, 07 Jun 2007 15:50:12 -0700
changeset 2208 b6f38ea71dcbe358fb500a28b6bf2e07031e7f48
parent 2207 bfa503f9919c032c0314fa13cf96a2b1c6d296c6
child 2209 a497d25163d62b33a3a2bdbc5265461e9b35e740
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs381031
milestone1.9a6pre
Bug 381031: make JS1.8 the default for <xul:script>, and add a JSVERSION_LATEST #define to simplify future changes, patch by Nickolay Ponomarev <asqueella@gmail.com>, r+sr=brendan
content/xul/document/src/nsXULContentSink.cpp
extensions/jssh/nsJSSh.cpp
js/src/jspubtd.h
js/src/xpconnect/loader/mozJSComponentLoader.cpp
--- a/content/xul/document/src/nsXULContentSink.cpp
+++ b/content/xul/document/src/nsXULContentSink.cpp
@@ -1035,16 +1035,17 @@ XULContentSinkImpl::OpenScript(const PRU
               if (mimeType.LowerCaseEqualsASCII(jsTypes[i])) {
                   isJavaScript = PR_TRUE;
                   break;
               }
           }
 
           if (isJavaScript) {
               langID = nsIProgrammingLanguage::JAVASCRIPT;
+              version = JSVERSION_LATEST;
           } else {
               // Use the script object factory to locate the language.
               nsCOMPtr<nsIScriptRuntime> runtime;
               rv = NS_GetScriptRuntime(mimeType, getter_AddRefs(runtime));
               if (NS_FAILED(rv) || runtime == nsnull) {
                   // Failed to get the explicitly specified language
                   NS_WARNING("Failed to find a scripting language");
                   langID = nsIProgrammingLanguage::UNKNOWN;
@@ -1054,30 +1055,30 @@ XULContentSinkImpl::OpenScript(const PRU
 
           if (langID != nsIProgrammingLanguage::UNKNOWN) {
             // Get the version string, and ensure the language supports it.
             nsAutoString versionName;
             rv = mimeHdrParser->GetParameter(typeAndParams, "version",
                                              EmptyCString(), PR_FALSE, nsnull,
                                              versionName);
             if (NS_FAILED(rv)) {
-              // no version specified - version remains 0.
-                  if (rv != NS_ERROR_INVALID_ARG)
-                      return rv;
-              } else {
-                nsCOMPtr<nsIScriptRuntime> runtime;
-                rv = NS_GetScriptRuntimeByID(langID, getter_AddRefs(runtime));
-                if (NS_FAILED(rv))
-                    return rv;
-                rv = runtime->ParseVersion(versionName, &version);
-                if (NS_FAILED(rv)) {
-                    NS_WARNING("This script language version is not supported - ignored");
-                    langID = nsIProgrammingLanguage::UNKNOWN;
-                  }
+              if (rv != NS_ERROR_INVALID_ARG)
+                return rv;
+              // no version specified - version remains the default.
+            } else {
+              nsCOMPtr<nsIScriptRuntime> runtime;
+              rv = NS_GetScriptRuntimeByID(langID, getter_AddRefs(runtime));
+              if (NS_FAILED(rv))
+                return rv;
+              rv = runtime->ParseVersion(versionName, &version);
+              if (NS_FAILED(rv)) {
+                NS_WARNING("This script language version is not supported - ignored");
+                langID = nsIProgrammingLanguage::UNKNOWN;
               }
+            }
           }
           // Some js specifics yet to be abstracted.
           if (langID == nsIProgrammingLanguage::JAVASCRIPT) {
               // By default scripts in XUL documents have E4X turned on. We use
               // our implementation knowledge to reuse JSVERSION_HAS_XML as a
               // safe version flag. This is still OK if version is
               // JSVERSION_UNKNOWN (-1),
               version |= JSVERSION_HAS_XML;
--- a/extensions/jssh/nsJSSh.cpp
+++ b/extensions/jssh/nsJSSh.cpp
@@ -584,18 +584,18 @@ NS_IMETHODIMP nsJSSh::Init()
   if (!mJSContext) {
     NS_ERROR("JS_NewContext failed");
     return NS_ERROR_FAILURE;
   }
 
   // Enable e4x:
   JS_SetOptions(mJSContext, JS_GetOptions(mJSContext) | JSOPTION_XML);
   
-  // Enable js1.7 features (let, yield, etc - see bug#351515)
-  JS_SetVersion(mJSContext, JSVERSION_1_7);
+  // Always use the latest js version
+  JS_SetVersion(mJSContext, JSVERSION_LATEST);
   
   mContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
   if (!mContextStack) {
     NS_ERROR("failed to get the nsThreadJSContextStack service");
     return NS_ERROR_FAILURE;
   }
   
   JS_SetErrorReporter(mJSContext, my_ErrorReporter);
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -68,17 +68,18 @@ typedef enum JSVersion {
     JSVERSION_1_3     = 130,
     JSVERSION_1_4     = 140,
     JSVERSION_ECMA_3  = 148,
     JSVERSION_1_5     = 150,
     JSVERSION_1_6     = 160,
     JSVERSION_1_7     = 170,
     JSVERSION_1_8     = 180,
     JSVERSION_DEFAULT = 0,
-    JSVERSION_UNKNOWN = -1
+    JSVERSION_UNKNOWN = -1,
+    JSVERSION_LATEST  = JSVERSION_1_8
 } JSVersion;
 
 #define JSVERSION_IS_ECMA(version) \
     ((version) == JSVERSION_DEFAULT || (version) >= JSVERSION_1_3)
 
 /* Result of typeof operator enumeration. */
 typedef enum JSType {
     JSTYPE_VOID,                /* undefined */
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -506,19 +506,19 @@ mozJSComponentLoader::ReallyInit()
     // Create our compilation context.
     mContext = JS_NewContext(mRuntime, 256);
     if (!mContext)
         return NS_ERROR_OUT_OF_MEMORY;
 
     uint32 options = JS_GetOptions(mContext);
     JS_SetOptions(mContext, options | JSOPTION_XML);
 
-    // enable Javascript 1.7 features (let, yield, etc. - see bug#351515)
-    JS_SetVersion(mContext, JSVERSION_1_7);
-    
+  // Always use the latest js version
+  JS_SetVersion(mContext, JSVERSION_LATEST);
+
 #ifndef XPCONNECT_STANDALONE
     nsCOMPtr<nsIScriptSecurityManager> secman = 
         do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
     if (!secman)
         return NS_ERROR_FAILURE;
 
     rv = secman->GetSystemPrincipal(getter_AddRefs(mSystemPrincipal));
     if (NS_FAILED(rv) || !mSystemPrincipal)