зеркало из https://github.com/mozilla/gecko-dev.git
Bug 656647: File constructor should take nsIFiles. r=sicking
This commit is contained in:
Родитель
cbd257817b
Коммит
c582ba8b08
|
@ -629,16 +629,34 @@ nsDOMFile::Initialize(nsISupports* aOwner,
|
|||
PRUint32 aArgc,
|
||||
jsval* aArgv)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (!nsContentUtils::IsCallerChrome()) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR; // Real short trip
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(aArgc > 0, NS_ERROR_UNEXPECTED);
|
||||
|
||||
// We expect to get a path to represent as a File object
|
||||
if (!JSVAL_IS_STRING(aArgv[0]))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
// We expect to get a path to represent as a File object,
|
||||
// or an nsIFile
|
||||
nsCOMPtr<nsIFile> file;
|
||||
if (!JSVAL_IS_STRING(aArgv[0])) {
|
||||
// Lets see if it's an nsIFile
|
||||
if (!JSVAL_IS_OBJECT(aArgv[0])) {
|
||||
return NS_ERROR_UNEXPECTED; // We're not interested
|
||||
}
|
||||
|
||||
JSObject* obj = JSVAL_TO_OBJECT(aArgv[0]);
|
||||
NS_ASSERTION(obj, "This is a bit odd");
|
||||
|
||||
// Is it an nsIFile
|
||||
file = do_QueryInterface(
|
||||
nsContentUtils::XPConnect()->
|
||||
GetNativeOfWrapper(aCx, obj));
|
||||
if (!file)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
} else {
|
||||
// It's a string
|
||||
JSString* str = JS_ValueToString(aCx, aArgv[0]);
|
||||
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
|
||||
|
||||
|
@ -652,8 +670,9 @@ nsDOMFile::Initialize(nsISupports* aOwner,
|
|||
PR_FALSE, getter_AddRefs(localFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIFile> file = do_QueryInterface(localFile, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
file = do_QueryInterface(localFile);
|
||||
NS_ASSERTION(file, "This should never happen");
|
||||
}
|
||||
|
||||
PRBool exists;
|
||||
rv = file->Exists(&exists);
|
||||
|
|
|
@ -45,10 +45,13 @@ file.append("test");
|
|||
file.append("chrome");
|
||||
file.append("fileconstructor_file.png");
|
||||
|
||||
var domfile = new File(file.path);
|
||||
ok(domfile instanceof File, "File() should return a File");
|
||||
is(domfile.type, "image/png", "File should be a PNG");
|
||||
is(domfile.size, 95, "File has size 95 (and more importantly we can read it)");
|
||||
doTest(new File(file.path));
|
||||
doTest(new File(file));
|
||||
function doTest(domfile) {
|
||||
ok(domfile instanceof File, "File() should return a File");
|
||||
is(domfile.type, "image/png", "File should be a PNG");
|
||||
is(domfile.size, 95, "File has size 95 (and more importantly we can read it)");
|
||||
}
|
||||
|
||||
try {
|
||||
var boomfile = new File();
|
||||
|
|
Загрузка…
Ссылка в новой задаче