[v8-juice] r2259 committed - worked around the Get/SetAlignedPointer...() problems by using Get/Set...

3 views
Skip to first unread message

v8-j...@googlecode.com

unread,
Dec 23, 2012, 9:31:04 AM12/23/12
to v8-juice-...@googlegroups.com
Revision: 2259
Author: sgbeal
Date: Sun Dec 23 06:30:45 2012
Log: worked around the Get/SetAlignedPointer...() problems by using
Get/SetInternalField() directly with an External value.
http://code.google.com/p/v8-juice/source/detail?r=2259

Modified:
/convert/examples/ConvertDemo.cpp
/convert/include/cvv8/ClassCreator.hpp
/convert/include/cvv8/detail/convert_core.hpp

=======================================
--- /convert/examples/ConvertDemo.cpp Sun Apr 8 12:56:18 2012
+++ /convert/examples/ConvertDemo.cpp Sun Dec 23 06:30:45 2012
@@ -700,16 +700,17 @@
typedef cv::CtorForwarder<CFT * (v8::Arguments const &)> Cn;
ASS<( -1 == sl::Arity< Cn >::Value )>();
typedef CFT * (*CFTCtor)( v8::Arguments const & );
+#define USE(X) assert(NULL != X) /* "use" an otherwise unused var, to
avoid a gcc warnning. */
CFTCtor ctor;
- ctor = C0::Call;
- ctor = C1::Call;
- ctor = C2::Call;
+ ctor = C0::Call; USE(ctor);
+ ctor = C1::Call; USE(ctor);
+ ctor = C2::Call; USE(ctor);
//ctor = C0Sub::Ctor;
typedef cv::Signature< CFT (C0, C1, C2) > CtorList;
typedef cv::CtorArityDispatcher<CtorList> CDispatch;
typedef CtorFwdTest * (*FacT)( v8::Arguments const & argv );
FacT fac;
- fac = CDispatch::Call;
+ fac = CDispatch::Call; USE(fac);
typedef int (CFT::*M1)(int) ;
typedef int (CFT::*M2)(int,int) const;
ASS<( !(tmp::IsConst<CFT>::Value) )>();
@@ -776,10 +777,11 @@
> >::Value >();
ASS< !SIU< cv::MethodToInCa<BoundNative, int (v8::Arguments const
&), &BoundNative::invoInt > >::Value>();

-
v8::InvocationCallback cb;
cb = cv::InCaLikeMethod<BoundNative, int,
&BoundNative::invoInt>::Call;
+ USE(cb);
cb = cv::InCaLikeConstMethod<BoundNative, int,
&BoundNative::invoIntConst>::Call;
+ USE(cb);
//cb = cv::InCaLike<BoundNative, int, &BoundNative::invoInt>::Call;
//cb = cv::InCaLike<BoundNative, int,
&BoundNative::invoIntConst>::Call;
ASS< -1 == sl::Arity< cv::InCaLikeMethod<BoundNative, int,
&BoundNative::invoInt> >::Value >();
@@ -837,6 +839,7 @@
ASS< 0 == sl::Index< char const *, BNPuts >::Value >();
}
#undef ASS
+#undef USE
}

void test_new_typelist()
@@ -956,51 +959,54 @@
v8::AccessorGetter g;
v8::AccessorSetter s;

+#define USE(X) assert(NULL != X) /* "use" an otherwise unused var, to
avoid a gcc warnning. */
using namespace cvv8;

// Function-to-X conversions:
- c = FunctionTo< InCa, int(char const *), ::puts>::Call;
- c = FunctionTo< InCaVoid, int(char const *), ::puts>::Call;
- g = FunctionTo< Getter, int(void), ::getchar>::Get;
- s = FunctionTo< Setter, int(int), ::putchar>::Set;
+ c = FunctionTo< InCa, int(char const *), ::puts>::Call; USE(c);
+ c = FunctionTo< InCaVoid, int(char const *), ::puts>::Call; USE(c);
+ g = FunctionTo< Getter, int(void), ::getchar>::Get; USE(g);
+ s = FunctionTo< Setter, int(int), ::putchar>::Set; USE(s);

//#if __cplusplus >= 201103L /*
http://sourceforge.net/apps/mediawiki/predef/index.php?title=Standards */
//typedef FunctionToInCa11< InCa > F11;
//#endif

// Var-to-X conversions:
- g = VarTo< Getter, int, &aBoundInt >::Get;
- s = VarTo< Setter, int, &aBoundInt >::Set;
+ g = VarTo< Getter, int, &aBoundInt >::Get; USE(g);
+ s = VarTo< Setter, int, &aBoundInt >::Set; USE(s);
typedef VarTo< Accessors, int, &aBoundInt > VarGetSet;
- g = VarGetSet::Get;
- s = VarGetSet::Set;
+ g = VarGetSet::Get; USE(g);
+ s = VarGetSet::Set; USE(s);

typedef BoundNative T;

// Member Var-to-X conversions:
- g = MemberTo< Getter, T, int, &T::publicInt >::Get;
- s = MemberTo< Setter, T, int, &T::publicInt >::Set;
+ g = MemberTo< Getter, T, int, &T::publicInt >::Get; USE(g);
+ s = MemberTo< Setter, T, int, &T::publicInt >::Set; USE(s);
typedef MemberTo< Accessors, T, int, &T::publicInt > MemAcc;
- g = MemAcc::Get;
- s = MemAcc::Set;
+ g = MemAcc::Get; USE(g);
+ s = MemAcc::Set; USE(s);


// Method-to-X conversions:
- c = MethodTo< InCa, T, void (), &T::doFoo >::Call;
- c = MethodTo< InCaVoid, T, void (), &T::doFoo >::Call;
- g = MethodTo< Getter, const T, int (), &T::getInt >::Get;
- s = MethodTo< Setter, T, void (int), &T::setInt >::Set;
+ c = MethodTo< InCa, T, void (), &T::doFoo >::Call; USE(c);
+ c = MethodTo< InCaVoid, T, void (), &T::doFoo >::Call; USE(c);
+ g = MethodTo< Getter, const T, int (), &T::getInt >::Get; USE(g);
+ s = MethodTo< Setter, T, void (int), &T::setInt >::Set; USE(s);
// Const methods:
- c = MethodTo< InCa, const T, int (), &T::getInt >::Call;
- c = MethodTo< InCaVoid, const T, int (), &T::getInt >::Call;
+ c = MethodTo< InCa, const T, int (), &T::getInt >::Call; USE(c);
+ c = MethodTo< InCaVoid, const T, int (), &T::getInt >::Call; USE(c);


// Functor-to-X conversions:
typedef MyFunctor F;
- c = FunctorTo< InCaVoid, F, bool () >::Call;
- c = FunctorTo< InCa, F, bool (int) >::Call;
- g = FunctorTo< Getter, F, bool () >::Get;
- s = FunctorTo< Setter, F, void (bool) >::Set;
+ c = FunctorTo< InCaVoid, F, bool () >::Call; USE(c);
+ c = FunctorTo< InCa, F, bool (int) >::Call; USE(c);
+ g = FunctorTo< Getter, F, bool () >::Get; USE(g);
+ s = FunctorTo< Setter, F, void (bool) >::Set; USE(s);
+#undef USE
+
}


=======================================
--- /convert/include/cvv8/ClassCreator.hpp Sat Dec 22 04:30:40 2012
+++ /convert/include/cvv8/ClassCreator.hpp Sun Dec 23 06:30:45 2012
@@ -586,11 +586,6 @@

If nh is not found anywhere in the chain, an empty handle is
returned.
-
- Note that T must be non-cv qualified, so it is generally
- undesirable to allow the compiler to deduce its type from the
- parameter. Thus the T template parameter should not be omitted
- from calls to this function.
*/
static v8::Handle<v8::Object> FindHolder( v8::Handle<v8::Object>
const & jo,
T const * nh )
@@ -602,9 +597,12 @@
while( !ext && !proto.IsEmpty() && proto->IsObject() )
{
v8::Local<v8::Object> const & obj( v8::Object::Cast(
*proto ) );
- ext = (obj->InternalFieldCount() != InternalFields::Count)
- ? NULL
- : obj->GetAlignedPointerFromInternalField(
InternalFields::NativeIndex );
+ v8::Local<v8::Value> const & exv =
(obj->InternalFieldCount() != InternalFields::Count)
+ ? v8::Local<v8::Value>()
+ : obj->GetInternalField( InternalFields::NativeIndex );
+ ext = (!exv.IsEmpty() && exv->IsExternal() )
+ ? v8::External::Cast(*exv)->Value()
+ : NULL;
// FIXME: if InternalFields::TypeIDIndex>=0 then also do a
check on that one.
/*
If !ext, there is no bound pointer. If (ext &&
@@ -706,16 +704,16 @@
}
Factory::Delete(native);
#endif
+ /*
+ According to the v8 gurus i need to call pv.Dispose()
+ instead of pv.Clear(), but if i do then this dtor is
+ being called twice. If i don't call it, v8 is crashing
+ sometime after this function with a !NEAR_DEATH
+ assertion.
+ */
+ pv.Dispose();
+ pv.Clear();
}
- /*
- According to the v8 gurus i need to call pv.Dispose()
- instead of pv.Clear(), but if i do then this dtor is
- being called twice. If i don't call it, v8 is crashing
- sometime after this function with a !NEAR_DEATH
- assertion.
- */
- pv.Dispose();
- pv.Clear();
}

/**
@@ -775,9 +773,9 @@
self.MakeWeak( nobj, weak_dtor );
if( 0 <= InternalFields::TypeIDIndex )
{
- self->SetAlignedPointerInInternalField(
InternalFields::TypeIDIndex, (void *)TypeID::Value );
+ self->SetInternalField( InternalFields::TypeIDIndex,
v8::External::New((void *)TypeID::Value) );
}
- self->SetAlignedPointerInInternalField(
InternalFields::NativeIndex, nobj )
+ self->SetInternalField( InternalFields::NativeIndex,
v8::External::New(nobj) )
/* We do this after the call to Wrap() just in case
the Wrap() impl
accidentally writes to this field. In that case we
end up
losing the data they stored there. So this is just
as evil as
@@ -808,7 +806,9 @@
protoTmpl(v8::Persistent<v8::ObjectTemplate>::New(
ctorTmpl->PrototypeTemplate() )),
isSealed(false)
{
-
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(InternalFields::Count);
+ if(InternalFields::Count > 0){
+
ctorTmpl->InstanceTemplate()->SetInternalFieldCount(InternalFields::Count);
+ }
}
public:
/**
=======================================
--- /convert/include/cvv8/detail/convert_core.hpp Sat Dec 22 04:30:40 2012
+++ /convert/include/cvv8/detail/convert_core.hpp Sun Dec 23 06:30:45 2012
@@ -853,9 +853,12 @@
while( !ext && !proto.IsEmpty() && proto->IsObject() )
{
v8::Local<v8::Object> const & obj( v8::Object::Cast(
*proto ) );
- ext = (obj->InternalFieldCount() != InternalFieldCount)
- ? NULL
- : obj->GetAlignedPointerFromInternalField(
InternalFieldIndex );
+ v8::Local<v8::Value> const & exv =
(obj->InternalFieldCount() != InternalFieldCount)
+ ? v8::Local<v8::Value>()
+ : obj->GetInternalField( InternalFieldIndex );
+ ext = ( !exv.IsEmpty() && exv->IsExternal() )
+ ? v8::External::Cast(*exv)->Value()
+ : NULL;
if( ! ext )
{
if( !SearchPrototypeChain ) break;
@@ -986,11 +989,17 @@
while( !ext && !proto.IsEmpty() && proto->IsObject() )
{
v8::Local<v8::Object> const & obj( v8::Object::Cast(
*proto ) );
- tid = (obj->InternalFieldCount() != InternalFieldCount)
- ? NULL
- : obj->GetAlignedPointerFromInternalField(
TypeIdFieldIndex );
- ext = (tid == TypeID)
- ? obj->GetAlignedPointerFromInternalField(
ObjectFieldIndex )
+ v8::Local<v8::Value> const & tidv =
(obj->InternalFieldCount() != InternalFieldCount)
+ ? v8::Local<v8::Value>()
+ : obj->GetInternalField( TypeIdFieldIndex );
+ tid = ( !tidv.IsEmpty() && tidv->IsExternal() )
+ ? v8::External::Cast(*tidv)->Value()
+ : NULL;
+ v8::Local<v8::Value> const & exv = (tid == TypeID)
+ ? obj->GetInternalField( ObjectFieldIndex )
+ : v8::Local<v8::Value>();
+ ext = ( !exv.IsEmpty() && exv->IsExternal() )
+ ? v8::External::Cast(*exv)->Value()
: NULL;
if( ! ext )
{
Reply all
Reply to author
Forward
0 new messages