mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Merge inbound to mozilla-central r=merge a=merge
This commit is contained in:
commit
5a2831f643
@ -459,7 +459,9 @@ public:
|
||||
size_t Length = 0;
|
||||
for (std::string &Line : Nodupes) {
|
||||
Length += Line.length();
|
||||
fwrite(Line.c_str(), Line.length(), 1, Fp);
|
||||
if (fwrite(Line.c_str(), Line.length(), 1, Fp) != 1) {
|
||||
fprintf(stderr, "Unable to write to output file %s\n", Filename.c_str());
|
||||
}
|
||||
}
|
||||
fclose(Fp);
|
||||
|
||||
|
@ -1542,28 +1542,6 @@ nsContentUtils::IsJavaScriptLanguage(const nsString& aName)
|
||||
aName.LowerCaseEqualsLiteral("javascript1.5");
|
||||
}
|
||||
|
||||
JSVersion
|
||||
nsContentUtils::ParseJavascriptVersion(const nsAString& aVersionStr)
|
||||
{
|
||||
if (aVersionStr.Length() != 3 || aVersionStr[0] != '1' ||
|
||||
aVersionStr[1] != '.') {
|
||||
return JSVERSION_UNKNOWN;
|
||||
}
|
||||
|
||||
switch (aVersionStr[2]) {
|
||||
case '0': /* fall through */
|
||||
case '1': /* fall through */
|
||||
case '2': /* fall through */
|
||||
case '3': /* fall through */
|
||||
case '4': /* fall through */
|
||||
case '5': return JSVERSION_DEFAULT;
|
||||
case '6': return JSVERSION_1_6;
|
||||
case '7': return JSVERSION_1_7;
|
||||
case '8': return JSVERSION_1_8;
|
||||
default: return JSVERSION_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsContentUtils::SplitMimeType(const nsAString& aValue, nsString& aType,
|
||||
nsString& aParams)
|
||||
|
@ -2633,12 +2633,6 @@ public:
|
||||
*/
|
||||
static bool IsJavaScriptLanguage(const nsString& aName);
|
||||
|
||||
/**
|
||||
* Returns the JSVersion for a string of the form '1.n', n = 0, ..., 8, and
|
||||
* JSVERSION_UNKNOWN for other strings.
|
||||
*/
|
||||
static JSVersion ParseJavascriptVersion(const nsAString& aVersionStr);
|
||||
|
||||
static bool IsJavascriptMIMEType(const nsAString& aMIMEType);
|
||||
|
||||
static void SplitMimeType(const nsAString& aValue, nsString& aType,
|
||||
|
@ -29,13 +29,13 @@ NS_IMPL_ADDREF_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
NS_IMPL_RELEASE_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
|
||||
ModuleLoadRequest::ModuleLoadRequest(nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
ValidJSVersion aValidJSVersion,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata& aIntegrity,
|
||||
ScriptLoader* aLoader)
|
||||
: ScriptLoadRequest(ScriptKind::Module,
|
||||
aElement,
|
||||
aVersion,
|
||||
aValidJSVersion,
|
||||
aCORSMode,
|
||||
aIntegrity),
|
||||
mIsTopLevel(true),
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ModuleLoadRequest, ScriptLoadRequest)
|
||||
|
||||
ModuleLoadRequest(nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
ValidJSVersion aValidJSVersion,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata& aIntegrity,
|
||||
ScriptLoader* aLoader);
|
||||
|
@ -40,7 +40,7 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
ValidJSVersion aValidJSVersion,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
const mozilla::dom::SRIMetadata& aIntegrity)
|
||||
: mKind(aKind)
|
||||
@ -63,7 +63,7 @@ ScriptLoadRequest::ScriptLoadRequest(ScriptKind aKind,
|
||||
, mScriptText()
|
||||
, mScriptBytecode()
|
||||
, mBytecodeOffset(0)
|
||||
, mJSVersion(aVersion)
|
||||
, mValidJSVersion(aValidJSVersion)
|
||||
, mLineNo(1)
|
||||
, mCORSMode(aCORSMode)
|
||||
, mIntegrity(aIntegrity)
|
||||
|
@ -29,6 +29,11 @@ enum class ScriptKind {
|
||||
Module
|
||||
};
|
||||
|
||||
enum class ValidJSVersion : bool {
|
||||
Invalid,
|
||||
Valid
|
||||
};
|
||||
|
||||
/*
|
||||
* A class that handles loading and evaluation of <script> elements.
|
||||
*/
|
||||
@ -48,7 +53,7 @@ protected:
|
||||
public:
|
||||
ScriptLoadRequest(ScriptKind aKind,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
ValidJSVersion aValidJSVersion,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
const mozilla::dom::SRIMetadata &aIntegrity);
|
||||
|
||||
@ -178,7 +183,7 @@ public:
|
||||
mozilla::Vector<uint8_t> mScriptBytecode;
|
||||
uint32_t mBytecodeOffset; // Offset of the bytecode in mScriptBytecode
|
||||
|
||||
uint32_t mJSVersion;
|
||||
ValidJSVersion mValidJSVersion;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
|
||||
|
@ -746,7 +746,7 @@ ScriptLoader::StartFetchingModuleAndDependencies(ModuleLoadRequest* aRequest,
|
||||
MOZ_ASSERT(aURI);
|
||||
|
||||
RefPtr<ModuleLoadRequest> childRequest =
|
||||
new ModuleLoadRequest(aRequest->mElement, aRequest->mJSVersion,
|
||||
new ModuleLoadRequest(aRequest->mElement, aRequest->mValidJSVersion,
|
||||
aRequest->mCORSMode, aRequest->mIntegrity, this);
|
||||
|
||||
childRequest->mIsTopLevel = false;
|
||||
@ -1039,7 +1039,7 @@ ScriptLoader::StartLoad(ScriptLoadRequest* aRequest)
|
||||
aRequest->mCacheInfo = nullptr;
|
||||
nsCOMPtr<nsICacheInfoChannel> cic(do_QueryInterface(channel));
|
||||
if (cic && nsContentUtils::IsBytecodeCacheEnabled() &&
|
||||
aRequest->mJSVersion == JSVERSION_DEFAULT) {
|
||||
aRequest->mValidJSVersion == ValidJSVersion::Valid) {
|
||||
if (!aRequest->IsLoadingSource()) {
|
||||
// Inform the HTTP cache that we prefer to have information coming from the
|
||||
// bytecode cache instead of the sources, if such entry is already registered.
|
||||
@ -1169,12 +1169,29 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns ValidJSVersion::Valid if aVersionStr is a string of the form
|
||||
* '1.n', n = 0, ..., 8, and ValidJSVersion::Invalid for other strings.
|
||||
*/
|
||||
static ValidJSVersion
|
||||
ParseJavascriptVersion(const nsAString& aVersionStr)
|
||||
{
|
||||
if (aVersionStr.Length() != 3 || aVersionStr[0] != '1' ||
|
||||
aVersionStr[1] != '.') {
|
||||
return ValidJSVersion::Invalid;
|
||||
}
|
||||
if ('0' <= aVersionStr[2] && aVersionStr[2] <= '8') {
|
||||
return ValidJSVersion::Valid;
|
||||
}
|
||||
return ValidJSVersion::Invalid;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
ParseTypeAttribute(const nsAString& aType, JSVersion* aVersion)
|
||||
ParseTypeAttribute(const nsAString& aType, ValidJSVersion* aVersion)
|
||||
{
|
||||
MOZ_ASSERT(!aType.IsEmpty());
|
||||
MOZ_ASSERT(aVersion);
|
||||
MOZ_ASSERT(*aVersion == JSVERSION_DEFAULT);
|
||||
MOZ_ASSERT(*aVersion == ValidJSVersion::Valid);
|
||||
|
||||
nsContentTypeParser parser(aType);
|
||||
|
||||
@ -1191,7 +1208,7 @@ ParseTypeAttribute(const nsAString& aType, JSVersion* aVersion)
|
||||
rv = parser.GetParameter("version", versionName);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aVersion = nsContentUtils::ParseJavascriptVersion(versionName);
|
||||
*aVersion = ParseJavascriptVersion(versionName);
|
||||
} else if (rv != NS_ERROR_INVALID_ARG) {
|
||||
return false;
|
||||
}
|
||||
@ -1230,11 +1247,13 @@ CSPAllowsInlineScript(nsIScriptElement* aElement, nsIDocument* aDocument)
|
||||
ScriptLoadRequest*
|
||||
ScriptLoader::CreateLoadRequest(ScriptKind aKind,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion, CORSMode aCORSMode,
|
||||
ValidJSVersion aValidJSVersion,
|
||||
CORSMode aCORSMode,
|
||||
const SRIMetadata& aIntegrity)
|
||||
{
|
||||
if (aKind == ScriptKind::Classic) {
|
||||
ScriptLoadRequest* slr = new ScriptLoadRequest(aKind, aElement, aVersion, aCORSMode,
|
||||
ScriptLoadRequest* slr = new ScriptLoadRequest(aKind, aElement,
|
||||
aValidJSVersion, aCORSMode,
|
||||
aIntegrity);
|
||||
|
||||
LOG(("ScriptLoader %p creates ScriptLoadRequest %p", this, slr));
|
||||
@ -1242,7 +1261,8 @@ ScriptLoader::CreateLoadRequest(ScriptKind aKind,
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aKind == ScriptKind::Module);
|
||||
return new ModuleLoadRequest(aElement, aVersion, aCORSMode, aIntegrity, this);
|
||||
return new ModuleLoadRequest(aElement, aValidJSVersion, aCORSMode,
|
||||
aIntegrity, this);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -1265,7 +1285,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
|
||||
return false;
|
||||
}
|
||||
|
||||
JSVersion version = JSVERSION_DEFAULT;
|
||||
ValidJSVersion validJSVersion = ValidJSVersion::Valid;
|
||||
|
||||
// Check the type attribute to determine language and version.
|
||||
// If type exists, it trumps the deprecated 'language='
|
||||
@ -1277,7 +1297,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
|
||||
if (ModuleScriptsEnabled() && type.LowerCaseEqualsASCII("module")) {
|
||||
scriptKind = ScriptKind::Module;
|
||||
} else {
|
||||
NS_ENSURE_TRUE(ParseTypeAttribute(type, &version), false);
|
||||
NS_ENSURE_TRUE(ParseTypeAttribute(type, &validJSVersion), false);
|
||||
}
|
||||
} else if (!hasType) {
|
||||
// no 'type=' element
|
||||
@ -1380,7 +1400,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
|
||||
principal = scriptContent->NodePrincipal();
|
||||
}
|
||||
|
||||
request = CreateLoadRequest(scriptKind, aElement, version, ourCORSMode,
|
||||
request = CreateLoadRequest(scriptKind, aElement, validJSVersion, ourCORSMode,
|
||||
sriMetadata);
|
||||
request->mURI = scriptURI;
|
||||
request->mTriggeringPrincipal = Move(principal);
|
||||
@ -1422,7 +1442,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
|
||||
NS_ASSERTION(!request->InCompilingStage(),
|
||||
"Request should not yet be in compiling stage.");
|
||||
|
||||
request->mJSVersion = version;
|
||||
request->mValidJSVersion = validJSVersion;
|
||||
|
||||
if (aElement->GetScriptAsync()) {
|
||||
request->mIsAsync = true;
|
||||
@ -1523,9 +1543,9 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement* aElement)
|
||||
}
|
||||
|
||||
// Inline scripts ignore ther CORS mode and are always CORS_NONE
|
||||
request = CreateLoadRequest(scriptKind, aElement, version, CORS_NONE,
|
||||
request = CreateLoadRequest(scriptKind, aElement, validJSVersion, CORS_NONE,
|
||||
SRIMetadata()); // SRI doesn't apply
|
||||
request->mJSVersion = version;
|
||||
request->mValidJSVersion = validJSVersion;
|
||||
request->mIsInline = true;
|
||||
request->mURI = mDocument->GetDocumentURI();
|
||||
request->mTriggeringPrincipal = mDocument->NodePrincipal();
|
||||
@ -2145,8 +2165,7 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSVersion version = JSVersion(aRequest->mJSVersion);
|
||||
if (version == JSVERSION_UNKNOWN) {
|
||||
if (aRequest->mValidJSVersion == ValidJSVersion::Invalid) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -3110,7 +3129,7 @@ ScriptLoader::PreloadURI(nsIURI* aURI, const nsAString& aCharset,
|
||||
}
|
||||
|
||||
RefPtr<ScriptLoadRequest> request =
|
||||
CreateLoadRequest(ScriptKind::Classic, nullptr, 0,
|
||||
CreateLoadRequest(ScriptKind::Classic, nullptr, ValidJSVersion::Valid,
|
||||
Element::StringToCORSMode(aCrossOrigin), sriMetadata);
|
||||
request->mURI = aURI;
|
||||
request->mTriggeringPrincipal = mDocument->NodePrincipal();
|
||||
|
@ -341,7 +341,7 @@ private:
|
||||
|
||||
ScriptLoadRequest* CreateLoadRequest(ScriptKind aKind,
|
||||
nsIScriptElement* aElement,
|
||||
uint32_t aVersion,
|
||||
ValidJSVersion aValidJSVersion,
|
||||
mozilla::CORSMode aCORSMode,
|
||||
const mozilla::dom::SRIMetadata& aIntegrity);
|
||||
|
||||
|
@ -835,7 +835,6 @@ XULContentSinkImpl::OpenScript(const char16_t** aAttributes,
|
||||
const uint32_t aLineNumber)
|
||||
{
|
||||
bool isJavaScript = true;
|
||||
uint32_t version = JSVERSION_DEFAULT;
|
||||
nsresult rv;
|
||||
|
||||
// Look for SRC attribute and look for a LANGUAGE attribute
|
||||
@ -861,7 +860,6 @@ XULContentSinkImpl::OpenScript(const char16_t** aAttributes,
|
||||
|
||||
if (nsContentUtils::IsJavascriptMIMEType(mimeType)) {
|
||||
isJavaScript = true;
|
||||
version = JSVERSION_DEFAULT;
|
||||
|
||||
// Get the version string, and ensure that JavaScript supports it.
|
||||
nsAutoString versionName;
|
||||
@ -888,7 +886,6 @@ XULContentSinkImpl::OpenScript(const char16_t** aAttributes,
|
||||
nsAutoString lang(aAttributes[1]);
|
||||
if (nsContentUtils::IsJavaScriptLanguage(lang)) {
|
||||
isJavaScript = true;
|
||||
version = JSVERSION_DEFAULT;
|
||||
}
|
||||
}
|
||||
aAttributes += 2;
|
||||
@ -904,7 +901,7 @@ XULContentSinkImpl::OpenScript(const char16_t** aAttributes,
|
||||
if (doc)
|
||||
globalObject = do_QueryInterface(doc->GetWindow());
|
||||
RefPtr<nsXULPrototypeScript> script =
|
||||
new nsXULPrototypeScript(aLineNumber, version);
|
||||
new nsXULPrototypeScript(aLineNumber);
|
||||
|
||||
// If there is a SRC attribute...
|
||||
if (! src.IsEmpty()) {
|
||||
|
@ -2251,7 +2251,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
|
||||
break;
|
||||
case eType_Script: {
|
||||
// language version/options obtained during deserialization.
|
||||
RefPtr<nsXULPrototypeScript> script = new nsXULPrototypeScript(0, 0);
|
||||
RefPtr<nsXULPrototypeScript> script = new nsXULPrototypeScript(0);
|
||||
|
||||
rv = aStream->ReadBoolean(&script->mOutOfLine);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
|
||||
@ -2392,13 +2392,12 @@ nsXULPrototypeElement::TraceAllScripts(JSTracer* aTrc)
|
||||
// nsXULPrototypeScript
|
||||
//
|
||||
|
||||
nsXULPrototypeScript::nsXULPrototypeScript(uint32_t aLineNo, uint32_t aVersion)
|
||||
nsXULPrototypeScript::nsXULPrototypeScript(uint32_t aLineNo)
|
||||
: nsXULPrototypeNode(eType_Script),
|
||||
mLineNo(aLineNo),
|
||||
mSrcLoading(false),
|
||||
mOutOfLine(true),
|
||||
mSrcLoadWaiters(nullptr),
|
||||
mLangVersion(aVersion),
|
||||
mScriptObject(nullptr)
|
||||
{
|
||||
}
|
||||
@ -2431,7 +2430,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
|
||||
nsresult rv;
|
||||
rv = aStream->Write32(mLineNo);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = aStream->Write32(mLangVersion);
|
||||
rv = aStream->Write32(0); // See bug 1418294.
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
@ -2501,7 +2500,8 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
|
||||
// Read basic prototype data
|
||||
rv = aStream->Read32(&mLineNo);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = aStream->Read32(&mLangVersion);
|
||||
uint32_t dummy;
|
||||
rv = aStream->Read32(&dummy); // See bug 1418294.
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
@ -2696,7 +2696,6 @@ nsXULPrototypeScript::Compile(JS::SourceBufferHolder& aSrcBuf,
|
||||
}
|
||||
|
||||
// Ok, compile it to create a prototype script object!
|
||||
NS_ENSURE_TRUE(JSVersion(mLangVersion) != JSVERSION_UNKNOWN, NS_OK);
|
||||
JS::CompileOptions options(cx);
|
||||
options.setIntroductionType("scriptElement")
|
||||
.setFileAndLine(urlspec.get(), aLineNo);
|
||||
|
@ -212,7 +212,7 @@ class XULDocument;
|
||||
class nsXULPrototypeScript : public nsXULPrototypeNode
|
||||
{
|
||||
public:
|
||||
nsXULPrototypeScript(uint32_t aLineNo, uint32_t version);
|
||||
explicit nsXULPrototypeScript(uint32_t aLineNo);
|
||||
virtual ~nsXULPrototypeScript();
|
||||
|
||||
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
|
||||
@ -269,7 +269,6 @@ public:
|
||||
bool mSrcLoading;
|
||||
bool mOutOfLine;
|
||||
mozilla::dom::XULDocument* mSrcLoadWaiters; // [OWNER] but not COMPtr
|
||||
uint32_t mLangVersion;
|
||||
private:
|
||||
JS::Heap<JSScript*> mScriptObject;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user