Merge pull request #2631 from artillery/webidl-types

WebIDL Support for byte, octet, and unsigned shorts and longs.
This commit is contained in:
Alon Zakai 2014-08-06 18:02:35 -07:00
Родитель 80c9a24b65 526ccf5304
Коммит 17d837a33c
5 изменённых файлов: 66 добавлений и 0 удалений

Просмотреть файл

@ -58,5 +58,14 @@ object
1
34,34
78
return char 127
char: 127
char: -1
return unsigned char -1
unsigned char: 255
return unsigned short -1
unsigned short int: 65535
return unsigned long -1
unsigned long int: 4294967295
done.

Просмотреть файл

@ -125,6 +125,25 @@ Module.print([enumClassInstance.GetEnum(), Module.EnumClass.e_val].join(','));
// in namespaces, see `Inner` above.
Module.print(Module.e_namespace_val);
typeTester = new TypeTestClass();
Module.print('return char ' + typeTester.ReturnCharMethod());
typeTester.AcceptCharMethod((2<<6)-1);
// Prints -1 because the c++ code accepts unsigned char.
typeTester.AcceptCharMethod((2<<7)-1);
// Prints -1 because all integers are signed in javascript.
Module.print('return unsigned char ' + typeTester.ReturnUnsignedCharMethod());
typeTester.AcceptUnsignedCharMethod((2<<7)-1);
// Prints -1 because all integers are signed in javascript.
Module.print('return unsigned short ' + typeTester.ReturnUnsignedShortMethod());
typeTester.AcceptUnsignedShortMethod((2<<15)-1);
// Prints -1 because all integers are signed in javascript.
Module.print('return unsigned long ' + typeTester.ReturnUnsignedLongMethod());
typeTester.AcceptUnsignedLongMethod((2<<31)-1);
//
Module.print('\ndone.')

Просмотреть файл

@ -93,3 +93,18 @@ class EnumClass {
EnumNamespace::EnumInNamespace GetEnumFromNameSpace() { return EnumNamespace::e_namespace_val; }
};
class TypeTestClass {
public:
char ReturnCharMethod() { return (2<<6)-1; }
void AcceptCharMethod(char x) { printf("char: %d\n", x); }
unsigned char ReturnUnsignedCharMethod() { return (2<<7)-1; }
void AcceptUnsignedCharMethod(unsigned char x) { printf("unsigned char: %u\n", x); }
unsigned short int ReturnUnsignedShortMethod() { return (2<<15)-1; }
void AcceptUnsignedShortMethod(unsigned short x) { printf("unsigned short int: %u\n", x); }
unsigned long ReturnUnsignedLongMethod() { return (2<<31)-1; }
void AcceptUnsignedLongMethod(unsigned long x) { printf("unsigned long int: %u\n", x); }
};

Просмотреть файл

@ -86,3 +86,18 @@ interface EnumClass {
EnumNamespace_EnumInNamespace GetEnumFromNameSpace();
};
interface TypeTestClass {
void TypeTestClass();
byte ReturnCharMethod();
void AcceptCharMethod(byte x);
octet ReturnUnsignedCharMethod();
void AcceptUnsignedCharMethod(octet x);
unsigned short ReturnUnsignedShortMethod();
void AcceptUnsignedShortMethod(unsigned short x);
unsigned long ReturnUnsignedLongMethod();
void AcceptUnsignedLongMethod(unsigned long x);
};

Просмотреть файл

@ -139,8 +139,16 @@ def type_to_c(t, non_pointing=False):
t = t.replace(' (Wrapper)', '')
if t == 'Long':
return 'int'
elif t == 'UnsignedLong':
return 'unsigned int'
elif t == 'Short':
return 'short'
elif t == 'UnsignedShort':
return 'unsigned short'
elif t == 'Byte':
return 'char'
elif t == 'Octet':
return 'unsigned char'
elif t == 'Void':
return 'void'
elif t == 'String':