diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 2d1b52f0908..5043714341a 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -80,6 +80,7 @@ #include "nsIObserverService.h" #include "nsIContent.h" #include "nsAutoPtr.h" +#include "nsDOMJSUtils.h" static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 27877994b49..985181e639c 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -3384,8 +3384,9 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, if (manager) { nsIDocument *ownerDoc = GetOwnerDoc(); + PRUint32 lang = nsIProgrammingLanguage::JAVASCRIPT; // XXX - fix me! rv = - manager->AddScriptEventListener(target, aAttribute, aValue, defer, + manager->AddScriptEventListener(target, aAttribute, aValue, lang, defer, !nsContentUtils::IsChromeDoc(ownerDoc)); } diff --git a/mozilla/content/base/src/nsParserUtils.cpp b/mozilla/content/base/src/nsParserUtils.cpp index 2d278225b1d..5dac3f6035e 100644 --- a/mozilla/content/base/src/nsParserUtils.cpp +++ b/mozilla/content/base/src/nsParserUtils.cpp @@ -40,6 +40,7 @@ #include "jsapi.h" #include "nsReadableUtils.h" #include "nsCRT.h" +#include "nsIProgrammingLanguage.h" #define SKIP_WHITESPACE(iter, end_iter) \ while ((iter) != (end_iter) && nsCRT::IsAsciiSpace(*(iter))) { \ @@ -124,7 +125,7 @@ nsParserUtils::GetQuotedAttributeValue(const nsAString& aSource, // Returns PR_TRUE if the language name is a version of JavaScript and // PR_FALSE otherwise PRBool -nsParserUtils::IsJavaScriptLanguage(const nsString& aName, const char* *aVersion) +nsParserUtils::IsJavaScriptLanguage(const nsString& aName, PRUint32 *aFlags) { JSVersion version = JSVERSION_UNKNOWN; @@ -153,7 +154,7 @@ nsParserUtils::IsJavaScriptLanguage(const nsString& aName, const char* *aVersion } if (version == JSVERSION_UNKNOWN) return PR_FALSE; - *aVersion = JS_VersionToString(version); + *aFlags = version; return PR_TRUE; } diff --git a/mozilla/content/base/src/nsParserUtils.h b/mozilla/content/base/src/nsParserUtils.h index 4f8228389c7..befee835b97 100644 --- a/mozilla/content/base/src/nsParserUtils.h +++ b/mozilla/content/base/src/nsParserUtils.h @@ -48,7 +48,7 @@ public: nsAString& aValue); static PRBool - IsJavaScriptLanguage(const nsString& aName, const char* *aVersion); + IsJavaScriptLanguage(const nsString& aName, PRUint32 *aVerFlags); static void SplitMimeType(const nsAString& aValue, nsString& aType, diff --git a/mozilla/content/base/src/nsScriptLoader.cpp b/mozilla/content/base/src/nsScriptLoader.cpp index 322ae8fd760..7c46742570e 100644 --- a/mozilla/content/base/src/nsScriptLoader.cpp +++ b/mozilla/content/base/src/nsScriptLoader.cpp @@ -48,6 +48,7 @@ #include "nsNetUtil.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" +#include "nsILanguageRuntime.h" #include "nsINodeInfo.h" #include "nsIScriptSecurityManager.h" #include "nsIPrincipal.h" @@ -63,6 +64,7 @@ #include "nsAutoPtr.h" static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); +static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); ////////////////////////////////////////////////////////////// // @@ -108,8 +110,7 @@ class nsScriptLoadRequest : public nsISupports { public: nsScriptLoadRequest(nsIScriptElement* aElement, nsIScriptLoaderObserver* aObserver, - const char* aVersionString, - PRBool aHasE4XOption); + PRUint32 aVersion); virtual ~nsScriptLoadRequest(); NS_DECL_ISUPPORTS @@ -123,21 +124,19 @@ public: PRPackedBool mLoading; // Are we still waiting for a load to complete? PRPackedBool mWasPending; // Processed immediately or pending PRPackedBool mIsInline; // Is the script inline or loaded? - PRPackedBool mHasE4XOption; // Has E4X=1 script type parameter nsString mScriptText; // Holds script for loaded scripts - const char* mJSVersion; // We don't own this string + PRUint32 mJSVersion; nsCOMPtr mURI; PRInt32 mLineNo; }; nsScriptLoadRequest::nsScriptLoadRequest(nsIScriptElement* aElement, nsIScriptLoaderObserver* aObserver, - const char* aVersionString, - PRBool aHasE4XOption) : + PRUint32 aVersion) : mElement(aElement), mObserver(aObserver), mLoading(PR_TRUE), mWasPending(PR_FALSE), - mIsInline(PR_TRUE), mHasE4XOption(aHasE4XOption), - mJSVersion(aVersionString), mLineNo(1) + mIsInline(PR_TRUE), + mJSVersion(aVersion), mLineNo(1) { } @@ -380,6 +379,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement, // Script evaluation can also be disabled in the current script // context even though it's enabled in the document. + // XXXMarkh - note we are still checking js here even though another + // language may be specified. Need to clarify the "IsEnabled()" semantics nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); if (globalObject) { @@ -393,35 +394,20 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement, } } - PRBool isJavaScript = PR_TRUE; - PRBool hasE4XOption = PR_FALSE; - const char* jsVersionString = nsnull; + nsCOMPtr factory = do_GetService(kDOMScriptObjectFactoryCID); + NS_ENSURE_TRUE(factory, nsnull); + + nsCOMPtr languageRuntime; + PRUint32 version = 0; + PRBool seenLanguage = PR_FALSE; + nsAutoString language, type, src; - // "language" is a deprecated attribute of HTML, so we check it only for - // HTML script elements. - nsCOMPtr htmlScriptElement = - do_QueryInterface(aElement); - if (htmlScriptElement) { - // Check the language attribute first, so type can trump language. - htmlScriptElement->GetAttribute(NS_LITERAL_STRING("language"), language); - if (!language.IsEmpty()) { - isJavaScript = nsParserUtils::IsJavaScriptLanguage(language, - &jsVersionString); - - // IE, Opera, etc. do not respect language version, so neither should - // we at this late date in the browser wars saga. Note that this change - // affects HTML but not XUL or SVG (but note also that XUL has its own - // code to check nsParserUtils::IsJavaScriptLanguage -- that's probably - // a separate bug, one we may not be able to fix short of XUL2). See - // bug 255895 (https://bugzilla.mozilla.org/show_bug.cgi?id=255895). - jsVersionString = ::JS_VersionToString(JSVERSION_DEFAULT); - } - } - // Check the type attribute to determine language and version. + // If type exists, it trumps the deprecated 'language=' aElement->GetScriptType(type); if (!type.IsEmpty()) { + seenLanguage = PR_TRUE; nsCOMPtr mimeHdrParser = do_GetService("@mozilla.org/network/mime-hdrparam;1"); NS_ENSURE_TRUE(mimeHdrParser, NS_ERROR_FAILURE); @@ -434,6 +420,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement, mimeType); NS_ENSURE_SUCCESS(rv, rv); + // Javascript keeps the fast path, optimized for most-likely type // Table ordered from most to least likely JS MIME types. // See bug 62485, feel free to add