//////////////////////////////////////////////////////////////////////////////// /// @brief V8-vocbase bridge /// /// @file /// /// DISCLAIMER /// /// Copyright 2004-2013 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Dr. Frank Celler /// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #ifndef TRIAGENS_V8_V8_GLOBALS_H #define TRIAGENS_V8_V8_GLOBALS_H 1 #include "Basics/Common.h" #include #include #include "Basics/ReadWriteLock.h" // ----------------------------------------------------------------------------- // --SECTION-- public macros // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup V8VocBase /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief create a v8 symbol for the specified string //////////////////////////////////////////////////////////////////////////////// #define TRI_V8_SYMBOL(name) v8::String::NewSymbol(name, strlen(name)) //////////////////////////////////////////////////////////////////////////////// /// @brief shortcut for throwing an exception with an error code //////////////////////////////////////////////////////////////////////////////// #define TRI_V8_EXCEPTION(code) \ return scope.Close(v8::ThrowException(TRI_CreateErrorObject(code))) //////////////////////////////////////////////////////////////////////////////// /// @brief shortcut for throwing a usage exception and returning //////////////////////////////////////////////////////////////////////////////// #define TRI_V8_EXCEPTION_USAGE(usage) \ return scope.Close(v8::ThrowException(TRI_CreateErrorObject(TRI_ERROR_BAD_PARAMETER, "usage: " usage))) //////////////////////////////////////////////////////////////////////////////// /// @brief shortcut for throwing an exception and returning //////////////////////////////////////////////////////////////////////////////// #define TRI_V8_EXCEPTION_MESSAGE(code, message) \ return scope.Close(v8::ThrowException(TRI_CreateErrorObject(code, message))) //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public types // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup V8Globals /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief globals stored in the isolate //////////////////////////////////////////////////////////////////////////////// typedef struct TRI_v8_global_s { //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// TRI_v8_global_s () : JSBarriers(), ErrorTempl(), GeneralCursorTempl(), TransactionTempl(), VocbaseColTempl(), VocbaseTempl(), DictionaryTempl(), DidKey(), FromKey(), IidKey(), OldRevKey(), RevKey(), ToKey(), BodyKey(), BodyFromFileKey(), ContentTypeKey(), IsSystemKey(), IsVolatileKey(), JournalSizeKey(), KeyOptionsKey(), ParametersKey(), PathKey(), PrefixKey(), ResponseCodeKey(), SuffixKey(), UrlKey(), UserKey(), WaitForSyncKey(), DocumentIdRegex(), DocumentKeyRegex(), IndexIdRegex(), IdRegex(), _currentTransaction(), _vocbase(0) { } ~TRI_v8_global_s () { regfree(&DocumentIdRegex); regfree(&DocumentKeyRegex); regfree(&IndexIdRegex); regfree(&IdRegex); } //////////////////////////////////////////////////////////////////////////////// /// @brief barrier mapping for weak pointers //////////////////////////////////////////////////////////////////////////////// std::map< void*, v8::Persistent > JSBarriers; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- JAVASCRIPT OBJECT TEMPLATES // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup V8Globals /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief error template //////////////////////////////////////////////////////////////////////////////// v8::Persistent ErrorTempl; //////////////////////////////////////////////////////////////////////////////// /// @brief general cursor template //////////////////////////////////////////////////////////////////////////////// v8::Persistent GeneralCursorTempl; //////////////////////////////////////////////////////////////////////////////// /// @brief transaction template //////////////////////////////////////////////////////////////////////////////// v8::Persistent TransactionTempl; //////////////////////////////////////////////////////////////////////////////// /// @brief TRI_vocbase_col_t template //////////////////////////////////////////////////////////////////////////////// v8::Persistent VocbaseColTempl; //////////////////////////////////////////////////////////////////////////////// /// @brief TRI_vocbase_t template //////////////////////////////////////////////////////////////////////////////// v8::Persistent VocbaseTempl; //////////////////////////////////////////////////////////////////////////////// /// @brief TRI_shaped_json_t template //////////////////////////////////////////////////////////////////////////////// v8::Persistent ShapedJsonTempl; //////////////////////////////////////////////////////////////////////////////// /// @brief dictionary template //////////////////////////////////////////////////////////////////////////////// v8::Persistent DictionaryTempl; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- JAVASCRIPT CONSTANTS // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup V8Globals /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief "DELETE" function name //////////////////////////////////////////////////////////////////////////////// v8::Persistent DeleteConstant; //////////////////////////////////////////////////////////////////////////////// /// @brief "GET" function name //////////////////////////////////////////////////////////////////////////////// v8::Persistent GetConstant; //////////////////////////////////////////////////////////////////////////////// /// @brief "HEAD" function name //////////////////////////////////////////////////////////////////////////////// v8::Persistent HeadConstant; //////////////////////////////////////////////////////////////////////////////// /// @brief "OPTIONS" function name //////////////////////////////////////////////////////////////////////////////// v8::Persistent OptionsConstant; //////////////////////////////////////////////////////////////////////////////// /// @brief "PATCH" function name //////////////////////////////////////////////////////////////////////////////// v8::Persistent PatchConstant; //////////////////////////////////////////////////////////////////////////////// /// @brief "POST" function name //////////////////////////////////////////////////////////////////////////////// v8::Persistent PostConstant; //////////////////////////////////////////////////////////////////////////////// /// @brief "PUT" function name //////////////////////////////////////////////////////////////////////////////// v8::Persistent PutConstant; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- JAVASCRIPT KEY NAMES // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup V8Globals /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief "_id" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent DidKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "_key" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent KeyKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "_from" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent FromKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "id" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent IidKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "_oldRev" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent OldRevKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "_rev" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent RevKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "_to" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent ToKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "body" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent BodyKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "bodyFromFile" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent BodyFromFileKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "contentType" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent ContentTypeKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "headers" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent HeadersKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "isSystem" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent IsSystemKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "isVolatile" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent IsVolatileKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "journalSize" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent JournalSizeKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "keyOptions" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent KeyOptionsKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "parameters" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent ParametersKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "path" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent PathKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "prefix" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent PrefixKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "requestBody" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent RequestBodyKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "requestType" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent RequestTypeKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "responseCode" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent ResponseCodeKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "suffix" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent SuffixKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "transformations" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent TransformationsKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "url" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent UrlKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "user" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent UserKey; //////////////////////////////////////////////////////////////////////////////// /// @brief "waitForSync" key name //////////////////////////////////////////////////////////////////////////////// v8::Persistent WaitForSyncKey; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- REGULAR EXPRESSIONS // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup V8Globals /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief document identifier as collection name/key //////////////////////////////////////////////////////////////////////////////// regex_t DocumentIdRegex; //////////////////////////////////////////////////////////////////////////////// /// @brief document identifier //////////////////////////////////////////////////////////////////////////////// regex_t DocumentKeyRegex; //////////////////////////////////////////////////////////////////////////////// /// @brief index identifier as collection-name:index-id //////////////////////////////////////////////////////////////////////////////// regex_t IndexIdRegex; //////////////////////////////////////////////////////////////////////////////// /// @brief numeric id, used for index ids //////////////////////////////////////////////////////////////////////////////// regex_t IdRegex; //////////////////////////////////////////////////////////////////////////////// /// @brief currently running transaction //////////////////////////////////////////////////////////////////////////////// void* _currentTransaction; //////////////////////////////////////////////////////////////////////////////// /// @brief pointer to the vocbase (TRI_vocbase_t*) //////////////////////////////////////////////////////////////////////////////// void* _vocbase; } TRI_v8_global_t; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- GLOBAL FUNCTIONS // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup V8Globals /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief adds a method to a prototype object //////////////////////////////////////////////////////////////////////////////// void TRI_AddProtoMethodVocbase (v8::Handle tpl, const char* const name, v8::Handle(*func)(v8::Arguments const&), const bool isHidden = false); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a method to an object //////////////////////////////////////////////////////////////////////////////// void TRI_AddMethodVocbase (v8::Handle tpl, const char* const name, v8::Handle(*func)(v8::Arguments const&), const bool isHidden = false); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a global function to the given context //////////////////////////////////////////////////////////////////////////////// void TRI_AddGlobalFunctionVocbase (v8::Handle context, const char* const name, v8::Handle(*func)(v8::Arguments const&)); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a global function to the given context //////////////////////////////////////////////////////////////////////////////// void TRI_AddGlobalFunctionVocbase (v8::Handle context, const char* const name, v8::Handle func); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a global variable to the given context //////////////////////////////////////////////////////////////////////////////// void TRI_AddGlobalVariableVocbase (v8::Handle context, const char* const name, v8::Handle value); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: outline-minor // outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}" // End: