Permalink
Browse files

Remove all unused vendor directories

  • Loading branch information...
1 parent 42088c9 commit e0aeedcff0584ebe00aed2c03c8ecd10839df908 @tbranyen tbranyen committed Jul 11, 2014
Showing with 0 additions and 23,133 deletions.
  1. +0 −1,286 vendor/libv8-convert/cvv8/ClassCreator.hpp
  2. +0 −8 vendor/libv8-convert/cvv8/Makefile
  3. +0 −183 vendor/libv8-convert/cvv8/NativeToJSMap.hpp
  4. +0 −650 vendor/libv8-convert/cvv8/V8Shell.hpp
  5. +0 −281 vendor/libv8-convert/cvv8/XTo.hpp
  6. +0 −817 vendor/libv8-convert/cvv8/arguments.hpp
  7. +0 −66 vendor/libv8-convert/cvv8/convert.hpp
  8. +0 −2 vendor/libv8-convert/cvv8/detail/Makefile
  9. +0 −2,054 vendor/libv8-convert/cvv8/detail/convert_core.hpp
  10. +0 −28 vendor/libv8-convert/cvv8/detail/doxygen_hack.hpp
  11. +0 −2,202 vendor/libv8-convert/cvv8/detail/invocable_core.hpp
  12. +0 −3,588 vendor/libv8-convert/cvv8/detail/invocable_generated.hpp
  13. +0 −498 vendor/libv8-convert/cvv8/detail/signature_core.hpp
  14. +0 −911 vendor/libv8-convert/cvv8/detail/signature_generated.hpp
  15. +0 −120 vendor/libv8-convert/cvv8/detail/tmp.hpp
  16. +0 −72 vendor/libv8-convert/cvv8/generator/Signature.hpp
  17. +0 −67 vendor/libv8-convert/cvv8/invocable.hpp
  18. +0 −730 vendor/libv8-convert/cvv8/properties.hpp
  19. +0 −70 vendor/libv8-convert/cvv8/signature.hpp
  20. +0 −169 vendor/libv8-convert/cvv8/v8-convert.hpp
  21. +0 −286 vendor/naturaldocs/Config/Languages.txt
  22. +0 −382 vendor/naturaldocs/Config/Topics.txt
  23. +0 −52 vendor/naturaldocs/Help/customizinglanguages.html
  24. +0 −74 vendor/naturaldocs/Help/customizingtopics.html
  25. +0 −58 vendor/naturaldocs/Help/documenting.html
  26. +0 −147 vendor/naturaldocs/Help/documenting/reference.html
  27. +0 −181 vendor/naturaldocs/Help/documenting/walkthrough.html
  28. +0 −528 vendor/naturaldocs/Help/example/Default.css
  29. +0 −204 vendor/naturaldocs/Help/example/NaturalDocs.js
  30. +0 −507 vendor/naturaldocs/Help/example/Roman.css
  31. +0 −507 vendor/naturaldocs/Help/example/Small.css
  32. +0 −43 vendor/naturaldocs/Help/example/showstyle.html
  33. +0 −90 vendor/naturaldocs/Help/examples.css
  34. BIN vendor/naturaldocs/Help/images/header/background.png
  35. BIN vendor/naturaldocs/Help/images/header/leftside.png
  36. BIN vendor/naturaldocs/Help/images/header/logo.png
  37. BIN vendor/naturaldocs/Help/images/header/overbody.png
  38. BIN vendor/naturaldocs/Help/images/header/overbodybg.png
  39. BIN vendor/naturaldocs/Help/images/header/overleftmargin.png
  40. BIN vendor/naturaldocs/Help/images/header/overmenu.png
  41. BIN vendor/naturaldocs/Help/images/header/overmenubg.png
  42. BIN vendor/naturaldocs/Help/images/header/rightside.png
  43. BIN vendor/naturaldocs/Help/images/menu/about.png
  44. BIN vendor/naturaldocs/Help/images/menu/background.png
  45. BIN vendor/naturaldocs/Help/images/menu/bottomleft.png
  46. BIN vendor/naturaldocs/Help/images/menu/bottomright.png
  47. BIN vendor/naturaldocs/Help/images/menu/community.png
  48. BIN vendor/naturaldocs/Help/images/menu/customizing.png
  49. BIN vendor/naturaldocs/Help/images/menu/using.png
  50. +0 −9 vendor/naturaldocs/Help/index.html
  51. +0 −77 vendor/naturaldocs/Help/javascript/BrowserStyles.js
  52. +0 −72 vendor/naturaldocs/Help/javascript/PNGHandling.js
  53. +0 −38 vendor/naturaldocs/Help/keywords.html
  54. +0 −32 vendor/naturaldocs/Help/languages.html
  55. +0 −79 vendor/naturaldocs/Help/menu.html
  56. +0 −84 vendor/naturaldocs/Help/output.html
  57. +0 −40 vendor/naturaldocs/Help/running.html
  58. +0 −292 vendor/naturaldocs/Help/styles.css
  59. +0 −52 vendor/naturaldocs/Help/styles.html
  60. +0 −18 vendor/naturaldocs/Help/troubleshooting.html
  61. +0 −947 vendor/naturaldocs/Info/CSSGuide.txt
  62. +0 −83 vendor/naturaldocs/Info/File Parsing.txt
  63. +0 −270 vendor/naturaldocs/Info/HTMLTestCases.pm
  64. +0 −107 vendor/naturaldocs/Info/Languages.txt
  65. +0 −92 vendor/naturaldocs/Info/NDMarkup.txt
  66. +0 −59 vendor/naturaldocs/Info/Symbol Management.txt
  67. BIN vendor/naturaldocs/Info/images/Logo.png
  68. +0 −1,526 vendor/naturaldocs/JavaScript/GooglePrettify.js
  69. +0 −841 vendor/naturaldocs/JavaScript/NaturalDocs.js
  70. +0 −275 vendor/naturaldocs/License.txt
  71. +0 −295 vendor/naturaldocs/Modules/NaturalDocs/BinaryFile.pm
  72. +0 −281 vendor/naturaldocs/Modules/NaturalDocs/Builder.pm
  73. +0 −349 vendor/naturaldocs/Modules/NaturalDocs/Builder/Base.pm
  74. +0 −354 vendor/naturaldocs/Modules/NaturalDocs/Builder/FramedHTML.pm
Sorry, we could not display the entire diff because it was too big.
View
1,286 vendor/libv8-convert/cvv8/ClassCreator.hpp
@@ -1,1286 +0,0 @@
-#if !defined(CODE_GOOGLE_COM_P_V8_CONVERT_CLASS_CREATOR_HPP_INCLUDED)
-#define CODE_GOOGLE_COM_P_V8_CONVERT_CLASS_CREATOR_HPP_INCLUDED 1
-/** LICENSE
-
- This software's source code, including accompanying documentation and
- demonstration applications, are licensed under the following
- conditions...
-
- The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/])
- explicitly disclaims copyright in all jurisdictions which recognize
- such a disclaimer. In such jurisdictions, this software is released
- into the Public Domain.
-
- In jurisdictions which do not recognize Public Domain property
- (e.g. Germany as of 2011), this software is Copyright (c) 2011
- by Stephan G. Beal, and is released under the terms of the MIT License
- (see below).
-
- In jurisdictions which recognize Public Domain property, the user of
- this software may choose to accept it either as 1) Public Domain, 2)
- under the conditions of the MIT License (see below), or 3) under the
- terms of dual Public Domain/MIT License conditions described here, as
- they choose.
-
- The MIT License is about as close to Public Domain as a license can
- get, and is described in clear, concise terms at:
-
- http://en.wikipedia.org/wiki/MIT_License
-
- The full text of the MIT License follows:
-
- --
- Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/)
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-
- --END OF MIT LICENSE--
-
- For purposes of the above license, the term "Software" includes
- documentation and demonstration source code which accompanies
- this software. ("Accompanies" = is contained in the Software's
- primary public source code repository.)
-
-*/
-
-#include <cassert>
-#include <stdexcept>
-#include "convert.hpp"
-//#include <iostream> // only for debuggering
-#include "NativeToJSMap.hpp"
-namespace cvv8 {
-
- /**
- Policy template used by ClassCreator<T> for
- instantiating T objects.
- */
- template <typename T>
- class ClassCreator_Factory
- {
- public:
- typedef T * ReturnType;
- /**
- Must instantiate a new T object based on the given
- arguments. On error it should throw an exception (which the
- binding framework will convert to a JS-side exception). It
- may also return NULL on error, but the error message
- probably won't be as clear for the user.
-
- Ownership of the object is passed to the caller (the
- binding API internals), and eventually given to v8.
-
- jsSelf will be the newly-created JS-side 'this' object. It
- is not normally required by this function but it is
- sometimes useful when we need to bind supplementary
- properties in the ctor, especially when binding a "pure
- C++" class which has no native place to store such
- properties.
-
- At the time this is called, jsSelf is not connected to the
- native (because it hasn't yet been created).
- Implementations must not perform the actual binding of the
- returned native to jsSelf - ClassCreator will do that
- immediately after Create() returns the new object.
-
- The default implementation simply return (new T).
- */
- static ReturnType Create( v8::Persistent<v8::Object> & jsSelf, v8::Arguments const & argv )
- {
- return new T;
- }
-
- /**
- Must destroy obj using a mechanism complementary to its
- construction via a prior call to Create().
-
- The default implementation simply calls (delete obj).
- */
- static void Delete( T * obj )
- {
- delete obj;
- }
- };
-
- /**
- Base class for static ClassCreator options.
- */
- template <typename ValT, ValT Val>
- struct Opt_ConstVal
- {
- typedef ValT Type;
- const static Type Value = Val;
- };
-
- /**
- Base class for static integer ClassCreator options.
- */
- template <int Val>
- struct Opt_Int : Opt_ConstVal<int,Val>
- {};
-
- /**
- Base class for static boolean ClassCreator options.
- */
- template <bool Val>
- struct Opt_Bool : Opt_ConstVal<bool,Val>
- {};
-
- /**
- A ClassCreator policy/option class responsible specifying whether
- or not a ClassCreator-bound class should allow "Foo()" and "new
- Foo()" to behave the same or not. If the Value member is false
- (the default) then "Foo()" is not allowed to behave as a
- constructor call (it will generate an error), otherwise it will
- be treated exactly as if "new Foo()" had been called.
- */
- template <typename T>
- struct ClassCreator_AllowCtorWithoutNew : Opt_Bool<false>
- {};
-
- /**
- ClassCreator policy which determines whether lookups for native
- types in JS objects should walk through the prototype
- chain. This can decrease the speed of JS-to-this operations and
- is necessary only if bound types will be subclassed (either from
- other bound native types or from JS classes).
-
- The default value is true for the sake of usability. If JS-side
- subclassing will never be used, you can potentially optimize out a
- few lookup operations by creating the specialization by subclassing
- Opt_Bool<false>.
- */
- template <typename T>
- struct ClassCreator_SearchPrototypeForThis : Opt_Bool<true>
- {};
-
- /**
- ClassCreator policy type which defines a "type ID" value
- for a type wrapped using ClassCreator. This is used
- together with JSToNative_ObjectWithInternalFieldsTypeSafe
- (type THAT 10 times fast) to provide a lightweight
- (but highly effective) type check when extracting
- natives from v8 (as void pointers). The default
- implementation is fine for all cases i can think of, but i can
- concieve of one or two uses for specializations (e.g. storing the
- JS-side name of the class as the type ID).
-
- The type id must be unique per type except that subtypes may
- (depending on various other binding options) may need use the same
- value as the parent type. If multiple types share the same type ID,
- the type-safety check can be bypassed, _potentially_ leading to an
- illegal static_cast() and subsequent mis-use of the pointer. i
- stress the word "potentially" because to get that condition one
- would have to (A) abuse the object via the C++ API (which doesn't
- happen via the binding process, and you're probably also not going
- to do it) or (B) write some script code to confuse two bound native
- types about who is really who when a particular member is called.
-
- In the case of subclassed bound types, the
- ClassCreator_TypeID<SubClass> impl should subclass
- ClassCreator_TypeID<ParentClass>. Whether or not this is _required_
- for proper functionality depends at least in part on whether
- (ClassCreator_InternalFields<ParentType>::TypeIDIndex>=0). If it is
- negative, subclasses do not need to explicitly define this policy
- because the type ID won't be used for purposes of validating a JS-held
- pointer's native type.
-
- TODO: see if we can consolidate this type with TypeName<>. The problem
- at the moment is that JSToNative_ObjectWithInternalFieldsTypeSafe
- takes a (void const * &) and TypeName::Value is a (char const *), which
- won't convert to (void const *) in the context of template parameters.
- */
- template <typename T>
- struct ClassCreator_TypeID
- {
- const static void * Value;
- };
- template <typename T>
- const void * ClassCreator_TypeID<T>::Value = TypeName<T>::Value;
-
- /**
- Convenience base type for ClassCreator_InternalFields
- implementations.
-
- See the member documentation for the meaning of
- HowMany and Index.
-
- If any of the following conditions are met then
- a compile-time assertion is triggered:
-
- - (ObjectIndex<0)
-
- - (ObjectIndex>=HowMany)
-
- - (TypeIndex>=HowMany).
-
- - (TypeIndex == ObjectIndex)
-
- TypeIndex may be negative, which indicates to ClassCreator that the
- binding should not store type ID information. However, if it is
- negative then T must not be used together with
- JSToNative_ObjectWithInternalFieldsTypeSafe - doing so will trigger
- a compile-time assertion.
- */
- template <typename T, int HowMany = 2, int TypeIndex = 0, int ObjectIndex = 1>
- struct ClassCreator_InternalFields_Base
- {
- /**
- Total number of internal fields assigned to JS-side T
- objects.
- */
- static const int Count = HowMany;
-
- /**
- The internal field index at which ClassCreator policies should
- expect the native object to be found in any given JS object.
- It must be 0 or greater, and must be less than Value.
- */
- static const int NativeIndex = ObjectIndex;
-
- /**
- The internal field index at which ClassCreator policies
- should expect a type identifier tag to be stored.
- This can be used in conjunction with
- JSToNative_ObjectWithInternalFieldsTypeSafe (or similar)
- to provide an extra level of type safety at JS runtime.
-
- */
- static const int TypeIDIndex = TypeIndex;
- private:
- typedef char AssertFields[
- (HowMany > TypeIndex)
- && (HowMany > ObjectIndex)
- && (TypeIndex != ObjectIndex)
- && (ObjectIndex >= 0)
- ? 1 : -1];
- };
-
- /**
- The ClassCreator policy which sets the number of internal
- fields reserved for JS objects and the internal field index
- (0-based) at which the native object is stored . The Count
- value must be greater than 0 and greater than the NativeIndex
- member. Failing to meet these prerequisites will cause a
- compile-time assertion to be triggered.
-
- ACHTUNG SUBCLASSERS:
-
- When using a heirarchy of native types, more than one of which
- is compatible with CastFromJS(), conversions from subtype to
- base type will fail unless all subtypes use the same internal
- field placement as the parent type. If this code can detect a
- mismatch then it will fail gracefully (e.g. a JS-side
- exception), and if not then it might mis-cast an object and
- cause Undefined Behaviour.
-
- If a given parent type uses a custom ClassCreator_InternalFields
- specialization then to ensure that subclasses always have the
- same placement, they "should" define their own policy like
- this:
-
- @code
- template <>
- struct ClassCreator_InternalFields< SubType >
- : ClassCreator_InternalFields< ParentType >
- {};
- @endcode
-
- That prohibits special internal field handling in the subtypes,
- but experience hasn't shown that subclasses need their own
- internal fields. Normaly a single internal field is all we need
- when binding native data. And when i say "normally", i mean
- "almost always."
-
- This must-match requirement is partially a side-effect of the library
- internally using the field count as a santiy check before trying to
- extract data from internal fields. It also exists so that the
- optional (but recommended) type-safety-check support (added in late
- June 2011: see JSToNative_ObjectWithInternalFieldsTypeSafe) will
- treat the subclasses as instances of the base class.
- */
- template <typename T>
- struct ClassCreator_InternalFields : ClassCreator_InternalFields_Base<T>
- {
- };
-
-
- /**
- This policy is used by ClassCreator::SetupBindings() as the generic
- interface for plugging in a bound class. Clients are not required to
- specialise this, but see this class' Initialize() for what might
- happen if they don't.
- */
- template <typename T>
- struct ClassCreator_SetupBindings
- {
- /**
- Specializations should perform any class/function-related binding
- here, adding their functionality to the given object (which is
- normally the logical global object but need not be). (Note that the
- handle refererence is const but that object itself can be modified.
-
- The default implementation throws an exception deriving from
- std::exception, so it must be specialized to be useful. A default
- specialization exists because there are probably a few cases
- out there which don't really need this. But most (if not all)
- need a setup function, and this is the official one for
- ClassCreator-wrapped types. Implementations may of course simply
- forward the call to another, client-provided function.
-
- On error the binding should throw a NATIVE exception (ideally
- deriving from std::exception because (A) it's portable practice
- and (B) parts of the cvv8 API handles those explicitly).
-
- Several years of experience have shown that this function (or
- similar implementations) should take some care to make sure
- not to set up their bindings twice. We can do that by using the
- following pattern:
-
- @code
- typedef ClassCreator<T> CC;
- CC & cc( CC::Instance() );
- if( cc.IsSealed() ) {
- cc.AddClassTo( "T", dest );
- return;
- }
-
- // ... do your bindings here...
-
- // As the final step:
- cc.AddClassTo( "T", dest );
- return;
- @endcode
-
- If you do not actually want to add the class to the dest object,
- you should call Seal() instead of AddClassTo() (or pass a different
- destination object to AddClassTo().
- */
- static void Initialize( v8::Handle<v8::Object> const & target )
- {
- throw std::runtime_error("ClassCreator_SetupBindings<T> MUST be specialized "
- "in order to be useful!");
- }
- };
-
- /**
- A concrete ClassCreator_SetupBindings implementation which forwards
- the call to a user-defined function.
- */
- template <typename T, void (*Func)( v8::Handle<v8::Object> const &) >
- struct ClassCreator_SetupBindings_ClientFunc
- {
- /**
- Calls Func(target).
- */
- static void Initialize( v8::Handle<v8::Object> const & target )
- {
- Func(target);
- }
- };
-
- /**
- The ClassCreator policy class responsible for doing optional
- class-specific binding-related work as part of the JS/Native
- object construction process.
-
- The default specialization does nothing (which is okay for the
- general case) but defines the interface which specializations
- must implement.
-
- Reminder to self: we could arguably benefit by splitting this policy
- into 3 classes, but experience has shown that the metadata used by
- the 3 functions are typically shared amongst the 3 implementations
- (or 2 of them in most cases).
- */
- template <typename T>
- struct ClassCreator_WeakWrap
- {
- typedef typename TypeInfo<T>::NativeHandle NativeHandle;
-
- /**
- Similar to Wrap(), but this is called before the native constructor is called.
- It is rarely needed, but is necessary if one needs to manipulate the JS
- "this" object before the native object is constructed, so that the native ctor
- can access information stored in the JS-side internal fields.
-
- If this throws a native exception, construction of the
- object will fail and Unwrap() is called, passed
- (jsSelf,NULL), to clean up any data which this function might have
- stored in jsSelf.
-
- The argv object is the arguments passed to the constructor.
-
- The default implementation does nothing.
- */
- static void PreWrap( v8::Persistent<v8::Object> const &, v8::Arguments const & )
- {
- return;
- }
-
-
- /**
- This operation is called one time from ClassCreator for each
- new object, directly after the native has been connected to
- a Persistent handle.
-
- Note that the ClassCreator code which calls this has already
- taken care of connecting nativeSelf to jsSelf. Client
- specializations of this policy may opt to add their own
- binding mechanisms, e.g. to allow CastToJS<T>() to work.
-
- Clients should do any bindings-related cleanup in
- Factory::Destruct() or Unwrap(), as appropriate for their
- case.
-
- Ownership of the objects is unchanged by calling this.
-
- On error, this function may throw a native exception. If
- that happens, ClassCreator will call
- Unwrap(jsSelf,nativeHandle) and
- Factory<T>::Destruct(nativeSelf) to clean up, and will then
- propagate the exception.
-
- The default implementation does nothing.
- */
- static void Wrap( v8::Persistent<v8::Object> const &, NativeHandle )
- {
- return;
- }
-
- /**
- This is called from the ClassCreator-generated destructor,
- just before the native destructor is called. If nativeSelf
- is NULL then it means that native construction failed,
- but implementations must (if necessary) clean up any data
- stored in jsSelf by the PreWrap() function.
-
- Specializations may use this to clean up data stored in
- other internal fields of the object (_not_ the field used
- to hold the native itself - that is removed by the
- framework). Optionally, such cleanup may be done in the
- corresponding Factory::Destruct() routine, and must be done
- there if the dtor will need access to such data.
-
- Note that when this is called, jsSelf and nativeSelf are
- about to be destroyed, so do not do anything crazy with the
- contents of jsSelf and DO NOT destroy nativeSelf (that is
- the job of the ClassCreator_Factory policy).
-
- Ownership of the objects is unchanged by calling this.
-
- Unwrap() is called during destruction or when construction
- fails (via a native exception), so any cleanup required for
- the jsSelf object can be delegated to this function, as
- opposed to being performed (and possibly duplicated) in
- PreWrap() and/or Wrap().
-
- The default implementation does nothing.
- */
- static void Unwrap( v8::Handle<v8::Object> const &, NativeHandle )
- {
- return;
- }
- };
-
-
-#if 0
- namespace Detail
- {
- template <typename Context>
- struct SharedType : public Context
- {
- private:
- SharedType(){}
- public:
- static SharedType & Instance()
- {
- static SharedType bob;
- return bob;
- }
- };
- }
-#endif
- /**
- A basic Native-to-JS class binding mechanism. This class does
- not aim to be a monster framework, just something simple,
- mainly for purposes of showing (and testing) what the core
- cvv8 can do.
-
- The framework must know how to convert JS objects to T objects,
- and for this to work client code must define a JSToNative<T>
- specialization in this manner:
-
- @code
- template <>
- struct JSToNative<T>
- : JSToNative_ClassCreator<T>
- {};
- @endcode
-
- If the internal field configuration must be customized then the
- client must define the number of fields by
- specializing/customizing the ClassCreator_InternalFields<T>
- policy class. Additionally, if the client does NOT use the
- above JSToNative<T> implementation then he should create his
- implementation by subclassing
- JSToNative_ObjectWithInternalFields<T,N,M>, where (N,M) are the
- number of internals fields and the index of the field where the
- native object is to be stored. See JSToNative_ClassCreator
- for an example.
-
- TODOs:
-
- - Certain operations may not work properly when inheriting
- bound classes from JS space, and possibly not even when
- inheriting bound natives from one another. That depends on
- several factors too complex to summarize here.
-
- - See how much of the v8::juice::cw::ClassWrap
- inheritance-related code we can salvage for re-use here.
-
- - There are known problems when trying to bind inherited methods
- when the parent class has no bound them to JS. i'm not sure how
- i can fix the templates to get this working.
- */
- template <typename T>
- class ClassCreator
- {
- private:
- typedef ClassCreator_InternalFields<T> InternalFields;
- typedef ClassCreator_WeakWrap<T> WeakWrap;
- typedef ClassCreator_TypeID<T> TypeID;
- v8::Persistent<v8::FunctionTemplate> ctorTmpl;
- v8::Handle<v8::ObjectTemplate> protoTmpl;
- bool isSealed;
- typedef ClassCreator_Factory<T> Factory;
-
-
- /**
- A utility function primarily intended to support various
- ClassCreator policy implementations.
-
- This function tries to extract a native handle from jo by
- looking in the internal field defined by
- ClassCreator_InternalFields<T>::NativeIndex. If a native is
- found in that field and it is the same as nh, then jo is
- returned. If none is found, jo's prototype object is searched,
- recursively, until either nh is found in the prototype chain or
- the end of the chain is reached. If a match is found, the JS
- object in which the native was found is returned. This does no
- casting - it only compares by address.
-
- 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 )
- {
- if( !nh || jo.IsEmpty() ) return v8::Handle<v8::Object>();
- v8::Handle<v8::Value> proto(jo);
- void const * ext = NULL;
- typedef ClassCreator_SearchPrototypeForThis<T> SPFT;
- while( !ext && !proto.IsEmpty() && proto->IsObject() )
- {
- v8::Local<v8::Object> const & obj( v8::Object::Cast( *proto ) );
- ext = (obj->InternalFieldCount() != InternalFields::Count)
- ? NULL
- : obj->GetPointerFromInternalField( InternalFields::NativeIndex );
- // FIXME: if InternalFields::TypeIDIndex>=0 then also do a check on that one.
- /*
- If !ext, there is no bound pointer. If (ext &&
- (ext!=nh)) then there is one, but it's not the droid
- we're looking for. In either case, (possibly) check the
- prototype...
- */
- if( ext == nh ) return obj;
- else if( !SPFT::Value ) break;
- else proto = obj->GetPrototype();
- }
- return v8::Handle<v8::Object>();
- }
-
- static void weak_dtor( v8::Persistent< v8::Value > pv, void *nobj )
- {
- using namespace v8;
- //std::cerr << "Entering weak_dtor<>(native="<<(void const *)nobj<<")\n";
- Local<Object> jobj( Object::Cast(*pv) );
- typedef typename JSToNative<T>::ResultType NT;
- NT native = CastFromJS<T>( pv );
- if( !native )
- {
- /* see: http://code.google.com/p/v8-juice/issues/detail?id=27
-
- When i call pv.Dispose(), this function is getting called twice,
- and the second time won't work. i'm going to igore (return w/o
- side-effects) this for now for the sake of avoiding a crash
- which i'm seeing only on 64-bit platforms.
-
- However, even if i return here, v8 is crashing with a
- !NEAR_DEATH assertion right after the second call is made.
-
- The extra pair of Dispose()/Clear() calls seems to eliminate that
- crash, but the fact that this code block is hit AT ALL is a
- sign of a problem - the dtor shouldn't be called twice!
- */
- pv.Dispose();
- pv.Clear();
-#if 1 /* i believe this problem was fixed. If you are reading this b/c
- you followed an assert() message, please report this as a bug.
- */
- assert( 0 && "weak_dtor() got no native object!");
-#endif
- return;
- }
- else
- {
- /**
- Reminder: the FindHolder() bits are here to
- assist when the bound native exists somewhere in the
- prototype chain other than jobj itself. In that case,
- jobj is valid but we cannot clear out the native handle
- internal field on it because it has no internal fields
- (or none that belong to us).
-
- To fix this properly we have to be able to know
- _exactly_ which JS object in the prototype chain nh is
- bound to.
- */
- v8::Handle<v8::Object> nholder = FindHolder( jobj, native );
-#if 1 /* reminder: i've never actually seen this error happen, i'm just pedantic about checking... */
- assert( ! nholder.IsEmpty() );
- WeakWrap::Unwrap( nholder /*jobj? subtle difference!*/, native );
- if( nholder.IsEmpty() || (nholder->InternalFieldCount() != InternalFields::Count) )
- {
- StringBuffer msg;
- msg << "SERIOUS INTERNAL ERROR:\n"
- << "ClassCreator<T>::weak_dtor() "
- << "validated that the JS/Native belong together, but "
- << "FindHolder() returned an "
- << (nholder.IsEmpty() ? "empty" : "invalid")
- << " handle!\n"
- << "From JS=@"<<(void const *)nobj
- << ", Converted to Native=@"<<(void const *)native
- << ", nholder field count="<<nholder->InternalFieldCount()
- << ", jobj field count="<<jobj->InternalFieldCount()
- << "\nTHIS MAY LEAD TO A CRASH IF THIS JS HANDLE IS USED AGAIN!!!\n"
- ;
- Factory::Delete(native);
- pv.Dispose(); pv.Clear(); /* see comments below!*/
- v8::ThrowException(msg.toError());
- return;
- }
- else
- {
- nholder->SetInternalField( InternalFields::NativeIndex, Null() );
- if( 0 <= InternalFields::TypeIDIndex )
- {
- nholder->SetInternalField( InternalFields::TypeIDIndex, Null() );
- }
- Factory::Delete(native);
- }
-#else
- WeakWrap::Unwrap( nholder, native );
- nholder->SetInternalField( InternalFields::NativeIndex, Null() );
- if( 0 <= InternalFields::TypeIDIndex )
- {
- nholder->SetInternalField( InternalFields::TypeIDIndex, Null() );
- }
- 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();
- }
-
- /**
- Gets installed as the NewInstance() handler for T.
- */
- static v8::Handle<v8::Value> ctor_proxy( v8::Arguments const & argv )
- {
- using namespace v8;
- if(ClassCreator_AllowCtorWithoutNew<T>::Value)
- {
- /**
- Allow construction without 'new' by forcing this
- function to be called in a ctor context...
- */
- if (!argv.IsConstructCall())
- {
- const int argc = argv.Length();
- Handle<Function> ctor( Function::Cast(*argv.Callee()));
- std::vector< Handle<Value> > av(static_cast<size_t>(argc),Undefined());
- for( int i = 0; i < argc; ++i ) av[i] = argv[i];
- return ctor->NewInstance( argc, &av[0] );
- }
- }
- else
- {
- /**
- Why have this limitation? If we don't, v8 pukes
- when the ctor is called, with
- "v8::Object::SetInternalField() Writing internal
- field out of bounds".
- */
- if (!argv.IsConstructCall())
- {
- return Toss("This constructor cannot be called as function!");
- }
- }
- Local<Object> const & jobj( argv.This()
- /*CastToJS<T>(*nobj)
-
- We are not yet far enough
- along in the binding that
- CastToJS() can work. And it
- can't work for the generic
- case, anyway.
- */);
- if( jobj.IsEmpty() ) return jobj /* assume exception*/;
- Persistent<Object> self( Persistent<Object>::New(jobj) );
- T * nobj = NULL;
- try
- {
- WeakWrap::PreWrap( self, argv );
- nobj = Factory::Create( self, argv );
- if( ! nobj )
- {
- return CastToJS<std::exception>(std::runtime_error("Native constructor failed."));
- }
- WeakWrap::Wrap( self, nobj );
- self.MakeWeak( nobj, weak_dtor );
- if( 0 <= InternalFields::TypeIDIndex )
- {
- self->SetPointerInInternalField( InternalFields::TypeIDIndex, (void *)TypeID::Value );
- }
- self->SetPointerInInternalField( InternalFields::NativeIndex, 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
- adding the internal field before Wrap(), but only when the
- client mis-uses the internal fields.
- */
- ;
- }
- catch(std::exception const &ex)
- {
- WeakWrap::Unwrap( self, nobj );
- if( nobj ) Factory::Delete( nobj );
- self.Clear();
- return Toss(CastToJS(ex));
- }
- catch(...)
- {
- WeakWrap::Unwrap( self, nobj );
- if( nobj ) Factory::Delete( nobj );
- self.Clear();
- return Toss("Native constructor threw an unknown exception!");
- }
- return self;
- }
-
- ClassCreator()
- : ctorTmpl(v8::Persistent<v8::FunctionTemplate>::New( v8::FunctionTemplate::New(ctor_proxy) )),
- protoTmpl(v8::Persistent<v8::ObjectTemplate>::New( ctorTmpl->PrototypeTemplate() )),
- isSealed(false)
- {
- ctorTmpl->InstanceTemplate()->SetInternalFieldCount(InternalFields::Count);
- }
- public:
- /**
- The native type being bound to JS.
- */
- typedef typename tmp::PlainType<T>::Type Type;
-
- /**
- Returns the shared instance of this class.
- */
- static ClassCreator & Instance()
- {
- static ClassCreator bob;
- return bob;
- }
-
- /**
- Returns this class' prototype object.
- */
- inline v8::Handle<v8::ObjectTemplate> Prototype()
- {
- return this->protoTmpl;
- }
-
- /**
- Returns this class' constructor template object.
- */
- inline v8::Handle<v8::FunctionTemplate> CtorTemplate()
- {
- return this->ctorTmpl;
- }
-
- /**
- Returns this class' constructor template.
-
- ACHTUNG: after this is called, changes made to the Prototype()
- object might not have any effect. Thus this should only be
- called after the prototype object has been fully set up.
- (i have no idea why v8 behaves this way.)
-
- After calling this, IsSealed() will return true.
- */
- inline v8::Handle<v8::Function> CtorFunction()
- {
- // In my experience, if GetFunction() is called BEFORE setting up
- // the Prototype object, v8 gets very unhappy (class member lookups don't work?).
- this->isSealed = true;
- return this->ctorTmpl->GetFunction();
- }
-
- /**
- Returns true if CtorFunction() has been called. See that
- function for why.
- */
- inline bool IsSealed() const
- {
- return this->isSealed;
- }
-
- /**
- Creates a new instanced of the object via the JS API. It calls
- ClassCreator_Factory<T>::Create(), passing it argv, to
- instantiate the object. On success a JS handle to the object is
- returned (it is owned by v8), and the caller can get the native
- pointer with:
-
- @code
- T * t = CastFromJS<T>(theHandle);
- @endcode
- */
- inline v8::Handle<v8::Object> NewInstance( int argc, v8::Handle<v8::Value> argv[] )
- {
- return this->CtorFunction()->NewInstance(argc, argv);
- }
-
- /**
- A convenience form of NewInstance() which returns the JS version
- of the object and assigns tgt to the native pointer (which will
- be NULL on error).
-
- If tgt is NULL when this function returns, or
- returnedObj.IsEmpty(), then we assume that a v8 exception is
- propagating, and the caller should return to v8 as soon as
- possible so the exception can be triggered JS-side (it is not
- actually triggered until we return to v8).
-
- The returned object is owned by v8.
- */
- v8::Handle<v8::Object> NewInstance( int argc, v8::Handle<v8::Value> argv[], T * & tgt )
- {
- v8::Handle<v8::Object> const & obj( this->CtorFunction()->NewInstance(argc, argv) );
- if( obj.IsEmpty() ) return obj /* assume exception is propagating. */;
- else
- {
- tgt = CastFromJS<T>(obj);
- if( !tgt ) {
- Toss(StringBuffer()<<"Internal error: NewInstance() returned a non-empty "
- << "Handle but CastFromJS<"<<TypeName<T>::Value<<">() failed. "
- << "This is either a serious cvv8 bug or the JSToNative specialization "
- << "is not working properly.");
- return v8::Handle<v8::Object>();
- }
- else return obj;
- }
- }
-
- /**
- Convenience method to add the given property to the
- prototype. Returns this object, for call chaining.
-
- CastToJS<ValueT>(val) must be valid or a compile-time
- error will be triggered.
- */
- template <typename ValueT>
- inline ClassCreator & Set( char const * name, ValueT val )
- {
- this->protoTmpl->Set(v8::String::New(name), CastToJS(val));
- return *this;
- }
- //! Not quite sure why i need this overload, but i do.
- inline ClassCreator & Set( char const * name, v8::InvocationCallback val )
- {
- this->protoTmpl->Set(v8::String::New(name), CastToJS(val));
- return *this;
- }
- /**
- Equivalent to Set().
- */
- template <typename ValueT>
- inline ClassCreator & operator()( char const * name, ValueT val )
- {
- return this->Set(name, val);
- }
- /**
- Overload to avoid an ambiguity.
- */
- inline ClassCreator & operator()( char const * name, v8::InvocationCallback val )
- {
- return this->Set(name, val);
- }
-
- /**
- Adds CtorFunction() to dest using the given property name.
- This implicitly "seals" the class (see CtorFunction() for
- details).
- */
- inline void AddClassTo( char const * thisClassName, v8::Handle<v8::Object> const & dest )
- {
- dest->Set(v8::String::New(thisClassName),
- this->CtorFunction());
- }
-
- /**
- Destroys the given object by disconnecting its associated
- native object and calling the native destructor function
- for it.
-
- If jo cannot be converted to a T then false is
- returned. Otherwise the true is returned and the native
- object referenced by jo is no longer valid (it should not
- be used by JS code).
-
- Native functions bound to that object should take care to
- bail out with an exception once the native pointer is gone,
- as opposed to blindly stepping on its null/dangling pointer
- (which _might_ have been re-allocated to a different
- object, even of a different type, in the mean time).
- */
- static bool DestroyObject( v8::Handle<v8::Object> const & jo )
- {
- T * t = CastFromJS<T>(jo);
- if( ! t ) return false;
- else
- {
- v8::Persistent<v8::Object> p( v8::Persistent<v8::Object>::New( jo ) );
- p.ClearWeak(); // avoid a second call to weak_dtor() via gc!
- weak_dtor( p, t );
- return true;
- }
- }
- /**
- If jv is empty or !jv->IsObject() then false is returned,
- otherwise it returns the result of
- DestroyObject(Handle<Object>).
- */
- static bool DestroyObject( v8::Handle<v8::Value> const & jv )
- {
- return (jv.IsEmpty() || !jv->IsObject())
- ? false
- : DestroyObject( v8::Handle<v8::Object>( v8::Object::Cast(*jv) ) );
- }
-
- /**
- A v8::InvocationCallback implementation which calls
- DestroyObject( argv.This() ).
-
- It is intended to be used as a "manual destructor" for
- classes which need it. The canonical examples are
- Stream.close() and Database.close().
-
- This function is not called DestroyObject to avoid name
- collisions during binding using Set(...,DestroyObjectCallback).
- */
- static v8::Handle<v8::Value> DestroyObjectCallback( v8::Arguments const & argv )
- {
- return DestroyObject(argv.This()) ? v8::True() : v8::False();
- }
-
- /**
- Tells v8 that this bound type inherits ParentType.
- ParentType _must_ be a class wrapped by ClassCreator.
- This function throws if
- ClassCreator<ParentType>::Instance().IsSealed() returns
- false). We require that the parent class be sealed to
- avoid accidental mis-use caused by registering a
- subclass of a class which has not yet been bound (and may
- may never be bound).
- */
- template <typename ParentType>
- void Inherit()
- {
- typedef ClassCreator<ParentType> PT;
- PT & p(PT::Instance());
- if( ! p.IsSealed() )
- {
- throw std::runtime_error("ClassCreator<ParentType> has not been sealed yet!");
- }
- this->CtorTemplate()->Inherit( p.CtorTemplate() );
- }
-
- /**
- Simply runs ClassCreator_SetupBindings<T>::Initialize( target ).
- It is provided here to simplify the client-side interface.
- */
- static void SetupBindings( v8::Handle<v8::Object> const & target )
- {
- ClassCreator_SetupBindings<T>::Initialize( target );
- }
-
- };
-
- /**
- Intended to be the base class for JSToNative<T> specializations
- when T is JS-bound using ClassCreator.
-
- This particular implementation must be defined _after_
- any of the following policies are customized for T:
-
- - ClassCreator_InternalFields
- - ClassCreator_SearchPrototypeForThis
- - ClassCreator_TypeID (only if TypeSafe is true!)
-
- If the client will not specialize those types type then the order is
- irrelevant, but when specializing any of them, they must come before
- this JSToNative implementation is instantiated.
-
- If TypeSafe is true then this type is a proxy for
- JSToNative_ObjectWithInternalFieldsTypeSafe, else it is a proxy for
- JSToNative_ObjectWithInternalFields. Note that ClassCreator is
- hard-wired to implant/deplant type id information if
- ClassCreator_InternalFields<T>::TypeIDIndex is not negative, with the
- _hope_ that JSToNative<T> will use it, but it does not enforce that
- the type ID is used. For types where the internal fields' TypeIDIndex
- is negative, ClassCreator will not set up bits for the type check,
- which means a slightly smaller runtime memory footprint.
- */
- template <typename T, bool TypeSafe = ClassCreator_InternalFields<T>::TypeIDIndex >= 0 >
- struct JSToNative_ClassCreator :
- tmp::IfElse< TypeSafe,
- JSToNative_ObjectWithInternalFieldsTypeSafe<T,
- ClassCreator_TypeID<T>::Value,
- ClassCreator_InternalFields<T>::Count,
- ClassCreator_InternalFields<T>::TypeIDIndex,
- ClassCreator_InternalFields<T>::NativeIndex,
- ClassCreator_SearchPrototypeForThis<T>::Value
- >,
- JSToNative_ObjectWithInternalFields<T,
- ClassCreator_InternalFields<T>::Count,
- ClassCreator_InternalFields<T>::NativeIndex,
- ClassCreator_SearchPrototypeForThis<T>::Value
- >
- >::Type
- {
- };
-
-#if 0
- //! Experimental.
- template <typename ParentT, typename SubT >
- struct JSToNative_ClassCreator_Subclass
- {
- typedef typename TypeInfo<SubT>::NativeHandle ResultType;
- ResultType operator()( v8::Handle<v8::Value> const & h ) const
- {
- typedef typename TypeInfo<ParentT>::NativeHandle PTP;
- PTP typeCheck; typeCheck = (ResultType)NULL
- /* If compiler errors led you here then SubT probably does not
- publicly subclass ParentT. */
- ;
- PTP p = CastFromJS<ParentT>(h);
- //std::cerr << "dyncast="<<dynamic_cast<ResultType>(p)<<"\n";
- return p ? dynamic_cast<ResultType>(p) : NULL;
- }
- };
-#endif
-
-#if !defined(DOXYGEN)
- namespace Detail
- {
- /**
- A base class for ClassCreator_Factory_CtorArityDispatcher.
- We don't really need this level of indirection, i think.
- */
- template <typename T>
- struct Factory_CtorForwarder_Base
- {
- typedef typename TypeInfo<T>::Type Type;
- typedef typename TypeInfo<T>::NativeHandle NativeHandle;
- static void Delete( NativeHandle nself )
- {
- delete nself;
- }
- protected:
- /**
- If argv.Length() >= Arity then this function ignores errmsg and
- returns true, otherwise it writes a descriptive error message
- to errmsg and return false.
- */
- static bool argv_check( v8::Arguments const & argv, int Arity )
- {
- if( argv.Length() >= Arity ) return true;
- else
- {
- StringBuffer msg;
- msg << "constructor requires " << Arity << " arguments!";
- throw std::range_error(msg.Content().c_str());
- return false;
- }
- }
- };
- }
-#endif // !DOXYGEN
-
- /**
- Can be used as a concrete ClassCreator_Factor<T>
- specialization to forward JS ctor calls directly to native
- ctors.
-
- T must be the ClassCreator'd type to construct. CtorProxy must
- be a type having this interface:
-
- @code
- TypeInfo<T>::NativeHandle Call( v8::Arguments const & );
- @endcode
-
- Normally CtorProxy would be CtorForwarder or CtorArityDispatcher,
- but any interface-compatible type will do.
-
- It must return a new object instance on success. On error it
- may return NULL and "should" throw a native exception explaining
- the problem. The exception will be caught by ClassCreator and
- transformed into a JS-side exception.
-
- If CtorProxy::Call() succeeds (returns non-NULL and does not throw)
- then NativeToJSMap<T> is used to create a native-to-JS mapping.
- To make use of this, the client should do the following:
-
- @code
- // in the cvv8 namespace:
- template <>
- struct NativeToJS<T> : NativeToJSMap<T>::NativeToJSImpl {};
- @endcode
-
- After that, CastToJS<T>( theNativeObject ) can work.
-
- The mapping is cleaned up when (if!) the object is sent through
- the JS garbage collector or the client somehow triggers its
- JS-aware destruction (e.g. via ClassCreator::DestroyObject(),
- assuming the type was wrapped using ClassCreator).
- */
- template <typename T, typename CtorProxy>
- struct ClassCreator_Factory_NativeToJSMap : Detail::Factory_CtorForwarder_Base<T>
- {
- public:
- typedef NativeToJSMap<T> N2JMap;
- typedef typename TypeInfo<T>::Type Type;
- typedef typename TypeInfo<T>::NativeHandle NativeHandle;
-
- /**
- If CtorProxy::Call(argv) succeeds, N2JMap::Insert(jself, theNative)
- is called. The result of CtorProxy::Call() is returned.
- */
- static NativeHandle Create( v8::Persistent<v8::Object> jself, v8::Arguments const & argv )
- {
- NativeHandle n = CtorProxy::Call( argv );
- if( n ) N2JMap::Insert( jself, n );
- return n;
- }
- /**
- Calls N2JMap::Remove( nself ) then (delete nself).
- */
- static void Delete( NativeHandle nself )
- {
- N2JMap::Remove( nself );
- delete nself;
- }
- };
-
- /** @deprecated Use ClassCreator_Factory_Dispatcher instead (same interface).
- */
- template <typename T,typename CtorForwarderList>
- struct ClassCreator_Factory_CtorArityDispatcher : Detail::Factory_CtorForwarder_Base<T>
- {
- public:
- typedef typename TypeInfo<T>::Type Type;
- typedef typename TypeInfo<T>::NativeHandle NativeHandle;
- static NativeHandle Create( v8::Persistent<v8::Object> , v8::Arguments const & argv )
- {
- typedef CtorArityDispatcher<CtorForwarderList> Proxy;
- return Proxy::Call( argv );
- }
- };
-
- /**
- A ClassCreator_Factory implementation which forwards its Create()
- member to CtorT::Call() (the interface used by CtorForwarder and friends).
-
- T must (or is assumed to) be a ClassCreator<T>-wrapped class.
- CtorForwarderList must be a Signature typelist of CtorForwarder
- types and its "return type" must be T (optionally pointer-qualified).
-
- Example:
-
- @code
- typedef CtorForwarder<MyType *()> C0;
- typedef CtorForwarder<MyType *(int)> C1;
- typedef CtorForwarder<MyType *(int, double)> C2;
- typedef Signature< CFT (C0, C1, C2) > CtorList;
-
- // Then create Factory specialization based on those:
- template <>
- struct ClassCreator_Factory<MyType> :
- ClassCreator_Factory_Dispatcher<MyType, CtorArityDispatcher<CtorList> > {};
- @endcode
-
- Or:
-
- @code
- template <>
- struct ClassCreator_Factory<MyType> :
- ClassCreator_Factory_Dispatcher< MyType, CtorForwarder<MyType *()> >
- {};
- @endcode
- */
- template <typename T,typename CtorT>
- struct ClassCreator_Factory_Dispatcher : Detail::Factory_CtorForwarder_Base<T>
- {
- public:
- typedef typename TypeInfo<T>::Type Type;
- typedef typename TypeInfo<T>::NativeHandle NativeHandle;
- static NativeHandle Create( v8::Persistent<v8::Object> jself, v8::Arguments const & argv )
- {
- return CtorT::Call( argv );
- }
- };
-
-
-}// namespaces
-
-#endif /* CODE_GOOGLE_COM_P_V8_CONVERT_CLASS_CREATOR_HPP_INCLUDED */
View
8 vendor/libv8-convert/cvv8/Makefile
@@ -1,8 +0,0 @@
-all:
-
-EXAMPLE_DIR := ../../examples
-ifneq (,$(wildcard $(EXAMPLE_DIR)/Makefile))
-$(sort all $(MAKECMDGOALS)):
- $(MAKE) -C ../../examples $@
-endif
-
View
183 vendor/libv8-convert/cvv8/NativeToJSMap.hpp
@@ -1,183 +0,0 @@
-#if ! defined(V8_CONVERT_NATIVE_JS_MAPPER_HPP_INCLUDED)
-#define V8_CONVERT_NATIVE_JS_MAPPER_HPP_INCLUDED
-
-#include "detail/convert_core.hpp"
-namespace cvv8 {
- /**
- A helper class to assist in the "two-way-binding" of
- natives to JS objects. This class holds native-to-JS
- binding information.
-
- In the general case, a native-to-JS conversion is only
- needed at the framework-level if bound/converted
- functions/methods will _return_ bound native
- pointers/references. If they only return "core" types (numbers
- and strings, basically), or explicitly return v8-supported
- types (e.g. v8::Handle<v8::Value>) then no native-to-JS
- conversion is typically needed.
-
- Known limitations:
-
- This type does not fully support subclass conversions.
- e.g. the following function binding:
-
- @code
- virtual MyType * (MyType::*)();
- @endcode
-
- _should_ be able to return a MySubType from derived implementations
- but it currently cannot. Handling this requires that a parent class
- be told each of its subclasses, and that we add internal handlers
- which try lookups on those classes if a conversion to MyType fails.
-
- Reminder to self: the v8::juice tree has an example of that which we
- can probably plunder.
- */
- template <typename T>
- struct NativeToJSMap
- {
- private:
- typedef TypeInfo<T> TI;
- typedef typename TI::Type Type;
- /**
- The native type to bind to.
- */
- typedef typename TI::NativeHandle NativeHandle;
- /** The type for holding the JS 'this' object. */
- typedef v8::Persistent<v8::Object> JSObjHandle;
- //typedef v8::Handle<v8::Object> JSObjHandle; // Hmmm.
- typedef std::pair<NativeHandle,JSObjHandle> ObjBindT;
- typedef std::map<void const *, ObjBindT> OneOfUsT;
- /** Maps (void const *) to ObjBindT.
-
- Reminder to self: we might need to make this map a static
- non-function member to work around linking problems (at
- least on Windows) which lead to multiple instances of
- the returned map being created when the types being
- bound are loaded from multiple DLLs. The out-of-class
- initialization of the member is going to require a really
- ugly set of template parameters, though.
- */
- static OneOfUsT & Map()
- {
- static OneOfUsT bob;
- return bob;
- }
- public:
- /** Maps obj as a lookup key for jself. Returns false if !obj,
- else true. */
- static bool Insert( JSObjHandle const & jself,
- NativeHandle obj )
- {
- return obj
- ? (Map().insert( std::make_pair( obj, std::make_pair( obj, jself ) ) ),true)
- : 0;
- }
-
- /**
- Removes any mapping of the given key. Returns the
- mapped native, or 0 if none is found.
- */
- static NativeHandle Remove( void const * key )
- {
- typedef typename OneOfUsT::iterator Iterator;
- OneOfUsT & map( Map() );
- Iterator it = map.find( key );
- if( map.end() == it )
- {
- return 0;
- }
- else
- {
- NativeHandle victim = (*it).second.first;
- map.erase(it);
- return victim;
- }
- }
-
- /**
- Returns the native associated (via Insert())
- with key, or 0 if none is found.
- */
- static NativeHandle GetNative( void const * key )
- {
- if( ! key ) return 0;
- else
- {
- typename OneOfUsT::iterator it = Map().find(key);
- return (Map().end() == it)
- ? 0
- : (*it).second.first;
- }
- }
-
- /**
- Returns the JS object associated with key, or
- an empty handle if !key or no object is found.
- */
- static v8::Handle<v8::Object> GetJSObject( void const * key )
- {
- if( ! key ) return v8::Handle<v8::Object>();
- typename OneOfUsT::const_iterator it = Map().find(key);
- if( Map().end() == it ) return v8::Handle<v8::Object>();
- else return (*it).second.second;
- }
-
- /**
- A base NativeToJS<T> implementation for classes which use NativeToJSMap<T>
- to hold their native-to-JS bindings. To be used like this:
-
- @code
- // must be in the v8::convert namespace!
- template <>
- struct NativeToJS<MyType> : NativeToJSMap<MyType>::NativeToJSImpl {};
- @endcode
- */
- struct NativeToJSImpl
- {
- v8::Handle<v8::Value> operator()( Type const * n ) const
- {
- typedef NativeToJSMap<T> BM;
- v8::Handle<v8::Value> const & rc( BM::GetJSObject(n) );
- if( rc.IsEmpty() ) return v8::Null();
- else return rc;
- }
- v8::Handle<v8::Value> operator()( Type const & n ) const
- {
- return this->operator()( &n );
- }
- };
-
-#if 0
- //! Experimental
- template <typename ParentType>
- struct NativeToJSImpl_Subclass
- {
- v8::Handle<v8::Value> operator()( Type const * n ) const
- {
- typedef NativeToJSMap<T> BM;
- v8::Handle<v8::Value> const & rc( BM::GetJSObject(n) );
- if( rc.IsEmpty() )
- {
- typedef typename NativeToJSMap<ParentType>::NativeToJSImpl PI;
- return PI()(n);
-#if 0
- typedef typename TypeInfo<ParentType>::NativeHandle PH;
- rc = CastToJS<ParentType>(n);
- if( rc.IsEmpty() ) return v8::Null();
- else return rc;
-#endif
- }
- else return rc;
- }
- v8::Handle<v8::Value> operator()( Type const & n ) const
- {
- return this->operator()( &n );
- }
- };
-#endif
- };
-
-} // namespaces
-
-#endif /* include guard */
View
650 vendor/libv8-convert/cvv8/V8Shell.hpp
@@ -1,650 +0,0 @@
-#if !defined(V8_CONVERT_V8Shell_HPP_INCLUDED)
-#define V8_CONVERT_V8Shell_HPP_INCLUDED
-/** @file V8Shell.hpp
-
- This file contains the v8::convert::V8Shell class, a convenience
- wrapper for bootstrapping integration of v8 into arbitrary
- client applications.
-
- Dependencies: v8 and the STL.
-
- License: released into the Public Domain by its author,
- Stephan Beal (http://wanderinghorse.net/home/stephan/).
-*/
-#include <cstdio>
-#include <string>
-#include <vector>
-#include <iostream>
-#include <sstream>
-#include <algorithm>
-#include <iterator>
-#include <fstream>
-
-#include <v8.h>
-
-namespace cvv8 {
- namespace Detail {
- template <bool UseLocker>
- struct V8MaybeLocker
- {
- private:
- v8::Locker lock;
- public:
- V8MaybeLocker() : lock() {}
- };
- template <>
- struct V8MaybeLocker<false>
- {
- };
- }
- /**
- This class implements a very basic shell for v8.
-
-
- These objects are basically thin wrappers around the
- bootstrap code necessary for getting v8 running in an
- application. They are intended to be stack-created in main()
- (or equivalent) and used as a front-end for passing JS code
- into v8 for execution.
-
- Because library-level JS code activated via this class
- _might_ use v8::Unlocker to unlock the VM while C-level
- routines are running, each instance of this class includes a
- v8::Locker instance if UseLocker is true. (If it did not,
- clients would be required to add one or accept crashes when
- called code uses v8::Unlocker.) Only set UseLocker to false
- if you _know_ that _no_ JS code run through this API will
- end up trying to unlock v8. (If you're using this class
- together with the v8::convert function binding API then you
- are almost certainly using v8::Unlocker without realizing it.)
-
- Maintenance reminder: keep this class free of dependencies
- on other library-level code so that we can re-use it
- in arbitrary v8 clients.
-
- FIXME: the way this class uses v8::TryCatch is "all wrong", and any
- functions using it need to be revisited.
- */
- template <bool UseLocker = true>
- class V8Shell
- {
- public:
- /**
- A callback function signature for reporing JS-side
- exception messages to the native world.
-
- TODO: consider passing a v8::Handle<v8::Value> argument
- instead of a (char const *) and possibly a (void *) State
- handle for use by the client.
- */
- typedef void (*ErrorMessageReporter)( char const * msg );
- private:
- // The declaration order of the v8-related objects is important!
- Detail::V8MaybeLocker<UseLocker> locker;
- v8::HandleScope hscope;
- //v8::Handle<v8::ObjectTemplate> globt;
- v8::Handle<v8::Context> context;
- v8::Context::Scope cxscope;
- v8::Handle<v8::Object> global;
- /**
- tryCatch is only here until i can track down a post-main()
- v8 assertion which happens when V8Shell-executed JS code
- exits with an exception. It is just a workaround.
- */
- v8::TryCatch tryCatch;
- ErrorMessageReporter reporter;
- static void DefaultErrorMessageReporter( char const * msg )
- {
- if( msg && *msg ) std::cerr
- //<< "[V8Shell default exception reporter says:]\n"
- << msg << std::endl;
- }
-
- /**
- An v8::InvocationCallback implementation which implements a
- JS-conventional print() routine. OS must be a pointer to
- an ostream, e.g. std::cout or std::cerr.
-
- Each argument is converted to a string (using
- v8::String::Utf8Value) and is output, separated by a
- space. For compatibility with other toolkits' print()
- implementations (some of which only accept one
- argument), it is recommended that client script code
- only rely on the first argument being output.
-
- Always returns v8::Undefined().
-
- It is a little-known fact that one can replace the output
- buffer used by std::cout (and other std::ostreams) with a
- custom one, such that calling print() from JS code will
- redirect the output to a different destination. This can
- be used, e.g., to redirect std::cout to a libcurses window.
- */
- template <std::ostream * OS>
- static v8::Handle<v8::Value> PrintToStdOstream( v8::Arguments const & argv )
- {
- v8::HandleScope hscope;
- int const argc = argv.Length();
- const char * cstr = NULL;
- for (int i = 0; i < argc; i++)
- {
- if( 0 != i ) *OS << ' ';
- v8::String::Utf8Value const str(argv[i]);
- cstr = *str;
- if( cstr ) *OS << cstr;
- }
- *OS << '\n';
- OS->flush();
- return v8::Undefined();
- }
-
- void init( char const * globalObjectName,
- int argc, char const * const * argv,
- unsigned short argOffset )
- {
- if( globalObjectName && *globalObjectName )
- {
- this->global->Set( v8::String::New(globalObjectName), this->global );
- }
- if( (0 < argc) && (NULL != argv) )
- {
- this->ProcessMainArgv( argc, argv, argOffset );
- }
- }
-
- static void SetupTryCatch( v8::TryCatch & tc )
- {
- tc.SetVerbose(true);
- tc.SetCaptureMessage(true);
- }
- public:
- /**
- Initialize a v8 context and global object belonging to this object.
-
- If globalObjectName is not null and not empty then the global object
- is given a refernce to itself using the given name, such that client
- JS code can then refer to it.
-
- If argc is greater than 0 and argv is not NULL then argv is
- assumed to be an arguments list in the format conventional
- for main() and ProcessMainArgv(argc,argv,argOffset) is called.
- */
- V8Shell( char const * globalObjectName = NULL,
- int argc = 0, char const * const * argv = NULL,
- unsigned short argOffset = 1 ) :
- locker(),
- hscope(),
- //globt( v8::ObjectTemplate::New() ),
- context( v8::Context::New(NULL, v8::ObjectTemplate::New()) ),
- cxscope(context),
- global( context->Global() ),
- reporter( DefaultErrorMessageReporter )
- {
- this->init( globalObjectName, argc, argv, argOffset );
- }
-
- /**
- Destructs all v8 resources used by this object, e.g. the JS context.
- */
- ~V8Shell()
- {
- if( ! v8::V8::IsDead() ) {
- tryCatch.Reset();
- }
- }
-
- /**
- Sets the error reporter function used by
- ExecuteString(). Passing 0 will disable exception
- reporting. The default reporter sends its output to
- std::cerr.
- */
- void SetExecuteErrorReporter( ErrorMessageReporter r )
- {
- this->reporter = r;
- }
-
- /**
- Outputs an exception message using the current
- error reporter function.
-
- If try_catch or the current error reporter are
- null then nothing is done.
-
- @see SetExecuteErrorReporter().
- */
-
- void ReportException(v8::TryCatch* try_catch)
- {
- if( !try_catch || ! this->reporter ) return;
- v8::HandleScope hsc;
- v8::String::Utf8Value const excUtf(try_catch->Exception());
-#define TOCSTR(X) (*X ? *X : "<exception string conversion failed!>")
- const char* excCstr = TOCSTR(excUtf);
- v8::Handle<v8::Message> const & message( try_catch->Message() );
- std::ostringstream os;
- os << "V8Shell Exception Reporter: ";
- if (message.IsEmpty())
- {
- // V8 didn't provide any extra information about this error; just
- // print the exception.
- os << excCstr << '\n';
- }
- else
- {
- // output (filename):(line number): (message)...
- int linenum = message->GetLineNumber();
- os << *v8::String::Utf8Value(message->GetScriptResourceName()) << ':'
- << std::dec << linenum << ": "
- << excCstr << '\n';
- // output source code line...
- os << *v8::String::AsciiValue(message->GetSourceLine()) << '\n';
- // output decoration pointing to error location...
- int start = message->GetStartColumn();
- for (int i = 0; i < start; i++) {
- os << '-';
- }
- int end = message->GetEndColumn();
- for (int i = start; i < end; i++) {
- os << '^';
- }
- os << '\n';
- }
- std::string const & str( os.str() );
- this->reporter( str.c_str() );
-#undef TOCSTR
- }
-
- /**
- Adds the given function to the global object.
-
- Returns this object.
- */
- V8Shell & operator()( char const * name, v8::Handle<v8::Function> const & f )
- {
- this->global->Set( v8::String::New(name), f );
- return *this;
- }
-
- /**
- Adds the given function to the global object.
-
- Returns this object.
- */
- V8Shell & operator()( char const * name, v8::Handle<v8::FunctionTemplate> const & f )
- {
- return this->operator()( name, f->GetFunction() );
- }
-
- /**
- Adds the given function to the global object.
-
- Returns this object.
- */
- V8Shell & operator()( char const * name, v8::InvocationCallback const f )
- {
- return this->operator()( name, v8::FunctionTemplate::New(f) );
- }
-
- /**
- Returns the global object for this shell.
- */
- v8::Handle<v8::Object> Global()
- {
- return this->global;
- }
-
- /**
- Returns the context object for this shell.
- */
- v8::Handle<v8::Context> Context()
- {
- return this->context;
- }
-
-#if 0 // changes made to global ObjectTemplate have no effect after cx is set up.
- v8::Handle<v8::ObjectTemplate> GlobalTemplate()
- {
- return this->globt;
- }
-#endif
-
- /**
- Intended to be called from main() and passed the argc/argv
- which are passed to main. offset is the number of arguments
- to skip, and defaults to one to skip the argv[0] argument,
- which is conventionally the application name.
-
- It skips all arguments up to "--". For each argument after
- "--", it adds the argument to a list. At the end of the
- list, the global object is assigned a property named
- "arguments" which contains that list.
-
- If the argument list has no arguments after a "--" entry
- then the "arguments" global value will be an empty array,
- as opposed to null or undefined.
-
- This function does no interpretation of the arguments.
- */
- V8Shell & ProcessMainArgv( int argc, char const * const * _argv, unsigned short offset = 1 )
- {
- if( (argc<1) || !_argv ) return *this;
- char const * endofargs = "--";
- v8::Handle<v8::Array> argv( v8::Array::New() );
- int i = (int)offset;
- for( ; i < argc; ++i )
- {
- if( 0 == strcmp(_argv[i],endofargs) )
- {
- ++i;
- break;
- }
- }
- int ndx = 0;
- for( ; i < argc; ++i )
- {
- char const * arg = _argv[i];
- if( arg )
- { // String::New() calls strlen(), which hates NULL
- argv->Set( ndx++, v8::String::New(arg) );
- }
- }
- this->global->Set( v8::String::New("arguments"), argv );
- return *this;
- }
-
- /**
- Executes the given source string in the current
- context.
-
- If the script throws an exception then a TryCatch object is used
- to build an error string, which is passed to this object's error
- reporter function. The default sends the output to std::cerr.
-
- If resultGoesTo is not null and the result a valid handle, then
- the result is converted to a string and sent to that stream.
-
- Returns the result of the last expression evaluated in the script,
- or an empty handle on error.
- */
- v8::Handle<v8::Value> ExecuteString(v8::Handle<v8::String> const & source,
- v8::Handle<v8::Value> name,
- std::ostream * out = NULL )
- {
- //this->executeThrew = false;
- v8::HandleScope scope;
- v8::TryCatch tc;
- SetupTryCatch(tc);
- v8::Handle<v8::Script> script = v8::Script::Compile(source, name);
- if( script.IsEmpty())//tc.HasCaught())
- {
- // Report errors that happened during compilation.
- //this->executeThrew = true;
- this->ReportException(&tc);
- return scope.Close(tc.ReThrow());
- //return v8::Handle<v8::Value>();
- }
- else
- {
- v8::Handle<v8::Value> const & result( script->Run() );
- if( tc.HasCaught())//(result.IsEmpty())
- {
- //this->executeThrew = true;
- this->ReportException(&tc);
- //return v8::Handle<v8::Value>();
- return scope.Close(tc.ReThrow());
- }
- else
- {
- if (out && !result.IsEmpty())
- {
- (*out) << *v8::String::Utf8Value(result) << '\n';
- }
- return scope.Close(result);
- }
- }
- }
-
-#if 0
- bool ExecThrewException() const
- {
- return this->executeThrew;
- }
-#endif
-
- /**
- Convenience form of ExecuteString(source,"some default name", reportExceptions, 0).
- */
- v8::Handle<v8::Value> ExecuteString(std::string const & source,
- std::string const & name,
- std::ostream * resultGoesTo )
- {
- v8::HandleScope scope;
- v8::Local<v8::String> const & s( v8::String::New( source.c_str(), static_cast<int>(source.size()) ) );
- v8::Local<v8::String> const & n( v8::String::New( name.c_str(), static_cast<int>(name.size()) ) );
- return scope.Close(this->ExecuteString( s, n, resultGoesTo ));
- }
-
- /**
- Convenience overload taking input from a native string.
- */
- v8::Handle<v8::Value> ExecuteString(std::string const & source )
- {
- return this->ExecuteString(source, "ExecuteString()", 0);
- }
-
- /**
- Convenience form of ExecuteString(source,"some default name", 0, reportExceptions).
- */
- v8::Handle<v8::Value> ExecuteString(v8::Handle<v8::String> source )
- {
- return this->ExecuteString(source, v8::String::New("ExecuteString()"), 0);
- }
-
- /**
- Convenience form of ExecuteString() reading from an opened input stream.
-
- Throws a std::exception if reading fails or the input is empty.
-
- An empty input is not necessarily an error. Todo: re-think this decision.
- */
- v8::Handle<v8::Value> ExecuteStream( std::istream & is, std::string const & name,
- std::ostream * resultGoesTo = NULL )
- {
- std::ostringstream os;
- is >> std::noskipws;
- std::copy( std::istream_iterator<char>(is), std::istream_iterator<char>(), std::ostream_iterator<char>(os) );
- std::string const & str( os.str() );
- if( str.empty() )
- {
- std::ostringstream msg;
- msg << "Input stream ["<<name<<"] is empty.";
- //return v8::ThrowException(v8::Exception::Error(v8::String::New(msg.str().c_str())));
- std::string const & str(os.str());
- throw std::runtime_error(str.c_str());
- }
- return this->ExecuteString( str, name, resultGoesTo );
- }
-
- /**
- Convenience form of ExecuteString() reading from a local file.
- */
- v8::Handle<v8::Value> ExecuteFile( char const * filename,
- std::ostream * resultGoesTo = NULL )
- {
- if( ! filename || !*filename )
- {
- throw std::runtime_error("filename argument must not be NULL/empty.");
- }
- std::ifstream inf(filename);
- if( ! inf.good() )
- {
- // FIXME: throw a v8 exception and report it via our reporter.
- // Nevermind: the result is useless b/c the exception has no proper vm stack/state info here...
- std::ostringstream msg;
- msg << "Could not open file ["<<filename<<"].";
- std::string const & str( msg.str() );
- throw std::runtime_error( str.c_str() );
- }
- return this->ExecuteStream( inf, filename, resultGoesTo );
- }
-
- /**
- An v8::InvocationCallback implementation which implements
- a JS-conventional print() routine, sending its output to
- std::cout. See PrintToStdOstream() for the exact semantics
- argument/return.
- */
- static v8::Handle<v8::Value> PrintToCout( v8::Arguments const & argv )
- {
- return PrintToStdOstream<&std::cout>( argv );
- }
-
- /**
- Identical to PrintToCout(), but sends its output to
- std::cerr instead.
- */
- static v8::Handle<v8::Value> PrintToCerr( v8::Arguments const & argv )
- {
- return PrintToStdOstream<&std::cerr>( argv );
- }
-
- private:
- static v8::Handle<v8::Value> Include( v8::Arguments const & argv )
- {
- int const argc = argv.Length();
- if( argc < 1 ) return v8::Undefined();
- v8::HandleScope hsc;
- v8::Local<v8::Value> const jvself(argv.Data());
- if( jvself.IsEmpty() || !jvself->IsExternal() )
- {
- return v8::ThrowException(v8::Exception::Error(v8::String::New("Include() callback is missing its native V8Shell object.")));
- }
- V8Shell * self = static_cast<V8Shell *>( v8::External::Cast(*jvself)->Value() );
- v8::String::Utf8Value fn(argv[0]);
- try
- {
- return hsc.Close(self->ExecuteFile( *fn ));
- }
- catch( std::exception const & ex )
- {
- char const * msg = ex.what();
- return v8::ThrowException(v8::Exception::Error(v8::String::New(msg ? msg : "Unspecified native exception.")));
- }
- }
-
- public:
- /**
- Returns a Function object implementing conventional
- include(filename) functionality (called load() in some JS
- shells). This function must be created dynamically
- because the generated function internally refers back to
- this object (so that we can re-use ExecuteString() for the
- implementation).
-
- The return value of the Function is the value of the last
- expression evaluated in the given JS code.
-
- Results are undefined, and almost certainly fatal, if
- the generated function is ever called after this native
- object has been destructed. For best results, to avoid
- potential lifetime issues, never install the returned
- function in any object other than this object's Global().
- */
- v8::Handle<v8::Function> CreateIncludeFunction()
- {
- return v8::FunctionTemplate::New(Include, v8::External::New(this))->GetFunction();
- }
-
- /**
- Implements the v8::InvocationCallback interface and has the
- following JS interface:
-
- @code
- Array getStracktrace([unsigned int limit = some reasonable default])
- @endcode
-
- Each element in the returned array represents a stack frame and
- is a plain object with the following properties:
-
- column = 1-based column number (note that this is
- different from most editors, but this is how v8 returns
- this value).
-
- line = 1-based line number
-
- scriptName = name of the script
-
- functionName = name of the function
-
- isConstructor = true if this is a constructor call
-
- isEval = true if this is part of an eval()
-
- TODO:
-
- - Add a toString() member to the returned array which creates a
- conventional-looking stacktrace string.
- */
- static v8::Handle<v8::Value> GetStackTrace( v8::Arguments const & argv )
- {
- using namespace v8;
- int32_t limitSigned = (argv.Length() > 0) ? argv[0]->Int32Value() : 0;
- if( limitSigned <= 0 ) limitSigned = 8;
- else if( limitSigned > 100 ) limitSigned = 100;
- uint32_t limit = static_cast<uint32_t>(limitSigned);
- HandleScope hsc;
- Local<StackTrace> const st = StackTrace::CurrentStackTrace( limit, StackTrace::kDetailed );
- int const fcountI = st->GetFrameCount();
- // Who the hell designed the StackTrace API to return an int in GetFrameCount() but take
- // an unsigned int in GetFrame()???
- uint32_t const fcount = static_cast<uint32_t>(fcountI);
- Local<Array> jst = Array::New(fcount);
-#define STR(X) v8::String::New(X)
- for( uint32_t i = 0; (i < fcount) && (i<limit); ++i )
- {
- Local<StackFrame> const & sf( st->GetFrame(i) );
- Local<Object> jsf = Object::New();
- jsf->Set(STR("column"), v8::Integer::New(sf->GetColumn()));
- jsf->Set(STR("functionName"), sf->GetFunctionName());
- jsf->Set(STR("line"), v8::Integer::New(sf->GetLineNumber()));
- jsf->Set(STR("scriptName"), sf->GetScriptName());
- jsf->Set(STR("isConstructor"), sf->IsConstructor() ? v8::True() : v8::False() );
- jsf->Set(STR("isEval"), sf->IsEval() ? v8::True() : v8::False() );
- jst->Set(i,jsf);
- }
- return hsc.Close(jst);
-#undef STR
- }
-
- /**
- Can optionally be called to include the following functionality
- in this shell's Global() object:
-
- JS Functions:
-
- print(...) (see PrintToCout())
-
- getStacktrace([int limit]) (see GetStackTrace())
-
- load(filename) (see CreateIncludeFunction())
-
- Returns this object, for use in chaining.
- */
- V8Shell & SetupDefaultBindings()
- {
- (*this)( "print", PrintToCout )
- ("getStacktrace", GetStackTrace)
- ("load", this->CreateIncludeFunction())
- ;
- return *this;
- }
- };
-
- /**
- Convenience typedef for V8Shell<>.
- */
- typedef V8Shell<> Shell;
-
-}
-#endif /* V8_CONVERT_V8Shell_HPP_INCLUDED */
View
281 vendor/libv8-convert/cvv8/XTo.hpp
@@ -1,281 +0,0 @@
-#if !defined (CVV8_TO_X_HPP_INCLUDED)
-#define CVV8_TO_X_HPP_INCLUDED
-#include "invocable.hpp"
-#include "properties.hpp"
-/** @file XTo.hpp
-
- This file provides an alternate approach to the function
- conversion API. It covers:
-
- - Converting functions and methods to to v8::InvocationCallback,
- v8::AccessorGetter, and v8::AccessorSetter.
-
- - Converting variables to v8::AccessorGetter and v8::AccessorSetter.
-
- All conversions of a given category, e.g. FunctionToXYZ or MethodToXYZ
- have a common template, e.g. FunctionTo or MethodTo. The first type
- passed to that template is a "tag" type which tells us what conversion
- to perform. e.g. a function can be used as an v8::InvocationCallback,
- v8::AccessorGetter, or v8::AccessorSetter.
-
- An example probably explains it best:
-
- @code
- int aBoundInt = 3;
- void test_to_bindings()
- {
- v8::InvocationCallback cb;
- v8::AccessorGetter g;
- v8::AccessorSetter s;
-
- using namespace cvv8;
-
- typedef FunctionTo< InCa, int(char const *), ::puts> FPuts;
- typedef FunctionTo< Getter, int(void), ::getchar> GetChar;
- typedef FunctionTo< Setter, int(int), ::putchar> SetChar;
- cb = FPuts::Call;
- g = GetChar::Get;
- s = SetChar::Set;
-
- typedef VarTo< Getter, int, &aBoundInt > VarGet;
- typedef VarTo< Setter, int, &aBoundInt > VarSet;
- g = VarGet::Get;
- s = VarSet::Set;
- typedef VarTo< Accessors, int, &aBoundInt > VarGetSet;
- g = VarGetSet::Get;
- s = VarGetSet::Set;
-
- typedef BoundNative T;
- typedef MethodTo< InCa, const T, int (), &T::getInt > MemInCa;
- typedef MethodTo< Getter, const T, int (), &T::getInt > MemGet;
- typedef MethodTo< Setter, T, void (int), &T::setInt > MemSet;
- cb = MemInCa::Call;
- g = MemGet::Get;
- s = MemSet::Set;
- }
- @endcode
-
- This unconventional, but nonetheless interesting and arguably
- very readable/writable approach was first proposed by Coen
- Campman.
-*/
-
-
-namespace cvv8 {
-
- /**
- Base (unimplemented) FunctionTo interface.
-
- Specializations act as proxies for FunctionToInCa,
- FunctionToGetter and FunctionToSetter. Tag must be one of
- (InCa, InCaVoid, Getter, Setter). The other args are as
- documented for the aforementioned proxied types.
-
- See FunctionToInCa for more information about the parameters.
- */
- template <typename Tag, typename Sig, typename FunctionSignature<Sig>::FunctionType Func,
- bool UnlockV8 = SignatureIsUnlockable< FunctionSignature<Sig> >::Value >
- struct FunctionTo DOXYGEN_FWD_DECL_KLUDGE;
-
- //! Behaves like FunctionToInCa.
- template <typename Sig, typename FunctionSignature<Sig>::FunctionType Func, bool UnlockV8>
- struct FunctionTo< InCa, Sig, Func, UnlockV8 > : FunctionToInCa<Sig, Func, UnlockV8>
- {};
-
- //! Behaves like FunctionToInCaVoid.
- template <typename Sig, typename FunctionSignature<Sig>::FunctionType Func, bool UnlockV8>
- struct FunctionTo< InCaVoid, Sig, Func, UnlockV8 > : FunctionToInCaVoid<Sig, Func, UnlockV8>
- {};
-
- //! Behaves like FunctionToGetter.
- template <typename Sig, typename FunctionSignature<Sig>::FunctionType Func, bool UnlockV8>
- struct FunctionTo< Getter, Sig, Func, UnlockV8 > : FunctionToGetter<Sig,Func>
- {};
-
- //! Behaves like FunctionToSetter.
- template <typename Sig, typename FunctionSignature<Sig>::FunctionType Func, bool UnlockV8>
- struct FunctionTo< Setter, Sig, Func, UnlockV8 > : FunctionToSetter<Sig,Func>
- {};
-
- /** @class VarTo
-
- Base (unimplemented) VarTo interface.
-
- Acts as a proxy for VarToGetter and VarToSetter. Tag must be
- one of (Getter, Setter, Accessors). The other args are as
- documented for VarToGetter and VarToSetter.
- */
- template <typename Tag, typename PropertyType, PropertyType * const SharedVar>
- struct VarTo DOXYGEN_FWD_DECL_KLUDGE;
-
- //! Behaves like VarToGetter.
- template <typename PropertyType, PropertyType * const SharedVar>
- struct VarTo< Getter, PropertyType,SharedVar> : VarToGetter<PropertyType,SharedVar>
- {};
-
- //! Behaves like VarToSetter.
- template <typename PropertyType, PropertyType * const SharedVar>
- struct VarTo< Setter, PropertyType,SharedVar> : VarToSetter<PropertyType,SharedVar>
- {};
-
- //! Behaves like VarToAccessors.
- template <typename PropertyType, PropertyType * const SharedVar>
- struct VarTo< Accessors, PropertyType,SharedVar> : VarToAccessors<PropertyType,SharedVar>
- {};
-
- /**
- Base (unimplemented) type for MemberTo-xxx conversions.
-
- Acts as a proxy for MemberToGetter, MemberToSetter and
- MemberToAccessors. Tag must be one of (Getter, Setter, Accessors).
- The other args are as documented for MemberToGetter and
- MemberToSetter.
- */
- template <typename Tag, typename T, typename PropertyType, PropertyType T::*MemVar>
- struct MemberTo DOXYGEN_FWD_DECL_KLUDGE;
-
- //! Behaves like MemberToGetter.
- template <typename T, typename PropertyType, PropertyType T::*MemVar>
- struct MemberTo<Getter, T, PropertyType, MemVar > : MemberToGetter< T, PropertyType, MemVar > {};
-
- //! Behaves like MemberToSetter.
- template <typename T, typename PropertyType, PropertyType T::*MemVar>
- struct MemberTo<Setter, T, PropertyType, MemVar > : MemberToSetter< T, PropertyType, MemVar > {};
-
- //! Behaves like MemberToAccessors.
- template <typename T, typename PropertyType, PropertyType T::*MemVar>
- struct MemberTo<Accessors, T, PropertyType, MemVar > : MemberToAccessors< T, PropertyType, MemVar > {};
-
- /**
- Base (unimplemented) MethodTo interface.
-
- Acts as a proxy for MethodToInCa, MethodToGetter and
- MethodToSetter (or their const cousins if T is
- const-qualified). Tag must be one of (InCa, InCaVoid,
- Getter, Setter). The other args are as documented for the
- aforementioned proxied types.
-
- See MethodToInCa for more information about the parameters.
- */
- template <typename Tag, typename T, typename Sig, typename MethodSignature<T,Sig>::FunctionType Func,
- bool UnlockV8 = SignatureIsUnlockable< MethodSignature<T,Sig> >::Value>
- struct MethodTo DOXYGEN_FWD_DECL_KLUDGE;
-
- //! Behaves like MethodToInCa. For const methods, const-qualify T.
- template <typename T, typename Sig, typename MethodSignature<T,Sig>::FunctionType Func, bool UnlockV8>
- struct MethodTo< InCa, T, Sig, Func, UnlockV8 > : MethodToInCa<T, Sig, Func, UnlockV8>
- {};
-
- //! Behaves like MethodToInCaVoid. For const methods, const-qualify T.
- template <typename T, typename Sig, typename MethodSignature<T,Sig>::FunctionType Func, bool UnlockV8>
- struct MethodTo< InCaVoid, T, Sig, Func, UnlockV8 > : MethodToInCaVoid<T, Sig, Func, UnlockV8>
- {};
-
- //! Behaves like MethodToGetter. For const methods, const-qualify T.
- template <typename T, typename Sig, typename MethodSignature<T,Sig>::FunctionType Func, bool UnlockV8>
- struct MethodTo< Getter, T, Sig, Func, UnlockV8 > : MethodToGetter<T,Sig,Func>
- {};
-
- //! Behaves like MethodToSetter. For const methods, const-qualify T.
- template <typename T, typename Sig, typename MethodSignature<T,Sig>::FunctionType Func, bool UnlockV8>
- struct MethodTo< Setter, T, Sig, Func, UnlockV8 > : MethodToSetter<T,Sig,Func>
- {};
-
- /**
- Base (unimplemented) FunctorTo interface.
-
- Behaves like one of the following, depending on the Tag type:
-
- FunctorToInCa (Tag=InCa), FunctorToInCaVoid (Tag=InCaVoid),
- FunctorToGetter (Tag=Getter), FunctorToSetter (Tag=Setter)
-
- See FunctorToInCa for more information about the parameters.
- */
- template <typename Tag, typename FtorT, typename Sig,
- bool UnlockV8 = SignatureIsUnlockable< MethodSignature<FtorT,Sig> >::Value
- >
- struct FunctorTo DOXYGEN_FWD_DECL_KLUDGE;
-
- //! Behaves like FunctorToInCa.
- template <typename FtorT, typename Sig, bool UnlockV8>
- struct FunctorTo< InCa, FtorT, Sig, UnlockV8 > : FunctorToInCa<FtorT,Sig>
- {};
-
- //! Behaves like FunctorToInCaVoid.
- template <typename FtorT, typename Sig, bool UnlockV8>
- struct FunctorTo< InCaVoid, FtorT, Sig, UnlockV8 > : FunctorToInCaVoid<FtorT,Sig>
- {};
-
- //! Behaves like FunctorToGetter.
- template <typename FtorT, typename Sig, bool UnlockV8>
- struct FunctorTo< Getter, FtorT, Sig, UnlockV8 > : FunctorToGetter<FtorT,Sig>
- {};
-
- //! Behaves like FunctorToSetter.
- template <typename FtorT, typename Sig, bool UnlockV8>
- struct FunctorTo< Setter, FtorT, Sig, UnlockV8 > : FunctorToSetter<FtorT,Sig>
- {};
-}
-/** LICENSE
-
- This software's source code, including accompanying documentation and
- demonstration applications, are licensed under the following
- conditions...
-
- The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/])
- explicitly disclaims copyright in all jurisdictions which recognize
- such a disclaimer. In such jurisdictions, this software is released
- into the Public Domain.
-
- In jurisdictions which do not recognize Public Domain property
- (e.g. Germany as of 2011), this software is Copyright (c) 2011
- by Stephan G. Beal, and is released under the terms of the MIT License
- (see below).
-
- In jurisdictions which recognize Public Domain property, the user of
- this software may choose to accept it either as 1) Public Domain, 2)
- under the conditions of the MIT License (see below), or 3) under the
- terms of dual Public Domain/MIT License conditions described here, as
- they choose.
-
- The MIT License is about as close to Public Domain as a license can
- get, and is described in clear, concise terms at:
-
- http://en.wikipedia.org/wiki/MIT_License
-