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
00045 #ifdef __MINGW32__
00046 #include <stdint.h>
00047 #else // __MINGW32__
00048 typedef signed char int8_t;
00049 typedef unsigned char uint8_t;
00050 typedef short int16_t;
00051 typedef unsigned short uint16_t;
00052 typedef int int32_t;
00053 typedef unsigned int uint32_t;
00054 typedef __int64 int64_t;
00055 typedef unsigned __int64 uint64_t;
00056
00057 #endif // __MINGW32__
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
00069 #error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
00070 build configuration to ensure that at most one of these is set
00071 #endif
00072
00073 #ifdef BUILDING_V8_SHARED
00074 #define V8EXPORT __declspec(dllexport)
00075 #define V8EXPORT_INLINE __declspec(dllexport)
00076 #elif USING_V8_SHARED
00077 #define V8EXPORT __declspec(dllimport)
00078 #define V8EXPORT_INLINE
00079 #else
00080 #define V8EXPORT
00081 #define V8EXPORT_INLINE
00082 #endif // BUILDING_V8_SHARED
00083
00084 #else // _WIN32
00085
00086 #include <stdint.h>
00087
00088
00089
00090
00091 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
00092 #define V8EXPORT __attribute__ ((visibility("default")))
00093 #define V8EXPORT_INLINE __attribute__ ((visibility("default")))
00094 #else // defined(__GNUC__) && (__GNUC__ >= 4)
00095 #define V8EXPORT
00096 #define V8EXPORT_INLINE
00097 #endif // defined(__GNUC__) && (__GNUC__ >= 4)
00098
00099 #endif // _WIN32
00100
00104 namespace v8 {
00105
00106 class Context;
00107 class String;
00108 class Value;
00109 class Utils;
00110 class Number;
00111 class Object;
00112 class Array;
00113 class Int32;
00114 class Uint32;
00115 class External;
00116 class Primitive;
00117 class Boolean;
00118 class Integer;
00119 class Function;
00120 class Date;
00121 class ImplementationUtilities;
00122 class Signature;
00123 template <class T> class Handle;
00124 template <class T> class Local;
00125 template <class T> class Persistent;
00126 class FunctionTemplate;
00127 class ObjectTemplate;
00128 class Data;
00129
00130 namespace internal {
00131
00132 class Arguments;
00133 class Object;
00134 class Top;
00135
00136 }
00137
00138
00139
00140
00141
00148 typedef void (*WeakReferenceCallback)(Persistent<Value> object,
00149 void* parameter);
00150
00151
00152
00153
00154 #define TYPE_CHECK(T, S) \
00155 while (false) { \
00156 *(static_cast<T**>(0)) = static_cast<S*>(0); \
00157 }
00158
00184 template <class T> class V8EXPORT_INLINE Handle {
00185 public:
00186
00190 inline Handle();
00191
00195 explicit Handle(T* val) : val_(val) { }
00196
00207 template <class S> inline Handle(Handle<S> that)
00208 : val_(reinterpret_cast<T*>(*that)) {
00214 TYPE_CHECK(T, S);
00215 }
00216
00220 bool IsEmpty() const { return val_ == 0; }
00221
00222 T* operator->() const { return val_; }
00223
00224 T* operator*() const { return val_; }
00225
00229 void Clear() { this->val_ = 0; }
00230
00237 template <class S> bool operator==(Handle<S> that) const {
00238 internal::Object** a = reinterpret_cast<internal::Object**>(**this);
00239 internal::Object** b = reinterpret_cast<internal::Object**>(*that);
00240 if (a == 0) return b == 0;
00241 if (b == 0) return false;
00242 return *a == *b;
00243 }
00244
00251 template <class S> bool operator!=(Handle<S> that) const {
00252 return !operator==(that);
00253 }
00254
00255 template <class S> static inline Handle<T> Cast(Handle<S> that) {
00256 #ifdef V8_ENABLE_CHECKS
00257
00258
00259 if (that.IsEmpty()) return Handle<T>();
00260 #endif
00261 return Handle<T>(T::Cast(*that));
00262 }
00263
00264 private:
00265 T* val_;
00266 };
00267
00268
00276 template <class T> class V8EXPORT_INLINE Local : public Handle<T> {
00277 public:
00278 inline Local();
00279 template <class S> inline Local(Local<S> that)
00280 : Handle<T>(reinterpret_cast<T*>(*that)) {
00286 TYPE_CHECK(T, S);
00287 }
00288 template <class S> inline Local(S* that) : Handle<T>(that) { }
00289 template <class S> static inline Local<T> Cast(Local<S> that) {
00290 #ifdef V8_ENABLE_CHECKS
00291
00292
00293 if (that.IsEmpty()) return Local<T>();
00294 #endif
00295 return Local<T>(T::Cast(*that));
00296 }
00297
00302 inline static Local<T> New(Handle<T> that);
00303 };
00304
00305
00323 template <class T> class V8EXPORT_INLINE Persistent : public Handle<T> {
00324 public:
00325
00330 inline Persistent();
00331
00343 template <class S> inline Persistent(Persistent<S> that)
00344 : Handle<T>(reinterpret_cast<T*>(*that)) {
00350 TYPE_CHECK(T, S);
00351 }
00352
00353 template <class S> inline Persistent(S* that) : Handle<T>(that) { }
00354
00359 template <class S> explicit inline Persistent(Handle<S> that)
00360 : Handle<T>(*that) { }
00361
00362 template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
00363 #ifdef V8_ENABLE_CHECKS
00364
00365
00366 if (that.IsEmpty()) return Persistent<T>();
00367 #endif
00368 return Persistent<T>(T::Cast(*that));
00369 }
00370
00375 inline static Persistent<T> New(Handle<T> that);
00376
00383 inline void Dispose();
00384
00391 inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
00392
00394 inline void ClearWeak();
00395
00399 inline bool IsNearDeath() const;
00400
00404 inline bool IsWeak() const;
00405
00406 private:
00407 friend class ImplementationUtilities;
00408 friend class ObjectTemplate;
00409 };
00410
00411
00426 class V8EXPORT HandleScope {
00427 public:
00428 HandleScope();
00429
00430 ~HandleScope();
00431
00436 template <class T> Local<T> Close(Handle<T> value);
00437
00441 static int NumberOfHandles();
00442
00446 static internal::Object** CreateHandle(internal::Object* value);
00447
00448 private:
00449
00450
00451 HandleScope(const HandleScope&);
00452 void operator=(const HandleScope&);
00453 void* operator new(size_t size);
00454 void operator delete(void*, size_t);
00455
00456
00457
00458 class V8EXPORT Data {
00459 public:
00460 int extensions;
00461 internal::Object** next;
00462 internal::Object** limit;
00463 inline void Initialize() {
00464 extensions = -1;
00465 next = limit = NULL;
00466 }
00467 };
00468
00469 Data previous_;
00470
00471
00472
00473 bool is_closed_;
00474 internal::Object** RawClose(internal::Object** value);
00475
00476 friend class ImplementationUtilities;
00477 };
00478
00479
00480
00481
00482
00486 class V8EXPORT Data {
00487 private:
00488 Data();
00489 };
00490
00491
00498 class V8EXPORT ScriptData {
00499 public:
00500 virtual ~ScriptData() { }
00501 static ScriptData* PreCompile(const char* input, int length);
00502 static ScriptData* New(unsigned* data, int length);
00503
00504 virtual int Length() = 0;
00505 virtual unsigned* Data() = 0;
00506 virtual bool HasError() = 0;
00507 };
00508
00509
00513 class V8EXPORT ScriptOrigin {
00514 public:
00515 ScriptOrigin(Handle<Value> resource_name,
00516 Handle<Integer> resource_line_offset = Handle<Integer>(),
00517 Handle<Integer> resource_column_offset = Handle<Integer>())
00518 : resource_name_(resource_name),
00519 resource_line_offset_(resource_line_offset),
00520 resource_column_offset_(resource_column_offset) { }
00521 inline Handle<Value> ResourceName() const;
00522 inline Handle<Integer> ResourceLineOffset() const;
00523 inline Handle<Integer> ResourceColumnOffset() const;
00524 private:
00525 Handle<Value> resource_name_;
00526 Handle<Integer> resource_line_offset_;
00527 Handle<Integer> resource_column_offset_;
00528 };
00529
00530
00534 class V8EXPORT Script {
00535 public:
00536
00545 static Local<Script> New(Handle<String> source,
00546 ScriptOrigin* origin = NULL,
00547 ScriptData* pre_data = NULL);
00548
00556 static Local<Script> New(Handle<String> source,
00557 Handle<Value> file_name);
00558
00568 static Local<Script> Compile(Handle<String> source,
00569 ScriptOrigin* origin = NULL,
00570 ScriptData* pre_data = NULL);
00571
00580 static Local<Script> Compile(Handle<String> source,
00581 Handle<Value> file_name);
00582
00590 Local<Value> Run();
00591
00595 Local<Value> Id();
00596
00602 void SetData(Handle<String> data);
00603 };
00604
00605
00609 class V8EXPORT Message {
00610 public:
00611 Local<String> Get() const;
00612 Local<String> GetSourceLine() const;
00613
00618 Handle<Value> GetScriptResourceName() const;
00619
00624 Handle<Value> GetScriptData() const;
00625
00629 int GetLineNumber() const;
00630
00635 int GetStartPosition() const;
00636
00641 int GetEndPosition() const;
00642
00647 int GetStartColumn() const;
00648
00653 int GetEndColumn() const;
00654
00655
00656 static void PrintCurrentStackTrace(FILE* out);
00657 };
00658
00659
00660
00661
00662
00666 class V8EXPORT Value : public Data {
00667 public:
00668
00673 bool IsUndefined() const;
00674
00679 bool IsNull() const;
00680
00684 bool IsTrue() const;
00685
00689 bool IsFalse() const;
00690
00695 inline bool IsString() const;
00696
00700 bool IsFunction() const;
00701
00705 bool IsArray() const;
00706
00710 bool IsObject() const;
00711
00715 bool IsBoolean() const;
00716
00720 bool IsNumber() const;
00721
00725 bool IsExternal() const;
00726
00730 bool IsInt32() const;
00731
00735 bool IsDate() const;
00736
00737 Local<Boolean> ToBoolean() const;
00738 Local<Number> ToNumber() const;
00739 Local<String> ToString() const;
00740 Local<String> ToDetailString() const;
00741 Local<Object> ToObject() const;
00742 Local<Integer> ToInteger() const;
00743 Local<Uint32> ToUint32() const;
00744 Local<Int32> ToInt32() const;
00745
00750 Local<Uint32> ToArrayIndex() const;
00751
00752 bool BooleanValue() const;
00753 double NumberValue() const;
00754 int64_t IntegerValue() const;
00755 uint32_t Uint32Value() const;
00756 int32_t Int32Value() const;
00757
00759 bool Equals(Handle<Value> that) const;
00760 bool StrictEquals(Handle<Value> that) const;
00761
00762 private:
00763 inline bool QuickIsString() const;
00764 bool FullIsString() const;
00765 };
00766
00767
00771 class V8EXPORT Primitive : public Value { };
00772
00773
00778 class V8EXPORT Boolean : public Primitive {
00779 public:
00780 bool Value() const;
00781 static inline Handle<Boolean> New(bool value);
00782 };
00783
00784
00788 class V8EXPORT String : public Primitive {
00789 public:
00790
00794 int Length() const;
00795
00800 int Utf8Length() const;
00801
00819 int Write(uint16_t* buffer, int start = 0, int length = -1) const;
00820 int WriteAscii(char* buffer, int start = 0, int length = -1) const;
00821 int WriteUtf8(char* buffer, int length = -1) const;
00822
00826 static v8::Local<v8::String> Empty();
00827
00831 bool IsExternal() const;
00832
00836 bool IsExternalAscii() const;
00837
00838 class V8EXPORT ExternalStringResourceBase {
00839 public:
00840 virtual ~ExternalStringResourceBase() {}
00841 protected:
00842 ExternalStringResourceBase() {}
00843 private:
00844
00845 ExternalStringResourceBase(const ExternalStringResourceBase&);
00846 void operator=(const ExternalStringResourceBase&);
00847 };
00848
00855 class V8EXPORT ExternalStringResource
00856 : public ExternalStringResourceBase {
00857 public:
00862 virtual ~ExternalStringResource() {}
00864 virtual const uint16_t* data() const = 0;
00866 virtual size_t length() const = 0;
00867 protected:
00868 ExternalStringResource() {}
00869 };
00870
00882 class V8EXPORT ExternalAsciiStringResource
00883 : public ExternalStringResourceBase {
00884 public:
00889 virtual ~ExternalAsciiStringResource() {}
00891 virtual const char* data() const = 0;
00893 virtual size_t length() const = 0;
00894 protected:
00895 ExternalAsciiStringResource() {}
00896 };
00897
00902 inline ExternalStringResource* GetExternalStringResource() const;
00903
00908 ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
00909
00910 static inline String* Cast(v8::Value* obj);
00911
00921 static Local<String> New(const char* data, int length = -1);
00922
00924 static Local<String> New(const uint16_t* data, int length = -1);
00925
00927 static Local<String> NewSymbol(const char* data, int length = -1);
00928
00933 static Local<String> Concat(Handle<String> left, Handle<String>right);
00934
00943 static Local<String> NewExternal(ExternalStringResource* resource);
00944
00953 bool MakeExternal(ExternalStringResource* resource);
00954
00963 static Local<String> NewExternal(ExternalAsciiStringResource* resource);
00964
00973 bool MakeExternal(ExternalAsciiStringResource* resource);
00974
00978 bool CanMakeExternal();
00979
00981 static Local<String> NewUndetectable(const char* data, int length = -1);
00982
00984 static Local<String> NewUndetectable(const uint16_t* data, int length = -1);
00985
00993 class V8EXPORT Utf8Value {
00994 public:
00995 explicit Utf8Value(Handle<v8::Value> obj);
00996 ~Utf8Value();
00997 char* operator*() { return str_; }
00998 const char* operator*() const { return str_; }
00999 int length() const { return length_; }
01000 private:
01001 char* str_;
01002 int length_;
01003
01004
01005 Utf8Value(const Utf8Value&);
01006 void operator=(const Utf8Value&);
01007 };
01008
01016 class V8EXPORT AsciiValue {
01017 public:
01018 explicit AsciiValue(Handle<v8::Value> obj);
01019 ~AsciiValue();
01020 char* operator*() { return str_; }
01021 const char* operator*() const { return str_; }
01022 int length() const { return length_; }
01023 private:
01024 char* str_;
01025 int length_;
01026
01027
01028 AsciiValue(const AsciiValue&);
01029 void operator=(const AsciiValue&);
01030 };
01031
01038 class V8EXPORT Value {
01039 public:
01040 explicit Value(Handle<v8::Value> obj);
01041 ~Value();
01042 uint16_t* operator*() { return str_; }
01043 const uint16_t* operator*() const { return str_; }
01044 int length() const { return length_; }
01045 private:
01046 uint16_t* str_;
01047 int length_;
01048
01049
01050 Value(const Value&);
01051 void operator=(const Value&);
01052 };
01053
01054 private:
01055 void VerifyExternalStringResource(ExternalStringResource* val) const;
01056 static void CheckCast(v8::Value* obj);
01057 };
01058
01059
01063 class V8EXPORT Number : public Primitive {
01064 public:
01065 double Value() const;
01066 static Local<Number> New(double value);
01067 static inline Number* Cast(v8::Value* obj);
01068 private:
01069 Number();
01070 static void CheckCast(v8::Value* obj);
01071 };
01072
01073
01077 class V8EXPORT Integer : public Number {
01078 public:
01079 static Local<Integer> New(int32_t value);
01080 static Local<Integer> NewFromUnsigned(uint32_t value);
01081 int64_t Value() const;
01082 static inline Integer* Cast(v8::Value* obj);
01083 private:
01084 Integer();
01085 static void CheckCast(v8::Value* obj);
01086 };
01087
01088
01092 class V8EXPORT Int32 : public Integer {
01093 public:
01094 int32_t Value() const;
01095 private:
01096 Int32();
01097 };
01098
01099
01103 class V8EXPORT Uint32 : public Integer {
01104 public:
01105 uint32_t Value() const;
01106 private:
01107 Uint32();
01108 };
01109
01110
01114 class V8EXPORT Date : public Value {
01115 public:
01116 static Local<Value> New(double time);
01117
01122 double NumberValue() const;
01123
01124 static inline Date* Cast(v8::Value* obj);
01125 private:
01126 static void CheckCast(v8::Value* obj);
01127 };
01128
01129
01130 enum PropertyAttribute {
01131 None = 0,
01132 ReadOnly = 1 << 0,
01133 DontEnum = 1 << 1,
01134 DontDelete = 1 << 2
01135 };
01136
01137 enum ExternalArrayType {
01138 kExternalByteArray = 1,
01139 kExternalUnsignedByteArray,
01140 kExternalShortArray,
01141 kExternalUnsignedShortArray,
01142 kExternalIntArray,
01143 kExternalUnsignedIntArray,
01144 kExternalFloatArray
01145 };
01146
01150 class V8EXPORT Object : public Value {
01151 public:
01152 bool Set(Handle<Value> key,
01153 Handle<Value> value,
01154 PropertyAttribute attribs = None);
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164 bool ForceSet(Handle<Value> key,
01165 Handle<Value> value,
01166 PropertyAttribute attribs = None);
01167
01168 Local<Value> Get(Handle<Value> key);
01169
01170
01171
01172 bool Has(Handle<String> key);
01173
01174 bool Delete(Handle<String> key);
01175
01176
01177
01178 bool ForceDelete(Handle<Value> key);
01179
01180 bool Has(uint32_t index);
01181
01182 bool Delete(uint32_t index);
01183
01190 Local<Array> GetPropertyNames();
01191
01197 Local<Value> GetPrototype();
01198
01203 Local<Object> FindInstanceInPrototypeChain(Handle<FunctionTemplate> tmpl);
01204
01210 Local<String> ObjectProtoToString();
01211
01213 int InternalFieldCount();
01215 inline Local<Value> GetInternalField(int index);
01217 void SetInternalField(int index, Handle<Value> value);
01218
01220 inline void* GetPointerFromInternalField(int index);
01221
01223 void SetPointerInInternalField(int index, void* value);
01224
01225
01226 bool HasRealNamedProperty(Handle<String> key);
01227 bool HasRealIndexedProperty(uint32_t index);
01228 bool HasRealNamedCallbackProperty(Handle<String> key);
01229
01234 Local<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
01235
01241 Local<Value> GetRealNamedProperty(Handle<String> key);
01242
01244 bool HasNamedLookupInterceptor();
01245
01247 bool HasIndexedLookupInterceptor();
01248
01254 void TurnOnAccessCheck();
01255
01263 int GetIdentityHash();
01264
01271 bool SetHiddenValue(Handle<String> key, Handle<Value> value);
01272 Local<Value> GetHiddenValue(Handle<String> key);
01273 bool DeleteHiddenValue(Handle<String> key);
01274
01282 bool IsDirty();
01283
01288 Local<Object> Clone();
01289
01297 void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
01298
01306 void SetIndexedPropertiesToExternalArrayData(void* data,
01307 ExternalArrayType array_type,
01308 int number_of_elements);
01309
01310 static Local<Object> New();
01311 static inline Object* Cast(Value* obj);
01312 private:
01313 Object();
01314 static void CheckCast(Value* obj);
01315 Local<Value> CheckedGetInternalField(int index);
01316 void* SlowGetPointerFromInternalField(int index);
01317
01322 inline Local<Value> UncheckedGetInternalField(int index);
01323 };
01324
01325
01329 class V8EXPORT Array : public Object {
01330 public:
01331 uint32_t Length() const;
01332
01337 Local<Object> CloneElementAt(uint32_t index);
01338
01339 static Local<Array> New(int length = 0);
01340 static inline Array* Cast(Value* obj);
01341 private:
01342 Array();
01343 static void CheckCast(Value* obj);
01344 };
01345
01346
01350 class V8EXPORT Function : public Object {
01351 public:
01352 Local<Object> NewInstance() const;
01353 Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
01354 Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]);
01355 void SetName(Handle<String> name);
01356 Handle<Value> GetName() const;
01357 static inline Function* Cast(Value* obj);
01358 private:
01359 Function();
01360 static void CheckCast(Value* obj);
01361 };
01362
01363
01375 class V8EXPORT External : public Value {
01376 public:
01377 static Local<Value> Wrap(void* data);
01378 static inline void* Unwrap(Handle<Value> obj);
01379
01380 static Local<External> New(void* value);
01381 static inline External* Cast(Value* obj);
01382 void* Value() const;
01383 private:
01384 External();
01385 static void CheckCast(v8::Value* obj);
01386 static inline void* QuickUnwrap(Handle<v8::Value> obj);
01387 static void* FullUnwrap(Handle<v8::Value> obj);
01388 };
01389
01390
01391
01392
01393
01397 class V8EXPORT Template : public Data {
01398 public:
01400 void Set(Handle<String> name, Handle<Data> value,
01401 PropertyAttribute attributes = None);
01402 inline void Set(const char* name, Handle<Data> value);
01403 private:
01404 Template();
01405
01406 friend class ObjectTemplate;
01407 friend class FunctionTemplate;
01408 };
01409
01410
01417 class V8EXPORT Arguments {
01418 public:
01419 inline int Length() const;
01420 inline Local<Value> operator[](int i) const;
01421 inline Local<Function> Callee() const;
01422 inline Local<Object> This() const;
01423 inline Local<Object> Holder() const;
01424 inline bool IsConstructCall() const;
01425 inline Local<Value> Data() const;
01426 private:
01427 Arguments();
01428 friend class ImplementationUtilities;
01429 inline Arguments(Local<Value> data,
01430 Local<Object> holder,
01431 Local<Function> callee,
01432 bool is_construct_call,
01433 void** values, int length);
01434 Local<Value> data_;
01435 Local<Object> holder_;
01436 Local<Function> callee_;
01437 bool is_construct_call_;
01438 void** values_;
01439 int length_;
01440 };
01441
01442
01447 class V8EXPORT AccessorInfo {
01448 public:
01449 inline AccessorInfo(internal::Object** args)
01450 : args_(args) { }
01451 inline Local<Value> Data() const;
01452 inline Local<Object> This() const;
01453 inline Local<Object> Holder() const;
01454 private:
01455 internal::Object** args_;
01456 };
01457
01458
01459 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
01460
01461 typedef int (*LookupCallback)(Local<Object> self, Local<String> name);
01462
01467 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
01468 const AccessorInfo& info);
01469
01470
01471 typedef void (*AccessorSetter)(Local<String> property,
01472 Local<Value> value,
01473 const AccessorInfo& info);
01474
01475
01480 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
01481 const AccessorInfo& info);
01482
01483
01488 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
01489 Local<Value> value,
01490 const AccessorInfo& info);
01491
01492
01497 typedef Handle<Boolean> (*NamedPropertyQuery)(Local<String> property,
01498 const AccessorInfo& info);
01499
01500
01506 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
01507 const AccessorInfo& info);
01508
01513 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
01514
01515
01520 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
01521 const AccessorInfo& info);
01522
01523
01528 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
01529 Local<Value> value,
01530 const AccessorInfo& info);
01531
01532
01537 typedef Handle<Boolean> (*IndexedPropertyQuery)(uint32_t index,
01538 const AccessorInfo& info);
01539
01545 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
01546 const AccessorInfo& info);
01547
01552 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
01553
01554
01568 enum AccessControl {
01569 DEFAULT = 0,
01570 ALL_CAN_READ = 1,
01571 ALL_CAN_WRITE = 1 << 1,
01572 PROHIBITS_OVERWRITING = 1 << 2
01573 };
01574
01575
01579 enum AccessType {
01580 ACCESS_GET,
01581 ACCESS_SET,
01582 ACCESS_HAS,
01583 ACCESS_DELETE,
01584 ACCESS_KEYS
01585 };
01586
01587
01592 typedef bool (*NamedSecurityCallback)(Local<Object> host,
01593 Local<Value> key,
01594 AccessType type,
01595 Local<Value> data);
01596
01597
01602 typedef bool (*IndexedSecurityCallback)(Local<Object> host,
01603 uint32_t index,
01604 AccessType type,
01605 Local<Value> data);
01606
01607
01700 class V8EXPORT FunctionTemplate : public Template {
01701 public:
01703 static Local<FunctionTemplate> New(
01704 InvocationCallback callback = 0,
01705 Handle<Value> data = Handle<Value>(),
01706 Handle<Signature> signature = Handle<Signature>());
01708 Local<Function> GetFunction();
01709
01715 void SetCallHandler(InvocationCallback callback,
01716 Handle<Value> data = Handle<Value>());
01717
01719 Local<ObjectTemplate> InstanceTemplate();
01720
01722 void Inherit(Handle<FunctionTemplate> parent);
01723
01728 Local<ObjectTemplate> PrototypeTemplate();
01729
01730
01736 void SetClassName(Handle<String> name);
01737
01750 void SetHiddenPrototype(bool value);
01751
01756 bool HasInstance(Handle<Value> object);
01757
01758 private:
01759 FunctionTemplate();
01760 void AddInstancePropertyAccessor(Handle<String> name,
01761 AccessorGetter getter,
01762 AccessorSetter setter,
01763 Handle<Value> data,
01764 AccessControl settings,
01765 PropertyAttribute attributes);
01766 void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
01767 NamedPropertySetter setter,
01768 NamedPropertyQuery query,
01769 NamedPropertyDeleter remover,
01770 NamedPropertyEnumerator enumerator,
01771 Handle<Value> data);
01772 void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
01773 IndexedPropertySetter setter,
01774 IndexedPropertyQuery query,
01775 IndexedPropertyDeleter remover,
01776 IndexedPropertyEnumerator enumerator,
01777 Handle<Value> data);
01778 void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
01779 Handle<Value> data);
01780
01781 friend class Context;
01782 friend class ObjectTemplate;
01783 };
01784
01785
01792 class V8EXPORT ObjectTemplate : public Template {
01793 public:
01795 static Local<ObjectTemplate> New();
01796
01798 Local<Object> NewInstance();
01799
01824 void SetAccessor(Handle<String> name,
01825 AccessorGetter getter,
01826 AccessorSetter setter = 0,
01827 Handle<Value> data = Handle<Value>(),
01828 AccessControl settings = DEFAULT,
01829 PropertyAttribute attribute = None);
01830
01847 void SetNamedPropertyHandler(NamedPropertyGetter getter,
01848 NamedPropertySetter setter = 0,
01849 NamedPropertyQuery query = 0,
01850 NamedPropertyDeleter deleter = 0,
01851 NamedPropertyEnumerator enumerator = 0,
01852 Handle<Value> data = Handle<Value>());
01853
01870 void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
01871 IndexedPropertySetter setter = 0,
01872 IndexedPropertyQuery query = 0,
01873 IndexedPropertyDeleter deleter = 0,
01874 IndexedPropertyEnumerator enumerator = 0,
01875 Handle<Value> data = Handle<Value>());
01882 void SetCallAsFunctionHandler(InvocationCallback callback,
01883 Handle<Value> data = Handle<Value>());
01884
01893 void MarkAsUndetectable();
01894
01906 void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
01907 IndexedSecurityCallback indexed_handler,
01908 Handle<Value> data = Handle<Value>(),
01909 bool turned_on_by_default = true);
01910
01915 int InternalFieldCount();
01916
01921 void SetInternalFieldCount(int value);
01922
01923 private:
01924 ObjectTemplate();
01925 static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
01926 friend class FunctionTemplate;
01927 };
01928
01929
01934 class V8EXPORT Signature : public Data {
01935 public:
01936 static Local<Signature> New(Handle<FunctionTemplate> receiver =
01937 Handle<FunctionTemplate>(),
01938 int argc = 0,
01939 Handle<FunctionTemplate> argv[] = 0);
01940 private:
01941 Signature();
01942 };
01943
01944
01949 class V8EXPORT TypeSwitch : public Data {
01950 public:
01951 static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
01952 static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
01953 int match(Handle<Value> value);
01954 private:
01955 TypeSwitch();
01956 };
01957
01958
01959
01960
01961
01965 class V8EXPORT Extension {
01966 public:
01967 Extension(const char* name,
01968 const char* source = 0,
01969 int dep_count = 0,
01970 const char** deps = 0);
01971 virtual ~Extension() { }
01972 virtual v8::Handle<v8::FunctionTemplate>
01973 GetNativeFunction(v8::Handle<v8::String> name) {
01974 return v8::Handle<v8::FunctionTemplate>();
01975 }
01976
01977 const char* name() { return name_; }
01978 const char* source() { return source_; }
01979 int dependency_count() { return dep_count_; }
01980 const char** dependencies() { return deps_; }
01981 void set_auto_enable(bool value) { auto_enable_ = value; }
01982 bool auto_enable() { return auto_enable_; }
01983
01984 private:
01985 const char* name_;
01986 const char* source_;
01987 int dep_count_;
01988 const char** deps_;
01989 bool auto_enable_;
01990
01991
01992 Extension(const Extension&);
01993 void operator=(const Extension&);
01994 };
01995
01996
01997 void V8EXPORT RegisterExtension(Extension* extension);
01998
01999
02003 class V8EXPORT DeclareExtension {
02004 public:
02005 inline DeclareExtension(Extension* extension) {
02006 RegisterExtension(extension);
02007 }
02008 };
02009
02010
02011
02012
02013
02014 Handle<Primitive> V8EXPORT Undefined();
02015 Handle<Primitive> V8EXPORT Null();
02016 Handle<Boolean> V8EXPORT True();
02017 Handle<Boolean> V8EXPORT False();
02018
02019
02029 class V8EXPORT ResourceConstraints {
02030 public:
02031 ResourceConstraints();
02032 int max_young_space_size() const { return max_young_space_size_; }
02033 void set_max_young_space_size(int value) { max_young_space_size_ = value; }
02034 int max_old_space_size() const { return max_old_space_size_; }
02035 void set_max_old_space_size(int value) { max_old_space_size_ = value; }
02036 uint32_t* stack_limit() const { return stack_limit_; }
02037
02038 void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
02039 private:
02040 int max_young_space_size_;
02041 int max_old_space_size_;
02042 uint32_t* stack_limit_;
02043 };
02044
02045
02046 bool SetResourceConstraints(ResourceConstraints* constraints);
02047
02048
02049
02050
02051
02052 typedef void (*FatalErrorCallback)(const char* location, const char* message);
02053
02054
02055 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
02056
02057
02064 Handle<Value> V8EXPORT ThrowException(Handle<Value> exception);
02065
02070 class V8EXPORT Exception {
02071 public:
02072 static Local<Value> RangeError(Handle<String> message);
02073 static Local<Value> ReferenceError(Handle<String> message);
02074 static Local<Value> SyntaxError(Handle<String> message);
02075 static Local<Value> TypeError(Handle<String> message);
02076 static Local<Value> Error(Handle<String> message);
02077 };
02078
02079
02080
02081
02082 typedef int* (*CounterLookupCallback)(const char* name);
02083
02084 typedef void* (*CreateHistogramCallback)(const char* name,
02085 int min,
02086 int max,
02087 size_t buckets);
02088
02089 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
02090
02091
02092 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
02093 AccessType type,
02094 Local<Value> data);
02095
02096
02097
02105 typedef void (*GCCallback)();
02106
02107
02108
02109
02114 typedef Persistent<Context> (*ContextGenerator)();
02115
02116
02125 enum ProfilerModules {
02126 PROFILER_MODULE_NONE = 0,
02127 PROFILER_MODULE_CPU = 1,
02128 PROFILER_MODULE_HEAP_STATS = 1 << 1,
02129 PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2,
02130 PROFILER_MODULE_HEAP_SNAPSHOT = 1 << 16
02131 };
02132
02133
02140 class V8EXPORT HeapStatistics {
02141 public:
02142 HeapStatistics();
02143 size_t total_heap_size() { return total_heap_size_; }
02144 size_t used_heap_size() { return used_heap_size_; }
02145
02146 private:
02147 void set_total_heap_size(size_t size) { total_heap_size_ = size; }
02148 void set_used_heap_size(size_t size) { used_heap_size_ = size; }
02149
02150 size_t total_heap_size_;
02151 size_t used_heap_size_;
02152
02153 friend class V8;
02154 };
02155
02156
02160 class V8EXPORT V8 {
02161 public:
02163 static void SetFatalErrorHandler(FatalErrorCallback that);
02164
02177 static void IgnoreOutOfMemoryException();
02178
02183 static bool IsDead();
02184
02191 static bool AddMessageListener(MessageCallback that,
02192 Handle<Value> data = Handle<Value>());
02193
02197 static void RemoveMessageListeners(MessageCallback that);
02198
02202 static void SetFlagsFromString(const char* str, int length);
02203
02207 static void SetFlagsFromCommandLine(int* argc,
02208 char** argv,
02209 bool remove_flags);
02210
02212 static const char* GetVersion();
02213
02218 static void SetCounterFunction(CounterLookupCallback);
02219
02226 static void SetCreateHistogramFunction(CreateHistogramCallback);
02227 static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
02228
02233 static void EnableSlidingStateWindow();
02234
02236 static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
02237
02245 static void SetGlobalGCPrologueCallback(GCCallback);
02246
02254 static void SetGlobalGCEpilogueCallback(GCCallback);
02255
02264 static void AddObjectGroup(Persistent<Value>* objects, size_t length);
02265
02271 static bool Initialize();
02272
02287 static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
02288
02298 static void PauseProfiler();
02299
02304 static void ResumeProfiler();
02305
02309 static bool IsProfilerPaused();
02310
02318 static void ResumeProfilerEx(int flags);
02319
02327 static void PauseProfilerEx(int flags);
02328
02335 static int GetActiveProfilerModules();
02336
02352 static int GetLogLines(int from_pos, char* dest_buf, int max_size);
02353
02360 static int GetCurrentThreadId();
02361
02386 static void TerminateExecution(int thread_id);
02387
02394 static void TerminateExecution();
02395
02405 static bool Dispose();
02406
02410 static void GetHeapStatistics(HeapStatistics* heap_statistics);
02411
02420 static bool IdleNotification();
02421
02426 static void LowMemoryNotification();
02427
02428 private:
02429 V8();
02430
02431 static internal::Object** GlobalizeReference(internal::Object** handle);
02432 static void DisposeGlobal(internal::Object** global_handle);
02433 static void MakeWeak(internal::Object** global_handle,
02434 void* data,
02435 WeakReferenceCallback);
02436 static void ClearWeak(internal::Object** global_handle);
02437 static bool IsGlobalNearDeath(internal::Object** global_handle);
02438 static bool IsGlobalWeak(internal::Object** global_handle);
02439
02440 template <class T> friend class Handle;
02441 template <class T> friend class Local;
02442 template <class T> friend class Persistent;
02443 friend class Context;
02444 };
02445
02446
02450 class V8EXPORT TryCatch {
02451 public:
02452
02456 TryCatch();
02457
02461 ~TryCatch();
02462
02466 bool HasCaught() const;
02467
02481 bool CanContinue() const;
02482
02490 Handle<Value> ReThrow();
02491
02498 Local<Value> Exception() const;
02499
02504 Local<Value> StackTrace() const;
02505
02513 Local<v8::Message> Message() const;
02514
02524 void Reset();
02525
02534 void SetVerbose(bool value);
02535
02541 void SetCaptureMessage(bool value);
02542
02543 private:
02544 void* next_;
02545 void* exception_;
02546 void* message_;
02547 bool is_verbose_ : 1;
02548 bool can_continue_ : 1;
02549 bool capture_message_ : 1;
02550 bool rethrow_ : 1;
02551
02552 friend class v8::internal::Top;
02553 };
02554
02555
02556
02557
02558
02562 class V8EXPORT ExtensionConfiguration {
02563 public:
02564 ExtensionConfiguration(int name_count, const char* names[])
02565 : name_count_(name_count), names_(names) { }
02566 private:
02567 friend class ImplementationUtilities;
02568 int name_count_;
02569 const char** names_;
02570 };
02571
02572
02577 class V8EXPORT Context {
02578 public:
02580 Local<Object> Global();
02581
02586 void DetachGlobal();
02587
02589 static Persistent<Context> New(
02590 ExtensionConfiguration* extensions = 0,
02591 Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
02592 Handle<Value> global_object = Handle<Value>());
02593
02595 static Local<Context> GetEntered();
02596
02598 static Local<Context> GetCurrent();
02599
02605 static Local<Context> GetCalling();
02606
02611 void SetSecurityToken(Handle<Value> token);
02612
02614 void UseDefaultSecurityToken();
02615
02617 Handle<Value> GetSecurityToken();
02618
02625 void Enter();
02626
02631 void Exit();
02632
02634 bool HasOutOfMemoryException();
02635
02637 static bool InContext();
02638
02644 void SetData(Handle<String> data);
02645 Local<Value> GetData();
02646
02651 class V8EXPORT Scope {
02652 public:
02653 inline Scope(Handle<Context> context) : context_(context) {
02654 context_->Enter();
02655 }
02656 inline ~Scope() { context_->Exit(); }
02657 private:
02658 Handle<Context> context_;
02659 };
02660
02661 private:
02662 friend class Value;
02663 friend class Script;
02664 friend class Object;
02665 friend class Function;
02666 };
02667
02668
02737 class V8EXPORT Unlocker {
02738 public:
02739 Unlocker();
02740 ~Unlocker();
02741 };
02742
02743
02744 class V8EXPORT Locker {
02745 public:
02746 Locker();
02747 ~Locker();
02748
02756 static void StartPreemption(int every_n_ms);
02757
02761 static void StopPreemption();
02762
02766 static bool IsLocked();
02767
02771 static bool IsActive() { return active_; }
02772
02773 private:
02774 bool has_lock_;
02775 bool top_level_;
02776
02777 static bool active_;
02778
02779
02780 Locker(const Locker&);
02781 void operator=(const Locker&);
02782 };
02783
02784
02785
02786
02787
02788
02789 namespace internal {
02790
02791
02792
02793 const int kHeapObjectTag = 1;
02794 const int kHeapObjectTagSize = 2;
02795 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
02796
02797
02798 const int kSmiTag = 0;
02799 const int kSmiTagSize = 1;
02800 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
02801
02802 template <size_t ptr_size> struct SmiConstants;
02803
02804
02805 template <> struct SmiConstants<4> {
02806 static const int kSmiShiftSize = 0;
02807 static const int kSmiValueSize = 31;
02808 static inline int SmiToInt(internal::Object* value) {
02809 int shift_bits = kSmiTagSize + kSmiShiftSize;
02810
02811 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
02812 }
02813 };
02814
02815
02816 template <> struct SmiConstants<8> {
02817 static const int kSmiShiftSize = 31;
02818 static const int kSmiValueSize = 32;
02819 static inline int SmiToInt(internal::Object* value) {
02820 int shift_bits = kSmiTagSize + kSmiShiftSize;
02821
02822 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
02823 }
02824 };
02825
02826 const int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize;
02827 const int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize;
02828
02829 template <size_t ptr_size> struct InternalConstants;
02830
02831
02832 template <> struct InternalConstants<4> {
02833 static const int kStringResourceOffset = 3 * sizeof(void*);
02834 };
02835
02836
02837 template <> struct InternalConstants<8> {
02838 static const int kStringResourceOffset = 2 * sizeof(void*);
02839 };
02840
02846 class Internals {
02847 public:
02848
02849
02850
02851 static const int kHeapObjectMapOffset = 0;
02852 static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int);
02853 static const int kStringResourceOffset =
02854 InternalConstants<sizeof(void*)>::kStringResourceOffset;
02855
02856 static const int kProxyProxyOffset = sizeof(void*);
02857 static const int kJSObjectHeaderSize = 3 * sizeof(void*);
02858 static const int kFullStringRepresentationMask = 0x07;
02859 static const int kExternalTwoByteRepresentationTag = 0x03;
02860
02861
02862
02863 V8EXPORT static int kJSObjectType;
02864 V8EXPORT static int kFirstNonstringType;
02865 V8EXPORT static int kProxyType;
02866
02867 static inline bool HasHeapObjectTag(internal::Object* value) {
02868 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
02869 kHeapObjectTag);
02870 }
02871
02872 static inline bool HasSmiTag(internal::Object* value) {
02873 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
02874 }
02875
02876 static inline int SmiValue(internal::Object* value) {
02877 return SmiConstants<sizeof(void*)>::SmiToInt(value);
02878 }
02879
02880 static inline int GetInstanceType(internal::Object* obj) {
02881 typedef internal::Object O;
02882 O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
02883 return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
02884 }
02885
02886 static inline void* GetExternalPointer(internal::Object* obj) {
02887 if (HasSmiTag(obj)) {
02888 return obj;
02889 } else if (GetInstanceType(obj) == kProxyType) {
02890 return ReadField<void*>(obj, kProxyProxyOffset);
02891 } else {
02892 return NULL;
02893 }
02894 }
02895
02896 static inline bool IsExternalTwoByteString(int instance_type) {
02897 int representation = (instance_type & kFullStringRepresentationMask);
02898 return representation == kExternalTwoByteRepresentationTag;
02899 }
02900
02901 template <typename T>
02902 static inline T ReadField(Object* ptr, int offset) {
02903 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
02904 return *reinterpret_cast<T*>(addr);
02905 }
02906
02907 };
02908
02909 }
02910
02911
02912 template <class T>
02913 Handle<T>::Handle() : val_(0) { }
02914
02915
02916 template <class T>
02917 Local<T>::Local() : Handle<T>() { }
02918
02919
02920 template <class T>
02921 Local<T> Local<T>::New(Handle<T> that) {
02922 if (that.IsEmpty()) return Local<T>();
02923 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
02924 return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
02925 }
02926
02927
02928 template <class T>
02929 Persistent<T> Persistent<T>::New(Handle<T> that) {
02930 if (that.IsEmpty()) return Persistent<T>();
02931 internal::Object** p = reinterpret_cast<internal::Object**>(*that);
02932 return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
02933 }
02934
02935
02936 template <class T>
02937 bool Persistent<T>::IsNearDeath() const {
02938 if (this->IsEmpty()) return false;
02939 return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
02940 }
02941
02942
02943 template <class T>
02944 bool Persistent<T>::IsWeak() const {
02945 if (this->IsEmpty()) return false;
02946 return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
02947 }
02948
02949
02950 template <class T>
02951 void Persistent<T>::Dispose() {
02952 if (this->IsEmpty()) return;
02953 V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
02954 }
02955
02956
02957 template <class T>
02958 Persistent<T>::Persistent() : Handle<T>() { }
02959
02960 template <class T>
02961 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
02962 V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
02963 parameters,
02964 callback);
02965 }
02966
02967 template <class T>
02968 void Persistent<T>::ClearWeak() {
02969 V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
02970 }
02971
02972 Local<Value> Arguments::operator[](int i) const {
02973 if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
02974 return Local<Value>(reinterpret_cast<Value*>(values_ - i));
02975 }
02976
02977
02978 Local<Function> Arguments::Callee() const {
02979 return callee_;
02980 }
02981
02982
02983 Local<Object> Arguments::This() const {
02984 return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
02985 }
02986
02987
02988 Local<Object> Arguments::Holder() const {
02989 return holder_;
02990 }
02991
02992
02993 Local<Value> Arguments::Data() const {
02994 return data_;
02995 }
02996
02997
02998 bool Arguments::IsConstructCall() const {
02999 return is_construct_call_;
03000 }
03001
03002
03003 int Arguments::Length() const {
03004 return length_;
03005 }
03006
03007
03008 template <class T>
03009 Local<T> HandleScope::Close(Handle<T> value) {
03010 internal::Object** before = reinterpret_cast<internal::Object**>(*value);
03011 internal::Object** after = RawClose(before);
03012 return Local<T>(reinterpret_cast<T*>(after));
03013 }
03014
03015 Handle<Value> ScriptOrigin::ResourceName() const {
03016 return resource_name_;
03017 }
03018
03019
03020 Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
03021 return resource_line_offset_;
03022 }
03023
03024
03025 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
03026 return resource_column_offset_;
03027 }
03028
03029
03030 Handle<Boolean> Boolean::New(bool value) {
03031 return value ? True() : False();
03032 }
03033
03034
03035 void Template::Set(const char* name, v8::Handle<Data> value) {
03036 Set(v8::String::New(name), value);
03037 }
03038
03039
03040 Local<Value> Object::GetInternalField(int index) {
03041 #ifndef V8_ENABLE_CHECKS
03042 Local<Value> quick_result = UncheckedGetInternalField(index);
03043 if (!quick_result.IsEmpty()) return quick_result;
03044 #endif
03045 return CheckedGetInternalField(index);
03046 }
03047
03048
03049 Local<Value> Object::UncheckedGetInternalField(int index) {
03050 typedef internal::Object O;
03051 typedef internal::Internals I;
03052 O* obj = *reinterpret_cast<O**>(this);
03053 if (I::GetInstanceType(obj) == I::kJSObjectType) {
03054
03055
03056
03057 int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index);
03058 O* value = I::ReadField<O*>(obj, offset);
03059 O** result = HandleScope::CreateHandle(value);
03060 return Local<Value>(reinterpret_cast<Value*>(result));
03061 } else {
03062 return Local<Value>();
03063 }
03064 }
03065
03066
03067 void* External::Unwrap(Handle<v8::Value> obj) {
03068 #ifdef V8_ENABLE_CHECKS
03069 return FullUnwrap(obj);
03070 #else
03071 return QuickUnwrap(obj);
03072 #endif
03073 }
03074
03075
03076 void* External::QuickUnwrap(Handle<v8::Value> wrapper) {
03077 typedef internal::Object O;
03078 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
03079 return internal::Internals::GetExternalPointer(obj);
03080 }
03081
03082
03083 void* Object::GetPointerFromInternalField(int index) {
03084 typedef internal::Object O;
03085 typedef internal::Internals I;
03086
03087 O* obj = *reinterpret_cast<O**>(this);
03088
03089 if (I::GetInstanceType(obj) == I::kJSObjectType) {
03090
03091
03092
03093 int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index);
03094 O* value = I::ReadField<O*>(obj, offset);
03095 return I::GetExternalPointer(value);
03096 }
03097
03098 return SlowGetPointerFromInternalField(index);
03099 }
03100
03101
03102 String* String::Cast(v8::Value* value) {
03103 #ifdef V8_ENABLE_CHECKS
03104 CheckCast(value);
03105 #endif
03106 return static_cast<String*>(value);
03107 }
03108
03109
03110 String::ExternalStringResource* String::GetExternalStringResource() const {
03111 typedef internal::Object O;
03112 typedef internal::Internals I;
03113 O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
03114 String::ExternalStringResource* result;
03115 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
03116 void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
03117 result = reinterpret_cast<String::ExternalStringResource*>(value);
03118 } else {
03119 result = NULL;
03120 }
03121 #ifdef V8_ENABLE_CHECKS
03122 VerifyExternalStringResource(result);
03123 #endif
03124 return result;
03125 }
03126
03127
03128 bool Value::IsString() const {
03129 #ifdef V8_ENABLE_CHECKS
03130 return FullIsString();
03131 #else
03132 return QuickIsString();
03133 #endif
03134 }
03135
03136 bool Value::QuickIsString() const {
03137 typedef internal::Object O;
03138 typedef internal::Internals I;
03139 O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
03140 if (!I::HasHeapObjectTag(obj)) return false;
03141 return (I::GetInstanceType(obj) < I::kFirstNonstringType);
03142 }
03143
03144
03145 Number* Number::Cast(v8::Value* value) {
03146 #ifdef V8_ENABLE_CHECKS
03147 CheckCast(value);
03148 #endif
03149 return static_cast<Number*>(value);
03150 }
03151
03152
03153 Integer* Integer::Cast(v8::Value* value) {
03154 #ifdef V8_ENABLE_CHECKS
03155 CheckCast(value);
03156 #endif
03157 return static_cast<Integer*>(value);
03158 }
03159
03160
03161 Date* Date::Cast(v8::Value* value) {
03162 #ifdef V8_ENABLE_CHECKS
03163 CheckCast(value);
03164 #endif
03165 return static_cast<Date*>(value);
03166 }
03167
03168
03169 Object* Object::Cast(v8::Value* value) {
03170 #ifdef V8_ENABLE_CHECKS
03171 CheckCast(value);
03172 #endif
03173 return static_cast<Object*>(value);
03174 }
03175
03176
03177 Array* Array::Cast(v8::Value* value) {
03178 #ifdef V8_ENABLE_CHECKS
03179 CheckCast(value);
03180 #endif
03181 return static_cast<Array*>(value);
03182 }
03183
03184
03185 Function* Function::Cast(v8::Value* value) {
03186 #ifdef V8_ENABLE_CHECKS
03187 CheckCast(value);
03188 #endif
03189 return static_cast<Function*>(value);
03190 }
03191
03192
03193 External* External::Cast(v8::Value* value) {
03194 #ifdef V8_ENABLE_CHECKS
03195 CheckCast(value);
03196 #endif
03197 return static_cast<External*>(value);
03198 }
03199
03200
03201 Local<Value> AccessorInfo::Data() const {
03202 return Local<Value>(reinterpret_cast<Value*>(&args_[-3]));
03203 }
03204
03205
03206 Local<Object> AccessorInfo::This() const {
03207 return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
03208 }
03209
03210
03211 Local<Object> AccessorInfo::Holder() const {
03212 return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
03213 }
03214
03215
03228 }
03229
03230
03231 #undef V8EXPORT
03232 #undef V8EXPORT_INLINE
03233 #undef TYPE_CHECK
03234
03235
03236 #endif // V8_H_