Bug 780111 - Share code with new DOM bindings for primitive conversions in XPCConvert::JSData2Native; r=bholley

This commit is contained in:
Ms2ger 2012-08-04 09:29:18 +02:00
Родитель 716239c705
Коммит f2a97792fa
2 изменённых файлов: 16 добавлений и 43 удалений

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

@ -62,15 +62,16 @@ EXPORTS_mozilla = \
$(NULL) $(NULL)
EXPORTS_$(binding_include_path) = \ EXPORTS_$(binding_include_path) = \
BindingUtils.h \
DOMJSClass.h \ DOMJSClass.h \
Errors.msg \ Errors.msg \
Nullable.h \
PrimitiveConversions.h \
PrototypeList.h \ PrototypeList.h \
RegisterBindings.h \ RegisterBindings.h \
Nullable.h \
TypedArray.h \ TypedArray.h \
BindingUtils.h \
UnionTypes.h \
UnionConversions.h \ UnionConversions.h \
UnionTypes.h \
$(exported_binding_headers) \ $(exported_binding_headers) \
$(NULL) $(NULL)

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

@ -25,6 +25,7 @@
#include "jsfriendapi.h" #include "jsfriendapi.h"
#include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/PrimitiveConversions.h"
using namespace xpc; using namespace xpc;
using namespace mozilla; using namespace mozilla;
@ -372,10 +373,6 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
JSContext* cx = ccx.GetJSContext(); JSContext* cx = ccx.GetJSContext();
int32_t ti;
uint32_t tu;
double td;
JSBool tb;
JSBool isDOMString = true; JSBool isDOMString = true;
if (pErr) if (pErr)
@ -383,52 +380,27 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s,
switch (type.TagPart()) { switch (type.TagPart()) {
case nsXPTType::T_I8 : case nsXPTType::T_I8 :
if (!JS_ValueToECMAInt32(cx, s, &ti)) return ValueToPrimitive(cx, s, static_cast<int8_t*>(d));
return false;
*((int8_t*)d) = int8_t(ti);
break;
case nsXPTType::T_I16 : case nsXPTType::T_I16 :
if (!JS_ValueToECMAInt32(cx, s, &ti)) return ValueToPrimitive(cx, s, static_cast<int16_t*>(d));
return false;
*((int16_t*)d) = int16_t(ti);
break;
case nsXPTType::T_I32 : case nsXPTType::T_I32 :
if (!JS_ValueToECMAInt32(cx, s, (int32_t*)d)) return ValueToPrimitive(cx, s, static_cast<int32_t*>(d));
return false;
break;
case nsXPTType::T_I64 : case nsXPTType::T_I64 :
return ValueToInt64(cx, s, (int64_t*)d); return ValueToPrimitive(cx, s, static_cast<int64_t*>(d));
case nsXPTType::T_U8 : case nsXPTType::T_U8 :
if (!JS_ValueToECMAUint32(cx, s, &tu)) return ValueToPrimitive(cx, s, static_cast<uint8_t*>(d));
return false;
*((uint8_t*)d) = uint8_t(tu);
break;
case nsXPTType::T_U16 : case nsXPTType::T_U16 :
if (!JS_ValueToECMAUint32(cx, s, &tu)) return ValueToPrimitive(cx, s, static_cast<uint16_t*>(d));
return false;
*((uint16_t*)d) = uint16_t(tu);
break;
case nsXPTType::T_U32 : case nsXPTType::T_U32 :
if (!JS_ValueToECMAUint32(cx, s, (uint32_t*)d)) return ValueToPrimitive(cx, s, static_cast<uint32_t*>(d));
return false;
break;
case nsXPTType::T_U64 : case nsXPTType::T_U64 :
return ValueToUint64(cx, s, (uint64_t*)d); return ValueToPrimitive(cx, s, static_cast<uint64_t*>(d));
case nsXPTType::T_FLOAT : case nsXPTType::T_FLOAT :
if (!JS_ValueToNumber(cx, s, &td)) return ValueToPrimitive(cx, s, static_cast<float*>(d));
return false;
*((float*)d) = (float) td;
break;
case nsXPTType::T_DOUBLE : case nsXPTType::T_DOUBLE :
if (!JS_ValueToNumber(cx, s, (double*)d)) return ValueToPrimitive(cx, s, static_cast<double*>(d));
return false;
break;
case nsXPTType::T_BOOL : case nsXPTType::T_BOOL :
JS_ValueToBoolean(cx, s, &tb); return ValueToPrimitive(cx, s, static_cast<bool*>(d));
*((bool*)d) = tb;
break;
case nsXPTType::T_CHAR : case nsXPTType::T_CHAR :
{ {
JSString* str = JS_ValueToString(cx, s); JSString* str = JS_ValueToString(cx, s);