Overhauled ClearScriptV8 string usage to fix Issue #42 and improve performance.

This commit is contained in:
ClearScript 2014-04-10 07:51:19 -04:00
Родитель 1d9a59279c
Коммит 19bc6944c3
38 изменённых файлов: 612 добавлений и 455 удалений

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

@ -94,7 +94,7 @@ public:
typedef TCallback CallbackT;
template <typename TResult>
static TResult CallWithLock(const function<TResult()>& function)
static TResult CallWithLock(const std::function<TResult()>& function)
{
BEGIN_MUTEX_SCOPE(*ms_pMutex)
@ -137,7 +137,7 @@ class CallbackSlot<TTraits, NIndex, TResult()>
public:
typedef TResult CallbackT();
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback()
{
@ -189,7 +189,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult>
function<TResult()>* CallbackSlot<TTraits, NIndex, TResult()>::ms_pFunction = nullptr;
std::function<TResult()>* CallbackSlot<TTraits, NIndex, TResult()>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0>
class CallbackSlot<TTraits, NIndex, TResult(T0)>
@ -199,7 +199,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0)>
public:
typedef TResult CallbackT(T0);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0)
{
@ -251,7 +251,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0>
function<TResult(T0)>* CallbackSlot<TTraits, NIndex, TResult(T0)>::ms_pFunction = nullptr;
std::function<TResult(T0)>* CallbackSlot<TTraits, NIndex, TResult(T0)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1)>
@ -261,7 +261,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1)>
public:
typedef TResult CallbackT(T0, T1);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1)
{
@ -313,7 +313,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1>
function<TResult(T0, T1)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2)>
@ -323,7 +323,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2)>
public:
typedef TResult CallbackT(T0, T1, T2);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2)
{
@ -375,7 +375,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2>
function<TResult(T0, T1, T2)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3)>
@ -385,7 +385,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3)>
public:
typedef TResult CallbackT(T0, T1, T2, T3);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3)
{
@ -437,7 +437,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3>
function<TResult(T0, T1, T2, T3)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4)>
@ -447,7 +447,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4)>
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4)
{
@ -499,7 +499,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4>
function<TResult(T0, T1, T2, T3, T4)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5)>
@ -509,7 +509,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5)>
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
{
@ -561,7 +561,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
function<TResult(T0, T1, T2, T3, T4, T5)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6)>
@ -571,7 +571,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6)>
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
{
@ -623,7 +623,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
function<TResult(T0, T1, T2, T3, T4, T5, T6)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7)>
@ -633,7 +633,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7)>
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
{
@ -685,7 +685,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8)>
@ -695,7 +695,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8)>
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8)
{
@ -747,7 +747,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>
@ -757,7 +757,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8,
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9)
{
@ -809,7 +809,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
@ -819,7 +819,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8,
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9, T10 a10)
{
@ -871,7 +871,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>
@ -881,7 +881,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8,
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9, T10 a10, T11 a11)
{
@ -933,7 +933,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>
@ -943,7 +943,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8,
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9, T10 a10, T11 a11, T12 a12)
{
@ -995,7 +995,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>
@ -1005,7 +1005,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8,
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9, T10 a10, T11 a11, T12 a12, T13 a13)
{
@ -1057,7 +1057,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>
@ -1067,7 +1067,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8,
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9, T10 a10, T11 a11, T12 a12, T13 a13, T14 a14)
{
@ -1119,7 +1119,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>::ms_pFunction = nullptr;
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15>
class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>
@ -1129,7 +1129,7 @@ class CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8,
public:
typedef TResult CallbackT(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9, T10 a10, T11 a11, T12 a12, T13 a13, T14 a14, T15 a15)
{
@ -1181,7 +1181,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult, typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15>
function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>::ms_pFunction = nullptr;
std::function<TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>* CallbackSlot<TTraits, NIndex, TResult(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>::ms_pFunction = nullptr;
//-----------------------------------------------------------------------------
// CallbackManager
@ -1195,7 +1195,7 @@ class CallbackManager
public:
typedef typename TTraits::CallbackT CallbackT;
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static CallbackT* Alloc(const FunctionT& function)
{

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

@ -100,7 +100,7 @@ public:
typedef TCallback CallbackT;
template <typename TResult>
static TResult CallWithLock(const function<TResult()>& function)
static TResult CallWithLock(const std::function<TResult()>& function)
{
BEGIN_MUTEX_SCOPE(*ms_pMutex)
@ -151,7 +151,7 @@ class CallbackSlot<TTraits, NIndex, TResult(<#= paramTypeList #>)>
public:
typedef TResult CallbackT(<#= paramTypeList #>);
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static TResult Callback(<#= paramList #>)
{
@ -203,7 +203,7 @@ private:
};
template <typename TTraits, size_t NIndex, typename TResult<#= typeParamList #>>
function<TResult(<#= paramTypeList #>)>* CallbackSlot<TTraits, NIndex, TResult(<#= paramTypeList #>)>::ms_pFunction = nullptr;
std::function<TResult(<#= paramTypeList #>)>* CallbackSlot<TTraits, NIndex, TResult(<#= paramTypeList #>)>::ms_pFunction = nullptr;
<#
}
#>
@ -220,7 +220,7 @@ class CallbackManager
public:
typedef typename TTraits::CallbackT CallbackT;
typedef function<CallbackT> FunctionT;
typedef std::function<CallbackT> FunctionT;
static CallbackT* Alloc(const FunctionT& function)
{

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

@ -212,7 +212,7 @@
<ClInclude Include="..\NativePlatform.h" />
<ClInclude Include="..\RefCount.h" />
<ClInclude Include="..\SharedPtr.h" />
<ClInclude Include="..\StringToUniPtr.h" />
<ClInclude Include="..\StdString.h" />
<ClInclude Include="..\V8Context.h" />
<ClInclude Include="..\V8ContextImpl.h" />
<ClInclude Include="..\V8ContextProxyImpl.h" />

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

@ -109,9 +109,6 @@
<ClInclude Include="..\SharedPtr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\StringToUniPtr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8Context.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -169,5 +166,8 @@
<ClInclude Include="..\V8IsolateHeapInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\StdString.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

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

@ -213,7 +213,7 @@
<ClInclude Include="..\NativePlatform.h" />
<ClInclude Include="..\RefCount.h" />
<ClInclude Include="..\SharedPtr.h" />
<ClInclude Include="..\StringToUniPtr.h" />
<ClInclude Include="..\StdString.h" />
<ClInclude Include="..\V8Context.h" />
<ClInclude Include="..\V8ContextImpl.h" />
<ClInclude Include="..\V8ContextProxyImpl.h" />

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

@ -109,9 +109,6 @@
<ClInclude Include="..\SharedPtr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\StringToUniPtr.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\V8Context.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -169,5 +166,8 @@
<ClInclude Include="..\V8IsolateHeapInfo.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\StdString.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

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

@ -62,6 +62,7 @@
#pragma once
#include "ManagedPlatform.h"
#include "StdString.h"
#include "Mutex.h"
#include "RefCount.h"
#include "SharedPtr.h"
@ -83,4 +84,3 @@
#include "V8ContextProxyImpl.h"
#include "V8ObjectImpl.h"
#include "V8ScriptImpl.h"
#include "StringToUniPtr.h"

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

@ -62,6 +62,8 @@
#pragma once
#include "NativePlatform.h"
#include "V8Platform.h"
#include "StdString.h"
#include "Mutex.h"
#include "CallbackManager.h"
#include "RefCount.h"
@ -80,7 +82,6 @@
#include "HostObjectHolderImpl.h"
#include "V8ObjectHelpers.h"
#include "HostObjectHelpers.h"
#include "V8Platform.h"
#include "V8IsolateImpl.h"
#include "V8ContextImpl.h"
#include "V8ObjectHolderImpl.h"

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

@ -68,13 +68,10 @@
#include <algorithm>
#include <functional>
#include <string>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
//-----------------------------------------------------------------------------
// global macros
//-----------------------------------------------------------------------------

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

@ -69,27 +69,15 @@ class HostException
{
public:
HostException(const wchar_t* pMessage, const V8Value& exception):
m_Exception(exception)
HostException(StdString&& message, V8Value&& exception):
m_Message(std::move(message)),
m_Exception(std::move(exception))
{
if (pMessage != nullptr)
{
m_Message = pMessage;
}
}
HostException(const wchar_t* pMessage, V8Value&& exception):
m_Exception(exception)
const StdString& GetMessage() const
{
if (pMessage != nullptr)
{
m_Message = pMessage;
}
}
const wchar_t* GetMessage() const
{
return m_Message.c_str();
return m_Message;
}
const V8Value& GetException() const
@ -99,6 +87,6 @@ public:
private:
wstring m_Message;
StdString m_Message;
V8Value m_Exception;
};

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

@ -69,7 +69,7 @@ using namespace Microsoft::ClearScript::V8;
static void DECLSPEC_NORETURN ThrowHostException(Exception^ gcException)
{
throw HostException(StringToUniPtr(gcException->Message), V8ContextProxyImpl::ImportValue(gcException));
throw HostException(StdString(gcException->Message), V8ContextProxyImpl::ImportValue(gcException));
}
//-----------------------------------------------------------------------------
@ -90,11 +90,11 @@ void HostObjectHelpers::Release(void* pvObject)
//-----------------------------------------------------------------------------
V8Value HostObjectHelpers::GetProperty(void* pvObject, const wchar_t* pName)
V8Value HostObjectHelpers::GetProperty(void* pvObject, const StdString& name)
{
try
{
return V8ContextProxyImpl::ImportValue(V8ProxyHelpers::GetHostObjectProperty(pvObject, gcnew String(pName)));
return V8ContextProxyImpl::ImportValue(V8ProxyHelpers::GetHostObjectProperty(pvObject, name.ToManagedString()));
}
catch (Exception^ gcException)
{
@ -104,11 +104,11 @@ V8Value HostObjectHelpers::GetProperty(void* pvObject, const wchar_t* pName)
//-----------------------------------------------------------------------------
void HostObjectHelpers::SetProperty(void* pvObject, const wchar_t* pName, const V8Value& value)
void HostObjectHelpers::SetProperty(void* pvObject, const StdString& name, const V8Value& value)
{
try
{
V8ProxyHelpers::SetHostObjectProperty(pvObject, gcnew String(pName), V8ContextProxyImpl::ExportValue(value));
V8ProxyHelpers::SetHostObjectProperty(pvObject, name.ToManagedString(), V8ContextProxyImpl::ExportValue(value));
}
catch (Exception^ gcException)
{
@ -118,11 +118,11 @@ void HostObjectHelpers::SetProperty(void* pvObject, const wchar_t* pName, const
//-----------------------------------------------------------------------------
bool HostObjectHelpers::DeleteProperty(void* pvObject, const wchar_t* pName)
bool HostObjectHelpers::DeleteProperty(void* pvObject, const StdString& name)
{
try
{
return V8ProxyHelpers::DeleteHostObjectProperty(pvObject, gcnew String(pName));
return V8ProxyHelpers::DeleteHostObjectProperty(pvObject, name.ToManagedString());
}
catch (Exception^ gcException)
{
@ -132,7 +132,7 @@ bool HostObjectHelpers::DeleteProperty(void* pvObject, const wchar_t* pName)
//-----------------------------------------------------------------------------
void HostObjectHelpers::GetPropertyNames(void* pvObject, vector<wstring>& names)
void HostObjectHelpers::GetPropertyNames(void* pvObject, std::vector<StdString>& names)
{
try
{
@ -142,7 +142,7 @@ void HostObjectHelpers::GetPropertyNames(void* pvObject, vector<wstring>& names)
names.resize(nameCount);
for (auto index = 0; index < nameCount; index++)
{
names[index] = StringToUniPtr(gcNames[index]);
names[index] = StdString(gcNames[index]);
}
}
catch (Exception^ gcException)
@ -195,7 +195,7 @@ bool HostObjectHelpers::DeleteProperty(void* pvObject, int index)
//-----------------------------------------------------------------------------
void HostObjectHelpers::GetPropertyIndices(void* pvObject, vector<int>& indices)
void HostObjectHelpers::GetPropertyIndices(void* pvObject, std::vector<int>& indices)
{
try
{
@ -216,7 +216,7 @@ void HostObjectHelpers::GetPropertyIndices(void* pvObject, vector<int>& indices)
//-----------------------------------------------------------------------------
V8Value HostObjectHelpers::Invoke(void* pvObject, const vector<V8Value>& args, bool asConstructor)
V8Value HostObjectHelpers::Invoke(void* pvObject, const std::vector<V8Value>& args, bool asConstructor)
{
try
{
@ -238,7 +238,7 @@ V8Value HostObjectHelpers::Invoke(void* pvObject, const vector<V8Value>& args, b
//-----------------------------------------------------------------------------
V8Value HostObjectHelpers::InvokeMethod(void* pvObject, const wchar_t* pName, const vector<V8Value>& args)
V8Value HostObjectHelpers::InvokeMethod(void* pvObject, const StdString& name, const std::vector<V8Value>& args)
{
try
{
@ -250,7 +250,7 @@ V8Value HostObjectHelpers::InvokeMethod(void* pvObject, const wchar_t* pName, co
exportedArgs[index] = V8ContextProxyImpl::ExportValue(args[index]);
}
return V8ContextProxyImpl::ImportValue(V8ProxyHelpers::InvokeHostObjectMethod(pvObject, gcnew String(pName), exportedArgs));
return V8ContextProxyImpl::ImportValue(V8ProxyHelpers::InvokeHostObjectMethod(pvObject, name.ToManagedString(), exportedArgs));
}
catch (Exception^ gcException)
{
@ -288,7 +288,7 @@ bool HostObjectHelpers::RemoveV8ObjectCacheEntry(void* pvCache, void* pvObject)
//-----------------------------------------------------------------------------
bool HostObjectHelpers::TryParseInt32(const wchar_t* pString, int& result)
bool HostObjectHelpers::TryParseInt32(const StdString& text, int& result)
{
return Int32::TryParse(gcnew String(pString), NumberStyles::Integer, CultureInfo::InvariantCulture, result);
return Int32::TryParse(text.ToManagedString(), NumberStyles::Integer, CultureInfo::InvariantCulture, result);
}

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

@ -74,23 +74,23 @@ public:
static void* AddRef(void* pvObject);
static void Release(void* pvObject);
static V8Value GetProperty(void* pvObject, const wchar_t* pName);
static void SetProperty(void* pvObject, const wchar_t* pName, const V8Value& value);
static bool DeleteProperty(void* pvObject, const wchar_t* pName);
static void GetPropertyNames(void* pvObject, vector<wstring>& names);
static V8Value GetProperty(void* pvObject, const StdString& name);
static void SetProperty(void* pvObject, const StdString& name, const V8Value& value);
static bool DeleteProperty(void* pvObject, const StdString& name);
static void GetPropertyNames(void* pvObject, std::vector<StdString>& names);
static V8Value GetProperty(void* pvObject, int index);
static void SetProperty(void* pvObject, int index, const V8Value& value);
static bool DeleteProperty(void* pvObject, int index);
static void GetPropertyIndices(void* pvObject, vector<int>& indices);
static void GetPropertyIndices(void* pvObject, std::vector<int>& indices);
static V8Value Invoke(void* pvObject, const vector<V8Value>& args, bool asConstructor);
static V8Value InvokeMethod(void* pvObject, const wchar_t* pName, const vector<V8Value>& args);
static V8Value Invoke(void* pvObject, const std::vector<V8Value>& args, bool asConstructor);
static V8Value InvokeMethod(void* pvObject, const StdString& name, const std::vector<V8Value>& args);
static void* CreateV8ObjectCache();
static void CacheV8Object(void* pvCache, void* pvObject, void* pvV8Object);
static void* GetCachedV8Object(void* pvCache, void* pvObject);
static bool RemoveV8ObjectCacheEntry(void* pvCache, void* pvObject);
static bool TryParseInt32(const wchar_t* pString, int& result);
static bool TryParseInt32(const StdString& text, int& result);
};

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

@ -87,7 +87,7 @@ public:
private:
mutex m_Mutex;
std::mutex m_Mutex;
};
//-----------------------------------------------------------------------------
@ -146,7 +146,7 @@ public:
private:
recursive_mutex m_Mutex;
std::recursive_mutex m_Mutex;
};
//-----------------------------------------------------------------------------

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

@ -88,7 +88,7 @@ public:
private:
atomic<size_t> m_Count;
std::atomic<size_t> m_Count;
};
//-----------------------------------------------------------------------------

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

@ -304,16 +304,16 @@ private:
m_pRefCount->Increment();
}
void DetachRefCount(SharedPtrTarget* /* pTarget */)
void DetachRefCount(SharedPtrTarget* /*pTarget*/)
{
}
void AttachRefCount(void* /* pvTarget */)
void AttachRefCount(void* /*pvTarget*/)
{
m_pRefCount = new RefCount(1);
}
void DetachRefCount(void* /* pvTarget */)
void DetachRefCount(void* /*pvTarget*/)
{
delete m_pRefCount;
}

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

@ -0,0 +1,303 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Microsoft Public License (MS-PL)
//
// This license governs use of the accompanying software. If you use the
// software, you accept this license. If you do not accept the license, do not
// use the software.
//
// 1. Definitions
//
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S. copyright law. A
// "contribution" is the original software, or any additions or changes to
// the software. A "contributor" is any person that distributes its
// contribution under this license. "Licensed patents" are a contributor's
// patent claims that read directly on its contribution.
//
// 2. Grant of Rights
//
// (A) Copyright Grant- Subject to the terms of this license, including the
// license conditions and limitations in section 3, each contributor
// grants you a non-exclusive, worldwide, royalty-free copyright license
// to reproduce its contribution, prepare derivative works of its
// contribution, and distribute its contribution or any derivative works
// that you create.
//
// (B) Patent Grant- Subject to the terms of this license, including the
// license conditions and limitations in section 3, each contributor
// grants you a non-exclusive, worldwide, royalty-free license under its
// licensed patents to make, have made, use, sell, offer for sale,
// import, and/or otherwise dispose of its contribution in the software
// or derivative works of the contribution in the software.
//
// 3. Conditions and Limitations
//
// (A) No Trademark License- This license does not grant you rights to use
// any contributors' name, logo, or trademarks.
//
// (B) If you bring a patent claim against any contributor over patents that
// you claim are infringed by the software, your patent license from such
// contributor to the software ends automatically.
//
// (C) If you distribute any portion of the software, you must retain all
// copyright, patent, trademark, and attribution notices that are present
// in the software.
//
// (D) If you distribute any portion of the software in source code form, you
// may do so only under this license by including a complete copy of this
// license with your distribution. If you distribute any portion of the
// software in compiled or object code form, you may only do so under a
// license that complies with this license.
//
// (E) The software is licensed "as-is." You bear the risk of using it. The
// contributors give no express warranties, guarantees or conditions. You
// may have additional consumer rights under your local laws which this
// license cannot change. To the extent permitted under your local laws,
// the contributors exclude the implied warranties of merchantability,
// fitness for a particular purpose and non-infringement.
//
#pragma once
#ifdef _M_CEE
//-----------------------------------------------------------------------------
// StringToUniPtr
//-----------------------------------------------------------------------------
class StringToUniPtr
{
public:
explicit StringToUniPtr(String^ gcValue):
m_pValue(Microsoft::ClearScript::V8::V8ProxyHelpers::AllocString(gcValue))
{
}
operator const wchar_t*() const
{
return m_pValue;
}
~StringToUniPtr()
{
Microsoft::ClearScript::V8::V8ProxyHelpers::FreeString(m_pValue);
}
private:
wchar_t* m_pValue;
};
#endif // _M_CEE
//-----------------------------------------------------------------------------
// StdString
//-----------------------------------------------------------------------------
class StdString
{
public:
//-------------------------------------------------------------------------
// constructors
//-------------------------------------------------------------------------
StdString()
{
}
StdString(const StdString& that):
m_Value(that.m_Value)
{
}
StdString(StdString&& that):
m_Value(std::move(that.m_Value))
{
}
explicit StdString(const std::wstring& value):
m_Value(value)
{
}
explicit StdString(std::wstring&& value):
m_Value(std::move(value))
{
}
explicit StdString(const wchar_t* pValue):
m_Value(EnsureNonNull(pValue))
{
}
//-------------------------------------------------------------------------
// assignment
//-------------------------------------------------------------------------
const StdString& operator=(const StdString& that)
{
m_Value = that.m_Value;
return *this;
}
const StdString& operator=(StdString&& that)
{
m_Value = std::move(that.m_Value);
return *this;
}
const StdString& operator=(const std::wstring& value)
{
m_Value = value;
return *this;
}
const StdString& operator=(std::wstring&& value)
{
m_Value = std::move(value);
return *this;
}
const StdString& operator=(const wchar_t* pValue)
{
m_Value = EnsureNonNull(pValue);
return *this;
}
//-------------------------------------------------------------------------
// concatenation
//-------------------------------------------------------------------------
const StdString& operator+=(const StdString& that)
{
m_Value += that.m_Value;
return *this;
}
const StdString& operator+=(const std::wstring& value)
{
m_Value += value;
return *this;
}
const StdString& operator+=(const wchar_t* pValue)
{
m_Value += EnsureNonNull(pValue);
return *this;
}
const StdString& operator+=(wchar_t value)
{
m_Value += value;
return *this;
}
//-------------------------------------------------------------------------
// comparison
//-------------------------------------------------------------------------
int Compare(const StdString& that) const { return m_Value.compare(that.m_Value); }
int Compare(const std::wstring& value) const { return m_Value.compare(value); }
int Compare(const wchar_t* pValue) const { return m_Value.compare(pValue); }
bool operator==(const StdString& that) const { return m_Value == that.m_Value; }
bool operator==(const std::wstring& value) const { return m_Value == value; }
bool operator==(const wchar_t* pValue) const { return m_Value == pValue; }
bool operator!=(const StdString& that) const { return m_Value != that.m_Value; }
bool operator!=(const std::wstring& value) const { return m_Value != value; }
bool operator!=(const wchar_t* pValue) const { return m_Value != pValue; }
bool operator<(const StdString& that) const { return m_Value < that.m_Value; }
bool operator<(const std::wstring& value) const { return m_Value < value; }
bool operator<(const wchar_t* pValue) const { return m_Value < pValue; }
bool operator<=(const StdString& that) const { return m_Value <= that.m_Value; }
bool operator<=(const std::wstring& value) const { return m_Value <= value; }
bool operator<=(const wchar_t* pValue) const { return m_Value <= pValue; }
bool operator>(const StdString& that) const { return m_Value > that.m_Value; }
bool operator>(const std::wstring& value) const { return m_Value > value; }
bool operator>(const wchar_t* pValue) const { return m_Value > pValue; }
bool operator>=(const StdString& that) const { return m_Value >= that.m_Value; }
bool operator>=(const std::wstring& value) const { return m_Value >= value; }
bool operator>=(const wchar_t* pValue) const { return m_Value >= pValue; }
//-------------------------------------------------------------------------
// miscellaneous
//-------------------------------------------------------------------------
int GetLength() const
{
return static_cast<int>(m_Value.length());
}
const wchar_t* ToCString() const
{
return m_Value.c_str();
}
#ifdef _M_CEE
//-------------------------------------------------------------------------
// managed extensions
//-------------------------------------------------------------------------
public:
explicit StdString(String^ gcValue):
m_Value(StringToUniPtr(gcValue), gcValue->Length)
{
}
String^ ToManagedString() const
{
return gcnew String(ToCString(), 0, GetLength());
}
#else // !_M_CEE
//-------------------------------------------------------------------------
// V8 extensions
//-------------------------------------------------------------------------
public:
explicit StdString(Handle<Value> hValue):
m_Value(GetValue(hValue))
{
}
Local<String> ToV8String(Isolate* pIsolate) const
{
return String::NewFromTwoByte(pIsolate, reinterpret_cast<const uint16_t*>(ToCString()), String::kNormalString, GetLength());
}
private:
static std::wstring GetValue(Handle<Value> hValue)
{
String::Value value(hValue);
return std::wstring(*value, value.length());
}
#endif // _M_CEE
private:
//-------------------------------------------------------------------------
// internals
//-------------------------------------------------------------------------
static const wchar_t* EnsureNonNull(const wchar_t* pValue)
{
return (pValue != nullptr) ? pValue : L"";
}
std::wstring m_Value;
};

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

@ -1,96 +0,0 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Microsoft Public License (MS-PL)
//
// This license governs use of the accompanying software. If you use the
// software, you accept this license. If you do not accept the license, do not
// use the software.
//
// 1. Definitions
//
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S. copyright law. A
// "contribution" is the original software, or any additions or changes to
// the software. A "contributor" is any person that distributes its
// contribution under this license. "Licensed patents" are a contributor's
// patent claims that read directly on its contribution.
//
// 2. Grant of Rights
//
// (A) Copyright Grant- Subject to the terms of this license, including the
// license conditions and limitations in section 3, each contributor
// grants you a non-exclusive, worldwide, royalty-free copyright license
// to reproduce its contribution, prepare derivative works of its
// contribution, and distribute its contribution or any derivative works
// that you create.
//
// (B) Patent Grant- Subject to the terms of this license, including the
// license conditions and limitations in section 3, each contributor
// grants you a non-exclusive, worldwide, royalty-free license under its
// licensed patents to make, have made, use, sell, offer for sale,
// import, and/or otherwise dispose of its contribution in the software
// or derivative works of the contribution in the software.
//
// 3. Conditions and Limitations
//
// (A) No Trademark License- This license does not grant you rights to use
// any contributors' name, logo, or trademarks.
//
// (B) If you bring a patent claim against any contributor over patents that
// you claim are infringed by the software, your patent license from such
// contributor to the software ends automatically.
//
// (C) If you distribute any portion of the software, you must retain all
// copyright, patent, trademark, and attribution notices that are present
// in the software.
//
// (D) If you distribute any portion of the software in source code form, you
// may do so only under this license by including a complete copy of this
// license with your distribution. If you distribute any portion of the
// software in compiled or object code form, you may only do so under a
// license that complies with this license.
//
// (E) The software is licensed "as-is." You bear the risk of using it. The
// contributors give no express warranties, guarantees or conditions. You
// may have additional consumer rights under your local laws which this
// license cannot change. To the extent permitted under your local laws,
// the contributors exclude the implied warranties of merchantability,
// fitness for a particular purpose and non-infringement.
//
#pragma once
namespace Microsoft {
namespace ClearScript {
namespace V8 {
//-------------------------------------------------------------------------
// StringToUniPtr
//-------------------------------------------------------------------------
private class StringToUniPtr
{
public:
explicit StringToUniPtr(String^ gcValue):
m_pValue(V8ProxyHelpers::AllocString(gcValue))
{
}
operator const wchar_t*() const
{
return m_pValue;
}
~StringToUniPtr()
{
V8ProxyHelpers::FreeString(m_pValue);
}
private:
wchar_t* m_pValue;
};
}}}

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

@ -65,7 +65,7 @@
// V8Context implementation
//-----------------------------------------------------------------------------
V8Context* V8Context::Create(const SharedPtr<V8Isolate>& spIsolate, const wchar_t* pName, bool enableDebugging, bool disableGlobalMembers, int debugPort)
V8Context* V8Context::Create(const SharedPtr<V8Isolate>& spIsolate, const StdString& name, bool enableDebugging, bool disableGlobalMembers, int debugPort)
{
return new V8ContextImpl(static_cast<V8IsolateImpl*>(spIsolate.GetRawPtr()), pName, enableDebugging, disableGlobalMembers, debugPort);
return new V8ContextImpl(static_cast<V8IsolateImpl*>(spIsolate.GetRawPtr()), name, enableDebugging, disableGlobalMembers, debugPort);
}

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

@ -69,7 +69,7 @@ class V8Context: public SharedPtrTarget
{
public:
static V8Context* Create(const SharedPtr<V8Isolate>& spIsolate, const wchar_t* pName, bool enableDebugging, bool disableGlobalMembers, int debugPort);
static V8Context* Create(const SharedPtr<V8Isolate>& spIsolate, const StdString& name, bool enableDebugging, bool disableGlobalMembers, int debugPort);
virtual size_t GetMaxIsolateStackUsage() = 0;
virtual void SetMaxIsolateStackUsage(size_t value) = 0;
@ -78,10 +78,10 @@ public:
virtual void CallWithLock(LockCallbackT* pCallback, void* pvArg) = 0;
virtual V8Value GetRootObject() = 0;
virtual void SetGlobalProperty(const wchar_t* pName, const V8Value& value, bool globalMembers) = 0;
virtual V8Value Execute(const wchar_t* pDocumentName, const wchar_t* pCode, bool evaluate, bool discard) = 0;
virtual void SetGlobalProperty(const StdString& name, const V8Value& value, bool globalMembers) = 0;
virtual V8Value Execute(const StdString& documentName, const StdString& code, bool evaluate, bool discard) = 0;
virtual V8ScriptHolder* Compile(const wchar_t* pDocumentName, const wchar_t* pCode) = 0;
virtual V8ScriptHolder* Compile(const StdString& documentName, const StdString& code) = 0;
virtual bool CanExecute(V8ScriptHolder* pHolder) = 0;
virtual V8Value Execute(V8ScriptHolder* pHolder, bool evaluate) = 0;

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

@ -199,16 +199,12 @@ static void* UnwrapHostObject(const FunctionCallbackInfo<T>& args)
//-----------------------------------------------------------------------------
V8ContextImpl::V8ContextImpl(V8IsolateImpl* pIsolateImpl, const wchar_t* pName, bool enableDebugging, bool disableGlobalMembers, int debugPort):
V8ContextImpl::V8ContextImpl(V8IsolateImpl* pIsolateImpl, const StdString& name, bool enableDebugging, bool disableGlobalMembers, int debugPort):
m_Name(name),
m_spIsolateImpl(pIsolateImpl)
{
VerifyNotOutOfMemory();
if (pName != nullptr)
{
m_Name = pName;
}
BEGIN_ISOLATE_SCOPE
if (disableGlobalMembers)
@ -234,11 +230,11 @@ V8ContextImpl::V8ContextImpl(V8IsolateImpl* pIsolateImpl, const wchar_t* pName,
// Be careful when renaming the cookie or changing the way host objects are marked.
// Such a change will require a corresponding change in the V8ScriptEngine constructor.
m_hHostObjectCookieName = CreatePersistent(CreateString("{c2cf47d3-916b-4a3f-be2a-6ff567425808}"));
m_hInnerExceptionName = CreatePersistent(CreateString("inner"));
m_hHostObjectCookieName = CreatePersistent(CreateString(StdString(L"{c2cf47d3-916b-4a3f-be2a-6ff567425808}")));
m_hInnerExceptionName = CreatePersistent(CreateString(StdString(L"inner")));
m_hHostObjectTemplate = CreatePersistent(CreateFunctionTemplate());
m_hHostObjectTemplate->SetClassName(CreateString("HostObject"));
m_hHostObjectTemplate->SetClassName(CreateString(StdString(L"HostObject")));
m_hHostObjectTemplate->InstanceTemplate()->SetInternalFieldCount(1);
m_hHostObjectTemplate->InstanceTemplate()->SetNamedPropertyHandler(GetHostObjectProperty, SetHostObjectProperty, QueryHostObjectProperty, DeleteHostObjectProperty, GetHostObjectPropertyNames, Wrap());
@ -293,12 +289,12 @@ V8Value V8ContextImpl::GetRootObject()
//-----------------------------------------------------------------------------
void V8ContextImpl::SetGlobalProperty(const wchar_t* pName, const V8Value& value, bool globalMembers)
void V8ContextImpl::SetGlobalProperty(const StdString& name, const V8Value& value, bool globalMembers)
{
BEGIN_CONTEXT_SCOPE
auto hValue = ImportValue(value);
m_hContext->Global()->ForceSet(CreateString(pName), hValue, (PropertyAttribute)(ReadOnly | DontDelete));
m_hContext->Global()->ForceSet(CreateString(name), hValue, (PropertyAttribute)(ReadOnly | DontDelete));
if (globalMembers && hValue->IsObject())
{
m_GlobalMembersStack.push_back(CreatePersistent(hValue->ToObject()));
@ -309,12 +305,12 @@ void V8ContextImpl::SetGlobalProperty(const wchar_t* pName, const V8Value& value
//-----------------------------------------------------------------------------
V8Value V8ContextImpl::Execute(const wchar_t* pDocumentName, const wchar_t* pCode, bool evaluate, bool /* discard */)
V8Value V8ContextImpl::Execute(const StdString& documentName, const StdString& code, bool evaluate, bool /* discard */)
{
BEGIN_CONTEXT_SCOPE
BEGIN_EXECUTION_SCOPE
auto hScript = VERIFY(Script::Compile(CreateString(pCode), CreateString(pDocumentName)));
auto hScript = VERIFY(Script::Compile(CreateString(code), CreateString(documentName)));
auto hResult = VERIFY(hScript->Run());
if (!evaluate)
{
@ -329,12 +325,12 @@ V8Value V8ContextImpl::Execute(const wchar_t* pDocumentName, const wchar_t* pCod
//-----------------------------------------------------------------------------
V8ScriptHolder* V8ContextImpl::Compile(const wchar_t* pDocumentName, const wchar_t* pCode)
V8ScriptHolder* V8ContextImpl::Compile(const StdString& documentName, const StdString& code)
{
BEGIN_CONTEXT_SCOPE
BEGIN_EXECUTION_SCOPE
auto hScript = VERIFY(Script::New(CreateString(pCode), CreateString(pDocumentName)));
auto hScript = VERIFY(Script::New(CreateString(code), CreateString(documentName)));
return new V8ScriptHolderImpl(m_spIsolateImpl, ::PtrFromScriptHandle(CreatePersistent(hScript)));
END_EXECUTION_SCOPE
@ -413,12 +409,12 @@ void V8ContextImpl::ReleaseV8Object(void* pvObject)
//-----------------------------------------------------------------------------
V8Value V8ContextImpl::GetV8ObjectProperty(void* pvObject, const wchar_t* pName)
V8Value V8ContextImpl::GetV8ObjectProperty(void* pvObject, const StdString& name)
{
BEGIN_CONTEXT_SCOPE
BEGIN_EXECUTION_SCOPE
return ExportValue(::ObjectHandleFromPtr(pvObject)->Get(CreateString(pName)));
return ExportValue(::ObjectHandleFromPtr(pvObject)->Get(CreateString(name)));
END_EXECUTION_SCOPE
END_CONTEXT_SCOPE
@ -426,12 +422,12 @@ V8Value V8ContextImpl::GetV8ObjectProperty(void* pvObject, const wchar_t* pName)
//-----------------------------------------------------------------------------
void V8ContextImpl::SetV8ObjectProperty(void* pvObject, const wchar_t* pName, const V8Value& value)
void V8ContextImpl::SetV8ObjectProperty(void* pvObject, const StdString& name, const V8Value& value)
{
BEGIN_CONTEXT_SCOPE
BEGIN_EXECUTION_SCOPE
::ObjectHandleFromPtr(pvObject)->Set(CreateString(pName), ImportValue(value));
::ObjectHandleFromPtr(pvObject)->Set(CreateString(name), ImportValue(value));
END_EXECUTION_SCOPE
END_CONTEXT_SCOPE
@ -439,18 +435,18 @@ void V8ContextImpl::SetV8ObjectProperty(void* pvObject, const wchar_t* pName, co
//-----------------------------------------------------------------------------
bool V8ContextImpl::DeleteV8ObjectProperty(void* pvObject, const wchar_t* pName)
bool V8ContextImpl::DeleteV8ObjectProperty(void* pvObject, const StdString& name)
{
BEGIN_CONTEXT_SCOPE
return ::ObjectHandleFromPtr(pvObject)->Delete(CreateString(pName));
return ::ObjectHandleFromPtr(pvObject)->Delete(CreateString(name));
END_CONTEXT_SCOPE
}
//-----------------------------------------------------------------------------
void V8ContextImpl::GetV8ObjectPropertyNames(void* pvObject, vector<wstring>& names)
void V8ContextImpl::GetV8ObjectPropertyNames(void* pvObject, std::vector<StdString>& names)
{
BEGIN_CONTEXT_SCOPE
@ -498,7 +494,7 @@ bool V8ContextImpl::DeleteV8ObjectProperty(void* pvObject, int index)
//-----------------------------------------------------------------------------
void V8ContextImpl::GetV8ObjectPropertyIndices(void* pvObject, vector<int>& indices)
void V8ContextImpl::GetV8ObjectPropertyIndices(void* pvObject, std::vector<int>& indices)
{
BEGIN_CONTEXT_SCOPE
@ -509,14 +505,14 @@ void V8ContextImpl::GetV8ObjectPropertyIndices(void* pvObject, vector<int>& indi
//-----------------------------------------------------------------------------
V8Value V8ContextImpl::InvokeV8Object(void* pvObject, const vector<V8Value>& args, bool asConstructor)
V8Value V8ContextImpl::InvokeV8Object(void* pvObject, const std::vector<V8Value>& args, bool asConstructor)
{
BEGIN_CONTEXT_SCOPE
BEGIN_EXECUTION_SCOPE
auto hObject = ::ObjectHandleFromPtr(pvObject);
vector<Handle<Value>> importedArgs;
std::vector<Handle<Value>> importedArgs;
ImportValues(args, importedArgs);
if (asConstructor)
@ -532,28 +528,28 @@ V8Value V8ContextImpl::InvokeV8Object(void* pvObject, const vector<V8Value>& arg
//-----------------------------------------------------------------------------
V8Value V8ContextImpl::InvokeV8ObjectMethod(void* pvObject, const wchar_t* pName, const vector<V8Value>& args)
V8Value V8ContextImpl::InvokeV8ObjectMethod(void* pvObject, const StdString& name, const std::vector<V8Value>& args)
{
BEGIN_CONTEXT_SCOPE
BEGIN_EXECUTION_SCOPE
auto hObject = ::ObjectHandleFromPtr(pvObject);
auto hName = CreateString(pName);
auto hName = CreateString(name);
if (!hObject->Has(hName))
{
auto hError = Exception::TypeError(CreateString("Method or property not found"))->ToObject();
throw V8Exception(V8Exception::Type_General, m_Name.c_str(), *String::Value(hError), *String::Value(hError->Get(CreateString("stack"))), V8Value(V8Value::Undefined));
auto hError = Exception::TypeError(CreateString(StdString(L"Method or property not found")))->ToObject();
throw V8Exception(V8Exception::Type_General, m_Name, StdString(hError), StdString(hError->Get(CreateString(StdString(L"stack")))), V8Value(V8Value::Undefined));
}
auto hValue = hObject->Get(hName);
if (hValue->IsUndefined() || hValue->IsNull())
{
auto hError = Exception::TypeError(CreateString("Property value does not support invocation"))->ToObject();
throw V8Exception(V8Exception::Type_General, m_Name.c_str(), *String::Value(hError), *String::Value(hError->Get(CreateString("stack"))), V8Value(V8Value::Undefined));
auto hError = Exception::TypeError(CreateString(StdString(L"Property value does not support invocation")))->ToObject();
throw V8Exception(V8Exception::Type_General, m_Name, StdString(hError), StdString(hError->Get(CreateString(StdString(L"stack")))), V8Value(V8Value::Undefined));
}
vector<Handle<Value>> importedArgs;
std::vector<Handle<Value>> importedArgs;
ImportValues(args, importedArgs);
auto hMethod = VERIFY(hValue->ToObject());
@ -635,7 +631,7 @@ Handle<Value> V8ContextImpl::Wrap()
//-----------------------------------------------------------------------------
void V8ContextImpl::GetV8ObjectPropertyNames(Handle<Object> hObject, vector<wstring>& names)
void V8ContextImpl::GetV8ObjectPropertyNames(Handle<Object> hObject, std::vector<StdString>& names)
{
names.clear();
@ -650,12 +646,12 @@ void V8ContextImpl::GetV8ObjectPropertyNames(Handle<Object> hObject, vector<wstr
auto hName = hNames->Get(index);
if (!hName.IsEmpty())
{
wstring name(*String::Value(hName));
StdString name(hName);
int propertyIndex;
if (!HostObjectHelpers::TryParseInt32(name.c_str(), propertyIndex))
if (!HostObjectHelpers::TryParseInt32(name, propertyIndex))
{
names.push_back(name);
names.push_back(std::move(name));
}
}
}
@ -664,7 +660,7 @@ void V8ContextImpl::GetV8ObjectPropertyNames(Handle<Object> hObject, vector<wstr
//-----------------------------------------------------------------------------
void V8ContextImpl::GetV8ObjectPropertyIndices(Handle<Object> hObject, vector<int>& indices)
void V8ContextImpl::GetV8ObjectPropertyIndices(Handle<Object> hObject, std::vector<int>& indices)
{
indices.clear();
@ -679,10 +675,10 @@ void V8ContextImpl::GetV8ObjectPropertyIndices(Handle<Object> hObject, vector<in
auto hName = hNames->Get(index);
if (!hName.IsEmpty())
{
wstring name(*String::Value(hName));
StdString name(hName);
int propertyIndex;
if (HostObjectHelpers::TryParseInt32(name.c_str(), propertyIndex))
if (HostObjectHelpers::TryParseInt32(name, propertyIndex))
{
indices.push_back(propertyIndex);
}
@ -701,7 +697,7 @@ void V8ContextImpl::GetGlobalProperty(Local<String> hName, const PropertyCallbac
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if ((stack.size() > 0) && !hName->Equals(pContextImpl->m_hHostObjectCookieName))
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -725,7 +721,7 @@ void V8ContextImpl::SetGlobalProperty(Local<String> hName, Local<Value> value, c
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if ((stack.size() > 0) && !hName->Equals(pContextImpl->m_hHostObjectCookieName))
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -749,7 +745,7 @@ void V8ContextImpl::QueryGlobalProperty(Local<String> hName, const PropertyCallb
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if ((stack.size() > 0) && !hName->Equals(pContextImpl->m_hHostObjectCookieName))
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -773,7 +769,7 @@ void V8ContextImpl::DeleteGlobalProperty(Local<String> hName, const PropertyCall
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -788,7 +784,7 @@ void V8ContextImpl::DeleteGlobalProperty(Local<String> hName, const PropertyCall
{
try
{
CALLBACK_RETURN(HostObjectHelpers::DeleteProperty(::GetHostObject(*it), *String::Value(hName)));
CALLBACK_RETURN(HostObjectHelpers::DeleteProperty(::GetHostObject(*it), StdString(hName)));
}
catch (const HostException&)
{
@ -815,13 +811,13 @@ void V8ContextImpl::GetGlobalPropertyNames(const PropertyCallbackInfo<Array>& in
{
try
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
{
vector<wstring> names;
std::vector<StdString> names;
for (auto it = stack.rbegin(); it != stack.rend(); it++)
{
vector<wstring> tempNames;
std::vector<StdString> tempNames;
if ((*it)->HasOwnProperty(pContextImpl->m_hHostObjectCookieName))
{
HostObjectHelpers::GetPropertyNames(::GetHostObject(*it), tempNames);
@ -841,7 +837,7 @@ void V8ContextImpl::GetGlobalPropertyNames(const PropertyCallbackInfo<Array>& in
auto hImportedNames = pContextImpl->CreateArray(nameCount);
for (auto index = 0; index < nameCount; index++)
{
hImportedNames->Set(index, pContextImpl->CreateString(names[index].c_str()));
hImportedNames->Set(index, pContextImpl->CreateString(names[index]));
}
CALLBACK_RETURN(hImportedNames);
@ -864,7 +860,7 @@ void V8ContextImpl::GetGlobalProperty(unsigned __int32 index, const PropertyCall
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -888,7 +884,7 @@ void V8ContextImpl::SetGlobalProperty(unsigned __int32 index, Local<Value> value
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
{
auto hName = pContextImpl->CreateInteger(index)->ToString();
@ -913,7 +909,7 @@ void V8ContextImpl::QueryGlobalProperty(unsigned __int32 index, const PropertyCa
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
{
for (auto it = stack.rbegin(); it != stack.rend(); it++)
@ -937,7 +933,7 @@ void V8ContextImpl::DeleteGlobalProperty(unsigned __int32 index, const PropertyC
auto pContextImpl = static_cast<V8ContextImpl*>(hGlobal->GetAlignedPointerFromInternalField(0));
if (pContextImpl != nullptr)
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
{
auto hName = pContextImpl->CreateInteger(index)->ToString();
@ -964,13 +960,13 @@ void V8ContextImpl::GetGlobalPropertyIndices(const PropertyCallbackInfo<Array>&
{
try
{
const vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
const std::vector<Persistent<Object>>& stack = pContextImpl->m_GlobalMembersStack;
if (stack.size() > 0)
{
vector<int> indices;
std::vector<int> indices;
for (auto it = stack.rbegin(); it != stack.rend(); it++)
{
vector<int> tempIndices;
std::vector<int> tempIndices;
if ((*it)->HasOwnProperty(pContextImpl->m_hHostObjectCookieName))
{
HostObjectHelpers::GetPropertyIndices(::GetHostObject(*it), tempIndices);
@ -1016,7 +1012,7 @@ void V8ContextImpl::GetHostObjectProperty(Local<String> hName, const PropertyCal
CALLBACK_RETURN(true);
}
CALLBACK_RETURN(pContextImpl->ImportValue(HostObjectHelpers::GetProperty(::UnwrapHostObject(info), *String::Value(hName))));
CALLBACK_RETURN(pContextImpl->ImportValue(HostObjectHelpers::GetProperty(::UnwrapHostObject(info), StdString(hName))));
}
catch (const HostException& exception)
{
@ -1032,7 +1028,7 @@ void V8ContextImpl::SetHostObjectProperty(Local<String> hName, Local<Value> hVal
try
{
HostObjectHelpers::SetProperty(::UnwrapHostObject(info), *String::Value(hName), pContextImpl->ExportValue(hValue));
HostObjectHelpers::SetProperty(::UnwrapHostObject(info), StdString(hName), pContextImpl->ExportValue(hValue));
CALLBACK_RETURN(hValue);
}
catch (const HostException& exception)
@ -1054,13 +1050,13 @@ void V8ContextImpl::QueryHostObjectProperty(Local<String> hName, const PropertyC
CALLBACK_RETURN(ReadOnly | DontEnum | DontDelete);
}
vector<wstring> names;
std::vector<StdString> names;
HostObjectHelpers::GetPropertyNames(::UnwrapHostObject(info), names);
String::Value nameValue(hName);
StdString name(hName);
for (auto it = names.begin(); it != names.end(); it++)
{
if (it->compare(*nameValue) == 0)
if (it->Compare(name) == 0)
{
CALLBACK_RETURN(None);
}
@ -1080,7 +1076,7 @@ void V8ContextImpl::DeleteHostObjectProperty(Local<String> hName, const Property
try
{
CALLBACK_RETURN(HostObjectHelpers::DeleteProperty(::UnwrapHostObject(info), *String::Value(hName)));
CALLBACK_RETURN(HostObjectHelpers::DeleteProperty(::UnwrapHostObject(info), StdString(hName)));
}
catch (const HostException& exception)
{
@ -1096,14 +1092,14 @@ void V8ContextImpl::GetHostObjectPropertyNames(const PropertyCallbackInfo<Array>
try
{
vector<wstring> names;
std::vector<StdString> names;
HostObjectHelpers::GetPropertyNames(::UnwrapHostObject(info), names);
auto nameCount = static_cast<int>(names.size());
auto hImportedNames = pContextImpl->CreateArray(nameCount);
for (auto index = 0; index < nameCount; index++)
{
hImportedNames->Set(index, pContextImpl->CreateString(names[index].c_str()));
hImportedNames->Set(index, pContextImpl->CreateString(names[index]));
}
CALLBACK_RETURN(hImportedNames);
@ -1155,7 +1151,7 @@ void V8ContextImpl::QueryHostObjectProperty(unsigned __int32 index, const Proper
try
{
vector<int> indices;
std::vector<int> indices;
HostObjectHelpers::GetPropertyIndices(::UnwrapHostObject(info), indices);
for (auto it = indices.begin(); it < indices.end(); it++)
@ -1196,7 +1192,7 @@ void V8ContextImpl::GetHostObjectPropertyIndices(const PropertyCallbackInfo<Arra
try
{
vector<int> indices;
std::vector<int> indices;
HostObjectHelpers::GetPropertyIndices(::UnwrapHostObject(info), indices);
auto indexCount = static_cast<int>(indices.size());
@ -1224,7 +1220,7 @@ void V8ContextImpl::InvokeHostObject(const FunctionCallbackInfo<Value>& info)
{
auto argCount = info.Length();
vector<V8Value> exportedArgs;
std::vector<V8Value> exportedArgs;
exportedArgs.reserve(argCount);
for (auto index = 0; index < argCount; index++)
@ -1305,10 +1301,10 @@ Handle<Value> V8ContextImpl::ImportValue(const V8Value& value)
}
{
const wchar_t* pResult;
if (value.AsString(pResult))
const StdString* pString;
if (value.AsString(pString))
{
return CreateString(pResult);
return CreateString(*pString);
}
}
@ -1389,7 +1385,7 @@ V8Value V8ContextImpl::ExportValue(Handle<Value> hValue)
if (hValue->IsString())
{
return V8Value(*String::Value(hValue));
return V8Value(new StdString(hValue));
}
if (hValue->IsObject())
@ -1408,7 +1404,7 @@ V8Value V8ContextImpl::ExportValue(Handle<Value> hValue)
//-----------------------------------------------------------------------------
void V8ContextImpl::ImportValues(const vector<V8Value>& values, vector<Handle<Value>>& importedValues)
void V8ContextImpl::ImportValues(const std::vector<V8Value>& values, std::vector<Handle<Value>>& importedValues)
{
importedValues.clear();
@ -1429,19 +1425,19 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
{
if (!tryCatch.CanContinue())
{
throw V8Exception(V8Exception::Type_Interrupt, m_Name.c_str(), L"Script execution interrupted by host", *String::Value(tryCatch.StackTrace()), V8Value(V8Value::Undefined));
throw V8Exception(V8Exception::Type_Interrupt, m_Name, StdString(L"Script execution interrupted by host"), StdString(tryCatch.StackTrace()), V8Value(V8Value::Undefined));
}
auto hException = tryCatch.Exception();
wstring message;
StdString message;
bool stackOverflow;
String::Value value(hException);
if (value.length() > 0)
StdString value(hException);
if (value.GetLength() > 0)
{
message = *value;
stackOverflow = (_wcsicmp(message.c_str(), L"RangeError: Maximum call stack size exceeded") == 0);
message = std::move(value);
stackOverflow = (_wcsicmp(message.ToCString(), L"RangeError: Maximum call stack size exceeded") == 0);
}
else
{
@ -1463,12 +1459,12 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
// from robust. These sanity checks are intended to mitigate this fragility.
_ASSERTE(hException->IsObject());
_ASSERTE(wstring(*String::Value(hException->ToObject()->GetConstructorName())) == L"RangeError");
_ASSERTE(StdString(hException->ToObject()->GetConstructorName()) == L"RangeError");
}
#endif // _DEBUG
wstring stackTrace;
StdString stackTrace;
V8Value innerException(V8Value::Undefined);
if (stackOverflow)
@ -1480,15 +1476,15 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
auto hStackTrace = tryCatch.StackTrace();
if (!hStackTrace.IsEmpty())
{
stackTrace = *String::Value(hStackTrace);
stackTrace = StdString(hStackTrace);
}
auto hMessage = tryCatch.Message();
if (!hMessage.IsEmpty())
{
if (message.length() < 1)
if (message.GetLength() < 1)
{
message = *String::Value(hMessage->Get());
message = StdString(hMessage->Get());
}
stackTrace = message;
@ -1505,7 +1501,7 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
if (!hScriptName.IsEmpty() && (hScriptName->Length() > 0))
{
stackTrace += L"\n at ";
stackTrace += *String::Value(hScriptName);
stackTrace += StdString(hScriptName);
}
else
{
@ -1518,15 +1514,15 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
}
stackTrace += L':';
stackTrace += to_wstring(hMessage->GetLineNumber());
stackTrace += std::to_wstring(hMessage->GetLineNumber());
stackTrace += L':';
stackTrace += to_wstring(hMessage->GetStartColumn() + 1);
stackTrace += std::to_wstring(hMessage->GetStartColumn() + 1);
auto hSourceLine = hMessage->GetSourceLine();
if (!hSourceLine.IsEmpty() && (hSourceLine->Length() > 0))
{
stackTrace += L" -> ";
stackTrace += *String::Value(hSourceLine);
stackTrace += StdString(hSourceLine);
}
}
else
@ -1544,14 +1540,14 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
stackTrace += L"new ";
}
stackTrace += *String::Value(hFunctionName);
stackTrace += StdString(hFunctionName);
stackTrace += L" (";
}
auto hScriptName = hFrame->GetScriptName();
if (!hScriptName.IsEmpty() && (hScriptName->Length() > 0))
{
stackTrace += *String::Value(hScriptName);
stackTrace += StdString(hScriptName);
}
else
{
@ -1562,14 +1558,14 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
auto lineNumber = hFrame->GetLineNumber();
if (lineNumber != Message::kNoLineNumberInfo)
{
stackTrace += to_wstring(lineNumber);
stackTrace += std::to_wstring(lineNumber);
}
stackTrace += L':';
auto column = hFrame->GetColumn();
if (column != Message::kNoColumnInfo)
{
stackTrace += to_wstring(column);
stackTrace += std::to_wstring(column);
}
if (!hFunctionName.IsEmpty() && (hFunctionName->Length() > 0))
@ -1583,7 +1579,7 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
if (!hSourceLine.IsEmpty() && (hSourceLine->Length() > 0))
{
stackTrace += L" -> ";
stackTrace += *String::Value(hSourceLine);
stackTrace += StdString(hSourceLine);
}
}
}
@ -1596,7 +1592,7 @@ void V8ContextImpl::Verify(const TryCatch& tryCatch)
}
}
throw V8Exception(V8Exception::Type_General, m_Name.c_str(), message.c_str(), stackTrace.c_str(), innerException);
throw V8Exception(V8Exception::Type_General, m_Name, std::move(message), std::move(stackTrace), std::move(innerException));
}
}

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

@ -71,16 +71,16 @@ class V8ContextImpl: public V8Context
public:
V8ContextImpl(V8IsolateImpl* pIsolateImpl, const wchar_t* pName, bool enableDebugging, bool disableGlobalMembers, int debugPort);
V8ContextImpl(V8IsolateImpl* pIsolateImpl, const StdString& name, bool enableDebugging, bool disableGlobalMembers, int debugPort);
size_t GetMaxIsolateStackUsage();
void SetMaxIsolateStackUsage(size_t value);
void CallWithLock(LockCallbackT* pCallback, void* pvArg);
V8Value GetRootObject();
void SetGlobalProperty(const wchar_t* pName, const V8Value& value, bool globalMembers);
V8Value Execute(const wchar_t* pDocumentName, const wchar_t* pCode, bool evaluate, bool discard);
V8ScriptHolder* Compile(const wchar_t* pDocumentName, const wchar_t* pCode);
void SetGlobalProperty(const StdString& name, const V8Value& value, bool globalMembers);
V8Value Execute(const StdString& documentName, const StdString& code, bool evaluate, bool discard);
V8ScriptHolder* Compile(const StdString& documentName, const StdString& code);
bool CanExecute(V8ScriptHolder* pHolder);
V8Value Execute(V8ScriptHolder* pHolder, bool evaluate);
void Interrupt();
@ -90,18 +90,18 @@ public:
void* AddRefV8Object(void* pvObject);
void ReleaseV8Object(void* pvObject);
V8Value GetV8ObjectProperty(void* pvObject, const wchar_t* pName);
void SetV8ObjectProperty(void* pvObject, const wchar_t* pName, const V8Value& value);
bool DeleteV8ObjectProperty(void* pvObject, const wchar_t* pName);
void GetV8ObjectPropertyNames(void* pvObject, vector<wstring>& names);
V8Value GetV8ObjectProperty(void* pvObject, const StdString& name);
void SetV8ObjectProperty(void* pvObject, const StdString& name, const V8Value& value);
bool DeleteV8ObjectProperty(void* pvObject, const StdString& name);
void GetV8ObjectPropertyNames(void* pvObject, std::vector<StdString>& names);
V8Value GetV8ObjectProperty(void* pvObject, int index);
void SetV8ObjectProperty(void* pvObject, int index, const V8Value& value);
bool DeleteV8ObjectProperty(void* pvObject, int index);
void GetV8ObjectPropertyIndices(void* pvObject, vector<int>& indices);
void GetV8ObjectPropertyIndices(void* pvObject, std::vector<int>& indices);
V8Value InvokeV8Object(void* pvObject, const vector<V8Value>& args, bool asConstructor);
V8Value InvokeV8ObjectMethod(void* pvObject, const wchar_t* pName, const vector<V8Value>& args);
V8Value InvokeV8Object(void* pvObject, const std::vector<V8Value>& args, bool asConstructor);
V8Value InvokeV8ObjectMethod(void* pvObject, const StdString& name, const std::vector<V8Value>& args);
void ProcessDebugMessages();
@ -124,7 +124,7 @@ private:
~Scope()
{
if (!uncaught_exception() && m_pContextImpl->m_hContext->HasOutOfMemoryException())
if (!std::uncaught_exception() && m_pContextImpl->m_hContext->HasOutOfMemoryException())
{
m_pContextImpl->m_spIsolateImpl->ThrowOutOfMemoryException();
}
@ -176,14 +176,9 @@ private:
return m_spIsolateImpl->CreateInteger(value);
}
Local<String> CreateString(const char* pValue)
Local<String> CreateString(const StdString& value)
{
return m_spIsolateImpl->CreateString(pValue);
}
Local<String> CreateString(const wchar_t* pValue)
{
return m_spIsolateImpl->CreateString(pValue);
return m_spIsolateImpl->CreateString(value);
}
Local<Array> CreateArray(int length = 0)
@ -261,8 +256,8 @@ private:
Handle<Value> Wrap();
void GetV8ObjectPropertyNames(Handle<Object> hObject, vector<wstring>& names);
void GetV8ObjectPropertyIndices(Handle<Object> hObject, vector<int>& indices);
void GetV8ObjectPropertyNames(Handle<Object> hObject, std::vector<StdString>& names);
void GetV8ObjectPropertyIndices(Handle<Object> hObject, std::vector<int>& indices);
static void GetGlobalProperty(Local<String> hName, const PropertyCallbackInfo<Value>& info);
static void SetGlobalProperty(Local<String> hName, Local<Value> value, const PropertyCallbackInfo<Value>& info);
@ -293,17 +288,17 @@ private:
Handle<Value> ImportValue(const V8Value& value);
V8Value ExportValue(Handle<Value> hValue);
void ImportValues(const vector<V8Value>& values, vector<Handle<Value>>& importedValues);
void ImportValues(const std::vector<V8Value>& values, std::vector<Handle<Value>>& importedValues);
void Verify(const TryCatch& tryCatch);
void VerifyNotOutOfMemory();
void ThrowScriptException(const HostException& exception);
wstring m_Name;
StdString m_Name;
SharedPtr<V8IsolateImpl> m_spIsolateImpl;
Persistent<Context> m_hContext;
Persistent<Object> m_hGlobal;
vector<Persistent<Object>> m_GlobalMembersStack;
std::vector<Persistent<Object>> m_GlobalMembersStack;
Persistent<String> m_hHostObjectCookieName;
Persistent<String> m_hInnerExceptionName;
Persistent<FunctionTemplate> m_hHostObjectTemplate;

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

@ -84,7 +84,7 @@ namespace V8 {
try
{
auto gcIsolateProxyImpl = dynamic_cast<V8IsolateProxyImpl^>(gcIsolateProxy);
m_pspContext = new SharedPtr<V8Context>(V8Context::Create(gcIsolateProxyImpl->GetIsolate(), StringToUniPtr(gcName), enableDebugging, disableGlobalMembers, debugPort));
m_pspContext = new SharedPtr<V8Context>(V8Context::Create(gcIsolateProxyImpl->GetIsolate(), StdString(gcName), enableDebugging, disableGlobalMembers, debugPort));
}
catch (const V8Exception& exception)
{
@ -140,7 +140,7 @@ namespace V8 {
{
try
{
GetContext()->SetGlobalProperty(StringToUniPtr(gcName), ImportValue(gcItem), globalMembers);
GetContext()->SetGlobalProperty(StdString(gcName), ImportValue(gcItem), globalMembers);
}
catch (const V8Exception& exception)
{
@ -154,7 +154,7 @@ namespace V8 {
{
try
{
return ExportValue(GetContext()->Execute(StringToUniPtr(gcDocumentName), StringToUniPtr(gcCode), evaluate, discard));
return ExportValue(GetContext()->Execute(StdString(gcDocumentName), StdString(gcCode), evaluate, discard));
}
catch (const V8Exception& exception)
{
@ -168,7 +168,7 @@ namespace V8 {
{
try
{
return gcnew V8ScriptImpl(gcDocumentName, GetContext()->Compile(StringToUniPtr(gcDocumentName), StringToUniPtr(gcCode)));
return gcnew V8ScriptImpl(gcDocumentName, GetContext()->Compile(StdString(gcDocumentName), StdString(gcCode)));
}
catch (const V8Exception& exception)
{
@ -389,7 +389,7 @@ namespace V8 {
auto gcValue = dynamic_cast<String^>(gcObject);
if (gcValue != nullptr)
{
return V8Value(StringToUniPtr(gcValue));
return V8Value(new StdString(gcValue));
}
}
@ -456,10 +456,10 @@ namespace V8 {
}
{
const wchar_t* pResult;
if (value.AsString(pResult))
const StdString* pString;
if (value.AsString(pString))
{
return gcnew String(pResult);
return pString->ToManagedString();
}
}

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

@ -70,9 +70,9 @@ using namespace Microsoft::ClearScript::V8;
void DECLSPEC_NORETURN V8Exception::ThrowScriptEngineException() const
{
auto gcEngineName = gcnew String(m_EngineName.c_str());
auto gcMessage = gcnew String(m_Message.c_str());
auto gcStackTrace = gcnew String(m_StackTrace.c_str());
auto gcEngineName = m_EngineName.ToManagedString();
auto gcMessage = m_Message.ToManagedString();
auto gcStackTrace = m_StackTrace.ToManagedString();
auto gcInnerException = dynamic_cast<Exception^>(V8ContextProxyImpl::ExportValue(m_InnerException));
switch (m_Type)

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

@ -76,44 +76,13 @@ public:
Type_Fatal
};
V8Exception(Type type, const wchar_t* pEngineName, const wchar_t* pMessage, const wchar_t* pStackTrace, const V8Value& innerException):
V8Exception(Type type, const StdString& engineName, StdString&& message, StdString&& stackTrace, V8Value&& innerException):
m_Type(type),
m_InnerException(innerException)
m_EngineName(engineName),
m_Message(std::move(message)),
m_StackTrace(std::move(stackTrace)),
m_InnerException(std::move(innerException))
{
if (pEngineName != nullptr)
{
m_EngineName = pEngineName;
}
if (pMessage != nullptr)
{
m_Message = pMessage;
}
if (pStackTrace != nullptr)
{
m_StackTrace = pStackTrace;
}
}
V8Exception(Type type, const wchar_t* pEngineName, const wchar_t* pMessage, const wchar_t* pStackTrace, V8Value&& innerException):
m_Type(type),
m_InnerException(innerException)
{
if (pEngineName != nullptr)
{
m_EngineName = pEngineName;
}
if (pMessage != nullptr)
{
m_Message = pMessage;
}
if (pStackTrace != nullptr)
{
m_StackTrace = pStackTrace;
}
}
void DECLSPEC_NORETURN ThrowScriptEngineException() const;
@ -121,8 +90,8 @@ public:
private:
Type m_Type;
wstring m_EngineName;
wstring m_Message;
wstring m_StackTrace;
StdString m_EngineName;
StdString m_Message;
StdString m_StackTrace;
V8Value m_InnerException;
};

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

@ -65,7 +65,7 @@
// V8Isolate implementation
//-----------------------------------------------------------------------------
V8Isolate* V8Isolate::Create(const wchar_t* pName, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort)
V8Isolate* V8Isolate::Create(const StdString& name, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort)
{
return new V8IsolateImpl(pName, pConstraints, enableDebugging, debugPort);
return new V8IsolateImpl(name, pConstraints, enableDebugging, debugPort);
}

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

@ -69,12 +69,12 @@ class V8Isolate: public WeakRefTarget<V8Isolate>
{
public:
static V8Isolate* Create(const wchar_t* pName, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort);
static V8Isolate* Create(const StdString& name, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort);
virtual size_t GetMaxStackUsage() = 0;
virtual void SetMaxStackUsage(size_t value) = 0;
virtual V8ScriptHolder* Compile(const wchar_t* pDocumentName, const wchar_t* pCode) = 0;
virtual V8ScriptHolder* Compile(const StdString& documentName, const StdString& code) = 0;
virtual void GetHeapInfo(V8IsolateHeapInfo& heapInfo) = 0;
virtual void CollectGarbage(bool exhaustive) = 0;

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

@ -108,7 +108,8 @@ static size_t* const s_pMinStackLimit = reinterpret_cast<size_t*>(sizeof(size_t)
//-----------------------------------------------------------------------------
V8IsolateImpl::V8IsolateImpl(const wchar_t* pName, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort) :
V8IsolateImpl::V8IsolateImpl(const StdString& name, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort):
m_Name(name),
m_pIsolate(Isolate::New()),
m_DebuggingEnabled(false),
m_DebugMessageDispatchCount(0),
@ -119,11 +120,6 @@ V8IsolateImpl::V8IsolateImpl(const wchar_t* pName, const V8IsolateConstraints* p
{
BEGIN_ADDREF_SCOPE
if (pName != nullptr)
{
m_Name = pName;
}
BEGIN_ISOLATE_ENTRY_SCOPE
V8::SetCaptureStackTraceForUncaughtExceptions(true, 64, StackTrace::kDetailed);
@ -209,7 +205,7 @@ void V8IsolateImpl::EnableDebugging(int debugPort)
_ASSERTE(m_pDebugMessageDispatcher);
Debug::SetDebugMessageDispatchHandler(m_pDebugMessageDispatcher);
ASSERT_EVAL(Debug::EnableAgent(*String::Utf8Value(CreateString(m_Name.c_str())), debugPort));
ASSERT_EVAL(Debug::EnableAgent(*String::Utf8Value(CreateString(m_Name)), debugPort));
m_DebuggingEnabled = true;
m_DebugPort = debugPort;
@ -254,12 +250,12 @@ void V8IsolateImpl::SetMaxStackUsage(size_t value)
//-----------------------------------------------------------------------------
V8ScriptHolder* V8IsolateImpl::Compile(const wchar_t* pDocumentName, const wchar_t* pCode)
V8ScriptHolder* V8IsolateImpl::Compile(const StdString& documentName, const StdString& code)
{
BEGIN_ISOLATE_SCOPE
SharedPtr<V8ContextImpl> spContextImpl((m_ContextPtrs.size() > 0) ? m_ContextPtrs.front() : new V8ContextImpl(this, nullptr, false, true, 0));
return spContextImpl->Compile(pDocumentName, pCode);
SharedPtr<V8ContextImpl> spContextImpl((m_ContextPtrs.size() > 0) ? m_ContextPtrs.front() : new V8ContextImpl(this, StdString(), false, true, 0));
return spContextImpl->Compile(documentName, code);
END_ISOLATE_SCOPE
}
@ -329,7 +325,7 @@ void V8IsolateImpl::ReleaseV8Script(void* pvScript)
void DECLSPEC_NORETURN V8IsolateImpl::ThrowOutOfMemoryException()
{
m_IsOutOfMemory = true;
throw V8Exception(V8Exception::Type_Fatal, m_Name.c_str(), L"The V8 runtime has exceeded its memory limit", nullptr, V8Value(V8Value::Undefined));
throw V8Exception(V8Exception::Type_Fatal, m_Name, StdString(L"The V8 runtime has exceeded its memory limit"), StdString(), V8Value(V8Value::Undefined));
}
//-----------------------------------------------------------------------------
@ -388,7 +384,7 @@ void V8IsolateImpl::EnterExecutionScope(size_t* pStackMarker)
if (maxStackUsage > 0)
{
// yes; ensure minimum breathing room
maxStackUsage = max(maxStackUsage, s_StackBreathingRoom);
maxStackUsage = std::max(maxStackUsage, s_StackBreathingRoom);
// calculate stack address limit
size_t* pStackLimit = pStackMarker - (maxStackUsage / sizeof(size_t));
@ -413,7 +409,7 @@ void V8IsolateImpl::EnterExecutionScope(size_t* pStackMarker)
else if ((m_pStackLimit != nullptr) && (pStackMarker < m_pStackLimit))
{
// stack usage limit exceeded (host-side detection)
throw V8Exception(V8Exception::Type_General, m_Name.c_str(), L"The V8 runtime has exceeded its stack usage limit", nullptr, V8Value(V8Value::Undefined));
throw V8Exception(V8Exception::Type_General, m_Name, StdString(L"The V8 runtime has exceeded its stack usage limit"), StdString(), V8Value(V8Value::Undefined));
}
m_ExecutionLevel++;

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

@ -121,7 +121,7 @@ public:
V8IsolateImpl* m_pIsolateImpl;
};
V8IsolateImpl(const wchar_t* pName, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort);
V8IsolateImpl(const StdString& name, const V8IsolateConstraints* pConstraints, bool enableDebugging, int debugPort);
Local<Context> CreateContext(ExtensionConfiguration* pExtensionConfiguation = nullptr, Handle<ObjectTemplate> hGlobalTemplate = Handle<ObjectTemplate>(), Handle<Value> hGlobalObject = Handle<Value>())
{
@ -163,14 +163,9 @@ public:
return Uint32::NewFromUnsigned(m_pIsolate, value);
}
Local<String> CreateString(const char* pValue)
Local<String> CreateString(const StdString& value)
{
return String::NewFromOneByte(m_pIsolate, reinterpret_cast<const uint8_t*>(pValue));
}
Local<String> CreateString(const wchar_t* pValue)
{
return String::NewFromTwoByte(m_pIsolate, reinterpret_cast<const uint16_t*>(pValue));
return value.ToV8String(m_pIsolate);
}
Local<Array> CreateArray(int length = 0)
@ -253,7 +248,7 @@ public:
size_t GetMaxStackUsage();
void SetMaxStackUsage(size_t value);
V8ScriptHolder* Compile(const wchar_t* pDocumentName, const wchar_t* pCode);
V8ScriptHolder* Compile(const StdString& documentName, const StdString& code);
void GetHeapInfo(V8IsolateHeapInfo& heapInfo);
void CollectGarbage(bool exhaustive);
@ -272,18 +267,18 @@ private:
void EnterExecutionScope(size_t* pStackMarker);
void ExitExecutionScope();
wstring m_Name;
StdString m_Name;
Isolate* m_pIsolate;
list<V8ContextImpl*> m_ContextPtrs;
std::list<V8ContextImpl*> m_ContextPtrs;
bool m_DebuggingEnabled;
int m_DebugPort;
Debug::DebugMessageDispatchHandler m_pDebugMessageDispatcher;
atomic<size_t> m_DebugMessageDispatchCount;
std::atomic<size_t> m_DebugMessageDispatchCount;
atomic<size_t> m_MaxStackUsage;
std::atomic<size_t> m_MaxStackUsage;
size_t m_ExecutionLevel;
size_t* m_pStackLimit;
atomic<bool> m_IsOutOfMemory;
std::atomic<bool> m_IsOutOfMemory;
};

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

@ -83,7 +83,7 @@ namespace V8 {
try
{
m_pspIsolate = new SharedPtr<V8Isolate>(V8Isolate::Create(StringToUniPtr(gcName), pConstraints, enableDebugging, debugPort));
m_pspIsolate = new SharedPtr<V8Isolate>(V8Isolate::Create(StdString(gcName), pConstraints, enableDebugging, debugPort));
}
catch (const V8Exception& exception)
{
@ -111,7 +111,7 @@ namespace V8 {
{
try
{
return gcnew V8ScriptImpl(gcDocumentName, GetIsolate()->Compile(StringToUniPtr(gcDocumentName), StringToUniPtr(gcCode)));
return gcnew V8ScriptImpl(gcDocumentName, GetIsolate()->Compile(StdString(gcDocumentName), StdString(gcCode)));
}
catch (const V8Exception& exception)
{

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

@ -74,28 +74,28 @@ V8ObjectHolderImpl* GetHolderImpl(V8ObjectHolder* pHolder)
// V8ObjectHelpers implementation
//-----------------------------------------------------------------------------
V8Value V8ObjectHelpers::GetProperty(V8ObjectHolder* pHolder, const wchar_t* pName)
V8Value V8ObjectHelpers::GetProperty(V8ObjectHolder* pHolder, const StdString& name)
{
return GetHolderImpl(pHolder)->GetProperty(pName);
return GetHolderImpl(pHolder)->GetProperty(name);
}
//-----------------------------------------------------------------------------
void V8ObjectHelpers::SetProperty(V8ObjectHolder* pHolder, const wchar_t* pName, const V8Value& value)
void V8ObjectHelpers::SetProperty(V8ObjectHolder* pHolder, const StdString& name, const V8Value& value)
{
GetHolderImpl(pHolder)->SetProperty(pName, value);
GetHolderImpl(pHolder)->SetProperty(name, value);
}
//-----------------------------------------------------------------------------
bool V8ObjectHelpers::DeleteProperty(V8ObjectHolder* pHolder, const wchar_t* pName)
bool V8ObjectHelpers::DeleteProperty(V8ObjectHolder* pHolder, const StdString& name)
{
return GetHolderImpl(pHolder)->DeleteProperty(pName);
return GetHolderImpl(pHolder)->DeleteProperty(name);
}
//-----------------------------------------------------------------------------
void V8ObjectHelpers::GetPropertyNames(V8ObjectHolder* pHolder, vector<wstring>& names)
void V8ObjectHelpers::GetPropertyNames(V8ObjectHolder* pHolder, std::vector<StdString>& names)
{
GetHolderImpl(pHolder)->GetPropertyNames(names);
}
@ -123,21 +123,21 @@ bool V8ObjectHelpers::DeleteProperty(V8ObjectHolder* pHolder, int index)
//-----------------------------------------------------------------------------
void V8ObjectHelpers::GetPropertyIndices(V8ObjectHolder* pHolder, vector<int>& indices)
void V8ObjectHelpers::GetPropertyIndices(V8ObjectHolder* pHolder, std::vector<int>& indices)
{
GetHolderImpl(pHolder)->GetPropertyIndices(indices);
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHelpers::Invoke(V8ObjectHolder* pHolder, const vector<V8Value>& args, bool asConstructor)
V8Value V8ObjectHelpers::Invoke(V8ObjectHolder* pHolder, const std::vector<V8Value>& args, bool asConstructor)
{
return GetHolderImpl(pHolder)->Invoke(args, asConstructor);
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHelpers::InvokeMethod(V8ObjectHolder* pHolder, const wchar_t* pName, const vector<V8Value>& args)
V8Value V8ObjectHelpers::InvokeMethod(V8ObjectHolder* pHolder, const StdString& name, const std::vector<V8Value>& args)
{
return GetHolderImpl(pHolder)->InvokeMethod(pName, args);
return GetHolderImpl(pHolder)->InvokeMethod(name, args);
}

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

@ -71,16 +71,16 @@ class V8ObjectHelpers
public:
static V8Value GetProperty(V8ObjectHolder* pHolder, const wchar_t* pName);
static void SetProperty(V8ObjectHolder* pHolder, const wchar_t* pName, const V8Value& value);
static bool DeleteProperty(V8ObjectHolder* pHolder, const wchar_t* pName);
static void GetPropertyNames(V8ObjectHolder* pHolder, vector<wstring>& names);
static V8Value GetProperty(V8ObjectHolder* pHolder, const StdString& name);
static void SetProperty(V8ObjectHolder* pHolder, const StdString& name, const V8Value& value);
static bool DeleteProperty(V8ObjectHolder* pHolder, const StdString& name);
static void GetPropertyNames(V8ObjectHolder* pHolder, std::vector<StdString>& names);
static V8Value GetProperty(V8ObjectHolder* pHolder, int index);
static void SetProperty(V8ObjectHolder* pHolder, int index, const V8Value& value);
static bool DeleteProperty(V8ObjectHolder* pHolder, int index);
static void GetPropertyIndices(V8ObjectHolder* pHolder, vector<int>& indices);
static void GetPropertyIndices(V8ObjectHolder* pHolder, std::vector<int>& indices);
static V8Value Invoke(V8ObjectHolder* pHolder, const vector<V8Value>& args, bool asConstructor);
static V8Value InvokeMethod(V8ObjectHolder* pHolder, const wchar_t* pName, const vector<V8Value>& args);
static V8Value Invoke(V8ObjectHolder* pHolder, const std::vector<V8Value>& args, bool asConstructor);
static V8Value InvokeMethod(V8ObjectHolder* pHolder, const StdString& name, const std::vector<V8Value>& args);
};

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

@ -95,28 +95,28 @@ void* V8ObjectHolderImpl::GetObject() const
//-----------------------------------------------------------------------------
V8Value V8ObjectHolderImpl::GetProperty(const wchar_t* pName) const
V8Value V8ObjectHolderImpl::GetProperty(const StdString& name) const
{
return m_spContextImpl->GetV8ObjectProperty(m_pvObject, pName);
return m_spContextImpl->GetV8ObjectProperty(m_pvObject, name);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::SetProperty(const wchar_t* pName, const V8Value& value) const
void V8ObjectHolderImpl::SetProperty(const StdString& name, const V8Value& value) const
{
m_spContextImpl->SetV8ObjectProperty(m_pvObject, pName, value);
m_spContextImpl->SetV8ObjectProperty(m_pvObject, name, value);
}
//-----------------------------------------------------------------------------
bool V8ObjectHolderImpl::DeleteProperty(const wchar_t* pName) const
bool V8ObjectHolderImpl::DeleteProperty(const StdString& name) const
{
return m_spContextImpl->DeleteV8ObjectProperty(m_pvObject, pName);
return m_spContextImpl->DeleteV8ObjectProperty(m_pvObject, name);
}
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::GetPropertyNames(vector<wstring>& names) const
void V8ObjectHolderImpl::GetPropertyNames(std::vector<StdString>& names) const
{
m_spContextImpl->GetV8ObjectPropertyNames(m_pvObject, names);
}
@ -144,23 +144,23 @@ bool V8ObjectHolderImpl::DeleteProperty(int index) const
//-----------------------------------------------------------------------------
void V8ObjectHolderImpl::GetPropertyIndices(vector<int>& indices) const
void V8ObjectHolderImpl::GetPropertyIndices(std::vector<int>& indices) const
{
m_spContextImpl->GetV8ObjectPropertyIndices(m_pvObject, indices);
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHolderImpl::Invoke(const vector<V8Value>& args, bool asConstructor) const
V8Value V8ObjectHolderImpl::Invoke(const std::vector<V8Value>& args, bool asConstructor) const
{
return m_spContextImpl->InvokeV8Object(m_pvObject, args, asConstructor);
}
//-----------------------------------------------------------------------------
V8Value V8ObjectHolderImpl::InvokeMethod(const wchar_t* pName, const vector<V8Value>& args) const
V8Value V8ObjectHolderImpl::InvokeMethod(const StdString& name, const std::vector<V8Value>& args) const
{
return m_spContextImpl->InvokeV8ObjectMethod(m_pvObject, pName, args);
return m_spContextImpl->InvokeV8ObjectMethod(m_pvObject, name, args);
}
//-----------------------------------------------------------------------------

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

@ -77,18 +77,18 @@ public:
V8ObjectHolderImpl* Clone() const;
void* GetObject() const;
V8Value GetProperty(const wchar_t* pName) const;
void SetProperty(const wchar_t* pName, const V8Value& value) const;
bool DeleteProperty(const wchar_t* pName) const;
void GetPropertyNames(vector<wstring>& names) const;
V8Value GetProperty(const StdString& name) const;
void SetProperty(const StdString& name, const V8Value& value) const;
bool DeleteProperty(const StdString& name) const;
void GetPropertyNames(std::vector<StdString>& names) const;
V8Value GetProperty(int index) const;
void SetProperty(int index, const V8Value& value) const;
bool DeleteProperty(int index) const;
void GetPropertyIndices(vector<int>& indices) const;
void GetPropertyIndices(std::vector<int>& indices) const;
V8Value Invoke(const vector<V8Value>& args, bool asConstructor) const;
V8Value InvokeMethod(const wchar_t* pName, const vector<V8Value>& args) const;
V8Value Invoke(const std::vector<V8Value>& args, bool asConstructor) const;
V8Value InvokeMethod(const StdString& name, const std::vector<V8Value>& args) const;
~V8ObjectHolderImpl();

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

@ -81,7 +81,7 @@ namespace V8 {
{
try
{
return V8ContextProxyImpl::ExportValue(V8ObjectHelpers::GetProperty(GetHolder(), StringToUniPtr(gcName)));
return V8ContextProxyImpl::ExportValue(V8ObjectHelpers::GetProperty(GetHolder(), StdString(gcName)));
}
catch (const V8Exception& exception)
{
@ -95,7 +95,7 @@ namespace V8 {
{
try
{
V8ObjectHelpers::SetProperty(GetHolder(), StringToUniPtr(gcName), V8ContextProxyImpl::ImportValue(gcValue));
V8ObjectHelpers::SetProperty(GetHolder(), StdString(gcName), V8ContextProxyImpl::ImportValue(gcValue));
}
catch (const V8Exception& exception)
{
@ -109,7 +109,7 @@ namespace V8 {
{
try
{
return V8ObjectHelpers::DeleteProperty(GetHolder(), StringToUniPtr(gcName));
return V8ObjectHelpers::DeleteProperty(GetHolder(), StdString(gcName));
}
catch (const V8Exception& exception)
{
@ -123,14 +123,14 @@ namespace V8 {
{
try
{
vector<wstring> names;
std::vector<StdString> names;
V8ObjectHelpers::GetPropertyNames(GetHolder(), names);
auto nameCount = static_cast<int>(names.size());
auto gcNames = gcnew array<String^>(nameCount);
for (auto index = 0; index < nameCount; index++)
{
gcNames[index] = gcnew String(names[index].c_str());
gcNames[index] = names[index].ToManagedString();
}
return gcNames;
@ -189,7 +189,7 @@ namespace V8 {
{
try
{
vector<int> indices;
std::vector<int> indices;
V8ObjectHelpers::GetPropertyIndices(GetHolder(), indices);
auto indexCount = static_cast<int>(indices.size());
@ -213,7 +213,7 @@ namespace V8 {
{
try
{
vector<V8Value> importedArgs;
std::vector<V8Value> importedArgs;
ImportValues(gcArgs, importedArgs);
return V8ContextProxyImpl::ExportValue(V8ObjectHelpers::Invoke(GetHolder(), importedArgs, asConstructor));
@ -230,10 +230,10 @@ namespace V8 {
{
try
{
vector<V8Value> importedArgs;
std::vector<V8Value> importedArgs;
ImportValues(gcArgs, importedArgs);
return V8ContextProxyImpl::ExportValue(V8ObjectHelpers::InvokeMethod(GetHolder(), StringToUniPtr(gcName), importedArgs));
return V8ContextProxyImpl::ExportValue(V8ObjectHelpers::InvokeMethod(GetHolder(), StdString(gcName), importedArgs));
}
catch (const V8Exception& exception)
{
@ -288,7 +288,7 @@ namespace V8 {
//-------------------------------------------------------------------------
void V8ObjectImpl::ImportValues(array<Object^>^ gcValues, vector<V8Value>& importedValues)
void V8ObjectImpl::ImportValues(array<Object^>^ gcValues, std::vector<V8Value>& importedValues)
{
importedValues.clear();
if (gcValues != nullptr)

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

@ -95,7 +95,7 @@ namespace V8 {
private:
static void ImportValues(array<Object^>^ gcValues, vector<V8Value>& importedValues);
static void ImportValues(array<Object^>^ gcValues, std::vector<V8Value>& importedValues);
Object^ m_gcLock;
SharedPtr<V8ObjectHolder>* m_pspHolder;

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

@ -123,10 +123,10 @@ public:
m_Data.UInt32Value = value;
}
explicit V8Value(const wchar_t* pValue):
explicit V8Value(const StdString* pString):
m_Type(Type_String)
{
m_Data.pString = new wstring(pValue);
m_Data.pString = pString;
}
explicit V8Value(V8ObjectHolder* pV8ObjectHolder):
@ -224,11 +224,11 @@ public:
return false;
}
bool AsString(const wchar_t*& pResult) const
bool AsString(const StdString*& pString) const
{
if (m_Type == Type_String)
{
pResult = m_Data.pString->c_str();
pString = m_Data.pString;
return true;
}
@ -284,7 +284,7 @@ private:
double DoubleValue;
__int32 Int32Value;
unsigned __int32 UInt32Value;
wstring* pString;
const StdString* pString;
V8ObjectHolder* pV8ObjectHolder;
HostObjectHolder* pHostObjectHolder;
};
@ -311,7 +311,7 @@ private:
}
else if (m_Type == Type_String)
{
m_Data.pString = new wstring(*that.m_Data.pString);
m_Data.pString = new StdString(*that.m_Data.pString);
}
else if (m_Type == Type_V8Object)
{

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

@ -112,7 +112,7 @@ class WeakRefUtil
private:
template <typename TResult>
static TResult CallWithLock(const function<TResult()>& callback)
static TResult CallWithLock(const std::function<TResult()>& callback)
{
BEGIN_MUTEX_SCOPE(*ms_pMutex)

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

@ -400,6 +400,19 @@ namespace Microsoft.ClearScript.Test
Assert.AreEqual(2L, HostItem.GetCoreBindCount());
}
[TestMethod, TestCategory("BugFix")]
public void BugFix_StringWithNullChar()
{
const string value = "abc\0def";
const string value2 = "ghi\0jkl";
dynamic func = engine.Evaluate("(function (x) { return x.length; }).valueOf()");
Assert.AreEqual(value.Length, func(value));
Assert.AreEqual(value, engine.Evaluate(@"'abc\0def'"));
dynamic obj = engine.Evaluate(@"({ 'abc\0def': 'ghi\0jkl' })");
Assert.IsTrue(((DynamicObject)obj).GetDynamicMemberNames().Contains(value));
Assert.AreEqual(value2, obj[value]);
}
// ReSharper restore InconsistentNaming
#endregion