From f2a97792fa3fb8091d5a83864ca191fc7a38cee5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 4 Aug 2012 09:29:18 +0200 Subject: [PATCH] Bug 780111 - Share code with new DOM bindings for primitive conversions in XPCConvert::JSData2Native; r=bholley --- dom/bindings/Makefile.in | 7 +++-- js/xpconnect/src/XPCConvert.cpp | 52 ++++++++------------------------- 2 files changed, 16 insertions(+), 43 deletions(-) diff --git a/dom/bindings/Makefile.in b/dom/bindings/Makefile.in index c8bdfaff54c4..dd9cc634fe95 100644 --- a/dom/bindings/Makefile.in +++ b/dom/bindings/Makefile.in @@ -62,15 +62,16 @@ EXPORTS_mozilla = \ $(NULL) EXPORTS_$(binding_include_path) = \ + BindingUtils.h \ DOMJSClass.h \ Errors.msg \ + Nullable.h \ + PrimitiveConversions.h \ PrototypeList.h \ RegisterBindings.h \ - Nullable.h \ TypedArray.h \ - BindingUtils.h \ - UnionTypes.h \ UnionConversions.h \ + UnionTypes.h \ $(exported_binding_headers) \ $(NULL) diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 97b654a60077..d0952d197a30 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -25,6 +25,7 @@ #include "jsfriendapi.h" #include "mozilla/dom/BindingUtils.h" +#include "mozilla/dom/PrimitiveConversions.h" using namespace xpc; using namespace mozilla; @@ -372,10 +373,6 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s, JSContext* cx = ccx.GetJSContext(); - int32_t ti; - uint32_t tu; - double td; - JSBool tb; JSBool isDOMString = true; if (pErr) @@ -383,52 +380,27 @@ XPCConvert::JSData2Native(XPCCallContext& ccx, void* d, jsval s, switch (type.TagPart()) { case nsXPTType::T_I8 : - if (!JS_ValueToECMAInt32(cx, s, &ti)) - return false; - *((int8_t*)d) = int8_t(ti); - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_I16 : - if (!JS_ValueToECMAInt32(cx, s, &ti)) - return false; - *((int16_t*)d) = int16_t(ti); - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_I32 : - if (!JS_ValueToECMAInt32(cx, s, (int32_t*)d)) - return false; - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_I64 : - return ValueToInt64(cx, s, (int64_t*)d); - + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_U8 : - if (!JS_ValueToECMAUint32(cx, s, &tu)) - return false; - *((uint8_t*)d) = uint8_t(tu); - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_U16 : - if (!JS_ValueToECMAUint32(cx, s, &tu)) - return false; - *((uint16_t*)d) = uint16_t(tu); - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_U32 : - if (!JS_ValueToECMAUint32(cx, s, (uint32_t*)d)) - return false; - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_U64 : - return ValueToUint64(cx, s, (uint64_t*)d); - + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_FLOAT : - if (!JS_ValueToNumber(cx, s, &td)) - return false; - *((float*)d) = (float) td; - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_DOUBLE : - if (!JS_ValueToNumber(cx, s, (double*)d)) - return false; - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_BOOL : - JS_ValueToBoolean(cx, s, &tb); - *((bool*)d) = tb; - break; + return ValueToPrimitive(cx, s, static_cast(d)); case nsXPTType::T_CHAR : { JSString* str = JS_ValueToString(cx, s);