mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 800493 - Remove now useless libxul code from OS.File. r=froydnj
This commit is contained in:
parent
c579dc0d63
commit
658c67c888
@ -19,10 +19,6 @@ EXTRA_PP_JS_MODULES = \
|
||||
osfile.jsm \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
osfileutils.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
@ -837,21 +837,6 @@
|
||||
};
|
||||
exports.OS.Shared.declareFFI = declareFFI;
|
||||
|
||||
|
||||
/**
|
||||
* Libxul-based utilities, shared by all back-ends.
|
||||
*/
|
||||
|
||||
// Lazy getter for libxul
|
||||
defineLazyGetter(exports.OS.Shared, "libxul",
|
||||
function init_libxul() {
|
||||
return ctypes.open(OS.Constants.Path.libxul);
|
||||
});
|
||||
|
||||
exports.OS.Shared.Utils = {};
|
||||
|
||||
let Strings = exports.OS.Shared.Utils.Strings = {};
|
||||
|
||||
// A bogus array type used to perform pointer arithmetics
|
||||
let gOffsetByType;
|
||||
|
||||
@ -896,73 +881,7 @@
|
||||
return ctypes.cast(addr, type);
|
||||
};
|
||||
|
||||
/**
|
||||
* Import a wide string (e.g. a |jschar.ptr|) as a string.
|
||||
*
|
||||
* @param {CData} wstring The C representation of a widechar string
|
||||
* (can be jschar* or a jschar[]).
|
||||
* @return {string} The same string, as a JavaScript String.
|
||||
*/
|
||||
Strings.importWString = function importWString(wstring) {
|
||||
return wstring.readString();
|
||||
};
|
||||
|
||||
|
||||
let Pointers = {};
|
||||
defineLazyGetter(Pointers, "NS_Free",
|
||||
function init_NS_Free() {
|
||||
return exports.OS.Shared.libxul.declare("osfile_ns_free",
|
||||
ctypes.default_abi,
|
||||
/*return*/ Types.void_t.implementation,
|
||||
/*ptr*/ Types.voidptr_t.implementation);
|
||||
});
|
||||
|
||||
/**
|
||||
* Export a string as a wide string (e.g. a |jschar.ptr|).
|
||||
*
|
||||
* @param {string} string A JavaScript String.
|
||||
* @return {CData} The C representation of that string, as a |jschar*|.
|
||||
* This value will be automatically garbage-collected once it is
|
||||
* not referenced anymore.
|
||||
*/
|
||||
defineLazyGetter(Strings, "exportWString",
|
||||
function init_exportWString() {
|
||||
return declareFFI(exports.OS.Shared.libxul,
|
||||
"osfile_wstrdup",
|
||||
ctypes.default_abi,
|
||||
/*return*/ Types.out_wstring.releaseWith(Pointers.NS_Free),
|
||||
/*ptr*/ Types.wstring);
|
||||
});
|
||||
|
||||
// Encodings
|
||||
|
||||
defineLazyGetter(Strings, "encodeAll",
|
||||
function init_encodeAll() {
|
||||
return declareFFI(exports.OS.Shared.libxul,
|
||||
"osfile_EncodeAll",
|
||||
ctypes.default_abi,
|
||||
/*return*/ Types.void_t.out_ptr.releaseWith(Pointers.NS_Free),
|
||||
/*encoding*/ Types.cstring,
|
||||
/*source*/ Types.wstring,
|
||||
/*bytes*/ Types.uint32_t.out_ptr);
|
||||
});
|
||||
|
||||
defineLazyGetter(Strings, "decodeAll",
|
||||
function init_decodeAll() {
|
||||
let _decodeAll = declareFFI(exports.OS.Shared.libxul, "osfile_DecodeAll",
|
||||
ctypes.default_abi,
|
||||
/*return*/ Types.out_wstring.releaseWith(Pointers.NS_Free),
|
||||
/*encoding*/ Types.cstring,
|
||||
/*source*/ Types.void_t.in_ptr,
|
||||
/*bytes*/ Types.uint32_t);
|
||||
return function decodeAll(encoding, source, bytes) {
|
||||
let decoded = _decodeAll(encoding, source, bytes);
|
||||
if (!decoded) {
|
||||
return null;
|
||||
}
|
||||
return Strings.importWString(decoded);
|
||||
};
|
||||
}
|
||||
);
|
||||
})(this);
|
||||
}
|
||||
|
@ -1,194 +0,0 @@
|
||||
|
||||
#include "mozilla/Scoped.h"
|
||||
|
||||
#include "osfileutils.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCRTGlue.h"
|
||||
|
||||
// Utilities for handling errors
|
||||
namespace {
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#include <windows.h>
|
||||
|
||||
/**
|
||||
* Set the OS-specific error to inform the OS that
|
||||
* the last operation failed because it is not supported.
|
||||
*/
|
||||
void error_not_supported() {
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OS-specific error to inform the OS that
|
||||
* the last operation failed because of an invalid
|
||||
* argument.
|
||||
*/
|
||||
void error_invalid_argument() {
|
||||
SetLastError(ERROR_INVALID_DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OS-specific error to inform the OS that
|
||||
* the last operation failed because of insufficient
|
||||
* memory.
|
||||
*/
|
||||
void error_no_memory() {
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "errno.h"
|
||||
|
||||
/**
|
||||
* Set the OS-specific error to inform the OS that
|
||||
* the last operation failed because it is not supported.
|
||||
*/
|
||||
void error_not_supported() {
|
||||
errno = ENOTSUP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OS-specific error to inform the OS that
|
||||
* the last operation failed because of an invalid
|
||||
* argument.
|
||||
*/
|
||||
void error_invalid_argument() {
|
||||
errno = EINVAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the OS-specific error to inform the OS that
|
||||
* the last operation failed because of insufficient
|
||||
* memory.
|
||||
*/
|
||||
void error_no_memory() {
|
||||
errno = ENOMEM;
|
||||
}
|
||||
|
||||
#endif // defined(XP_WIN)
|
||||
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Memory utilities
|
||||
|
||||
MOZ_EXPORT_API(void) osfile_ns_free(void* buf) {
|
||||
NS_Free(buf);
|
||||
}
|
||||
|
||||
// Unicode utilities
|
||||
|
||||
MOZ_EXPORT_API(PRUnichar*) osfile_wstrdup(PRUnichar* string) {
|
||||
return NS_strdup(string);
|
||||
}
|
||||
|
||||
MOZ_EXPORT_API(PRUnichar*) osfile_DecodeAll(
|
||||
const char* aEncoding,
|
||||
const char* aSource,
|
||||
const int32_t aBytesToDecode)
|
||||
{
|
||||
if (!aEncoding || !aSource) {
|
||||
error_invalid_argument();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICharsetConverterManager> manager =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
error_not_supported();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUnicodeDecoder> decoder;
|
||||
rv = manager->GetUnicodeDecoder(aEncoding, getter_AddRefs(decoder));
|
||||
if (NS_FAILED(rv)) {
|
||||
error_invalid_argument();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Compute an upper bound to the number of chars, allocate buffer
|
||||
|
||||
int32_t srcBytes = aBytesToDecode;
|
||||
int32_t upperBoundChars = 0;
|
||||
rv = decoder->GetMaxLength(aSource, srcBytes, &upperBoundChars);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
int32_t bufSize = (upperBoundChars + 1) * sizeof (PRUnichar);
|
||||
|
||||
mozilla::ScopedFreePtr<PRUnichar> dest((PRUnichar*)NS_Alloc(bufSize));
|
||||
if (dest.get() == nullptr) {
|
||||
error_no_memory();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Convert, add trailing \0
|
||||
|
||||
rv = decoder->Convert(aSource, &srcBytes, dest.rwget(), &upperBoundChars);
|
||||
if (NS_FAILED(rv)) {
|
||||
error_invalid_argument();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dest.rwget()[upperBoundChars] = '\0';
|
||||
|
||||
return dest.forget();
|
||||
}
|
||||
|
||||
MOZ_EXPORT_API(char*) osfile_EncodeAll(
|
||||
const char* aEncoding,
|
||||
const PRUnichar* aSource,
|
||||
int32_t* aBytesProduced)
|
||||
{
|
||||
if (!aEncoding || !aSource || !aBytesProduced) {
|
||||
error_invalid_argument();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsICharsetConverterManager> manager =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
error_not_supported();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIUnicodeEncoder> encoder;
|
||||
rv = manager->GetUnicodeEncoder(aEncoding, getter_AddRefs(encoder));
|
||||
if (NS_FAILED(rv)) {
|
||||
error_invalid_argument();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t srcChars = NS_strlen(aSource);
|
||||
|
||||
int32_t upperBoundBytes = 0;
|
||||
rv = encoder->GetMaxLength(aSource, srcChars, &upperBoundBytes);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
printf_stderr("Encoding %d chars into at up to %d bytes\n", srcChars, upperBoundBytes);
|
||||
int32_t bufSize = upperBoundBytes;
|
||||
mozilla::ScopedFreePtr<char> dest((char*)NS_Alloc(bufSize));
|
||||
|
||||
if (dest.get() == nullptr) {
|
||||
error_no_memory();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rv = encoder->Convert(aSource, &srcChars, dest.rwget(), &upperBoundBytes);
|
||||
if (NS_FAILED(rv)) {
|
||||
error_invalid_argument();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
*aBytesProduced = upperBoundBytes;
|
||||
return dest.forget();
|
||||
}
|
||||
|
||||
} // extern "C"
|
@ -1,65 +0,0 @@
|
||||
#ifndef mozilla_osfileutils_h__
|
||||
#define mozilla_osfileutils_h__
|
||||
|
||||
#include "mozilla/Types.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
#include "nsIUnicodeEncoder.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Memory utilities
|
||||
|
||||
/**
|
||||
* As |NS_Free|, but exported.
|
||||
*/
|
||||
MOZ_EXPORT_API(void) osfile_ns_free(void* buf);
|
||||
|
||||
// Unicode utilities
|
||||
|
||||
/**
|
||||
* Duplicate a Unicode string, as per wpcpy/StrDupW.
|
||||
*
|
||||
* @param source A well-formed, nul-terminated, Unicode string.
|
||||
*
|
||||
* @return Either |NULL| if there was not enough memory to copy the
|
||||
* string, or a new string with the same contents as |source|.
|
||||
* Memory MUST be released with |osfile_ns_free|.
|
||||
*/
|
||||
MOZ_EXPORT_API(PRUnichar*) osfile_wstrdup(PRUnichar* source);
|
||||
|
||||
/**
|
||||
* Decode a nul-terminated C string into a Unicode string.
|
||||
*
|
||||
* @param aEncoding The encoding to use.
|
||||
* @param aSource The C string to decode.
|
||||
* @param aBytesToDecode The number of bytes to decode from |aSource|.
|
||||
*
|
||||
* @return null in case of error, otherwise a sequence of Unicode
|
||||
* chars, representing |aSource|. This memory MUST be released with
|
||||
* |NS_Free|/|osfile_ns_free|.
|
||||
*/
|
||||
MOZ_EXPORT_API(PRUnichar*) osfile_DecodeAll(
|
||||
const char* aEncoding,
|
||||
const char* aSource,
|
||||
const int32_t aBytesToDecode);
|
||||
|
||||
/**
|
||||
* Encode a complete Unicode string into a set of bytes.
|
||||
*
|
||||
* @param aEncoding The encoding to use.
|
||||
* @param aSource The Unicode string to encode. Must be nul-terminated.
|
||||
* @param aBytesWritten (out) The number of bytes encoded.
|
||||
*
|
||||
* @return null in case of error, otherwise a new buffer. The
|
||||
* number of bytes actually allocated may be higher than
|
||||
* |aBytesWritten|. The buffer MUST be released with
|
||||
* |NS_Free|/|osfile_ns_free|.
|
||||
*/
|
||||
MOZ_EXPORT_API(char*) osfile_EncodeAll(
|
||||
const char* aEncoding,
|
||||
const PRUnichar* aSource,
|
||||
int32_t* aBytesWritten);
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // mozilla_osfileutils_h__
|
@ -24,7 +24,6 @@ self.onmessage = function onmessage_start(msg) {
|
||||
};
|
||||
try {
|
||||
test_init();
|
||||
test_unicode();
|
||||
test_offsetby();
|
||||
test_open_existing_file();
|
||||
test_open_non_existing_file();
|
||||
@ -66,30 +65,6 @@ function test_init() {
|
||||
importScripts("resource://gre/modules/osfile.jsm");
|
||||
}
|
||||
|
||||
|
||||
function test_unicode() {
|
||||
ok(true, "Starting test_unicode");
|
||||
function test_go_round(encoding, sentence) {
|
||||
let bytes = new OS.Shared.Type.uint32_t.implementation();
|
||||
let pBytes = bytes.address();
|
||||
ok(true, "test_unicode: testing encoding of " + sentence + " with encoding " + encoding);
|
||||
let encoded = OS.Shared.Utils.Strings.encodeAll(encoding, sentence, pBytes);
|
||||
let decoded = OS.Shared.Utils.Strings.decodeAll(encoding, encoded, bytes);
|
||||
isnot(decoded, null, "test_unicode: Decoding returned a string");
|
||||
is(decoded.length, sentence.length, "test_unicode: Decoding + encoding returns strings with the same length");
|
||||
is(decoded, sentence, "test_unicode: Decoding + encoding returns the same string");
|
||||
}
|
||||
let tests = ["This is a simple test","àáâäèéêëíìîïòóôöùúûüçß","骥䥚ぶ 䤦べ祌褦鋨 きょげヒャ蟥誨 もゴ 栩を愦 堦馺ぢょ䰯蟤 禺つみゃ期楥 勩谨障り䶥 蟤れ, 訦き モじゃむ㧦ゔ 勩谨障り䶥 堥駪グェ 竨ぢゅ嶥鏧䧦 捨ヴョに䋯ざ 䦧樚 焯じゅ妦 っ勯杯 堦馺ぢょ䰯蟤 滩シャ饥鎌䧺 珦ひゃ, ざやぎ えゐ へ簯ホゥ馯夦 槎褤せ檨壌","Νισλ αλικυιδ περτινασια ναμ ετ, νε ιρασυνδια νεγλεγενθυρ ηας, νο νυμκυαμ εφφισιενδι φις. Εως μινιμυμ ελειφενδ ατ, κυωτ μαλυισετ φυλπυτατε συμ ιδ."];
|
||||
let encodings = ["utf-8", "utf-16"];
|
||||
for each (let encoding in encodings) {
|
||||
for each (let i in tests) {
|
||||
test_go_round(encoding, i);
|
||||
}
|
||||
test_go_round(encoding, tests.join());
|
||||
}
|
||||
ok(true, "test_unicode: complete");
|
||||
}
|
||||
|
||||
function test_offsetby() {
|
||||
ok(true, "Starting test_offsetby");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user