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 "v8stdint.h"
00042
00043 #ifdef _WIN32
00044
00045
00046
00047
00048
00049
00050 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
00051 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
00052 build configuration to ensure that at most one of these is set
00053 #endif
00054
00055 #ifdef BUILDING_V8_SHARED
00056 #define V8EXPORT __declspec(dllexport)
00057 #elif USING_V8_SHARED
00058 #define V8EXPORT __declspec(dllimport)
00059 #else
00060 #define V8EXPORT
00061 #endif // BUILDING_V8_SHARED
00062
00063 #else // _WIN32
00064
00065
00066
00067
00068 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
00069 #define V8EXPORT __attribute__ ((visibility("default")))
00070 #else // defined(__GNUC__) && (__GNUC__ >= 4)
00071 #define V8EXPORT
00072 #endif // defined(__GNUC__) && (__GNUC__ >= 4)
00073
00074 #endif // _WIN32
00075
00079 namespace v8 {
00080
00081 class Context;
00082 class String;
00083 class Value;
00084 class Utils;
00085 class Number;
00086 class Object;
00087 class Array;
00088 class Int32;
00089 class Uint32;
00090 class External;
00091 class Primitive;
00092 class Boolean;
00093 class Integer;
00094 class Function;
00095 class Date;
00096 class ImplementationUtilities;
00097 class Signature;
00098 template <class T> class Handle;
00099 template <class T> class Local;
00100 template <class T> class Persistent;
00101 class FunctionTemplate;
00102 class ObjectTemplate;
00103 class Data;
00104 class AccessorInfo;
00105 class StackTrace;
00106 class StackFrame;
00107
00108 namespace internal {
00109
00110 class Arguments;
00111 class Object;
00112 class Heap;
00113 class HeapObject;
00114 class Isolate;
00115 }
00116
00117
00118
00119
00120
00130 typedef void (*WeakReferenceCallback)(Persistent<Value> object,
00131 void* parameter);
00132
00133
00134
00135
00136 #define TYPE_CHECK(T, S) \
00137 while (false) { \
00138 *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \
00139 }
00140
00166 template <class T> class Handle {
00167 public:
00171 inline Handle();
00172
00176 inline explicit Handle(T* val) : val_(val) { }
00177
00188 template <class S> inline Handle(Handle<S> that)
00189 : val_(reinterpret_cast<T*>(*that)) {
00195 TYPE_CHECK(T, S);
00196 }
00197
00201 inline bool IsEmpty() const { return val_ == 0; }
00202
00203 inline T* operator->() const { return val_; }
00204
00205 inline T* operator*() const { return val_; }
00206
00210 inline void Clear() { this->val_ = 0; }
00211
00218 template <class S> inline bool operator==(Handle<S> that) const {
00219 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
00220 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
00221 if (a == 0) return b == 0;
00222 if (b == 0) return false;
00223 return *a == *b;
00224 }
00225
00232 template <class S> inline bool operator!=(Handle<S> that) const {
00233 return !operator==(that);
00234 }
00235
00236 template <class S> static inline Handle<T> Cast(Handle<S> that) {
00237 #ifdef V8_ENABLE_CHECKS
00238
00239
00240 if (that.IsEmpty()) return Handle<T>();
00241 #endif
00242 return Handle<T>(T::Cast(*that));
00243 }
00244
00245 template <class S> inline Handle<S> As() {
00246 return Handle<S>::Cast(*this);
00247 }
00248
00249 private:
00250 T* val_;
00251 };
00252
00253
00261 template <class T> class Local : public Handle<T> {
00262 public:
00263 inline Local();
00264 template <class S> inline Local(Local<S> that)
00265 : Handle<T>(reinterpret_cast<T*>(*that)) {
00271 TYPE_CHECK(T, S);
00272 }
00273 template <class S> inline Local(S* that) : Handle<T>(that) { }
00274 template <class S> static inline Local<T> Cast(Local<S> that) {
00275 #ifdef V8_ENABLE_CHECKS
00276
00277
00278 if (that.IsEmpty()) return Local<T>();
00279 #endif
00280 return Local<T>(T::Cast(*that));
00281 }
00282
00283 template <class S> inline Local<S> As() {
00284 return Local<S>::Cast(*this);
00285 }
00286
00291 inline static Local<T> New(Handle<T> that);
00292 };
00293
00294
00312 template <class T> class Persistent : public Handle<T> {
00313 public:
00318 inline Persistent();
00319
00331 template <class S> inline Persistent(Persistent<S> that)
00332 : Handle<T>(reinterpret_cast<T*>(*that)) {
00338 TYPE_CHECK(T, S);
00339 }
00340
00341 template <class S> inline Persistent(S* that) : Handle<T>(that) { }
00342
00347 template <class S> explicit inline Persistent(Handle<S> that)
00348 : Handle<T>(*that) { }
00349
00350 template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
00351 #ifdef V8_ENABLE_CHECKS
00352
00353
00354 if (that.IsEmpty()) return Persistent<T>();
00355 #endif
00356 return Persistent<T>(T::Cast(*that));
00357 }
00358
00359 template <class S> inline Persistent<S> As() {
00360 return Persistent<S>::Cast(*this);
00361 }
00362
00367 inline static Persistent<T> New(Handle<T> that);
00368
00375 inline void Dispose();
00376
00383 inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
00384
00386 inline void ClearWeak();
00387
00395 inline void MarkIndependent();
00396
00400 inline bool IsNearDeath() const;
00401
00405 inline bool IsWeak() const;
00406
00411 inline void SetWrapperClassId(uint16_t class_id);
00412
00413 private:
00414 friend class ImplementationUtilities;
00415 friend class ObjectTemplate;
00416 };
00417
00418
00433 class V8EXPORT HandleScope {
00434 public:
00435 HandleScope();
00436
00437 ~HandleScope();
00438
00443 template <class T> Local<T> Close(Handle<T> value);
00444
00448 static int NumberOfHandles();
00449
00453 static internal::Object** CreateHandle(internal::Object* value);
00454
00455 static internal::Object** CreateHandle(internal::HeapObject* value);
00456
00457 private:
00458
00459
00460 HandleScope(const HandleScope&);
00461 void operator=(const HandleScope&);
00462 void* operator new(size_t size);
00463 void operator delete(void*, size_t);
00464
00465
00466
00467 class V8EXPORT Data {
00468 public:
00469 internal::Object** next;
00470 internal::Object** limit;
00471 int level;
00472 inline void Initialize() {
00473 next = limit = NULL;
00474 level = 0;
00475 }
00476 };
00477
00478 void Leave();
00479
00480 internal::Isolate* isolate_;
00481 internal::Object** prev_next_;
00482 internal::Object** prev_limit_;
00483
00484
00485
00486 bool is_closed_;
00487 internal::Object** RawClose(internal::Object** value);
00488
00489 friend class ImplementationUtilities;
00490 };
00491
00492
00493
00494
00495
00499 class V8EXPORT Data {
00500 private:
00501 Data();
00502 };
00503
00504
00511 class V8EXPORT ScriptData {
00512 public:
00513 virtual ~ScriptData() { }
00514
00521 static ScriptData* PreCompile(const char* input, int length);
00522
00531 static ScriptData* PreCompile(Handle<String> source);
00532
00540 static ScriptData* New(const char* data, int length);
00541
00545 virtual int Length() = 0;
00546
00551 virtual const char* Data() = 0;
00552
00556 virtual bool HasError() = 0;
00557 };
00558
00559
00563 class ScriptOrigin {
00564 public:
00565 inline ScriptOrigin(
00566 Handle<Value> resource_name,
00567 Handle<Integer> resource_line_offset = Handle<Integer>(),
00568 Handle<Integer> resource_column_offset = Handle<Integer>())
00569 : resource_name_(resource_name),
00570 resource_line_offset_(resource_line_offset),
00571 resource_column_offset_(resource_column_offset) { }
00572 inline Handle<Value> ResourceName() const;
00573 inline Handle<Integer> ResourceLineOffset() const;
00574 inline Handle<Integer> ResourceColumnOffset() const;
00575 private:
00576 Handle<Value> resource_name_;
00577 Handle<Integer> resource_line_offset_;
00578 Handle<Integer> resource_column_offset_;
00579 };
00580
00581
00585 class V8EXPORT Script {
00586 public:
00602 static Local<Script> New(Handle<String> source,
00603 ScriptOrigin* origin = NULL,
00604 ScriptData* pre_data = NULL,
00605 Handle<String> script_data = Handle<String>());
00606
00617 static Local<Script> New(Handle<String> source,
00618 Handle<Value> file_name);
00619
00636 static Local<Script> Compile(Handle<String> source,
00637 ScriptOrigin* origin = NULL,
00638 ScriptData* pre_data = NULL,
00639 Handle<String> script_data = Handle<String>());
00640
00654 static Local<Script> Compile(Handle<String> source,
00655 Handle<Value> file_name,
00656 Handle<String> script_data = Handle<String>());
00657
00665 Local<Value> Run();
00666
00670 Local<Value> Id();
00671
00677 void SetData(Handle<String> data);
00678 };
00679
00680
00684 class V8EXPORT Message {
00685 public:
00686 Local<String> Get() const;
00687 Local<String> GetSourceLine() const;
00688
00693 Handle<Value> GetScriptResourceName() const;
00694
00699 Handle<Value> GetScriptData() const;
00700
00706 Handle<StackTrace> GetStackTrace() const;
00707
00711 int GetLineNumber() const;
00712
00717 int GetStartPosition() const;
00718
00723 int GetEndPosition() const;
00724
00729 int GetStartColumn() const;
00730
00735 int GetEndColumn() const;
00736
00737
00738 static void PrintCurrentStackTrace(FILE* out);
00739
00740 static const int kNoLineNumberInfo = 0;
00741 static const int kNoColumnInfo = 0;
00742 };
00743
00744
00750 class V8EXPORT StackTrace {
00751 public:
00756 enum StackTraceOptions {
00757 kLineNumber = 1,
00758 kColumnOffset = 1 << 1 | kLineNumber,
00759 kScriptName = 1 << 2,
00760 kFunctionName = 1 << 3,
00761 kIsEval = 1 << 4,
00762 kIsConstructor = 1 << 5,
00763 kScriptNameOrSourceURL = 1 << 6,
00764 kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
00765 kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
00766 };
00767
00771 Local<StackFrame> GetFrame(uint32_t index) const;
00772
00776 int GetFrameCount() const;
00777
00781 Local<Array> AsArray();
00782
00790 static Local<StackTrace> CurrentStackTrace(
00791 int frame_limit,
00792 StackTraceOptions options = kOverview);
00793 };
00794
00795
00799 class V8EXPORT StackFrame {
00800 public:
00807 int GetLineNumber() const;
00808
00816 int GetColumn() const;
00817
00822 Local<String> GetScriptName() const;
00823
00829 Local<String> GetScriptNameOrSourceURL() const;
00830
00834 Local<String> GetFunctionName() const;
00835
00840 bool IsEval() const;
00841
00846 bool IsConstructor() const;
00847 };
00848
00849
00850
00851
00852
00856 class Value : public Data {
00857 public:
00862 V8EXPORT bool IsUndefined() const;
00863
00868 V8EXPORT bool IsNull() const;
00869
00873 V8EXPORT bool IsTrue() const;
00874
00878 V8EXPORT bool IsFalse() const;
00879
00884 inline bool IsString() const;
00885
00889 V8EXPORT bool IsFunction() const;
00890
00894 V8EXPORT bool IsArray() const;
00895
00899 V8EXPORT bool IsObject() const;
00900
00904 V8EXPORT bool IsBoolean() const;
00905
00909 V8EXPORT bool IsNumber() const;
00910
00914 V8EXPORT bool IsExternal() const;
00915
00919 V8EXPORT bool IsInt32() const;
00920
00924 V8EXPORT bool IsUint32() const;
00925
00929 V8EXPORT bool IsDate() const;
00930
00934 V8EXPORT bool IsRegExp() const;
00935
00936 V8EXPORT Local<Boolean> ToBoolean() const;
00937 V8EXPORT Local<Number> ToNumber() const;
00938 V8EXPORT Local<String> ToString() const;
00939 V8EXPORT Local<String> ToDetailString() const;
00940 V8EXPORT Local<Object> ToObject() const;
00941 V8EXPORT Local<Integer> ToInteger() const;
00942 V8EXPORT Local<Uint32> ToUint32() const;
00943 V8EXPORT Local<Int32> ToInt32() const;
00944
00949 V8EXPORT Local<Uint32> ToArrayIndex() const;
00950
00951 V8EXPORT bool BooleanValue() const;
00952 V8EXPORT double NumberValue() const;
00953 V8EXPORT int64_t IntegerValue() const;
00954 V8EXPORT uint32_t Uint32Value() const;
00955 V8EXPORT int32_t Int32Value() const;
00956
00958 V8EXPORT bool Equals(Handle<Value> that) const;
00959 V8EXPORT bool StrictEquals(Handle<Value> that) const;
00960
00961 private:
00962 inline bool QuickIsString() const;
00963 V8EXPORT bool FullIsString() const;
00964 };
00965
00966
00970 class Primitive : public Value { };
00971
00972
00977 class Boolean : public Primitive {
00978 public:
00979 V8EXPORT bool Value() const;
00980 static inline Handle<Boolean> New(bool value);
00981 };
00982
00983
00987 class String : public Primitive {
00988 public:
00992 V8EXPORT int Length() const;
00993
00998 V8EXPORT int Utf8Length() const;
00999
01025 enum WriteHints {
01026 NO_HINTS = 0,
01027 HINT_MANY_WRITES_EXPECTED = 1
01028 };
01029
01030 V8EXPORT int Write(uint16_t* buffer,
01031 int start = 0,
01032 int length = -1,
01033 WriteHints hints = NO_HINTS) const;
01034 V8EXPORT int WriteAscii(char* buffer,
01035 int start = 0,
01036 int length = -1,
01037 WriteHints hints = NO_HINTS) const;
01038 V8EXPORT int WriteUtf8(char* buffer,
01039 int length = -1,
01040 int* nchars_ref = NULL,
01041 WriteHints hints = NO_HINTS) const;
01042
01046 V8EXPORT static v8::Local<v8::String> Empty();
01047
01051 V8EXPORT bool IsExternal() const;
01052
01056 V8EXPORT bool IsExternalAscii() const;
01057
01058 class V8EXPORT ExternalStringResourceBase {
01059 public:
01060 virtual ~ExternalStringResourceBase() {}
01061
01062 protected:
01063 ExternalStringResourceBase() {}
01064
01071 virtual void Dispose() { delete this; }
01072
01073 private:
01074
01075 ExternalStringResourceBase(const ExternalStringResourceBase&);
01076 void operator=(const ExternalStringResourceBase&);
01077
01078 friend class v8::internal::Heap;
01079 };
01080
01087 class V8EXPORT ExternalStringResource
01088 : public ExternalStringResourceBase {
01089 public:
01094 virtual ~ExternalStringResource() {}
01095
01099 virtual const uint16_t* data() const = 0;
01100
01104 virtual size_t length() const = 0;
01105
01106 protected:
01107 ExternalStringResource() {}
01108 };
01109
01121 class V8EXPORT ExternalAsciiStringResource
01122 : public ExternalStringResourceBase {
01123 public:
01128 virtual ~ExternalAsciiStringResource() {}
01130 virtual const char* data() const = 0;
01132 virtual size_t length() const = 0;
01133 protected:
01134 ExternalAsciiStringResource() {}
01135 };
01136
01141 inline ExternalStringResource* GetExternalStringResource() const;
01142
01147 V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
01148
01149 static inline String* Cast(v8::Value* obj);
01150
01160 V8EXPORT static Local<String> New(const char* data, int length = -1);
01161
01163 V8EXPORT static Local<String> New(const uint16_t* data, int length = -1);
01164
01166 V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1);
01167
01172 V8EXPORT static Local<String> Concat(Handle<String> left,
01173 Handle<String>right);
01174
01183 V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource);
01184
01194 V8EXPORT bool MakeExternal(ExternalStringResource* resource);
01195
01204 V8EXPORT static Local<String> NewExternal(
01205 ExternalAsciiStringResource* resource);
01206
01216 V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
01217
01221 V8EXPORT bool CanMakeExternal();
01222
01224 V8EXPORT static Local<String> NewUndetectable(const char* data,
01225 int length = -1);
01226
01228 V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
01229 int length = -1);
01230
01238 class V8EXPORT Utf8Value {
01239 public:
01240 explicit Utf8Value(Handle<v8::Value> obj);
01241 ~Utf8Value();
01242 char* operator*() { return str_; }
01243 const char* operator*() const { return str_; }
01244 int length() const { return length_; }
01245 private:
01246 char* str_;
01247 int length_;
01248
01249
01250 Utf8Value(const Utf8Value&);
01251 void operator=(const Utf8Value&);
01252 };
01253
01261 class V8EXPORT AsciiValue {
01262 public:
01263 explicit AsciiValue(Handle<v8::Value> obj);
01264 ~AsciiValue();
01265 char* operator*() { return str_; }
01266 const char* operator*() const { return str_; }
01267 int length() const { return length_; }
01268 private:
01269 char* str_;
01270 int length_;
01271
01272
01273 AsciiValue(const AsciiValue&);
01274 void operator=(const AsciiValue&);
01275 };
01276
01283 class V8EXPORT Value {
01284 public:
01285 explicit Value(Handle<v8::Value> obj);
01286 ~Value();
01287 uint16_t* operator*() { return str_; }
01288 const uint16_t* operator*() const { return str_; }
01289 int length() const { return length_; }
01290 private:
01291 uint16_t* str_;
01292 int length_;
01293
01294
01295 Value(const Value&);
01296 void operator=(const Value&);
01297 };
01298
01299 private:
01300 V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const;
01301 V8EXPORT static void CheckCast(v8::Value* obj);
01302 };
01303
01304
01308 class Number : public Primitive {
01309 public:
01310 V8EXPORT double Value() const;
01311 V8EXPORT static Local<Number> New(double value);
01312 static inline Number* Cast(v8::Value* obj);
01313 private:
01314 V8EXPORT Number();
01315 static void CheckCast(v8::Value* obj);
01316 };
01317
01318
01322 class Integer : public Number {
01323 public:
01324 V8EXPORT static Local<Integer> New(int32_t value);
01325 V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value);
01326 V8EXPORT int64_t Value() const;
01327 static inline Integer* Cast(v8::Value* obj);
01328 private:
01329 V8EXPORT Integer();
01330 V8EXPORT static void CheckCast(v8::Value* obj);
01331 };
01332
01333
01337 class Int32 : public Integer {
01338 public:
01339 V8EXPORT int32_t Value() const;
01340 private:
01341 V8EXPORT Int32();
01342 };
01343
01344
01348 class Uint32 : public Integer {
01349 public:
01350 V8EXPORT uint32_t Value() const;
01351 private:
01352 V8EXPORT Uint32();
01353 };
01354
01355
01356 enum PropertyAttribute {
01357 None = 0,
01358 ReadOnly = 1 << 0,
01359 DontEnum = 1 << 1,
01360 DontDelete = 1 << 2
01361 };
01362
01363 enum ExternalArrayType {
01364 kExternalByteArray = 1,
01365 kExternalUnsignedByteArray,
01366 kExternalShortArray,
01367 kExternalUnsignedShortArray,
01368 kExternalIntArray,
01369 kExternalUnsignedIntArray,
01370 kExternalFloatArray,
01371 kExternalDoubleArray,
01372 kExternalPixelArray
01373 };
01374
01380 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
01381 const AccessorInfo& info);
01382
01383
01384 typedef void (*AccessorSetter)(Local<String> property,
01385 Local<Value> value,
01386 const AccessorInfo& info);
01387
01388
01402 enum AccessControl {
01403 DEFAULT = 0,
01404 ALL_CAN_READ = 1,
01405 ALL_CAN_WRITE = 1 << 1,
01406 PROHIBITS_OVERWRITING = 1 << 2
01407 };
01408
01409
01413 class Object : public Value {
01414 public:
01415 V8EXPORT bool Set(Handle<Value> key,
01416 Handle<Value> value,
01417 PropertyAttribute attribs = None);
01418
01419 V8EXPORT bool Set(uint32_t index,
01420 Handle<Value> value);
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430 V8EXPORT bool ForceSet(Handle<Value> key,
01431 Handle<Value> value,
01432 PropertyAttribute attribs = None);
01433
01434 V8EXPORT Local<Value> Get(Handle<Value> key);
01435
01436 V8EXPORT Local<Value> Get(uint32_t index);
01437
01438
01439
01440 V8EXPORT bool Has(Handle<String> key);
01441
01442 V8EXPORT bool Delete(Handle<String> key);
01443
01444
01445
01446 V8EXPORT bool ForceDelete(Handle<Value> key);
01447
01448 V8EXPORT bool Has(uint32_t index);
01449
01450 V8EXPORT bool Delete(uint32_t index);
01451
01452 V8EXPORT bool SetAccessor(Handle<String> name,
01453 AccessorGetter getter,
01454 AccessorSetter setter = 0,
01455 Handle<Value> data = Handle<Value>(),
01456 AccessControl settings = DEFAULT,
01457 PropertyAttribute attribute = None);
01458
01465 V8EXPORT Local<Array> GetPropertyNames();
01466
01472 V8EXPORT Local<Array> GetOwnPropertyNames();
01473
01479 V8EXPORT Local<Value> GetPrototype();
01480
01486 V8EXPORT bool SetPrototype(Handle<Value> prototype);
01487
01492 V8EXPORT Local<Object> FindInstanceInPrototypeChain(
01493 Handle<FunctionTemplate> tmpl);
01494
01500 V8EXPORT Local<String> ObjectProtoToString();
01501
01505 V8EXPORT Local<String> GetConstructorName();
01506
01508 V8EXPORT int InternalFieldCount();
01510 inline Local<Value> GetInternalField(int index);
01512 V8EXPORT void SetInternalField(int index, Handle<Value> value);
01513
01515 inline void* GetPointerFromInternalField(int index);
01516
01518 V8EXPORT void SetPointerInInternalField(int index, void* value);
01519
01520
01521 V8EXPORT bool HasOwnProperty(Handle<String> key);
01522 V8EXPORT bool HasRealNamedProperty(Handle<String> key);
01523 V8EXPORT bool HasRealIndexedProperty(uint32_t index);
01524 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key);
01525
01530 V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain(
01531 Handle<String> key);
01532
01538 V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key);
01539
01541 V8EXPORT bool HasNamedLookupInterceptor();
01542
01544 V8EXPORT bool HasIndexedLookupInterceptor();
01545
01551 V8EXPORT void TurnOnAccessCheck();
01552
01560 V8EXPORT int GetIdentityHash();
01561
01568 V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value);
01569 V8EXPORT Local<Value> GetHiddenValue(Handle<String> key);
01570 V8EXPORT bool DeleteHiddenValue(Handle<String> key);
01571
01579 V8EXPORT bool IsDirty();
01580
01585 V8EXPORT Local<Object> Clone();
01586
01590 V8EXPORT Local<Context> CreationContext();
01591
01599 V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
01600 V8EXPORT bool HasIndexedPropertiesInPixelData();
01601 V8EXPORT uint8_t* GetIndexedPropertiesPixelData();
01602 V8EXPORT int GetIndexedPropertiesPixelDataLength();
01603
01611 V8EXPORT void SetIndexedPropertiesToExternalArrayData(
01612 void* data,
01613 ExternalArrayType array_type,
01614 int number_of_elements);
01615 V8EXPORT bool HasIndexedPropertiesInExternalArrayData();
01616 V8EXPORT void* GetIndexedPropertiesExternalArrayData();
01617 V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
01618 V8EXPORT int GetIndexedPropertiesExternalArrayDataLength();
01619
01625 V8EXPORT bool IsCallable();
01626
01631 V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv,
01632 int argc,
01633 Handle<Value> argv[]);
01634
01640 V8EXPORT Local<Value> CallAsConstructor(int argc,
01641 Handle<Value> argv[]);
01642
01643 V8EXPORT static Local<Object> New();
01644 static inline Object* Cast(Value* obj);
01645
01646 private:
01647 V8EXPORT Object();
01648 V8EXPORT static void CheckCast(Value* obj);
01649 V8EXPORT Local<Value> CheckedGetInternalField(int index);
01650 V8EXPORT void* SlowGetPointerFromInternalField(int index);
01651
01656 inline Local<Value> UncheckedGetInternalField(int index);
01657 };
01658
01659
01663 class Array : public Object {
01664 public:
01665 V8EXPORT uint32_t Length() const;
01666
01671 V8EXPORT Local<Object> CloneElementAt(uint32_t index);
01672
01677 V8EXPORT static Local<Array> New(int length = 0);
01678
01679 static inline Array* Cast(Value* obj);
01680 private:
01681 V8EXPORT Array();
01682 static void CheckCast(Value* obj);
01683 };
01684
01685
01689 class Function : public Object {
01690 public:
01691 V8EXPORT Local<Object> NewInstance() const;
01692 V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
01693 V8EXPORT Local<Value> Call(Handle<Object> recv,
01694 int argc,
01695 Handle<Value> argv[]);
01696 V8EXPORT void SetName(Handle<String> name);
01697 V8EXPORT Handle<Value> GetName() const;
01698
01703 V8EXPORT int GetScriptLineNumber() const;
01704 V8EXPORT ScriptOrigin GetScriptOrigin() const;
01705 static inline Function* Cast(Value* obj);
01706 V8EXPORT static const int kLineOffsetNotFound;
01707 private:
01708 V8EXPORT Function();
01709 V8EXPORT static void CheckCast(Value* obj);
01710 };
01711
01712
01716 class Date : public Object {
01717 public:
01718 V8EXPORT static Local<Value> New(double time);
01719
01724 V8EXPORT double NumberValue() const;
01725
01726 static inline Date* Cast(v8::Value* obj);
01727
01740 V8EXPORT static void DateTimeConfigurationChangeNotification();
01741
01742 private:
01743 V8EXPORT static void CheckCast(v8::Value* obj);
01744 };
01745
01746
01750 class RegExp : public Object {
01751 public:
01756 enum Flags {
01757 kNone = 0,
01758 kGlobal = 1,
01759 kIgnoreCase = 2,
01760 kMultiline = 4
01761 };
01762
01773 V8EXPORT static Local<RegExp> New(Handle<String> pattern,
01774 Flags flags);
01775
01780 V8EXPORT Local<String> GetSource() const;
01781
01785 V8EXPORT Flags GetFlags() const;
01786
01787 static inline RegExp* Cast(v8::Value* obj);
01788
01789 private:
01790 V8EXPORT static void CheckCast(v8::Value* obj);
01791 };
01792
01793
01805 class External : public Value {
01806 public:
01807 V8EXPORT static Local<Value> Wrap(void* data);
01808 static inline void* Unwrap(Handle<Value> obj);
01809
01810 V8EXPORT static Local<External> New(void* value);
01811 static inline External* Cast(Value* obj);
01812 V8EXPORT void* Value() const;
01813 private:
01814 V8EXPORT External();
01815 V8EXPORT static void CheckCast(v8::Value* obj);
01816 static inline void* QuickUnwrap(Handle<v8::Value> obj);
01817 V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
01818 };
01819
01820
01821
01822
01823
01827 class V8EXPORT Template : public Data {
01828 public:
01830 void Set(Handle<String> name, Handle<Data> value,
01831 PropertyAttribute attributes = None);
01832 inline void Set(const char* name, Handle<Data> value);
01833 private:
01834 Template();
01835
01836 friend class ObjectTemplate;
01837 friend class FunctionTemplate;
01838 };
01839
01840
01847 class Arguments {
01848 public:
01849 inline int Length() const;
01850 inline Local<Value> operator[](int i) const;
01851 inline Local<Function> Callee() const;
01852 inline Local<Object> This() const;
01853 inline Local<Object> Holder() const;
01854 inline bool IsConstructCall() const;
01855 inline Local<Value> Data() const;
01856 private:
01857 static const int kDataIndex = 0;
01858 static const int kCalleeIndex = -1;
01859 static const int kHolderIndex = -2;
01860
01861 friend class ImplementationUtilities;
01862 inline Arguments(internal::Object** implicit_args,
01863 internal::Object** values,
01864 int length,
01865 bool is_construct_call);
01866 internal::Object** implicit_args_;
01867 internal::Object** values_;
01868 int length_;
01869 bool is_construct_call_;
01870 };
01871
01872
01877 class V8EXPORT AccessorInfo {
01878 public:
01879 inline AccessorInfo(internal::Object** args)
01880 : args_(args) { }
01881 inline Local<Value> Data() const;
01882 inline Local<Object> This() const;
01883 inline Local<Object> Holder() const;
01884 private:
01885 internal::Object** args_;
01886 };
01887
01888
01889 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
01890
01895 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
01896 const AccessorInfo& info);
01897
01898
01903 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
01904 Local<Value> value,
01905 const AccessorInfo& info);
01906
01912 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
01913 const AccessorInfo& info);
01914
01915
01921 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
01922 const AccessorInfo& info);
01923
01928 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
01929
01930
01935 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
01936 const AccessorInfo& info);
01937
01938
01943 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
01944 Local<Value> value,
01945 const AccessorInfo& info);
01946
01947
01952 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
01953 const AccessorInfo& info);
01954
01960 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
01961 const AccessorInfo& info);
01962
01967 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
01968
01969
01973 enum AccessType {
01974 ACCESS_GET,
01975 ACCESS_SET,
01976 ACCESS_HAS,
01977 ACCESS_DELETE,
01978 ACCESS_KEYS
01979 };
01980
01981
01986 typedef bool (*NamedSecurityCallback)(Local<Object> host,
01987 Local<Value> key,
01988 AccessType type,
01989 Local<Value> data);
01990
01991
01996 typedef bool (*IndexedSecurityCallback)(Local<Object> host,
01997 uint32_t index,
01998 AccessType type,
01999 Local<Value> data);
02000
02001
02094 class V8EXPORT FunctionTemplate : public Template {
02095 public:
02097 static Local<FunctionTemplate> New(
02098 InvocationCallback callback = 0,
02099 Handle<Value> data = Handle<Value>(),
02100 Handle<Signature> signature = Handle<Signature>());
02102 Local<Function> GetFunction();
02103
02109 void SetCallHandler(InvocationCallback callback,
02110 Handle<Value> data = Handle<Value>());
02111
02113 Local<ObjectTemplate> InstanceTemplate();
02114
02116 void Inherit(Handle<FunctionTemplate> parent);
02117
02122 Local<ObjectTemplate> PrototypeTemplate();
02123
02124
02130 void SetClassName(Handle<String> name);
02131
02144 void SetHiddenPrototype(bool value);
02145
02150 bool HasInstance(Handle<Value> object);
02151
02152 private:
02153 FunctionTemplate();
02154 void AddInstancePropertyAccessor(Handle<String> name,
02155 AccessorGetter getter,
02156 AccessorSetter setter,
02157 Handle<Value> data,
02158 AccessControl settings,
02159 PropertyAttribute attributes);
02160 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
02161 NamedPropertySetter setter,
02162 NamedPropertyQuery query,
02163 NamedPropertyDeleter remover,
02164 NamedPropertyEnumerator enumerator,
02165 Handle<Value> data);
02166 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
02167 IndexedPropertySetter setter,
02168 IndexedPropertyQuery query,
02169 IndexedPropertyDeleter remover,
02170 IndexedPropertyEnumerator enumerator,
02171 Handle<Value> data);
02172 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
02173 Handle<Value> data);
02174
02175 friend class Context;
02176 friend class ObjectTemplate;
02177 };
02178
02179
02186 class V8EXPORT ObjectTemplate : public Template {
02187 public:
02189 static Local<ObjectTemplate> New();
02190
02192 Local<Object> NewInstance();
02193
02218 void SetAccessor(Handle<String> name,
02219 AccessorGetter getter,
02220 AccessorSetter setter = 0,
02221 Handle<Value> data = Handle<Value>(),
02222 AccessControl settings = DEFAULT,
02223 PropertyAttribute attribute = None);
02224
02242 void SetNamedPropertyHandler(NamedPropertyGetter getter,
02243 NamedPropertySetter setter = 0,
02244 NamedPropertyQuery query = 0,
02245 NamedPropertyDeleter deleter = 0,
02246 NamedPropertyEnumerator enumerator = 0,
02247 Handle<Value> data = Handle<Value>());
02248
02265 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
02266 IndexedPropertySetter setter = 0,
02267 IndexedPropertyQuery query = 0,
02268 IndexedPropertyDeleter deleter = 0,
02269 IndexedPropertyEnumerator enumerator = 0,
02270 Handle<Value> data = Handle<Value>());
02271
02278 void SetCallAsFunctionHandler(InvocationCallback callback,
02279 Handle<Value> data = Handle<Value>());
02280
02289 void MarkAsUndetectable();
02290
02302 void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
02303 IndexedSecurityCallback indexed_handler,
02304 Handle<Value> data = Handle<Value>(),
02305 bool turned_on_by_default = true);
02306
02311 int InternalFieldCount();
02312
02317 void SetInternalFieldCount(int value);
02318
02319 private:
02320 ObjectTemplate();
02321 static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
02322 friend class FunctionTemplate;
02323 };
02324
02325
02330 class V8EXPORT Signature : public Data {
02331 public:
02332 static Local<Signature> New(Handle<FunctionTemplate> receiver =
02333 Handle<FunctionTemplate>(),
02334 int argc = 0,
02335 Handle<FunctionTemplate> argv[] = 0);
02336 private:
02337 Signature();
02338 };
02339
02340
02345 class V8EXPORT TypeSwitch : public Data {
02346 public:
02347 static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
02348 static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
02349 int match(Handle<Value> value);
02350 private:
02351 TypeSwitch();
02352 };
02353
02354
02355
02356
02357
02361 class V8EXPORT Extension {
02362 public:
02363 Extension(const char* name,
02364 const char* source = 0,
02365 int dep_count = 0,
02366 const char** deps = 0);
02367 virtual ~Extension() { }
02368 virtual v8::Handle<v8::FunctionTemplate>
02369 GetNativeFunction(v8::Handle<v8::String> name) {
02370 return v8::Handle<v8::FunctionTemplate>();
02371 }
02372
02373 const char* name() { return name_; }
02374 const char* source() { return source_; }
02375 int dependency_count() { return dep_count_; }
02376 const char** dependencies() { return deps_; }
02377 void set_auto_enable(bool value) { auto_enable_ = value; }
02378 bool auto_enable() { return auto_enable_; }
02379
02380 private:
02381 const char* name_;
02382 const char* source_;
02383 int dep_count_;
02384 const char** deps_;
02385 bool auto_enable_;
02386
02387
02388 Extension(const Extension&);
02389 void operator=(const Extension&);
02390 };
02391
02392
02393 void V8EXPORT RegisterExtension(Extension* extension);
02394
02395
02399 class V8EXPORT DeclareExtension {
02400 public:
02401 inline DeclareExtension(Extension* extension) {
02402 RegisterExtension(extension);
02403 }
02404 };
02405
02406
02407
02408
02409
02410 Handle<Primitive> V8EXPORT Undefined();
02411 Handle<Primitive> V8EXPORT Null();
02412 Handle<Boolean> V8EXPORT True();
02413 Handle<Boolean> V8EXPORT False();
02414
02415
02425 class V8EXPORT ResourceConstraints {
02426 public:
02427 ResourceConstraints();
02428 int max_young_space_size() const { return max_young_space_size_; }
02429 void set_max_young_space_size(int value) { max_young_space_size_ = value; }
02430 int max_old_space_size() const { return max_old_space_size_; }
02431 void set_max_old_space_size(int value) { max_old_space_size_ = value; }
02432 int max_executable_size() { return max_executable_size_; }
02433 void set_max_executable_size(int value) { max_executable_size_ = value; }
02434 uint32_t* stack_limit() const { return stack_limit_; }
02435
02436 void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
02437 private:
02438 int max_young_space_size_;
02439 int max_old_space_size_;
02440 int max_executable_size_;
02441 uint32_t* stack_limit_;
02442 };
02443
02444
02445 bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints);
02446
02447
02448
02449
02450
02451 typedef void (*FatalErrorCallback)(const char* location, const char* message);
02452
02453
02454 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
02455
02456
02463 Handle<Value> V8EXPORT ThrowException(Handle<Value> exception);
02464
02469 class V8EXPORT Exception {
02470 public:
02471 static Local<Value> RangeError(Handle<String> message);
02472 static Local<Value> ReferenceError(Handle<String> message);
02473 static Local<Value> SyntaxError(Handle<String> message);
02474 static Local<Value> TypeError(Handle<String> message);
02475 static Local<Value> Error(Handle<String> message);
02476 };
02477
02478
02479
02480
02481 typedef int* (*CounterLookupCallback)(const char* name);
02482
02483 typedef void* (*CreateHistogramCallback)(const char* name,
02484 int min,
02485 int max,
02486 size_t buckets);
02487
02488 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
02489
02490
02491 enum ObjectSpace {
02492 kObjectSpaceNewSpace = 1 << 0,
02493 kObjectSpaceOldPointerSpace = 1 << 1,
02494 kObjectSpaceOldDataSpace = 1 << 2,
02495 kObjectSpaceCodeSpace = 1 << 3,
02496 kObjectSpaceMapSpace = 1 << 4,
02497 kObjectSpaceLoSpace = 1 << 5,
02498
02499 kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
02500 kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
02501 kObjectSpaceLoSpace
02502 };
02503
02504 enum AllocationAction {
02505 kAllocationActionAllocate = 1 << 0,
02506 kAllocationActionFree = 1 << 1,
02507 kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
02508 };
02509
02510 typedef void (*MemoryAllocationCallback)(ObjectSpace space,
02511 AllocationAction action,
02512 int size);
02513
02514
02515 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
02516 AccessType type,
02517 Local<Value> data);
02518
02519
02520
02525 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
02526
02527
02528
02536 enum GCType {
02537 kGCTypeScavenge = 1 << 0,
02538 kGCTypeMarkSweepCompact = 1 << 1,
02539 kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
02540 };
02541
02542 enum GCCallbackFlags {
02543 kNoGCCallbackFlags = 0,
02544 kGCCallbackFlagCompacted = 1 << 0
02545 };
02546
02547 typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
02548 typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
02549
02550 typedef void (*GCCallback)();
02551
02552
02561 enum ProfilerModules {
02562 PROFILER_MODULE_NONE = 0,
02563 PROFILER_MODULE_CPU = 1,
02564 PROFILER_MODULE_HEAP_STATS = 1 << 1,
02565 PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2,
02566 PROFILER_MODULE_HEAP_SNAPSHOT = 1 << 16
02567 };
02568
02569
02576 class V8EXPORT HeapStatistics {
02577 public:
02578 HeapStatistics();
02579 size_t total_heap_size() { return total_heap_size_; }
02580 size_t total_heap_size_executable() { return total_heap_size_executable_; }
02581 size_t used_heap_size() { return used_heap_size_; }
02582 size_t heap_size_limit() { return heap_size_limit_; }
02583
02584 private:
02585 void set_total_heap_size(size_t size) { total_heap_size_ = size; }
02586 void set_total_heap_size_executable(size_t size) {
02587 total_heap_size_executable_ = size;
02588 }
02589 void set_used_heap_size(size_t size) { used_heap_size_ = size; }
02590 void set_heap_size_limit(size_t size) { heap_size_limit_ = size; }
02591
02592 size_t total_heap_size_;
02593 size_t total_heap_size_executable_;
02594 size_t used_heap_size_;
02595 size_t heap_size_limit_;
02596
02597 friend class V8;
02598 };
02599
02600
02601 class RetainedObjectInfo;
02602
02612 class V8EXPORT Isolate {
02613 public:
02618 class V8EXPORT Scope {
02619 public:
02620 explicit Scope(Isolate* isolate) : isolate_(isolate) {
02621 isolate->Enter();
02622 }
02623
02624 ~Scope() { isolate_->Exit(); }
02625
02626 private:
02627 Isolate* const isolate_;
02628
02629
02630 Scope(const Scope&);
02631 Scope& operator=(const Scope&);
02632 };
02633
02641 static Isolate* New();
02642
02647 static Isolate* GetCurrent();
02648
02659 void Enter();
02660
02668 void Exit();
02669
02674 void Dispose();
02675
02679 void SetData(void* data);
02680
02685 void* GetData();
02686
02687 private:
02688 Isolate();
02689 Isolate(const Isolate&);
02690 ~Isolate();
02691 Isolate& operator=(const Isolate&);
02692 void* operator new(size_t size);
02693 void operator delete(void*, size_t);
02694 };
02695
02696
02697 class StartupData {
02698 public:
02699 enum CompressionAlgorithm {
02700 kUncompressed,
02701 kBZip2
02702 };
02703
02704 const char* data;
02705 int compressed_size;
02706 int raw_size;
02707 };
02708
02709
02718 class V8EXPORT StartupDataDecompressor {
02719 public:
02720 StartupDataDecompressor();
02721 virtual ~StartupDataDecompressor();
02722 int Decompress();
02723
02724 protected:
02725 virtual int DecompressData(char* raw_data,
02726 int* raw_data_size,
02727 const char* compressed_data,
02728 int compressed_data_size) = 0;
02729
02730 private:
02731 char** raw_data;
02732 };
02733
02737 class V8EXPORT V8 {
02738 public:
02740 static void SetFatalErrorHandler(FatalErrorCallback that);
02741
02746 static void SetAllowCodeGenerationFromStringsCallback(
02747 AllowCodeGenerationFromStringsCallback that);
02748
02761 static void IgnoreOutOfMemoryException();
02762
02767 static bool IsDead();
02768
02788 static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
02789 static int GetCompressedStartupDataCount();
02790 static void GetCompressedStartupData(StartupData* compressed_data);
02791 static void SetDecompressedStartupData(StartupData* decompressed_data);
02792
02799 static bool AddMessageListener(MessageCallback that,
02800 Handle<Value> data = Handle<Value>());
02801
02805 static void RemoveMessageListeners(MessageCallback that);
02806
02811 static void SetCaptureStackTraceForUncaughtExceptions(
02812 bool capture,
02813 int frame_limit = 10,
02814 StackTrace::StackTraceOptions options = StackTrace::kOverview);
02815
02819 static void SetFlagsFromString(const char* str, int length);
02820
02824 static void SetFlagsFromCommandLine(int* argc,
02825 char** argv,
02826 bool remove_flags);
02827
02829 static const char* GetVersion();
02830
02835 static void SetCounterFunction(CounterLookupCallback);
02836
02843 static void SetCreateHistogramFunction(CreateHistogramCallback);
02844 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
02845
02850 static void EnableSlidingStateWindow();
02851
02853 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
02854
02865 static void AddGCPrologueCallback(
02866 GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
02867
02872 static void RemoveGCPrologueCallback(GCPrologueCallback callback);
02873
02882 static void SetGlobalGCPrologueCallback(GCCallback);
02883
02894 static void AddGCEpilogueCallback(
02895 GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
02896
02901 static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
02902
02911 static void SetGlobalGCEpilogueCallback(GCCallback);
02912
02917 static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
02918 ObjectSpace space,
02919 AllocationAction action);
02920
02925 static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
02926
02936 static void AddObjectGroup(Persistent<Value>* objects,
02937 size_t length,
02938 RetainedObjectInfo* info = NULL);
02939
02947 static void AddImplicitReferences(Persistent<Object> parent,
02948 Persistent<Value>* children,
02949 size_t length);
02950
02956 static bool Initialize();
02957
02972 static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
02973
02983 static void PauseProfiler();
02984
02989 static void ResumeProfiler();
02990
02994 static bool IsProfilerPaused();
02995
03006 static void ResumeProfilerEx(int flags, int tag = 0);
03007
03020 static void PauseProfilerEx(int flags, int tag = 0);
03021
03028 static int GetActiveProfilerModules();
03029
03045 static int GetLogLines(int from_pos, char* dest_buf, int max_size);
03046
03053 static const int kMinimumSizeForLogLinesBuffer = 2048;
03054
03061 static int GetCurrentThreadId();
03062
03087 static void TerminateExecution(int thread_id);
03088
03099 static void TerminateExecution(Isolate* isolate = NULL);
03100
03111 static bool IsExecutionTerminating(Isolate* isolate = NULL);
03112
03122 static bool Dispose();
03123
03127 static void GetHeapStatistics(HeapStatistics* heap_statistics);
03128
03137 static bool IdleNotification();
03138
03143 static void LowMemoryNotification();
03144
03151 static int ContextDisposedNotification();
03152
03153 private:
03154 V8();
03155
03156 static internal::Object** GlobalizeReference(internal::Object** handle);
03157 static void DisposeGlobal(internal::Object** global_handle);
03158 static void MakeWeak(internal::Object** global_handle,
03159 void* data,
03160 WeakReferenceCallback);
03161 static void ClearWeak(internal::Object** global_handle);
03162 static void MarkIndependent(internal::Object** global_handle);
03163 static bool IsGlobalNearDeath(internal::Object** global_handle);
03164 static bool IsGlobalWeak(internal::Object** global_handle);
03165 static void SetWrapperClassId(internal::Object** global_handle,
03166 uint16_t class_id);
03167
03168 template <class T> friend class Handle;
03169 template <class T> friend class Local;
03170 template <class T> friend class Persistent;
03171 friend class Context;
03172 };
03173
03174
03178 class V8EXPORT TryCatch {
03179 public:
03183 TryCatch();
03184
03188 ~TryCatch();
03189
03193 bool HasCaught() const;
03194
03208 bool CanContinue() const;
03209
03217 Handle<Value> ReThrow();
03218
03225 Local<Value> Exception() const;
03226
03231 Local<Value> StackTrace() const;
03232
03240 Local<v8::Message> Message() const;
03241
03251 void Reset();
03252
03261 void SetVerbose(bool value);
03262
03268 void SetCaptureMessage(bool value);
03269
03270 private:
03271 v8::internal::Isolate* isolate_;
03272 void* next_;
03273 void* exception_;
03274 void* message_;
03275 bool is_verbose_ : 1;
03276 bool can_continue_ : 1;
03277 bool capture_message_ : 1;
03278 bool rethrow_ : 1;
03279
03280 friend class v8::internal::Isolate;
03281 };
03282
03283
03284
03285
03286
03290 class V8EXPORT ExtensionConfiguration {
03291 public:
03292 ExtensionConfiguration(int name_count, const char* names[])
03293 : name_count_(name_count), names_(names) { }
03294 private:
03295 friend class ImplementationUtilities;
03296 int name_count_;
03297 const char** names_;
03298 };
03299
03300
03305 class V8EXPORT Context {
03306 public:
03323 Local<Object> Global();
03324
03329 void DetachGlobal();
03330
03341 void ReattachGlobal(Handle<Object> global_object);
03342
03361 static Persistent<Context> New(
03362 ExtensionConfiguration* extensions = NULL,
03363 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
03364 Handle<Value> global_object = Handle<Value>());
03365
03367 static Local<Context> GetEntered();
03368
03370 static Local<Context> GetCurrent();
03371
03377 static Local<Context> GetCalling();
03378
03383 void SetSecurityToken(Handle<Value> token);
03384
03386 void UseDefaultSecurityToken();
03387
03389 Handle<Value> GetSecurityToken();
03390
03397 void Enter();
03398
03403 void Exit();
03404
03406 bool HasOutOfMemoryException();
03407
03409 static bool InContext();
03410
03416 void SetData(Handle<String> data);
03417 Local<Value> GetData();
03418
03432 void AllowCodeGenerationFromStrings(bool allow);
03433
03438 class Scope {
03439 public:
03440 explicit inline Scope(Handle<Context> context) : context_(context) {
03441 context_->Enter();
03442 }
03443 inline ~Scope() { context_->Exit(); }
03444 private:
03445 Handle<Context> context_;
03446 };
03447
03448 private:
03449 friend class Value;
03450 friend class Script;
03451 friend class Object;
03452 friend class Function;
03453 };
03454
03455
03536 class V8EXPORT Unlocker {
03537 public:
03541 explicit Unlocker(Isolate* isolate = NULL);
03542 ~Unlocker();
03543 private:
03544 internal::Isolate* isolate_;
03545 };
03546
03547
03548 class V8EXPORT Locker {
03549 public:
03553 explicit Locker(Isolate* isolate = NULL);
03554 ~Locker();
03555
03563 static void StartPreemption(int every_n_ms);
03564
03568 static void StopPreemption();
03569
03574 static bool IsLocked(Isolate* isolate = NULL);
03575
03579 static bool IsActive() { return active_; }
03580
03581 private:
03582 bool has_lock_;
03583 bool top_level_;
03584 internal::Isolate* isolate_;
03585
03586 static bool active_;
03587
03588
03589 Locker(const Locker&);
03590 void operator=(const Locker&);
03591 };
03592
03593
03597 class V8EXPORT OutputStream {
03598 public:
03599 enum OutputEncoding {
03600 kAscii = 0
03601 };
03602 enum WriteResult {
03603 kContinue = 0,
03604 kAbort = 1
03605 };
03606 virtual ~OutputStream() {}
03608 virtual void EndOfStream() = 0;
03610 virtual int GetChunkSize() { return 1024; }
03612 virtual OutputEncoding GetOutputEncoding() { return kAscii; }
03618 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
03619 };
03620
03621
03626 class V8EXPORT ActivityControl {
03627 public:
03628 enum ControlOption {
03629 kContinue = 0,
03630 kAbort = 1
03631 };
03632 virtual ~ActivityControl() {}
03637 virtual ControlOption ReportProgressValue(int done, int total) = 0;
03638 };
03639
03640
03641
03642
03643
03644 namespace internal {
03645
03646 static const int kApiPointerSize = sizeof(void*);
03647 static const int kApiIntSize = sizeof(int);
03648
03649
03650 const int kHeapObjectTag = 1;
03651 const int kHeapObjectTagSize = 2;
03652 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
03653
03654
03655 const int kSmiTag = 0;
03656 const int kSmiTagSize = 1;
03657 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
03658
03659 template <size_t ptr_size> struct SmiTagging;
03660
03661
03662 template <> struct SmiTagging<4> {
03663 static const int kSmiShiftSize = 0;
03664 static const int kSmiValueSize = 31;
03665 static inline int SmiToInt(internal::Object* value) {
03666 int shift_bits = kSmiTagSize + kSmiShiftSize;
03667
03668 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
03669 }
03670
03671
03672
03673 static const uintptr_t kEncodablePointerMask = 0x1;
03674 static const int kPointerToSmiShift = 0;
03675 };
03676
03677
03678 template <> struct SmiTagging<8> {
03679 static const int kSmiShiftSize = 31;
03680 static const int kSmiValueSize = 32;
03681 static inline int SmiToInt(internal::Object* value) {
03682 int shift_bits = kSmiTagSize + kSmiShiftSize;
03683
03684 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
03685 }
03686
03687
03688
03689
03690
03691 static const int kPointerAlignment = 3;
03692
03693 static const uintptr_t kEncodablePointerMask =
03694 ~(uintptr_t(0xffffffff) << kPointerAlignment);
03695
03696 static const int kPointerToSmiShift =
03697 kSmiTagSize + kSmiShiftSize - kPointerAlignment;
03698 };
03699
03700 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
03701 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
03702 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
03703 const uintptr_t kEncodablePointerMask =
03704 PlatformSmiTagging::kEncodablePointerMask;
03705 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;
03706
03707 template <size_t ptr_size> struct InternalConstants;
03708
03709
03710 template <> struct InternalConstants<4> {
03711 static const int kStringResourceOffset = 3 * kApiPointerSize;
03712 };
03713
03714
03715 template <> struct InternalConstants<8> {
03716 static const int kStringResourceOffset = 3 * kApiPointerSize;
03717 };
03718
03724 class Internals {
03725 public:
03726
03727
03728 static const int kHeapObjectMapOffset = 0;
03729 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
03730 static const int kStringResourceOffset =
03731 InternalConstants<kApiPointerSize>::kStringResourceOffset;
03732
03733 static const int kForeignAddressOffset = kApiPointerSize;
03734 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
03735 static const int kFullStringRepresentationMask = 0x07;
03736 static const int kExternalTwoByteRepresentationTag = 0x02;
03737
03738 static const int kJSObjectType = 0xa3;
03739 static const int kFirstNonstringType = 0x80;
03740 static const int kForeignType = 0x85;
03741
03742 static inline bool HasHeapObjectTag(internal::Object* value) {
03743 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
03744 kHeapObjectTag);
03745 }
03746
03747 static inline bool HasSmiTag(internal::Object* value) {
03748 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
03749 }
03750
03751 static inline int SmiValue(internal::Object* value) {
03752 return PlatformSmiTagging::SmiToInt(value);
03753 }
03754
03755 static inline int GetInstanceType(internal::Object* obj) {
03756 typedef internal::Object O;
03757 O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
03758 return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
03759 }
03760
03761 static inline void* GetExternalPointerFromSmi(internal::Object* value) {
03762 const uintptr_t address = reinterpret_cast<uintptr_t>(value);
03763 return reinterpret_cast<void*>(address >> kPointerToSmiShift);
03764 }
03765
03766 static inline void* GetExternalPointer(internal::Object* obj) {
03767 if (HasSmiTag(obj)) {
03768 return GetExternalPointerFromSmi(obj);
03769 } else if (GetInstanceType(obj) == kForeignType) {
03770 return ReadField<void*>(obj, kForeignAddressOffset);
03771 } else {
03772 return NULL;
03773 }
03774 }
03775
03776 static inline bool IsExternalTwoByteString(int instance_type) {
03777 int representation = (instance_type & kFullStringRepresentationMask);
03778 return representation == kExternalTwoByteRepresentationTag;
03779 }
03780
03781 template <typename T>
03782 static inline T ReadField(Object* ptr, int offset) {
03783 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
03784 return *reinterpret_cast<T*>(addr);
03785 }
03786
03787 static inline bool CanCastToHeapObject(void* o) { return false; }
03788 static inline bool CanCastToHeapObject(Context* o) { return true; }
03789 static inline bool CanCastToHeapObject(String* o) { return true; }
03790 static inline bool CanCastToHeapObject(Object* o) { return true; }
03791 static inline bool CanCastToHeapObject(Message* o) { return true; }
03792 static inline bool CanCastToHeapObject(StackTrace* o) { return true; }
03793 static inline bool CanCastToHeapObject(StackFrame* o) { return true; }
03794 };
03795
03796 }
03797
03798
03799 template <class T>
03800 Handle<T>::Handle() : val_(0) { }
03801
03802
03803 template <class T>
03804 Local<T>::Local() : Handle<T>() { }
03805
03806
03807 template <class T>
03808 Local<T> Local<T>::New(Handle<T> that) {
03809 if (that.IsEmpty()) return Local<T>();
03810 T* that_ptr = *that;
03811 internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
03812 if (internal::Internals::CanCastToHeapObject(that_ptr)) {
03813 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
03814 reinterpret_cast<internal::HeapObject*>(*p))));
03815 }
03816 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
03817 }
03818
03819
03820 template <class T>
03821 Persistent<T> Persistent<T>::New(Handle<T> that) {
03822 if (that.IsEmpty()) return Persistent<T>();
03823 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
03824 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
03825 }
03826
03827
03828 template <class T>
03829 bool Persistent<T>::IsNearDeath() const {
03830 if (this->IsEmpty()) return false;
03831 return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
03832 }
03833
03834
03835 template <class T>
03836 bool Persistent<T>::IsWeak() const {
03837 if (this->IsEmpty()) return false;
03838 return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
03839 }
03840
03841
03842 template <class T>
03843 void Persistent<T>::Dispose() {
03844 if (this->IsEmpty()) return;
03845 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
03846 }
03847
03848
03849 template <class T>
03850 Persistent<T>::Persistent() : Handle<T>() { }
03851
03852 template <class T>
03853 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
03854 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
03855 parameters,
03856 callback);
03857 }
03858
03859 template <class T>
03860 void Persistent<T>::ClearWeak() {
03861 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
03862 }
03863
03864 template <class T>
03865 void Persistent<T>::MarkIndependent() {
03866 V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this));
03867 }
03868
03869 template <class T>
03870 void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
03871 V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id);
03872 }
03873
03874 Arguments::Arguments(internal::Object** implicit_args,
03875 internal::Object** values, int length,
03876 bool is_construct_call)
03877 : implicit_args_(implicit_args),
03878 values_(values),
03879 length_(length),
03880 is_construct_call_(is_construct_call) { }
03881
03882
03883 Local<Value> Arguments::operator[](int i) const {
03884 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
03885 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
03886 }
03887
03888
03889 Local<Function> Arguments::Callee() const {
03890 return Local<Function>(reinterpret_cast<Function*>(
03891 &implicit_args_[kCalleeIndex]));
03892 }
03893
03894
03895 Local<Object> Arguments::This() const {
03896 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
03897 }
03898
03899
03900 Local<Object> Arguments::Holder() const {
03901 return Local<Object>(reinterpret_cast<Object*>(
03902 &implicit_args_[kHolderIndex]));
03903 }
03904
03905
03906 Local<Value> Arguments::Data() const {
03907 return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
03908 }
03909
03910
03911 bool Arguments::IsConstructCall() const {
03912 return is_construct_call_;
03913 }
03914
03915
03916 int Arguments::Length() const {
03917 return length_;
03918 }
03919
03920
03921 template <class T>
03922 Local<T> HandleScope::Close(Handle<T> value) {
03923 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
03924 internal::Object** after = RawClose(before);
03925 return Local<T>(reinterpret_cast<T*>(after));
03926 }
03927
03928 Handle<Value> ScriptOrigin::ResourceName() const {
03929 return resource_name_;
03930 }
03931
03932
03933 Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
03934 return resource_line_offset_;
03935 }
03936
03937
03938 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
03939 return resource_column_offset_;
03940 }
03941
03942
03943 Handle<Boolean> Boolean::New(bool value) {
03944 return value ? True() : False();
03945 }
03946
03947
03948 void Template::Set(const char* name, v8::Handle<Data> value) {
03949 Set(v8::String::New(name), value);
03950 }
03951
03952
03953 Local<Value> Object::GetInternalField(int index) {
03954 #ifndef V8_ENABLE_CHECKS
03955 Local<Value> quick_result = UncheckedGetInternalField(index);
03956 if (!quick_result.IsEmpty()) return quick_result;
03957 #endif
03958 return CheckedGetInternalField(index);
03959 }
03960
03961
03962 Local<Value> Object::UncheckedGetInternalField(int index) {
03963 typedef internal::Object O;
03964 typedef internal::Internals I;
03965 O* obj = *reinterpret_cast<O**>(this);
03966 if (I::GetInstanceType(obj) == I::kJSObjectType) {
03967
03968
03969
03970 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
03971 O* value = I::ReadField<O*>(obj, offset);
03972 O** result = HandleScope::CreateHandle(value);
03973 return Local<Value>(reinterpret_cast<Value*>(result));
03974 } else {
03975 return Local<Value>();
03976 }
03977 }
03978
03979
03980 void* External::Unwrap(Handle<v8::Value> obj) {
03981 #ifdef V8_ENABLE_CHECKS
03982 return FullUnwrap(obj);
03983 #else
03984 return QuickUnwrap(obj);
03985 #endif
03986 }
03987
03988
03989 void* External::QuickUnwrap(Handle<v8::Value> wrapper) {
03990 typedef internal::Object O;
03991 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
03992 return internal::Internals::GetExternalPointer(obj);
03993 }
03994
03995
03996 void* Object::GetPointerFromInternalField(int index) {
03997 typedef internal::Object O;
03998 typedef internal::Internals I;
03999
04000 O* obj = *reinterpret_cast<O**>(this);
04001
04002 if (I::GetInstanceType(obj) == I::kJSObjectType) {
04003
04004
04005
04006 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
04007 O* value = I::ReadField<O*>(obj, offset);
04008 return I::GetExternalPointer(value);
04009 }
04010
04011 return SlowGetPointerFromInternalField(index);
04012 }
04013
04014
04015 String* String::Cast(v8::Value* value) {
04016 #ifdef V8_ENABLE_CHECKS
04017 CheckCast(value);
04018 #endif
04019 return static_cast<String*>(value);
04020 }
04021
04022
04023 String::ExternalStringResource* String::GetExternalStringResource() const {
04024 typedef internal::Object O;
04025 typedef internal::Internals I;
04026 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
04027 String::ExternalStringResource* result;
04028 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
04029 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
04030 result = reinterpret_cast<String::ExternalStringResource*>(value);
04031 } else {
04032 result = NULL;
04033 }
04034 #ifdef V8_ENABLE_CHECKS
04035 VerifyExternalStringResource(result);
04036 #endif
04037 return result;
04038 }
04039
04040
04041 bool Value::IsString() const {
04042 #ifdef V8_ENABLE_CHECKS
04043 return FullIsString();
04044 #else
04045 return QuickIsString();
04046 #endif
04047 }
04048
04049 bool Value::QuickIsString() const {
04050 typedef internal::Object O;
04051 typedef internal::Internals I;
04052 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
04053 if (!I::HasHeapObjectTag(obj)) return false;
04054 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
04055 }
04056
04057
04058 Number* Number::Cast(v8::Value* value) {
04059 #ifdef V8_ENABLE_CHECKS
04060 CheckCast(value);
04061 #endif
04062 return static_cast<Number*>(value);
04063 }
04064
04065
04066 Integer* Integer::Cast(v8::Value* value) {
04067 #ifdef V8_ENABLE_CHECKS
04068 CheckCast(value);
04069 #endif
04070 return static_cast<Integer*>(value);
04071 }
04072
04073
04074 Date* Date::Cast(v8::Value* value) {
04075 #ifdef V8_ENABLE_CHECKS
04076 CheckCast(value);
04077 #endif
04078 return static_cast<Date*>(value);
04079 }
04080
04081
04082 RegExp* RegExp::Cast(v8::Value* value) {
04083 #ifdef V8_ENABLE_CHECKS
04084 CheckCast(value);
04085 #endif
04086 return static_cast<RegExp*>(value);
04087 }
04088
04089
04090 Object* Object::Cast(v8::Value* value) {
04091 #ifdef V8_ENABLE_CHECKS
04092 CheckCast(value);
04093 #endif
04094 return static_cast<Object*>(value);
04095 }
04096
04097
04098 Array* Array::Cast(v8::Value* value) {
04099 #ifdef V8_ENABLE_CHECKS
04100 CheckCast(value);
04101 #endif
04102 return static_cast<Array*>(value);
04103 }
04104
04105
04106 Function* Function::Cast(v8::Value* value) {
04107 #ifdef V8_ENABLE_CHECKS
04108 CheckCast(value);
04109 #endif
04110 return static_cast<Function*>(value);
04111 }
04112
04113
04114 External* External::Cast(v8::Value* value) {
04115 #ifdef V8_ENABLE_CHECKS
04116 CheckCast(value);
04117 #endif
04118 return static_cast<External*>(value);
04119 }
04120
04121
04122 Local<Value> AccessorInfo::Data() const {
04123 return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
04124 }
04125
04126
04127 Local<Object> AccessorInfo::This() const {
04128 return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
04129 }
04130
04131
04132 Local<Object> AccessorInfo::Holder() const {
04133 return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
04134 }
04135
04136
04149 }
04150
04151
04152 #undef V8EXPORT
04153 #undef TYPE_CHECK
04154
04155
04156 #endif // V8_H_