js/ipc/CPOWTypes.h
author Robert Longson <longsonr@gmail.com>
Fri, 01 Jun 2012 16:53:57 -0700
changeset 99658 123be65017577f98542852fc557efa66581100f7
parent 98529 f4157e8c410708d76703f19e4dfb61859bfe32d8
child 120868 a1418d7f96712951913e9176b13a2e0ce42e84b2
permissions -rw-r--r--
Bug 758505, Part 3: Avoid unnecessary invalidations on repeated calls to set the same animated value (for SMIL animations of CSS, mapped attrs, and motion). r=dholbert

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sw=4 et tw=80:
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_jsipc_ContextWrapperTypes_h__
#define mozilla_jsipc_ContextWrapperTypes_h__

#include "jsapi.h"
#include "jspubtd.h"

using mozilla::void_t;

namespace mozilla {
namespace jsipc {

using namespace IPC;

template <typename P>
struct CPOWSingleton
{
    static void Write(Message*, const P&) {}
    static bool Read(const Message*, void**, P*) { return true; }
};

template <typename Type, typename As>
struct CPOWConvertible
{
    static void Write(Message* m, const Type& t) {
        WriteParam(m, As(t));
    }
    static bool Read(const Message* m, void** iter, Type* tp) {
        As a;
        return (ReadParam(m, iter, &a) &&
                (*tp = Type(a), true));
    }
}; 

} // namespace jsipc
} // namespace mozilla

namespace IPC {

using namespace mozilla::jsipc;

template <> struct ParamTraits<JSType> : public CPOWConvertible<JSType, int> {};

}

// TODO Use a more standard logging mechanism.
#ifdef LOGGING
#define CPOW_LOG(PRINTF_ARGS) \
    JS_BEGIN_MACRO            \
    printf("CPOW | ");        \
    printf PRINTF_ARGS ;      \
    printf("\n");             \
    JS_END_MACRO
#define JSVAL_TO_CSTR(CX, V) \
    NS_ConvertUTF16toUTF8(nsString(JS_GetStringChars(JS_ValueToString(CX, V)))).get()
#else
#define CPOW_LOG(_) JS_BEGIN_MACRO JS_END_MACRO
#define JSVAL_TO_CSTR(CX, V) ((char*)0)
#endif

#endif