00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00038 #ifndef V8_H_
00039 #define V8_H_
00040
00041 #include <stdio.h>
00042
00043 #ifdef _WIN32
00044 typedef int int32_t;
00045 typedef unsigned int uint32_t;
00046 typedef unsigned short uint16_t;
00047 typedef long long int64_t;
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
00059 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
00060 build configuration to ensure that at most one of these is set
00061 #endif
00062
00063 #ifdef BUILDING_V8_SHARED
00064 #define EXPORT __declspec(dllexport)
00065 #define EXPORT_INLINE __declspec(dllexport)
00066 #elif USING_V8_SHARED
00067 #define EXPORT __declspec(dllimport)
00068 #define EXPORT_INLINE
00069 #else
00070 #define EXPORT
00071 #define EXPORT_INLINE
00072 #endif // BUILDING_V8_SHARED
00073
00074 #else // _WIN32
00075
00076 #include <stdint.h>
00077
00078
00079
00080
00081
00082 #if defined(__GNUC__) && (__GNUC__ >= 4)
00083 #define EXPORT __attribute__ ((visibility("default")))
00084 #define EXPORT_INLINE __attribute__ ((visibility("default")))
00085 #else // defined(__GNUC__) && (__GNUC__ >= 4)
00086 #define EXPORT
00087 #define EXPORT_INLINE
00088 #endif // defined(__GNUC__) && (__GNUC__ >= 4)
00089
00090 #endif // _WIN32
00091
00095 namespace v8 {
00096
00097 class Context;
00098 class String;
00099 class Value;
00100 class Utils;
00101 class Number;
00102 class Object;
00103 class Array;
00104 class Int32;
00105 class Uint32;
00106 class External;
00107 class Primitive;
00108 class Boolean;
00109 class Integer;
00110 class Function;
00111 class Date;
00112 class ImplementationUtilities;
00113 class Signature;
00114 template <class T> class Handle;
00115 template <class T> class Local;
00116 template <class T> class Persistent;
00117 class FunctionTemplate;
00118 class ObjectTemplate;
00119 class Data;
00120
00121
00122
00123
00124
00131 typedef void (*WeakReferenceCallback)(Persistent<Value> object,
00132 void* parameter);
00133
00134
00135
00136
00137 #define TYPE_CHECK(T, S) \
00138 while (false) { \
00139 *(static_cast<T**>(0)) = static_cast<S*>(0); \
00140 }
00141
00167 template <class T> class EXPORT_INLINE Handle {
00168 public:
00169
00173 Handle();
00174
00178 explicit Handle(T* val) : val_(val) { }
00179
00190 template <class S> inline Handle(Handle<S> that)
00191 : val_(reinterpret_cast<T*>(*that)) {
00197 TYPE_CHECK(T, S);
00198 }
00199
00203 bool IsEmpty() { return val_ == 0; }
00204
00205 T* operator->();
00206
00207 T* operator*();
00208
00212 void Clear() { this->val_ = 0; }
00213
00220 template <class S> bool operator==(Handle<S> that) {
00221 void** a = reinterpret_cast<void**>(**this);
00222 void** b = reinterpret_cast<void**>(*that);
00223 if (a == 0) return b == 0;
00224 if (b == 0) return false;
00225 return *a == *b;
00226 }
00227
00234 template <class S> bool operator!=(Handle<S> that) {
00235 return !operator==(that);
00236 }
00237
00238 template <class S> static inline Handle<T> Cast(Handle<S> that) {
00239 if (that.IsEmpty()) return Handle<T>();
00240 return Handle<T>(T::Cast(*that));
00241 }
00242
00243 private:
00244 T* val_;
00245 };
00246
00247
00255 template <class T> class EXPORT_INLINE Local : public Handle<T> {
00256 public:
00257 Local();
00258 template <class S> inline Local(Local<S> that)
00259 : Handle<T>(reinterpret_cast<T*>(*that)) {
00265 TYPE_CHECK(T, S);
00266 }
00267 template <class S> inline Local(S* that) : Handle<T>(that) { }
00268 template <class S> static inline Local<T> Cast(Local<S> that) {
00269 if (that.IsEmpty()) return Local<T>();
00270 return Local<T>(T::Cast(*that));
00271 }
00272
00277 static Local<T> New(Handle<T> that);
00278 };
00279
00280
00298 template <class T> class EXPORT_INLINE Persistent : public Handle<T> {
00299 public:
00300
00305 Persistent();
00306
00318 template <class S> inline Persistent(Persistent<S> that)
00319 : Handle<T>(reinterpret_cast<T*>(*that)) {
00325 TYPE_CHECK(T, S);
00326 }
00327
00328 template <class S> inline Persistent(S* that) : Handle<T>(that) { }
00329
00334 template <class S> explicit inline Persistent(Handle<S> that)
00335 : Handle<T>(*that) { }
00336
00337 template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
00338 if (that.IsEmpty()) return Persistent<T>();
00339 return Persistent<T>(T::Cast(*that));
00340 }
00341
00346 static Persistent<T> New(Handle<T> that);
00347
00354 void Dispose();
00355
00362 void MakeWeak(void* parameters, WeakReferenceCallback callback);
00363
00365 void ClearWeak();
00366
00370 bool IsNearDeath();
00371
00375 bool IsWeak();
00376
00377 private:
00378 friend class ImplementationUtilities;
00379 friend class ObjectTemplate;
00380 };
00381
00382
00397 class EXPORT HandleScope {
00398 public:
00399 HandleScope() : previous_(current_), is_closed_(false) {
00400 current_.extensions = 0;
00401 }
00402
00403 ~HandleScope() {
00404
00405
00406
00407 if (!is_closed_) RestorePreviousState();
00408 }
00409
00415 template <class T> Local<T> Close(Handle<T> value);
00416
00420 static int NumberOfHandles();
00421
00425 static void** CreateHandle(void* value);
00426
00427 private:
00428
00429
00430 HandleScope(const HandleScope&);
00431 void operator=(const HandleScope&);
00432 void* operator new(size_t size);
00433 void operator delete(void*, size_t);
00434
00435 class EXPORT Data {
00436 public:
00437 int extensions;
00438 void** next;
00439 void** limit;
00440 inline void Initialize() {
00441 extensions = -1;
00442 next = limit = NULL;
00443 }
00444 };
00445
00446 static Data current_;
00447 const Data previous_;
00448
00453 void RestorePreviousState() {
00454 if (current_.extensions > 0) DeleteExtensions();
00455 current_ = previous_;
00456 #ifdef DEBUG
00457 ZapRange(current_.next, current_.limit);
00458 #endif
00459 }
00460
00461
00462 bool is_closed_;
00463 void** RawClose(void** value);
00464
00466 static void DeleteExtensions();
00467
00468
00469 static void ZapRange(void** start, void** end);
00470
00471 friend class ImplementationUtilities;
00472 };
00473
00474
00475
00476
00477
00481 class EXPORT Data {
00482 private:
00483 Data();
00484 };
00485
00486
00493 class EXPORT ScriptData {
00494 public:
00495 virtual ~ScriptData() { }
00496 static ScriptData* PreCompile(const char* input, int length);
00497 static ScriptData* New(unsigned* data, int length);
00498
00499 virtual int Length() = 0;
00500 virtual unsigned* Data() = 0;
00501 };
00502
00503
00507 class EXPORT ScriptOrigin {
00508 public:
00509 ScriptOrigin(Handle<Value> resource_name,
00510 Handle<Integer> resource_line_offset = Handle<Integer>(),
00511 Handle<Integer> resource_column_offset = Handle<Integer>())
00512 : resource_name_(resource_name),
00513 resource_line_offset_(resource_line_offset),
00514 resource_column_offset_(resource_column_offset) { }
00515 inline Handle<Value> ResourceName() const;
00516 inline Handle<Integer> ResourceLineOffset() const;
00517 inline Handle<Integer> ResourceColumnOffset() const;
00518 private:
00519 Handle<Value> resource_name_;
00520 Handle<Integer> resource_line_offset_;
00521 Handle<Integer> resource_column_offset_;
00522 };
00523
00524
00528 class EXPORT Script {
00529 public:
00530
00536 static Local<Script> Compile(Handle<String> source,
00537 ScriptOrigin* origin = NULL,
00538 ScriptData* pre_data = NULL);
00539
00544 static Local<Script> Compile(Handle<String> source,
00545 Handle<Value> file_name);
00546
00550 Local<Value> Run();
00551 };
00552
00553
00557 class EXPORT Message {
00558 public:
00559 Local<String> Get();
00560 Local<String> GetSourceLine();
00561
00562 Handle<Value> GetScriptResourceName();
00563
00567 int GetLineNumber();
00568
00573 int GetStartPosition();
00574
00579 int GetEndPosition();
00580
00585 int GetStartColumn();
00586
00591 int GetEndColumn();
00592
00593
00594 static void PrintCurrentStackTrace(FILE* out);
00595 };
00596
00597
00598
00599
00600
00604 class EXPORT Value : public Data {
00605 public:
00606
00611 bool IsUndefined();
00612
00617 bool IsNull();
00618
00622 bool IsTrue();
00623
00627 bool IsFalse();
00628
00633 bool IsString();
00634
00638 bool IsFunction();
00639
00643 bool IsArray();
00644
00648 bool IsObject();
00649
00653 bool IsBoolean();
00654
00658 bool IsNumber();
00659
00663 bool IsExternal();
00664
00668 bool IsInt32();
00669
00673 bool IsDate();
00674
00675 Local<Boolean> ToBoolean();
00676 Local<Number> ToNumber();
00677 Local<String> ToString();
00678 Local<String> ToDetailString();
00679 Local<Object> ToObject();
00680 Local<Integer> ToInteger();
00681 Local<Uint32> ToUint32();
00682 Local<Int32> ToInt32();
00683
00688 Local<Uint32> ToArrayIndex();
00689
00690 bool BooleanValue();
00691 double NumberValue();
00692 int64_t IntegerValue();
00693 uint32_t Uint32Value();
00694 int32_t Int32Value();
00695
00697 bool Equals(Handle<Value> that);
00698 bool StrictEquals(Handle<Value> that);
00699 };
00700
00701
00705 class EXPORT Primitive : public Value { };
00706
00707
00712 class EXPORT Boolean : public Primitive {
00713 public:
00714 bool Value();
00715 static inline Handle<Boolean> New(bool value);
00716 };
00717
00718
00722 class EXPORT String : public Primitive {
00723 public:
00724
00728 int Length();
00729
00734 int Utf8Length();
00735
00753 int Write(uint16_t* buffer, int start = 0, int length = -1);
00754 int WriteAscii(char* buffer, int start = 0, int length = -1);
00755 int WriteUtf8(char* buffer, int length = -1);
00756
00760 bool IsExternal();
00761
00765 bool IsExternalAscii();
00772 class EXPORT ExternalStringResource {
00773 public:
00778 virtual ~ExternalStringResource() {}
00780 virtual const uint16_t* data() const = 0;
00782 virtual size_t length() const = 0;
00783 protected:
00784 ExternalStringResource() {}
00785 private:
00786
00787 ExternalStringResource(const ExternalStringResource&);
00788 void operator=(const ExternalStringResource&);
00789 };
00790
00802 class EXPORT ExternalAsciiStringResource {
00803 public:
00808 virtual ~ExternalAsciiStringResource() {}
00810 virtual const char* data() const = 0;
00812 virtual size_t length() const = 0;
00813 protected:
00814 ExternalAsciiStringResource() {}
00815 private:
00816
00817 ExternalAsciiStringResource(const ExternalAsciiStringResource&);
00818 void operator=(const ExternalAsciiStringResource&);
00819 };
00820
00825 ExternalStringResource* GetExternalStringResource();
00826
00831 ExternalAsciiStringResource* GetExternalAsciiStringResource();
00832
00833 static String* Cast(v8::Value* obj);
00834
00844 static Local<String> New(const char* data, int length = -1);
00845
00847 static Local<String> New(const uint16_t* data, int length = -1);
00848
00850 static Local<String> NewSymbol(const char* data, int length = -1);
00851
00860 static Local<String> NewExternal(ExternalStringResource* resource);
00861
00870 static Local<String> NewExternal(ExternalAsciiStringResource* resource);
00871
00873 static Local<String> NewUndetectable(const char* data, int length = -1);
00874
00876 static Local<String> NewUndetectable(const uint16_t* data, int length = -1);
00877
00882 class EXPORT Utf8Value {
00883 public:
00884 explicit Utf8Value(Handle<v8::Value> obj);
00885 ~Utf8Value();
00886 char* operator*() { return str_; }
00887 int length() { return length_; }
00888 private:
00889 char* str_;
00890 int length_;
00891
00892
00893 Utf8Value(const Utf8Value&);
00894 void operator=(const Utf8Value&);
00895 };
00896
00901 class EXPORT AsciiValue {
00902 public:
00903 explicit AsciiValue(Handle<v8::Value> obj);
00904 ~AsciiValue();
00905 char* operator*() { return str_; }
00906 int length() { return length_; }
00907 private:
00908 char* str_;
00909 int length_;
00910
00911
00912 AsciiValue(const AsciiValue&);
00913 void operator=(const AsciiValue&);
00914 };
00915
00919 class EXPORT Value {
00920 public:
00921 explicit Value(Handle<v8::Value> obj);
00922 ~Value();
00923 uint16_t* operator*() { return str_; }
00924 int length() { return length_; }
00925 private:
00926 uint16_t* str_;
00927 int length_;
00928
00929
00930 Value(const Value&);
00931 void operator=(const Value&);
00932 };
00933 };
00934
00935
00939 class EXPORT Number : public Primitive {
00940 public:
00941 double Value();
00942 static Local<Number> New(double value);
00943 static Number* Cast(v8::Value* obj);
00944 private:
00945 Number();
00946 };
00947
00948
00952 class EXPORT Integer : public Number {
00953 public:
00954 static Local<Integer> New(int32_t value);
00955 int64_t Value();
00956 static Integer* Cast(v8::Value* obj);
00957 private:
00958 Integer();
00959 };
00960
00961
00965 class EXPORT Int32 : public Integer {
00966 public:
00967 int32_t Value();
00968 private:
00969 Int32();
00970 };
00971
00972
00976 class EXPORT Uint32 : public Integer {
00977 public:
00978 uint32_t Value();
00979 private:
00980 Uint32();
00981 };
00982
00983
00987 class EXPORT Date : public Value {
00988 public:
00989 static Local<Value> New(double time);
00990
00995 double NumberValue();
00996
00997 static Date* Cast(v8::Value* obj);
00998 };
00999
01000
01001 enum PropertyAttribute {
01002 None = 0,
01003 ReadOnly = 1 << 0,
01004 DontEnum = 1 << 1,
01005 DontDelete = 1 << 2
01006 };
01007
01011 class EXPORT Object : public Value {
01012 public:
01013 bool Set(Handle<Value> key,
01014 Handle<Value> value,
01015 PropertyAttribute attribs = None);
01016 Local<Value> Get(Handle<Value> key);
01017
01018
01019
01020 bool Has(Handle<String> key);
01021 bool Delete(Handle<String> key);
01022 bool Has(uint32_t index);
01023 bool Delete(uint32_t index);
01024
01031 Local<Array> GetPropertyNames();
01032
01038 Local<Value> GetPrototype();
01039
01045 Local<String> ObjectProtoToString();
01046
01048 int InternalFieldCount();
01050 Local<Value> GetInternalField(int index);
01052 void SetInternalField(int index, Handle<Value> value);
01053
01054
01055 bool HasRealNamedProperty(Handle<String> key);
01056 bool HasRealIndexedProperty(uint32_t index);
01057 bool HasRealNamedCallbackProperty(Handle<String> key);
01058
01063 Handle<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
01064
01066 bool HasNamedLookupInterceptor();
01067
01069 bool HasIndexedLookupInterceptor();
01070
01076 void TurnOnAccessCheck();
01077
01078 static Local<Object> New();
01079 static Object* Cast(Value* obj);
01080 private:
01081 Object();
01082 };
01083
01084
01088 class EXPORT Array : public Object {
01089 public:
01090 uint32_t Length();
01091
01092 static Local<Array> New(int length = 0);
01093 static Array* Cast(Value* obj);
01094 private:
01095 Array();
01096 };
01097
01098
01102 class EXPORT Function : public Object {
01103 public:
01104 Local<Object> NewInstance();
01105 Local<Object> NewInstance(int argc, Handle<Value> argv[]);
01106 Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]);
01107 void SetName(Handle<String> name);
01108 Handle<Value> GetName();
01109 static Function* Cast(Value* obj);
01110 private:
01111 Function();
01112 };
01113
01114
01120 class EXPORT External : public Value {
01121 public:
01122 static Local<External> New(void* value);
01123 static External* Cast(Value* obj);
01124 void* Value();
01125 private:
01126 External();
01127 };
01128
01129
01130
01131
01132
01136 class EXPORT Template : public Data {
01137 public:
01139 void Set(Handle<String> name, Handle<Data> value,
01140 PropertyAttribute attributes = None);
01141 inline void Set(const char* name, Handle<Data> value);
01142 private:
01143 Template();
01144
01145 friend class ObjectTemplate;
01146 friend class FunctionTemplate;
01147 };
01148
01149
01156 class EXPORT Arguments {
01157 public:
01158 inline int Length() const;
01159 inline Local<Value> operator[](int i) const;
01160 inline Local<Function> Callee() const;
01161 inline Local<Object> This() const;
01162 inline Local<Object> Holder() const;
01163 inline bool IsConstructCall() const;
01164 inline Local<Value> Data() const;
01165 private:
01166 Arguments();
01167 friend class ImplementationUtilities;
01168 inline Arguments(Local<Value> data,
01169 Local<Object> holder,
01170 Local<Function> callee,
01171 bool is_construct_call,
01172 void** values, int length);
01173 Local<Value> data_;
01174 Local<Object> holder_;
01175 Local<Function> callee_;
01176 bool is_construct_call_;
01177 void** values_;
01178 int length_;
01179 };
01180
01181
01186 class EXPORT AccessorInfo {
01187 public:
01188 inline AccessorInfo(Local<Object> self,
01189 Local<Value> data,
01190 Local<Object> holder)
01191 : self_(self), data_(data), holder_(holder) { }
01192 inline Local<Value> Data() const;
01193 inline Local<Object> This() const;
01194 inline Local<Object> Holder() const;
01195 private:
01196 Local<Object> self_;
01197 Local<Value> data_;
01198 Local<Object> holder_;
01199 };
01200
01201
01202 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
01203
01204 typedef int (*LookupCallback)(Local<Object> self, Local<String> name);
01205
01210 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
01211 const AccessorInfo& info);
01212
01213
01214 typedef void (*AccessorSetter)(Local<String> property,
01215 Local<Value> value,
01216 const AccessorInfo& info);
01217
01218
01223 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
01224 const AccessorInfo& info);
01225
01226
01231 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
01232 Local<Value> value,
01233 const AccessorInfo& info);
01234
01235
01240 typedef Handle<Boolean> (*NamedPropertyQuery)(Local<String> property,
01241 const AccessorInfo& info);
01242
01243
01249 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
01250 const AccessorInfo& info);
01251
01256 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
01257
01258
01263 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
01264 const AccessorInfo& info);
01265
01266
01271 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
01272 Local<Value> value,
01273 const AccessorInfo& info);
01274
01275
01280 typedef Handle<Boolean> (*IndexedPropertyQuery)(uint32_t index,
01281 const AccessorInfo& info);
01282
01288 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
01289 const AccessorInfo& info);
01290
01295 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
01296
01297
01305 enum AccessControl {
01306 DEFAULT = 0,
01307 ALL_CAN_READ = 1,
01308 ALL_CAN_WRITE = 2
01309 };
01310
01311
01315 enum AccessType {
01316 ACCESS_GET,
01317 ACCESS_SET,
01318 ACCESS_HAS,
01319 ACCESS_DELETE,
01320 ACCESS_KEYS
01321 };
01322
01323
01328 typedef bool (*NamedSecurityCallback)(Local<Object> global,
01329 Local<Value> key,
01330 AccessType type,
01331 Local<Value> data);
01332
01333
01338 typedef bool (*IndexedSecurityCallback)(Local<Object> global,
01339 uint32_t index,
01340 AccessType type,
01341 Local<Value> data);
01342
01343
01433 class EXPORT FunctionTemplate : public Template {
01434 public:
01436 static Local<FunctionTemplate> New(
01437 InvocationCallback callback = 0,
01438 Handle<Value> data = Handle<Value>(),
01439 Handle<Signature> signature = Handle<Signature>());
01441 Local<Function> GetFunction();
01442
01448 void SetCallHandler(InvocationCallback callback,
01449 Handle<Value> data = Handle<Value>());
01450
01452 Local<ObjectTemplate> InstanceTemplate();
01453
01455 void Inherit(Handle<FunctionTemplate> parent);
01456
01461 Local<ObjectTemplate> PrototypeTemplate();
01462
01463
01469 void SetClassName(Handle<String> name);
01470
01483 void SetHiddenPrototype(bool value);
01484
01489 bool HasInstance(Handle<Value> object);
01490
01491 private:
01492 FunctionTemplate();
01493 void AddInstancePropertyAccessor(Handle<String> name,
01494 AccessorGetter getter,
01495 AccessorSetter setter,
01496 Handle<Value> data,
01497 AccessControl settings,
01498 PropertyAttribute attributes);
01499 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
01500 NamedPropertySetter setter,
01501 NamedPropertyQuery query,
01502 NamedPropertyDeleter remover,
01503 NamedPropertyEnumerator enumerator,
01504 Handle<Value> data);
01505 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
01506 IndexedPropertySetter setter,
01507 IndexedPropertyQuery query,
01508 IndexedPropertyDeleter remover,
01509 IndexedPropertyEnumerator enumerator,
01510 Handle<Value> data);
01511 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
01512 Handle<Value> data);
01513
01514 friend class Context;
01515 friend class ObjectTemplate;
01516 };
01517
01518
01525 class EXPORT ObjectTemplate : public Template {
01526 public:
01528 static Local<ObjectTemplate> New();
01529
01531 Local<Object> NewInstance();
01532
01557 void SetAccessor(Handle<String> name,
01558 AccessorGetter getter,
01559 AccessorSetter setter = 0,
01560 Handle<Value> data = Handle<Value>(),
01561 AccessControl settings = DEFAULT,
01562 PropertyAttribute attribute = None);
01563
01580 void SetNamedPropertyHandler(NamedPropertyGetter getter,
01581 NamedPropertySetter setter = 0,
01582 NamedPropertyQuery query = 0,
01583 NamedPropertyDeleter deleter = 0,
01584 NamedPropertyEnumerator enumerator = 0,
01585 Handle<Value> data = Handle<Value>());
01586
01603 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
01604 IndexedPropertySetter setter = 0,
01605 IndexedPropertyQuery query = 0,
01606 IndexedPropertyDeleter deleter = 0,
01607 IndexedPropertyEnumerator enumerator = 0,
01608 Handle<Value> data = Handle<Value>());
01615 void SetCallAsFunctionHandler(InvocationCallback callback,
01616 Handle<Value> data = Handle<Value>());
01617
01626 void MarkAsUndetectable();
01627
01639 void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
01640 IndexedSecurityCallback indexed_handler,
01641 Handle<Value> data = Handle<Value>(),
01642 bool turned_on_by_default = true);
01643
01648 int InternalFieldCount();
01649
01654 void SetInternalFieldCount(int value);
01655
01656 private:
01657 ObjectTemplate();
01658 static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
01659 friend class FunctionTemplate;
01660 };
01661
01662
01667 class EXPORT Signature : public Data {
01668 public:
01669 static Local<Signature> New(Handle<FunctionTemplate> receiver =
01670 Handle<FunctionTemplate>(),
01671 int argc = 0,
01672 Handle<FunctionTemplate> argv[] = 0);
01673 private:
01674 Signature();
01675 };
01676
01677
01682 class EXPORT TypeSwitch : public Data {
01683 public:
01684 static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
01685 static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
01686 int match(Handle<Value> value);
01687 private:
01688 TypeSwitch();
01689 };
01690
01691
01692
01693
01694
01698 class EXPORT Extension {
01699 public:
01700 Extension(const char* name,
01701 const char* source = 0,
01702 int dep_count = 0,
01703 const char** deps = 0);
01704 virtual ~Extension() { }
01705 virtual v8::Handle<v8::FunctionTemplate>
01706 GetNativeFunction(v8::Handle<v8::String> name) {
01707 return v8::Handle<v8::FunctionTemplate>();
01708 }
01709
01710 const char* name() { return name_; }
01711 const char* source() { return source_; }
01712 int dependency_count() { return dep_count_; }
01713 const char** dependencies() { return deps_; }
01714 void set_auto_enable(bool value) { auto_enable_ = value; }
01715 bool auto_enable() { return auto_enable_; }
01716
01717 private:
01718 const char* name_;
01719 const char* source_;
01720 int dep_count_;
01721 const char** deps_;
01722 bool auto_enable_;
01723
01724
01725 Extension(const Extension&);
01726 void operator=(const Extension&);
01727 };
01728
01729
01730 void EXPORT RegisterExtension(Extension* extension);
01731
01732
01736 class EXPORT DeclareExtension {
01737 public:
01738 inline DeclareExtension(Extension* extension) {
01739 RegisterExtension(extension);
01740 }
01741 };
01742
01743
01744
01745
01746
01747 Handle<Primitive> EXPORT Undefined();
01748 Handle<Primitive> EXPORT Null();
01749 Handle<Boolean> EXPORT True();
01750 Handle<Boolean> EXPORT False();
01751
01752
01757 class EXPORT ResourceConstraints {
01758 public:
01759 ResourceConstraints();
01760 int max_young_space_size() const { return max_young_space_size_; }
01761 void set_max_young_space_size(int value) { max_young_space_size_ = value; }
01762 int max_old_space_size() const { return max_old_space_size_; }
01763 void set_max_old_space_size(int value) { max_old_space_size_ = value; }
01764 uint32_t* stack_limit() const { return stack_limit_; }
01765 void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
01766 private:
01767 int max_young_space_size_;
01768 int max_old_space_size_;
01769 uint32_t* stack_limit_;
01770 };
01771
01772
01773 bool SetResourceConstraints(ResourceConstraints* constraints);
01774
01775
01776
01777
01778
01779 typedef void (*FatalErrorCallback)(const char* location, const char* message);
01780
01781
01782 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
01783
01784
01791 Handle<Value> EXPORT ThrowException(Handle<Value> exception);
01792
01797 class EXPORT Exception {
01798 public:
01799 static Local<Value> RangeError(Handle<String> message);
01800 static Local<Value> ReferenceError(Handle<String> message);
01801 static Local<Value> SyntaxError(Handle<String> message);
01802 static Local<Value> TypeError(Handle<String> message);
01803 static Local<Value> Error(Handle<String> message);
01804 };
01805
01806
01807
01808
01809 typedef int* (*CounterLookupCallback)(const wchar_t* name);
01810
01811
01812 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
01813 AccessType type,
01814 Local<Value> data);
01815
01816
01817
01825 typedef void (*GCCallback)();
01826
01827
01828
01829
01834 typedef Persistent<Context> (*ContextGenerator)();
01835
01836
01840 class EXPORT V8 {
01841 public:
01843 static void SetFatalErrorHandler(FatalErrorCallback that);
01844
01857 static void IgnoreOutOfMemoryException();
01858
01863 static bool IsDead();
01864
01871 static bool AddMessageListener(MessageCallback that,
01872 Handle<Value> data = Handle<Value>());
01873
01877 static void RemoveMessageListeners(MessageCallback that);
01878
01882 static void SetFlagsFromString(const char* str, int length);
01883
01887 static void SetFlagsFromCommandLine(int* argc,
01888 char** argv,
01889 bool remove_flags);
01890
01892 static const char* GetVersion();
01893
01898 static void SetCounterFunction(CounterLookupCallback);
01899
01904 static void EnableSlidingStateWindow();
01905
01907 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
01908
01916 static void SetGlobalGCPrologueCallback(GCCallback);
01917
01925 static void SetGlobalGCEpilogueCallback(GCCallback);
01926
01935 static void AddObjectToGroup(void* id, Persistent<Object> obj);
01936
01941 static bool Initialize();
01942
01957 static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
01958
01959 private:
01960 V8();
01961
01962 static void** GlobalizeReference(void** handle);
01963 static void DisposeGlobal(void** global_handle);
01964 static void MakeWeak(void** global_handle, void* data, WeakReferenceCallback);
01965 static void ClearWeak(void** global_handle);
01966 static bool IsGlobalNearDeath(void** global_handle);
01967 static bool IsGlobalWeak(void** global_handle);
01968
01969 template <class T> friend class Handle;
01970 template <class T> friend class Local;
01971 template <class T> friend class Persistent;
01972 friend class Context;
01973 };
01974
01975
01979 class EXPORT TryCatch {
01980 public:
01981
01985 TryCatch();
01986
01990 ~TryCatch();
01991
01995 bool HasCaught() const;
01996
02003 Local<Value> Exception() const;
02004
02012 Local<v8::Message> Message() const;
02013
02023 void Reset();
02024
02033 void SetVerbose(bool value);
02034
02040 void SetCaptureMessage(bool value);
02041
02042 public:
02043 TryCatch* next_;
02044 void* exception_;
02045 void* message_;
02046 bool is_verbose_;
02047 bool capture_message_;
02048 };
02049
02050
02051
02052
02053
02057 class EXPORT ExtensionConfiguration {
02058 public:
02059 ExtensionConfiguration(int name_count, const char* names[])
02060 : name_count_(name_count), names_(names) { }
02061 private:
02062 friend class ImplementationUtilities;
02063 int name_count_;
02064 const char** names_;
02065 };
02066
02067
02072 class EXPORT Context {
02073 public:
02075 Local<Object> Global();
02076
02081 void DetachGlobal();
02082
02084 static Persistent<Context> New(
02085 ExtensionConfiguration* extensions = 0,
02086 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
02087 Handle<Value> global_object = Handle<Value>());
02088
02090 static Local<Context> GetEntered();
02091
02093 static Local<Context> GetCurrent();
02094
02099 void SetSecurityToken(Handle<Value> token);
02100
02102 void UseDefaultSecurityToken();
02103
02105 Handle<Value> GetSecurityToken();
02106
02113 void Enter();
02114
02119 void Exit();
02120
02122 bool HasOutOfMemoryException();
02123
02125 static bool InContext();
02126
02131 class EXPORT Scope {
02132 public:
02133 inline Scope(Handle<Context> context) : context_(context) {
02134 context_->Enter();
02135 }
02136 inline ~Scope() { context_->Exit(); }
02137 private:
02138 Handle<Context> context_;
02139 };
02140
02141 private:
02142 friend class Value;
02143 friend class Script;
02144 friend class Object;
02145 friend class Function;
02146 };
02147
02148
02217 class EXPORT Unlocker {
02218 public:
02219 Unlocker();
02220 ~Unlocker();
02221 };
02222
02223
02224 class EXPORT Locker {
02225 public:
02226 Locker();
02227 ~Locker();
02228
02236 static void StartPreemption(int every_n_ms);
02237
02241 static void StopPreemption();
02242
02246 static bool IsLocked();
02247
02248 private:
02249 bool has_lock_;
02250 bool top_level_;
02251
02252
02253 Locker(const Locker&);
02254 void operator=(const Locker&);
02255 };
02256
02257
02258
02259
02260
02261 template <class T>
02262 Handle<T>::Handle() : val_(0) { }
02263
02264
02265 template <class T>
02266 Local<T>::Local() : Handle<T>() { }
02267
02268
02269 template <class T>
02270 Local<T> Local<T>::New(Handle<T> that) {
02271 if (that.IsEmpty()) return Local<T>();
02272 void** p = reinterpret_cast<void**>(*that);
02273 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
02274 }
02275
02276
02277 template <class T>
02278 Persistent<T> Persistent<T>::New(Handle<T> that) {
02279 if (that.IsEmpty()) return Persistent<T>();
02280 void** p = reinterpret_cast<void**>(*that);
02281 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
02282 }
02283
02284
02285 template <class T>
02286 bool Persistent<T>::IsNearDeath() {
02287 if (this->IsEmpty()) return false;
02288 return V8::IsGlobalNearDeath(reinterpret_cast<void**>(**this));
02289 }
02290
02291
02292 template <class T>
02293 bool Persistent<T>::IsWeak() {
02294 if (this->IsEmpty()) return false;
02295 return V8::IsGlobalWeak(reinterpret_cast<void**>(**this));
02296 }
02297
02298
02299 template <class T>
02300 void Persistent<T>::Dispose() {
02301 if (this->IsEmpty()) return;
02302 V8::DisposeGlobal(reinterpret_cast<void**>(**this));
02303 }
02304
02305
02306 template <class T>
02307 Persistent<T>::Persistent() : Handle<T>() { }
02308
02309 template <class T>
02310 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
02311 V8::MakeWeak(reinterpret_cast<void**>(**this), parameters, callback);
02312 }
02313
02314 template <class T>
02315 void Persistent<T>::ClearWeak() {
02316 V8::ClearWeak(reinterpret_cast<void**>(**this));
02317 }
02318
02319 template <class T>
02320 T* Handle<T>::operator->() {
02321 return val_;
02322 }
02323
02324
02325 template <class T>
02326 T* Handle<T>::operator*() {
02327 return val_;
02328 }
02329
02330
02331 Local<Value> Arguments::operator[](int i) const {
02332 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
02333 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
02334 }
02335
02336
02337 Local<Function> Arguments::Callee() const {
02338 return callee_;
02339 }
02340
02341
02342 Local<Object> Arguments::This() const {
02343 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
02344 }
02345
02346
02347 Local<Object> Arguments::Holder() const {
02348 return holder_;
02349 }
02350
02351
02352 Local<Value> Arguments::Data() const {
02353 return data_;
02354 }
02355
02356
02357 bool Arguments::IsConstructCall() const {
02358 return is_construct_call_;
02359 }
02360
02361
02362 int Arguments::Length() const {
02363 return length_;
02364 }
02365
02366
02367 Local<Value> AccessorInfo::Data() const {
02368 return data_;
02369 }
02370
02371
02372 Local<Object> AccessorInfo::This() const {
02373 return self_;
02374 }
02375
02376
02377 Local<Object> AccessorInfo::Holder() const {
02378 return holder_;
02379 }
02380
02381
02382 template <class T>
02383 Local<T> HandleScope::Close(Handle<T> value) {
02384 void** after = RawClose(reinterpret_cast<void**>(*value));
02385 return Local<T>(reinterpret_cast<T*>(after));
02386 }
02387
02388 Handle<Value> ScriptOrigin::ResourceName() const {
02389 return resource_name_;
02390 }
02391
02392
02393 Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
02394 return resource_line_offset_;
02395 }
02396
02397
02398 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
02399 return resource_column_offset_;
02400 }
02401
02402
02403 Handle<Boolean> Boolean::New(bool value) {
02404 return value ? True() : False();
02405 }
02406
02407
02408 void Template::Set(const char* name, v8::Handle<Data> value) {
02409 Set(v8::String::New(name), value);
02410 }
02411
02412
02425 }
02426
02427
02428 #undef EXPORT
02429 #undef EXPORT_INLINE
02430 #undef TYPE_CHECK
02431
02432
02433 #endif // V8_H_