• Main Page
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

/home/ondras/svn/v8/include/v8.h

00001 // Copyright 2011 the V8 project authors. All rights reserved.
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions are
00004 // met:
00005 //
00006 //     * Redistributions of source code must retain the above copyright
00007 //       notice, this list of conditions and the following disclaimer.
00008 //     * Redistributions in binary form must reproduce the above
00009 //       copyright notice, this list of conditions and the following
00010 //       disclaimer in the documentation and/or other materials provided
00011 //       with the distribution.
00012 //     * Neither the name of Google Inc. nor the names of its
00013 //       contributors may be used to endorse or promote products derived
00014 //       from this software without specific prior written permission.
00015 //
00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 
00038 #ifndef V8_H_
00039 #define V8_H_
00040 
00041 #include "v8stdint.h"
00042 
00043 #ifdef _WIN32
00044 
00045 // Setup for Windows DLL export/import. When building the V8 DLL the
00046 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
00047 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
00048 // static library or building a program which uses the V8 static library neither
00049 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
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 // Setup for Linux shared library export. There is no need to distinguish
00066 // between building or using the V8 shared library, but we should not
00067 // export symbols when we are building a static library.
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 StringObject;
00084 class Value;
00085 class Utils;
00086 class Number;
00087 class NumberObject;
00088 class Object;
00089 class Array;
00090 class Int32;
00091 class Uint32;
00092 class External;
00093 class Primitive;
00094 class Boolean;
00095 class BooleanObject;
00096 class Integer;
00097 class Function;
00098 class Date;
00099 class ImplementationUtilities;
00100 class Signature;
00101 template <class T> class Handle;
00102 template <class T> class Local;
00103 template <class T> class Persistent;
00104 class FunctionTemplate;
00105 class ObjectTemplate;
00106 class Data;
00107 class AccessorInfo;
00108 class StackTrace;
00109 class StackFrame;
00110 
00111 namespace internal {
00112 
00113 class Arguments;
00114 class Object;
00115 class Heap;
00116 class HeapObject;
00117 class Isolate;
00118 }
00119 
00120 
00121 // --- Weak Handles ---
00122 
00123 
00133 typedef void (*WeakReferenceCallback)(Persistent<Value> object,
00134                                       void* parameter);
00135 
00136 
00137 // --- Handles ---
00138 
00139 #define TYPE_CHECK(T, S)                                       \
00140   while (false) {                                              \
00141     *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);      \
00142   }
00143 
00169 template <class T> class Handle {
00170  public:
00174   inline Handle();
00175 
00179   inline explicit Handle(T* val) : val_(val) { }
00180 
00191   template <class S> inline Handle(Handle<S> that)
00192       : val_(reinterpret_cast<T*>(*that)) {
00198     TYPE_CHECK(T, S);
00199   }
00200 
00204   inline bool IsEmpty() const { return val_ == 0; }
00205 
00206   inline T* operator->() const { return val_; }
00207 
00208   inline T* operator*() const { return val_; }
00209 
00213   inline void Clear() { this->val_ = 0; }
00214 
00221   template <class S> inline bool operator==(Handle<S> that) const {
00222     internal::Object** a = reinterpret_cast<internal::Object**>(**this);
00223     internal::Object** b = reinterpret_cast<internal::Object**>(*that);
00224     if (a == 0) return b == 0;
00225     if (b == 0) return false;
00226     return *a == *b;
00227   }
00228 
00235   template <class S> inline bool operator!=(Handle<S> that) const {
00236     return !operator==(that);
00237   }
00238 
00239   template <class S> static inline Handle<T> Cast(Handle<S> that) {
00240 #ifdef V8_ENABLE_CHECKS
00241     // If we're going to perform the type check then we have to check
00242     // that the handle isn't empty before doing the checked cast.
00243     if (that.IsEmpty()) return Handle<T>();
00244 #endif
00245     return Handle<T>(T::Cast(*that));
00246   }
00247 
00248   template <class S> inline Handle<S> As() {
00249     return Handle<S>::Cast(*this);
00250   }
00251 
00252  private:
00253   T* val_;
00254 };
00255 
00256 
00264 template <class T> class Local : public Handle<T> {
00265  public:
00266   inline Local();
00267   template <class S> inline Local(Local<S> that)
00268       : Handle<T>(reinterpret_cast<T*>(*that)) {
00274     TYPE_CHECK(T, S);
00275   }
00276   template <class S> inline Local(S* that) : Handle<T>(that) { }
00277   template <class S> static inline Local<T> Cast(Local<S> that) {
00278 #ifdef V8_ENABLE_CHECKS
00279     // If we're going to perform the type check then we have to check
00280     // that the handle isn't empty before doing the checked cast.
00281     if (that.IsEmpty()) return Local<T>();
00282 #endif
00283     return Local<T>(T::Cast(*that));
00284   }
00285 
00286   template <class S> inline Local<S> As() {
00287     return Local<S>::Cast(*this);
00288   }
00289 
00294   inline static Local<T> New(Handle<T> that);
00295 };
00296 
00297 
00315 template <class T> class Persistent : public Handle<T> {
00316  public:
00321   inline Persistent();
00322 
00334   template <class S> inline Persistent(Persistent<S> that)
00335       : Handle<T>(reinterpret_cast<T*>(*that)) {
00341     TYPE_CHECK(T, S);
00342   }
00343 
00344   template <class S> inline Persistent(S* that) : Handle<T>(that) { }
00345 
00350   template <class S> explicit inline Persistent(Handle<S> that)
00351       : Handle<T>(*that) { }
00352 
00353   template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
00354 #ifdef V8_ENABLE_CHECKS
00355     // If we're going to perform the type check then we have to check
00356     // that the handle isn't empty before doing the checked cast.
00357     if (that.IsEmpty()) return Persistent<T>();
00358 #endif
00359     return Persistent<T>(T::Cast(*that));
00360   }
00361 
00362   template <class S> inline Persistent<S> As() {
00363     return Persistent<S>::Cast(*this);
00364   }
00365 
00370   inline static Persistent<T> New(Handle<T> that);
00371 
00378   inline void Dispose();
00379 
00386   inline void MakeWeak(void* parameters, WeakReferenceCallback callback);
00387 
00389   inline void ClearWeak();
00390 
00398   inline void MarkIndependent();
00399 
00403   inline bool IsNearDeath() const;
00404 
00408   inline bool IsWeak() const;
00409 
00414   inline void SetWrapperClassId(uint16_t class_id);
00415 
00416  private:
00417   friend class ImplementationUtilities;
00418   friend class ObjectTemplate;
00419 };
00420 
00421 
00436 class V8EXPORT HandleScope {
00437  public:
00438   HandleScope();
00439 
00440   ~HandleScope();
00441 
00446   template <class T> Local<T> Close(Handle<T> value);
00447 
00451   static int NumberOfHandles();
00452 
00456   static internal::Object** CreateHandle(internal::Object* value);
00457   // Faster version, uses HeapObject to obtain the current Isolate.
00458   static internal::Object** CreateHandle(internal::HeapObject* value);
00459 
00460  private:
00461   // Make it impossible to create heap-allocated or illegal handle
00462   // scopes by disallowing certain operations.
00463   HandleScope(const HandleScope&);
00464   void operator=(const HandleScope&);
00465   void* operator new(size_t size);
00466   void operator delete(void*, size_t);
00467 
00468   // This Data class is accessible internally as HandleScopeData through a
00469   // typedef in the ImplementationUtilities class.
00470   class V8EXPORT Data {
00471    public:
00472     internal::Object** next;
00473     internal::Object** limit;
00474     int level;
00475     inline void Initialize() {
00476       next = limit = NULL;
00477       level = 0;
00478     }
00479   };
00480 
00481   void Leave();
00482 
00483   internal::Isolate* isolate_;
00484   internal::Object** prev_next_;
00485   internal::Object** prev_limit_;
00486 
00487   // Allow for the active closing of HandleScopes which allows to pass a handle
00488   // from the HandleScope being closed to the next top most HandleScope.
00489   bool is_closed_;
00490   internal::Object** RawClose(internal::Object** value);
00491 
00492   friend class ImplementationUtilities;
00493 };
00494 
00495 
00496 // --- Special objects ---
00497 
00498 
00502 class V8EXPORT Data {
00503  private:
00504   Data();
00505 };
00506 
00507 
00514 class V8EXPORT ScriptData {  // NOLINT
00515  public:
00516   virtual ~ScriptData() { }
00517 
00524   static ScriptData* PreCompile(const char* input, int length);
00525 
00534   static ScriptData* PreCompile(Handle<String> source);
00535 
00543   static ScriptData* New(const char* data, int length);
00544 
00548   virtual int Length() = 0;
00549 
00554   virtual const char* Data() = 0;
00555 
00559   virtual bool HasError() = 0;
00560 };
00561 
00562 
00566 class ScriptOrigin {
00567  public:
00568   inline ScriptOrigin(
00569       Handle<Value> resource_name,
00570       Handle<Integer> resource_line_offset = Handle<Integer>(),
00571       Handle<Integer> resource_column_offset = Handle<Integer>())
00572       : resource_name_(resource_name),
00573         resource_line_offset_(resource_line_offset),
00574         resource_column_offset_(resource_column_offset) { }
00575   inline Handle<Value> ResourceName() const;
00576   inline Handle<Integer> ResourceLineOffset() const;
00577   inline Handle<Integer> ResourceColumnOffset() const;
00578  private:
00579   Handle<Value> resource_name_;
00580   Handle<Integer> resource_line_offset_;
00581   Handle<Integer> resource_column_offset_;
00582 };
00583 
00584 
00588 class V8EXPORT Script {
00589  public:
00605   static Local<Script> New(Handle<String> source,
00606                            ScriptOrigin* origin = NULL,
00607                            ScriptData* pre_data = NULL,
00608                            Handle<String> script_data = Handle<String>());
00609 
00620   static Local<Script> New(Handle<String> source,
00621                            Handle<Value> file_name);
00622 
00639   static Local<Script> Compile(Handle<String> source,
00640                                ScriptOrigin* origin = NULL,
00641                                ScriptData* pre_data = NULL,
00642                                Handle<String> script_data = Handle<String>());
00643 
00657   static Local<Script> Compile(Handle<String> source,
00658                                Handle<Value> file_name,
00659                                Handle<String> script_data = Handle<String>());
00660 
00668   Local<Value> Run();
00669 
00673   Local<Value> Id();
00674 
00680   void SetData(Handle<String> data);
00681 };
00682 
00683 
00687 class V8EXPORT Message {
00688  public:
00689   Local<String> Get() const;
00690   Local<String> GetSourceLine() const;
00691 
00696   Handle<Value> GetScriptResourceName() const;
00697 
00702   Handle<Value> GetScriptData() const;
00703 
00709   Handle<StackTrace> GetStackTrace() const;
00710 
00714   int GetLineNumber() const;
00715 
00720   int GetStartPosition() const;
00721 
00726   int GetEndPosition() const;
00727 
00732   int GetStartColumn() const;
00733 
00738   int GetEndColumn() const;
00739 
00740   // TODO(1245381): Print to a string instead of on a FILE.
00741   static void PrintCurrentStackTrace(FILE* out);
00742 
00743   static const int kNoLineNumberInfo = 0;
00744   static const int kNoColumnInfo = 0;
00745 };
00746 
00747 
00753 class V8EXPORT StackTrace {
00754  public:
00759   enum StackTraceOptions {
00760     kLineNumber = 1,
00761     kColumnOffset = 1 << 1 | kLineNumber,
00762     kScriptName = 1 << 2,
00763     kFunctionName = 1 << 3,
00764     kIsEval = 1 << 4,
00765     kIsConstructor = 1 << 5,
00766     kScriptNameOrSourceURL = 1 << 6,
00767     kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
00768     kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
00769   };
00770 
00774   Local<StackFrame> GetFrame(uint32_t index) const;
00775 
00779   int GetFrameCount() const;
00780 
00784   Local<Array> AsArray();
00785 
00793   static Local<StackTrace> CurrentStackTrace(
00794       int frame_limit,
00795       StackTraceOptions options = kOverview);
00796 };
00797 
00798 
00802 class V8EXPORT StackFrame {
00803  public:
00810   int GetLineNumber() const;
00811 
00819   int GetColumn() const;
00820 
00825   Local<String> GetScriptName() const;
00826 
00832   Local<String> GetScriptNameOrSourceURL() const;
00833 
00837   Local<String> GetFunctionName() const;
00838 
00843   bool IsEval() const;
00844 
00849   bool IsConstructor() const;
00850 };
00851 
00852 
00853 // --- Value ---
00854 
00855 
00859 class Value : public Data {
00860  public:
00865   V8EXPORT bool IsUndefined() const;
00866 
00871   V8EXPORT bool IsNull() const;
00872 
00876   V8EXPORT bool IsTrue() const;
00877 
00881   V8EXPORT bool IsFalse() const;
00882 
00887   inline bool IsString() const;
00888 
00892   V8EXPORT bool IsFunction() const;
00893 
00897   V8EXPORT bool IsArray() const;
00898 
00902   V8EXPORT bool IsObject() const;
00903 
00907   V8EXPORT bool IsBoolean() const;
00908 
00912   V8EXPORT bool IsNumber() const;
00913 
00917   V8EXPORT bool IsExternal() const;
00918 
00922   V8EXPORT bool IsInt32() const;
00923 
00927   V8EXPORT bool IsUint32() const;
00928 
00932   V8EXPORT bool IsDate() const;
00933 
00937   V8EXPORT bool IsBooleanObject() const;
00938 
00942   V8EXPORT bool IsNumberObject() const;
00943 
00947   V8EXPORT bool IsStringObject() const;
00948 
00952   V8EXPORT bool IsNativeError() const;
00953 
00957   V8EXPORT bool IsRegExp() const;
00958 
00959   V8EXPORT Local<Boolean> ToBoolean() const;
00960   V8EXPORT Local<Number> ToNumber() const;
00961   V8EXPORT Local<String> ToString() const;
00962   V8EXPORT Local<String> ToDetailString() const;
00963   V8EXPORT Local<Object> ToObject() const;
00964   V8EXPORT Local<Integer> ToInteger() const;
00965   V8EXPORT Local<Uint32> ToUint32() const;
00966   V8EXPORT Local<Int32> ToInt32() const;
00967 
00972   V8EXPORT Local<Uint32> ToArrayIndex() const;
00973 
00974   V8EXPORT bool BooleanValue() const;
00975   V8EXPORT double NumberValue() const;
00976   V8EXPORT int64_t IntegerValue() const;
00977   V8EXPORT uint32_t Uint32Value() const;
00978   V8EXPORT int32_t Int32Value() const;
00979 
00981   V8EXPORT bool Equals(Handle<Value> that) const;
00982   V8EXPORT bool StrictEquals(Handle<Value> that) const;
00983 
00984  private:
00985   inline bool QuickIsString() const;
00986   V8EXPORT bool FullIsString() const;
00987 };
00988 
00989 
00993 class Primitive : public Value { };
00994 
00995 
01000 class Boolean : public Primitive {
01001  public:
01002   V8EXPORT bool Value() const;
01003   static inline Handle<Boolean> New(bool value);
01004 };
01005 
01006 
01010 class String : public Primitive {
01011  public:
01015   V8EXPORT int Length() const;
01016 
01021   V8EXPORT int Utf8Length() const;
01022 
01048   enum WriteHints {
01049     NO_HINTS = 0,
01050     HINT_MANY_WRITES_EXPECTED = 1
01051   };
01052 
01053   V8EXPORT int Write(uint16_t* buffer,
01054                      int start = 0,
01055                      int length = -1,
01056                      WriteHints hints = NO_HINTS) const;  // UTF-16
01057   V8EXPORT int WriteAscii(char* buffer,
01058                           int start = 0,
01059                           int length = -1,
01060                           WriteHints hints = NO_HINTS) const;  // ASCII
01061   V8EXPORT int WriteUtf8(char* buffer,
01062                          int length = -1,
01063                          int* nchars_ref = NULL,
01064                          WriteHints hints = NO_HINTS) const;  // UTF-8
01065 
01069   V8EXPORT static v8::Local<v8::String> Empty();
01070 
01074   V8EXPORT bool IsExternal() const;
01075 
01079   V8EXPORT bool IsExternalAscii() const;
01080 
01081   class V8EXPORT ExternalStringResourceBase {  // NOLINT
01082    public:
01083     virtual ~ExternalStringResourceBase() {}
01084 
01085    protected:
01086     ExternalStringResourceBase() {}
01087 
01094     virtual void Dispose() { delete this; }
01095 
01096    private:
01097     // Disallow copying and assigning.
01098     ExternalStringResourceBase(const ExternalStringResourceBase&);
01099     void operator=(const ExternalStringResourceBase&);
01100 
01101     friend class v8::internal::Heap;
01102   };
01103 
01110   class V8EXPORT ExternalStringResource
01111       : public ExternalStringResourceBase {
01112    public:
01117     virtual ~ExternalStringResource() {}
01118 
01122     virtual const uint16_t* data() const = 0;
01123 
01127     virtual size_t length() const = 0;
01128 
01129    protected:
01130     ExternalStringResource() {}
01131   };
01132 
01144   class V8EXPORT ExternalAsciiStringResource
01145       : public ExternalStringResourceBase {
01146    public:
01151     virtual ~ExternalAsciiStringResource() {}
01153     virtual const char* data() const = 0;
01155     virtual size_t length() const = 0;
01156    protected:
01157     ExternalAsciiStringResource() {}
01158   };
01159 
01164   inline ExternalStringResource* GetExternalStringResource() const;
01165 
01170   V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const;
01171 
01172   static inline String* Cast(v8::Value* obj);
01173 
01183   V8EXPORT static Local<String> New(const char* data, int length = -1);
01184 
01186   V8EXPORT static Local<String> New(const uint16_t* data, int length = -1);
01187 
01189   V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1);
01190 
01195   V8EXPORT static Local<String> Concat(Handle<String> left,
01196                                        Handle<String>right);
01197 
01206   V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource);
01207 
01217   V8EXPORT bool MakeExternal(ExternalStringResource* resource);
01218 
01227   V8EXPORT static Local<String> NewExternal(
01228       ExternalAsciiStringResource* resource);
01229 
01239   V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource);
01240 
01244   V8EXPORT bool CanMakeExternal();
01245 
01247   V8EXPORT static Local<String> NewUndetectable(const char* data,
01248                                                 int length = -1);
01249 
01251   V8EXPORT static Local<String> NewUndetectable(const uint16_t* data,
01252                                                 int length = -1);
01253 
01261   class V8EXPORT Utf8Value {
01262    public:
01263     explicit Utf8Value(Handle<v8::Value> obj);
01264     ~Utf8Value();
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     // Disallow copying and assigning.
01273     Utf8Value(const Utf8Value&);
01274     void operator=(const Utf8Value&);
01275   };
01276 
01284   class V8EXPORT AsciiValue {
01285    public:
01286     explicit AsciiValue(Handle<v8::Value> obj);
01287     ~AsciiValue();
01288     char* operator*() { return str_; }
01289     const char* operator*() const { return str_; }
01290     int length() const { return length_; }
01291    private:
01292     char* str_;
01293     int length_;
01294 
01295     // Disallow copying and assigning.
01296     AsciiValue(const AsciiValue&);
01297     void operator=(const AsciiValue&);
01298   };
01299 
01306   class V8EXPORT Value {
01307    public:
01308     explicit Value(Handle<v8::Value> obj);
01309     ~Value();
01310     uint16_t* operator*() { return str_; }
01311     const uint16_t* operator*() const { return str_; }
01312     int length() const { return length_; }
01313    private:
01314     uint16_t* str_;
01315     int length_;
01316 
01317     // Disallow copying and assigning.
01318     Value(const Value&);
01319     void operator=(const Value&);
01320   };
01321 
01322  private:
01323   V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const;
01324   V8EXPORT static void CheckCast(v8::Value* obj);
01325 };
01326 
01327 
01331 class Number : public Primitive {
01332  public:
01333   V8EXPORT double Value() const;
01334   V8EXPORT static Local<Number> New(double value);
01335   static inline Number* Cast(v8::Value* obj);
01336  private:
01337   V8EXPORT Number();
01338   static void CheckCast(v8::Value* obj);
01339 };
01340 
01341 
01345 class Integer : public Number {
01346  public:
01347   V8EXPORT static Local<Integer> New(int32_t value);
01348   V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value);
01349   V8EXPORT int64_t Value() const;
01350   static inline Integer* Cast(v8::Value* obj);
01351  private:
01352   V8EXPORT Integer();
01353   V8EXPORT static void CheckCast(v8::Value* obj);
01354 };
01355 
01356 
01360 class Int32 : public Integer {
01361  public:
01362   V8EXPORT int32_t Value() const;
01363  private:
01364   V8EXPORT Int32();
01365 };
01366 
01367 
01371 class Uint32 : public Integer {
01372  public:
01373   V8EXPORT uint32_t Value() const;
01374  private:
01375   V8EXPORT Uint32();
01376 };
01377 
01378 
01379 enum PropertyAttribute {
01380   None       = 0,
01381   ReadOnly   = 1 << 0,
01382   DontEnum   = 1 << 1,
01383   DontDelete = 1 << 2
01384 };
01385 
01386 enum ExternalArrayType {
01387   kExternalByteArray = 1,
01388   kExternalUnsignedByteArray,
01389   kExternalShortArray,
01390   kExternalUnsignedShortArray,
01391   kExternalIntArray,
01392   kExternalUnsignedIntArray,
01393   kExternalFloatArray,
01394   kExternalDoubleArray,
01395   kExternalPixelArray
01396 };
01397 
01403 typedef Handle<Value> (*AccessorGetter)(Local<String> property,
01404                                         const AccessorInfo& info);
01405 
01406 
01407 typedef void (*AccessorSetter)(Local<String> property,
01408                                Local<Value> value,
01409                                const AccessorInfo& info);
01410 
01411 
01425 enum AccessControl {
01426   DEFAULT               = 0,
01427   ALL_CAN_READ          = 1,
01428   ALL_CAN_WRITE         = 1 << 1,
01429   PROHIBITS_OVERWRITING = 1 << 2
01430 };
01431 
01432 
01436 class Object : public Value {
01437  public:
01438   V8EXPORT bool Set(Handle<Value> key,
01439                     Handle<Value> value,
01440                     PropertyAttribute attribs = None);
01441 
01442   V8EXPORT bool Set(uint32_t index,
01443                     Handle<Value> value);
01444 
01445   // Sets a local property on this object bypassing interceptors and
01446   // overriding accessors or read-only properties.
01447   //
01448   // Note that if the object has an interceptor the property will be set
01449   // locally, but since the interceptor takes precedence the local property
01450   // will only be returned if the interceptor doesn't return a value.
01451   //
01452   // Note also that this only works for named properties.
01453   V8EXPORT bool ForceSet(Handle<Value> key,
01454                          Handle<Value> value,
01455                          PropertyAttribute attribs = None);
01456 
01457   V8EXPORT Local<Value> Get(Handle<Value> key);
01458 
01459   V8EXPORT Local<Value> Get(uint32_t index);
01460 
01466   V8EXPORT PropertyAttribute GetPropertyAttributes(Handle<Value> key);
01467 
01468   // TODO(1245389): Replace the type-specific versions of these
01469   // functions with generic ones that accept a Handle<Value> key.
01470   V8EXPORT bool Has(Handle<String> key);
01471 
01472   V8EXPORT bool Delete(Handle<String> key);
01473 
01474   // Delete a property on this object bypassing interceptors and
01475   // ignoring dont-delete attributes.
01476   V8EXPORT bool ForceDelete(Handle<Value> key);
01477 
01478   V8EXPORT bool Has(uint32_t index);
01479 
01480   V8EXPORT bool Delete(uint32_t index);
01481 
01482   V8EXPORT bool SetAccessor(Handle<String> name,
01483                             AccessorGetter getter,
01484                             AccessorSetter setter = 0,
01485                             Handle<Value> data = Handle<Value>(),
01486                             AccessControl settings = DEFAULT,
01487                             PropertyAttribute attribute = None);
01488 
01495   V8EXPORT Local<Array> GetPropertyNames();
01496 
01502   V8EXPORT Local<Array> GetOwnPropertyNames();
01503 
01509   V8EXPORT Local<Value> GetPrototype();
01510 
01516   V8EXPORT bool SetPrototype(Handle<Value> prototype);
01517 
01522   V8EXPORT Local<Object> FindInstanceInPrototypeChain(
01523       Handle<FunctionTemplate> tmpl);
01524 
01530   V8EXPORT Local<String> ObjectProtoToString();
01531 
01535   V8EXPORT Local<String> GetConstructorName();
01536 
01538   V8EXPORT int InternalFieldCount();
01540   inline Local<Value> GetInternalField(int index);
01542   V8EXPORT void SetInternalField(int index, Handle<Value> value);
01543 
01545   inline void* GetPointerFromInternalField(int index);
01546 
01548   V8EXPORT void SetPointerInInternalField(int index, void* value);
01549 
01550   // Testers for local properties.
01551   V8EXPORT bool HasOwnProperty(Handle<String> key);
01552   V8EXPORT bool HasRealNamedProperty(Handle<String> key);
01553   V8EXPORT bool HasRealIndexedProperty(uint32_t index);
01554   V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key);
01555 
01560   V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain(
01561       Handle<String> key);
01562 
01568   V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key);
01569 
01571   V8EXPORT bool HasNamedLookupInterceptor();
01572 
01574   V8EXPORT bool HasIndexedLookupInterceptor();
01575 
01581   V8EXPORT void TurnOnAccessCheck();
01582 
01590   V8EXPORT int GetIdentityHash();
01591 
01598   V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value);
01599   V8EXPORT Local<Value> GetHiddenValue(Handle<String> key);
01600   V8EXPORT bool DeleteHiddenValue(Handle<String> key);
01601 
01609   V8EXPORT bool IsDirty();
01610 
01615   V8EXPORT Local<Object> Clone();
01616 
01620   V8EXPORT Local<Context> CreationContext();
01621 
01629   V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length);
01630   V8EXPORT bool HasIndexedPropertiesInPixelData();
01631   V8EXPORT uint8_t* GetIndexedPropertiesPixelData();
01632   V8EXPORT int GetIndexedPropertiesPixelDataLength();
01633 
01641   V8EXPORT void SetIndexedPropertiesToExternalArrayData(
01642       void* data,
01643       ExternalArrayType array_type,
01644       int number_of_elements);
01645   V8EXPORT bool HasIndexedPropertiesInExternalArrayData();
01646   V8EXPORT void* GetIndexedPropertiesExternalArrayData();
01647   V8EXPORT ExternalArrayType GetIndexedPropertiesExternalArrayDataType();
01648   V8EXPORT int GetIndexedPropertiesExternalArrayDataLength();
01649 
01655   V8EXPORT bool IsCallable();
01656 
01661   V8EXPORT Local<Value> CallAsFunction(Handle<Object> recv,
01662                                        int argc,
01663                                        Handle<Value> argv[]);
01664 
01670   V8EXPORT Local<Value> CallAsConstructor(int argc,
01671                                           Handle<Value> argv[]);
01672 
01673   V8EXPORT static Local<Object> New();
01674   static inline Object* Cast(Value* obj);
01675 
01676  private:
01677   V8EXPORT Object();
01678   V8EXPORT static void CheckCast(Value* obj);
01679   V8EXPORT Local<Value> CheckedGetInternalField(int index);
01680   V8EXPORT void* SlowGetPointerFromInternalField(int index);
01681 
01686   inline Local<Value> UncheckedGetInternalField(int index);
01687 };
01688 
01689 
01693 class Array : public Object {
01694  public:
01695   V8EXPORT uint32_t Length() const;
01696 
01701   V8EXPORT Local<Object> CloneElementAt(uint32_t index);
01702 
01707   V8EXPORT static Local<Array> New(int length = 0);
01708 
01709   static inline Array* Cast(Value* obj);
01710  private:
01711   V8EXPORT Array();
01712   static void CheckCast(Value* obj);
01713 };
01714 
01715 
01719 class Function : public Object {
01720  public:
01721   V8EXPORT Local<Object> NewInstance() const;
01722   V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const;
01723   V8EXPORT Local<Value> Call(Handle<Object> recv,
01724                              int argc,
01725                              Handle<Value> argv[]);
01726   V8EXPORT void SetName(Handle<String> name);
01727   V8EXPORT Handle<Value> GetName() const;
01728 
01733   V8EXPORT int GetScriptLineNumber() const;
01734   V8EXPORT ScriptOrigin GetScriptOrigin() const;
01735   static inline Function* Cast(Value* obj);
01736   V8EXPORT static const int kLineOffsetNotFound;
01737  private:
01738   V8EXPORT Function();
01739   V8EXPORT static void CheckCast(Value* obj);
01740 };
01741 
01742 
01746 class Date : public Object {
01747  public:
01748   V8EXPORT static Local<Value> New(double time);
01749 
01754   V8EXPORT double NumberValue() const;
01755 
01756   static inline Date* Cast(v8::Value* obj);
01757 
01770   V8EXPORT static void DateTimeConfigurationChangeNotification();
01771 
01772  private:
01773   V8EXPORT static void CheckCast(v8::Value* obj);
01774 };
01775 
01776 
01780 class NumberObject : public Object {
01781  public:
01782   V8EXPORT static Local<Value> New(double value);
01783 
01787   V8EXPORT double NumberValue() const;
01788 
01789   static inline NumberObject* Cast(v8::Value* obj);
01790 
01791  private:
01792   V8EXPORT static void CheckCast(v8::Value* obj);
01793 };
01794 
01795 
01799 class BooleanObject : public Object {
01800  public:
01801   V8EXPORT static Local<Value> New(bool value);
01802 
01806   V8EXPORT bool BooleanValue() const;
01807 
01808   static inline BooleanObject* Cast(v8::Value* obj);
01809 
01810  private:
01811   V8EXPORT static void CheckCast(v8::Value* obj);
01812 };
01813 
01814 
01818 class StringObject : public Object {
01819  public:
01820   V8EXPORT static Local<Value> New(Handle<String> value);
01821 
01825   V8EXPORT Local<String> StringValue() const;
01826 
01827   static inline StringObject* Cast(v8::Value* obj);
01828 
01829  private:
01830   V8EXPORT static void CheckCast(v8::Value* obj);
01831 };
01832 
01833 
01837 class RegExp : public Object {
01838  public:
01843   enum Flags {
01844     kNone = 0,
01845     kGlobal = 1,
01846     kIgnoreCase = 2,
01847     kMultiline = 4
01848   };
01849 
01860   V8EXPORT static Local<RegExp> New(Handle<String> pattern,
01861                                     Flags flags);
01862 
01867   V8EXPORT Local<String> GetSource() const;
01868 
01872   V8EXPORT Flags GetFlags() const;
01873 
01874   static inline RegExp* Cast(v8::Value* obj);
01875 
01876  private:
01877   V8EXPORT static void CheckCast(v8::Value* obj);
01878 };
01879 
01880 
01892 class External : public Value {
01893  public:
01894   V8EXPORT static Local<Value> Wrap(void* data);
01895   static inline void* Unwrap(Handle<Value> obj);
01896 
01897   V8EXPORT static Local<External> New(void* value);
01898   static inline External* Cast(Value* obj);
01899   V8EXPORT void* Value() const;
01900  private:
01901   V8EXPORT External();
01902   V8EXPORT static void CheckCast(v8::Value* obj);
01903   static inline void* QuickUnwrap(Handle<v8::Value> obj);
01904   V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
01905 };
01906 
01907 
01908 // --- Templates ---
01909 
01910 
01914 class V8EXPORT Template : public Data {
01915  public:
01917   void Set(Handle<String> name, Handle<Data> value,
01918            PropertyAttribute attributes = None);
01919   inline void Set(const char* name, Handle<Data> value);
01920  private:
01921   Template();
01922 
01923   friend class ObjectTemplate;
01924   friend class FunctionTemplate;
01925 };
01926 
01927 
01934 class Arguments {
01935  public:
01936   inline int Length() const;
01937   inline Local<Value> operator[](int i) const;
01938   inline Local<Function> Callee() const;
01939   inline Local<Object> This() const;
01940   inline Local<Object> Holder() const;
01941   inline bool IsConstructCall() const;
01942   inline Local<Value> Data() const;
01943  private:
01944   static const int kDataIndex = 0;
01945   static const int kCalleeIndex = -1;
01946   static const int kHolderIndex = -2;
01947 
01948   friend class ImplementationUtilities;
01949   inline Arguments(internal::Object** implicit_args,
01950                    internal::Object** values,
01951                    int length,
01952                    bool is_construct_call);
01953   internal::Object** implicit_args_;
01954   internal::Object** values_;
01955   int length_;
01956   bool is_construct_call_;
01957 };
01958 
01959 
01964 class V8EXPORT AccessorInfo {
01965  public:
01966   inline AccessorInfo(internal::Object** args)
01967       : args_(args) { }
01968   inline Local<Value> Data() const;
01969   inline Local<Object> This() const;
01970   inline Local<Object> Holder() const;
01971  private:
01972   internal::Object** args_;
01973 };
01974 
01975 
01976 typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
01977 
01982 typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
01983                                              const AccessorInfo& info);
01984 
01985 
01990 typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
01991                                              Local<Value> value,
01992                                              const AccessorInfo& info);
01993 
01999 typedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property,
02000                                               const AccessorInfo& info);
02001 
02002 
02008 typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
02009                                                 const AccessorInfo& info);
02010 
02015 typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
02016 
02017 
02022 typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
02023                                                const AccessorInfo& info);
02024 
02025 
02030 typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
02031                                                Local<Value> value,
02032                                                const AccessorInfo& info);
02033 
02034 
02039 typedef Handle<Integer> (*IndexedPropertyQuery)(uint32_t index,
02040                                                 const AccessorInfo& info);
02041 
02047 typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
02048                                                   const AccessorInfo& info);
02049 
02054 typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
02055 
02056 
02060 enum AccessType {
02061   ACCESS_GET,
02062   ACCESS_SET,
02063   ACCESS_HAS,
02064   ACCESS_DELETE,
02065   ACCESS_KEYS
02066 };
02067 
02068 
02073 typedef bool (*NamedSecurityCallback)(Local<Object> host,
02074                                       Local<Value> key,
02075                                       AccessType type,
02076                                       Local<Value> data);
02077 
02078 
02083 typedef bool (*IndexedSecurityCallback)(Local<Object> host,
02084                                         uint32_t index,
02085                                         AccessType type,
02086                                         Local<Value> data);
02087 
02088 
02181 class V8EXPORT FunctionTemplate : public Template {
02182  public:
02184   static Local<FunctionTemplate> New(
02185       InvocationCallback callback = 0,
02186       Handle<Value> data = Handle<Value>(),
02187       Handle<Signature> signature = Handle<Signature>());
02189   Local<Function> GetFunction();
02190 
02196   void SetCallHandler(InvocationCallback callback,
02197                       Handle<Value> data = Handle<Value>());
02198 
02200   Local<ObjectTemplate> InstanceTemplate();
02201 
02203   void Inherit(Handle<FunctionTemplate> parent);
02204 
02209   Local<ObjectTemplate> PrototypeTemplate();
02210 
02211 
02217   void SetClassName(Handle<String> name);
02218 
02231   void SetHiddenPrototype(bool value);
02232 
02237   void ReadOnlyPrototype();
02238 
02243   bool HasInstance(Handle<Value> object);
02244 
02245  private:
02246   FunctionTemplate();
02247   void AddInstancePropertyAccessor(Handle<String> name,
02248                                    AccessorGetter getter,
02249                                    AccessorSetter setter,
02250                                    Handle<Value> data,
02251                                    AccessControl settings,
02252                                    PropertyAttribute attributes);
02253   void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
02254                                        NamedPropertySetter setter,
02255                                        NamedPropertyQuery query,
02256                                        NamedPropertyDeleter remover,
02257                                        NamedPropertyEnumerator enumerator,
02258                                        Handle<Value> data);
02259   void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
02260                                          IndexedPropertySetter setter,
02261                                          IndexedPropertyQuery query,
02262                                          IndexedPropertyDeleter remover,
02263                                          IndexedPropertyEnumerator enumerator,
02264                                          Handle<Value> data);
02265   void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
02266                                         Handle<Value> data);
02267 
02268   friend class Context;
02269   friend class ObjectTemplate;
02270 };
02271 
02272 
02279 class V8EXPORT ObjectTemplate : public Template {
02280  public:
02282   static Local<ObjectTemplate> New();
02283 
02285   Local<Object> NewInstance();
02286 
02311   void SetAccessor(Handle<String> name,
02312                    AccessorGetter getter,
02313                    AccessorSetter setter = 0,
02314                    Handle<Value> data = Handle<Value>(),
02315                    AccessControl settings = DEFAULT,
02316                    PropertyAttribute attribute = None);
02317 
02335   void SetNamedPropertyHandler(NamedPropertyGetter getter,
02336                                NamedPropertySetter setter = 0,
02337                                NamedPropertyQuery query = 0,
02338                                NamedPropertyDeleter deleter = 0,
02339                                NamedPropertyEnumerator enumerator = 0,
02340                                Handle<Value> data = Handle<Value>());
02341 
02358   void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
02359                                  IndexedPropertySetter setter = 0,
02360                                  IndexedPropertyQuery query = 0,
02361                                  IndexedPropertyDeleter deleter = 0,
02362                                  IndexedPropertyEnumerator enumerator = 0,
02363                                  Handle<Value> data = Handle<Value>());
02364 
02371   void SetCallAsFunctionHandler(InvocationCallback callback,
02372                                 Handle<Value> data = Handle<Value>());
02373 
02382   void MarkAsUndetectable();
02383 
02395   void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
02396                                IndexedSecurityCallback indexed_handler,
02397                                Handle<Value> data = Handle<Value>(),
02398                                bool turned_on_by_default = true);
02399 
02404   int InternalFieldCount();
02405 
02410   void SetInternalFieldCount(int value);
02411 
02412  private:
02413   ObjectTemplate();
02414   static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
02415   friend class FunctionTemplate;
02416 };
02417 
02418 
02423 class V8EXPORT Signature : public Data {
02424  public:
02425   static Local<Signature> New(Handle<FunctionTemplate> receiver =
02426                                   Handle<FunctionTemplate>(),
02427                               int argc = 0,
02428                               Handle<FunctionTemplate> argv[] = 0);
02429  private:
02430   Signature();
02431 };
02432 
02433 
02438 class V8EXPORT TypeSwitch : public Data {
02439  public:
02440   static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
02441   static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
02442   int match(Handle<Value> value);
02443  private:
02444   TypeSwitch();
02445 };
02446 
02447 
02448 // --- Extensions ---
02449 
02450 
02454 class V8EXPORT Extension {  // NOLINT
02455  public:
02456   Extension(const char* name,
02457             const char* source = 0,
02458             int dep_count = 0,
02459             const char** deps = 0);
02460   virtual ~Extension() { }
02461   virtual v8::Handle<v8::FunctionTemplate>
02462       GetNativeFunction(v8::Handle<v8::String> name) {
02463     return v8::Handle<v8::FunctionTemplate>();
02464   }
02465 
02466   const char* name() { return name_; }
02467   const char* source() { return source_; }
02468   int dependency_count() { return dep_count_; }
02469   const char** dependencies() { return deps_; }
02470   void set_auto_enable(bool value) { auto_enable_ = value; }
02471   bool auto_enable() { return auto_enable_; }
02472 
02473  private:
02474   const char* name_;
02475   const char* source_;
02476   int dep_count_;
02477   const char** deps_;
02478   bool auto_enable_;
02479 
02480   // Disallow copying and assigning.
02481   Extension(const Extension&);
02482   void operator=(const Extension&);
02483 };
02484 
02485 
02486 void V8EXPORT RegisterExtension(Extension* extension);
02487 
02488 
02492 class V8EXPORT DeclareExtension {
02493  public:
02494   inline DeclareExtension(Extension* extension) {
02495     RegisterExtension(extension);
02496   }
02497 };
02498 
02499 
02500 // --- Statics ---
02501 
02502 
02503 Handle<Primitive> V8EXPORT Undefined();
02504 Handle<Primitive> V8EXPORT Null();
02505 Handle<Boolean> V8EXPORT True();
02506 Handle<Boolean> V8EXPORT False();
02507 
02508 
02518 class V8EXPORT ResourceConstraints {
02519  public:
02520   ResourceConstraints();
02521   int max_young_space_size() const { return max_young_space_size_; }
02522   void set_max_young_space_size(int value) { max_young_space_size_ = value; }
02523   int max_old_space_size() const { return max_old_space_size_; }
02524   void set_max_old_space_size(int value) { max_old_space_size_ = value; }
02525   int max_executable_size() { return max_executable_size_; }
02526   void set_max_executable_size(int value) { max_executable_size_ = value; }
02527   uint32_t* stack_limit() const { return stack_limit_; }
02528   // Sets an address beyond which the VM's stack may not grow.
02529   void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
02530  private:
02531   int max_young_space_size_;
02532   int max_old_space_size_;
02533   int max_executable_size_;
02534   uint32_t* stack_limit_;
02535 };
02536 
02537 
02538 bool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints);
02539 
02540 
02541 // --- Exceptions ---
02542 
02543 
02544 typedef void (*FatalErrorCallback)(const char* location, const char* message);
02545 
02546 
02547 typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
02548 
02549 
02556 Handle<Value> V8EXPORT ThrowException(Handle<Value> exception);
02557 
02562 class V8EXPORT Exception {
02563  public:
02564   static Local<Value> RangeError(Handle<String> message);
02565   static Local<Value> ReferenceError(Handle<String> message);
02566   static Local<Value> SyntaxError(Handle<String> message);
02567   static Local<Value> TypeError(Handle<String> message);
02568   static Local<Value> Error(Handle<String> message);
02569 };
02570 
02571 
02572 // --- Counters Callbacks ---
02573 
02574 typedef int* (*CounterLookupCallback)(const char* name);
02575 
02576 typedef void* (*CreateHistogramCallback)(const char* name,
02577                                          int min,
02578                                          int max,
02579                                          size_t buckets);
02580 
02581 typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
02582 
02583 // --- Memory Allocation Callback ---
02584   enum ObjectSpace {
02585     kObjectSpaceNewSpace = 1 << 0,
02586     kObjectSpaceOldPointerSpace = 1 << 1,
02587     kObjectSpaceOldDataSpace = 1 << 2,
02588     kObjectSpaceCodeSpace = 1 << 3,
02589     kObjectSpaceMapSpace = 1 << 4,
02590     kObjectSpaceLoSpace = 1 << 5,
02591 
02592     kObjectSpaceAll = kObjectSpaceNewSpace | kObjectSpaceOldPointerSpace |
02593       kObjectSpaceOldDataSpace | kObjectSpaceCodeSpace | kObjectSpaceMapSpace |
02594       kObjectSpaceLoSpace
02595   };
02596 
02597   enum AllocationAction {
02598     kAllocationActionAllocate = 1 << 0,
02599     kAllocationActionFree = 1 << 1,
02600     kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
02601   };
02602 
02603 typedef void (*MemoryAllocationCallback)(ObjectSpace space,
02604                                          AllocationAction action,
02605                                          int size);
02606 
02607 // --- Failed Access Check Callback ---
02608 typedef void (*FailedAccessCheckCallback)(Local<Object> target,
02609                                           AccessType type,
02610                                           Local<Value> data);
02611 
02612 // --- AllowCodeGenerationFromStrings callbacks ---
02613 
02618 typedef bool (*AllowCodeGenerationFromStringsCallback)(Local<Context> context);
02619 
02620 // --- Garbage Collection Callbacks ---
02621 
02629 enum GCType {
02630   kGCTypeScavenge = 1 << 0,
02631   kGCTypeMarkSweepCompact = 1 << 1,
02632   kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
02633 };
02634 
02635 enum GCCallbackFlags {
02636   kNoGCCallbackFlags = 0,
02637   kGCCallbackFlagCompacted = 1 << 0
02638 };
02639 
02640 typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
02641 typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
02642 
02643 typedef void (*GCCallback)();
02644 
02645 
02652 class V8EXPORT HeapStatistics {
02653  public:
02654   HeapStatistics();
02655   size_t total_heap_size() { return total_heap_size_; }
02656   size_t total_heap_size_executable() { return total_heap_size_executable_; }
02657   size_t used_heap_size() { return used_heap_size_; }
02658   size_t heap_size_limit() { return heap_size_limit_; }
02659 
02660  private:
02661   void set_total_heap_size(size_t size) { total_heap_size_ = size; }
02662   void set_total_heap_size_executable(size_t size) {
02663     total_heap_size_executable_ = size;
02664   }
02665   void set_used_heap_size(size_t size) { used_heap_size_ = size; }
02666   void set_heap_size_limit(size_t size) { heap_size_limit_ = size; }
02667 
02668   size_t total_heap_size_;
02669   size_t total_heap_size_executable_;
02670   size_t used_heap_size_;
02671   size_t heap_size_limit_;
02672 
02673   friend class V8;
02674 };
02675 
02676 
02677 class RetainedObjectInfo;
02678 
02688 class V8EXPORT Isolate {
02689  public:
02694   class V8EXPORT Scope {
02695    public:
02696     explicit Scope(Isolate* isolate) : isolate_(isolate) {
02697       isolate->Enter();
02698     }
02699 
02700     ~Scope() { isolate_->Exit(); }
02701 
02702    private:
02703     Isolate* const isolate_;
02704 
02705     // Prevent copying of Scope objects.
02706     Scope(const Scope&);
02707     Scope& operator=(const Scope&);
02708   };
02709 
02717   static Isolate* New();
02718 
02723   static Isolate* GetCurrent();
02724 
02735   void Enter();
02736 
02744   void Exit();
02745 
02750   void Dispose();
02751 
02755   void SetData(void* data);
02756 
02761   void* GetData();
02762 
02763  private:
02764   Isolate();
02765   Isolate(const Isolate&);
02766   ~Isolate();
02767   Isolate& operator=(const Isolate&);
02768   void* operator new(size_t size);
02769   void operator delete(void*, size_t);
02770 };
02771 
02772 
02773 class StartupData {
02774  public:
02775   enum CompressionAlgorithm {
02776     kUncompressed,
02777     kBZip2
02778   };
02779 
02780   const char* data;
02781   int compressed_size;
02782   int raw_size;
02783 };
02784 
02785 
02794 class V8EXPORT StartupDataDecompressor {  // NOLINT
02795  public:
02796   StartupDataDecompressor();
02797   virtual ~StartupDataDecompressor();
02798   int Decompress();
02799 
02800  protected:
02801   virtual int DecompressData(char* raw_data,
02802                              int* raw_data_size,
02803                              const char* compressed_data,
02804                              int compressed_data_size) = 0;
02805 
02806  private:
02807   char** raw_data;
02808 };
02809 
02810 
02815 typedef bool (*EntropySource)(unsigned char* buffer, size_t length);
02816 
02820 class V8EXPORT V8 {
02821  public:
02823   static void SetFatalErrorHandler(FatalErrorCallback that);
02824 
02829   static void SetAllowCodeGenerationFromStringsCallback(
02830       AllowCodeGenerationFromStringsCallback that);
02831 
02844   static void IgnoreOutOfMemoryException();
02845 
02850   static bool IsDead();
02851 
02871   static StartupData::CompressionAlgorithm GetCompressedStartupDataAlgorithm();
02872   static int GetCompressedStartupDataCount();
02873   static void GetCompressedStartupData(StartupData* compressed_data);
02874   static void SetDecompressedStartupData(StartupData* decompressed_data);
02875 
02882   static bool AddMessageListener(MessageCallback that,
02883                                  Handle<Value> data = Handle<Value>());
02884 
02888   static void RemoveMessageListeners(MessageCallback that);
02889 
02894   static void SetCaptureStackTraceForUncaughtExceptions(
02895       bool capture,
02896       int frame_limit = 10,
02897       StackTrace::StackTraceOptions options = StackTrace::kOverview);
02898 
02902   static void SetFlagsFromString(const char* str, int length);
02903 
02907   static void SetFlagsFromCommandLine(int* argc,
02908                                       char** argv,
02909                                       bool remove_flags);
02910 
02912   static const char* GetVersion();
02913 
02918   static void SetCounterFunction(CounterLookupCallback);
02919 
02926   static void SetCreateHistogramFunction(CreateHistogramCallback);
02927   static void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
02928 
02933   static void EnableSlidingStateWindow();
02934 
02936   static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
02937 
02948   static void AddGCPrologueCallback(
02949       GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
02950 
02955   static void RemoveGCPrologueCallback(GCPrologueCallback callback);
02956 
02965   static void SetGlobalGCPrologueCallback(GCCallback);
02966 
02977   static void AddGCEpilogueCallback(
02978       GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
02979 
02984   static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
02985 
02994   static void SetGlobalGCEpilogueCallback(GCCallback);
02995 
03000   static void AddMemoryAllocationCallback(MemoryAllocationCallback callback,
03001                                           ObjectSpace space,
03002                                           AllocationAction action);
03003 
03008   static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
03009 
03019   static void AddObjectGroup(Persistent<Value>* objects,
03020                              size_t length,
03021                              RetainedObjectInfo* info = NULL);
03022 
03030   static void AddImplicitReferences(Persistent<Object> parent,
03031                                     Persistent<Value>* children,
03032                                     size_t length);
03033 
03039   static bool Initialize();
03040 
03045   static void SetEntropySource(EntropySource source);
03046 
03061   static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
03062 
03072   static void PauseProfiler();
03073 
03078   static void ResumeProfiler();
03079 
03083   static bool IsProfilerPaused();
03084 
03091   static int GetCurrentThreadId();
03092 
03117   static void TerminateExecution(int thread_id);
03118 
03129   static void TerminateExecution(Isolate* isolate = NULL);
03130 
03141   static bool IsExecutionTerminating(Isolate* isolate = NULL);
03142 
03152   static bool Dispose();
03153 
03157   static void GetHeapStatistics(HeapStatistics* heap_statistics);
03158 
03167   static bool IdleNotification();
03168 
03173   static void LowMemoryNotification();
03174 
03181   static int ContextDisposedNotification();
03182 
03183  private:
03184   V8();
03185 
03186   static internal::Object** GlobalizeReference(internal::Object** handle);
03187   static void DisposeGlobal(internal::Object** global_handle);
03188   static void MakeWeak(internal::Object** global_handle,
03189                        void* data,
03190                        WeakReferenceCallback);
03191   static void ClearWeak(internal::Object** global_handle);
03192   static void MarkIndependent(internal::Object** global_handle);
03193   static bool IsGlobalNearDeath(internal::Object** global_handle);
03194   static bool IsGlobalWeak(internal::Object** global_handle);
03195   static void SetWrapperClassId(internal::Object** global_handle,
03196                                 uint16_t class_id);
03197 
03198   template <class T> friend class Handle;
03199   template <class T> friend class Local;
03200   template <class T> friend class Persistent;
03201   friend class Context;
03202 };
03203 
03204 
03208 class V8EXPORT TryCatch {
03209  public:
03213   TryCatch();
03214 
03218   ~TryCatch();
03219 
03223   bool HasCaught() const;
03224 
03238   bool CanContinue() const;
03239 
03247   Handle<Value> ReThrow();
03248 
03255   Local<Value> Exception() const;
03256 
03261   Local<Value> StackTrace() const;
03262 
03270   Local<v8::Message> Message() const;
03271 
03281   void Reset();
03282 
03291   void SetVerbose(bool value);
03292 
03298   void SetCaptureMessage(bool value);
03299 
03300  private:
03301   v8::internal::Isolate* isolate_;
03302   void* next_;
03303   void* exception_;
03304   void* message_;
03305   bool is_verbose_ : 1;
03306   bool can_continue_ : 1;
03307   bool capture_message_ : 1;
03308   bool rethrow_ : 1;
03309 
03310   friend class v8::internal::Isolate;
03311 };
03312 
03313 
03314 // --- Context ---
03315 
03316 
03320 class V8EXPORT ExtensionConfiguration {
03321  public:
03322   ExtensionConfiguration(int name_count, const char* names[])
03323       : name_count_(name_count), names_(names) { }
03324  private:
03325   friend class ImplementationUtilities;
03326   int name_count_;
03327   const char** names_;
03328 };
03329 
03330 
03335 class V8EXPORT Context {
03336  public:
03353   Local<Object> Global();
03354 
03359   void DetachGlobal();
03360 
03371   void ReattachGlobal(Handle<Object> global_object);
03372 
03391   static Persistent<Context> New(
03392       ExtensionConfiguration* extensions = NULL,
03393       Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
03394       Handle<Value> global_object = Handle<Value>());
03395 
03397   static Local<Context> GetEntered();
03398 
03400   static Local<Context> GetCurrent();
03401 
03407   static Local<Context> GetCalling();
03408 
03413   void SetSecurityToken(Handle<Value> token);
03414 
03416   void UseDefaultSecurityToken();
03417 
03419   Handle<Value> GetSecurityToken();
03420 
03427   void Enter();
03428 
03433   void Exit();
03434 
03436   bool HasOutOfMemoryException();
03437 
03439   static bool InContext();
03440 
03446   void SetData(Handle<String> data);
03447   Local<Value> GetData();
03448 
03462   void AllowCodeGenerationFromStrings(bool allow);
03463 
03468   class Scope {
03469    public:
03470     explicit inline Scope(Handle<Context> context) : context_(context) {
03471       context_->Enter();
03472     }
03473     inline ~Scope() { context_->Exit(); }
03474    private:
03475     Handle<Context> context_;
03476   };
03477 
03478  private:
03479   friend class Value;
03480   friend class Script;
03481   friend class Object;
03482   friend class Function;
03483 };
03484 
03485 
03566 class V8EXPORT Unlocker {
03567  public:
03571   explicit Unlocker(Isolate* isolate = NULL);
03572   ~Unlocker();
03573  private:
03574   internal::Isolate* isolate_;
03575 };
03576 
03577 
03578 class V8EXPORT Locker {
03579  public:
03583   explicit Locker(Isolate* isolate = NULL);
03584   ~Locker();
03585 
03593   static void StartPreemption(int every_n_ms);
03594 
03598   static void StopPreemption();
03599 
03604   static bool IsLocked(Isolate* isolate = NULL);
03605 
03609   static bool IsActive() { return active_; }
03610 
03611  private:
03612   bool has_lock_;
03613   bool top_level_;
03614   internal::Isolate* isolate_;
03615 
03616   static bool active_;
03617 
03618   // Disallow copying and assigning.
03619   Locker(const Locker&);
03620   void operator=(const Locker&);
03621 };
03622 
03623 
03627 class V8EXPORT OutputStream {  // NOLINT
03628  public:
03629   enum OutputEncoding {
03630     kAscii = 0  // 7-bit ASCII.
03631   };
03632   enum WriteResult {
03633     kContinue = 0,
03634     kAbort = 1
03635   };
03636   virtual ~OutputStream() {}
03638   virtual void EndOfStream() = 0;
03640   virtual int GetChunkSize() { return 1024; }
03642   virtual OutputEncoding GetOutputEncoding() { return kAscii; }
03648   virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
03649 };
03650 
03651 
03656 class V8EXPORT ActivityControl {  // NOLINT
03657  public:
03658   enum ControlOption {
03659     kContinue = 0,
03660     kAbort = 1
03661   };
03662   virtual ~ActivityControl() {}
03667   virtual ControlOption ReportProgressValue(int done, int total) = 0;
03668 };
03669 
03670 
03671 // --- Implementation ---
03672 
03673 
03674 namespace internal {
03675 
03676 static const int kApiPointerSize = sizeof(void*);  // NOLINT
03677 static const int kApiIntSize = sizeof(int);  // NOLINT
03678 
03679 // Tag information for HeapObject.
03680 const int kHeapObjectTag = 1;
03681 const int kHeapObjectTagSize = 2;
03682 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
03683 
03684 // Tag information for Smi.
03685 const int kSmiTag = 0;
03686 const int kSmiTagSize = 1;
03687 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
03688 
03689 template <size_t ptr_size> struct SmiTagging;
03690 
03691 // Smi constants for 32-bit systems.
03692 template <> struct SmiTagging<4> {
03693   static const int kSmiShiftSize = 0;
03694   static const int kSmiValueSize = 31;
03695   static inline int SmiToInt(internal::Object* value) {
03696     int shift_bits = kSmiTagSize + kSmiShiftSize;
03697     // Throw away top 32 bits and shift down (requires >> to be sign extending).
03698     return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
03699   }
03700 
03701   // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi
03702   // with a plain reinterpret_cast.
03703   static const uintptr_t kEncodablePointerMask = 0x1;
03704   static const int kPointerToSmiShift = 0;
03705 };
03706 
03707 // Smi constants for 64-bit systems.
03708 template <> struct SmiTagging<8> {
03709   static const int kSmiShiftSize = 31;
03710   static const int kSmiValueSize = 32;
03711   static inline int SmiToInt(internal::Object* value) {
03712     int shift_bits = kSmiTagSize + kSmiShiftSize;
03713     // Shift down and throw away top 32 bits.
03714     return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
03715   }
03716 
03717   // To maximize the range of pointers that can be encoded
03718   // in the available 32 bits, we require them to be 8 bytes aligned.
03719   // This gives 2 ^ (32 + 3) = 32G address space covered.
03720   // It might be not enough to cover stack allocated objects on some platforms.
03721   static const int kPointerAlignment = 3;
03722 
03723   static const uintptr_t kEncodablePointerMask =
03724       ~(uintptr_t(0xffffffff) << kPointerAlignment);
03725 
03726   static const int kPointerToSmiShift =
03727       kSmiTagSize + kSmiShiftSize - kPointerAlignment;
03728 };
03729 
03730 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
03731 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
03732 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
03733 const uintptr_t kEncodablePointerMask =
03734     PlatformSmiTagging::kEncodablePointerMask;
03735 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;
03736 
03737 template <size_t ptr_size> struct InternalConstants;
03738 
03739 // Internal constants for 32-bit systems.
03740 template <> struct InternalConstants<4> {
03741   static const int kStringResourceOffset = 3 * kApiPointerSize;
03742 };
03743 
03744 // Internal constants for 64-bit systems.
03745 template <> struct InternalConstants<8> {
03746   static const int kStringResourceOffset = 3 * kApiPointerSize;
03747 };
03748 
03754 class Internals {
03755  public:
03756   // These values match non-compiler-dependent values defined within
03757   // the implementation of v8.
03758   static const int kHeapObjectMapOffset = 0;
03759   static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
03760   static const int kStringResourceOffset =
03761       InternalConstants<kApiPointerSize>::kStringResourceOffset;
03762 
03763   static const int kForeignAddressOffset = kApiPointerSize;
03764   static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
03765   static const int kFullStringRepresentationMask = 0x07;
03766   static const int kExternalTwoByteRepresentationTag = 0x02;
03767 
03768   static const int kJSObjectType = 0xa3;
03769   static const int kFirstNonstringType = 0x80;
03770   static const int kForeignType = 0x85;
03771 
03772   static inline bool HasHeapObjectTag(internal::Object* value) {
03773     return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
03774             kHeapObjectTag);
03775   }
03776 
03777   static inline bool HasSmiTag(internal::Object* value) {
03778     return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
03779   }
03780 
03781   static inline int SmiValue(internal::Object* value) {
03782     return PlatformSmiTagging::SmiToInt(value);
03783   }
03784 
03785   static inline int GetInstanceType(internal::Object* obj) {
03786     typedef internal::Object O;
03787     O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
03788     return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
03789   }
03790 
03791   static inline void* GetExternalPointerFromSmi(internal::Object* value) {
03792     const uintptr_t address = reinterpret_cast<uintptr_t>(value);
03793     return reinterpret_cast<void*>(address >> kPointerToSmiShift);
03794   }
03795 
03796   static inline void* GetExternalPointer(internal::Object* obj) {
03797     if (HasSmiTag(obj)) {
03798       return GetExternalPointerFromSmi(obj);
03799     } else if (GetInstanceType(obj) == kForeignType) {
03800       return ReadField<void*>(obj, kForeignAddressOffset);
03801     } else {
03802       return NULL;
03803     }
03804   }
03805 
03806   static inline bool IsExternalTwoByteString(int instance_type) {
03807     int representation = (instance_type & kFullStringRepresentationMask);
03808     return representation == kExternalTwoByteRepresentationTag;
03809   }
03810 
03811   template <typename T>
03812   static inline T ReadField(Object* ptr, int offset) {
03813     uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
03814     return *reinterpret_cast<T*>(addr);
03815   }
03816 
03817   static inline bool CanCastToHeapObject(void* o) { return false; }
03818   static inline bool CanCastToHeapObject(Context* o) { return true; }
03819   static inline bool CanCastToHeapObject(String* o) { return true; }
03820   static inline bool CanCastToHeapObject(Object* o) { return true; }
03821   static inline bool CanCastToHeapObject(Message* o) { return true; }
03822   static inline bool CanCastToHeapObject(StackTrace* o) { return true; }
03823   static inline bool CanCastToHeapObject(StackFrame* o) { return true; }
03824 };
03825 
03826 }  // namespace internal
03827 
03828 
03829 template <class T>
03830 Handle<T>::Handle() : val_(0) { }
03831 
03832 
03833 template <class T>
03834 Local<T>::Local() : Handle<T>() { }
03835 
03836 
03837 template <class T>
03838 Local<T> Local<T>::New(Handle<T> that) {
03839   if (that.IsEmpty()) return Local<T>();
03840   T* that_ptr = *that;
03841   internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr);
03842   if (internal::Internals::CanCastToHeapObject(that_ptr)) {
03843     return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(
03844         reinterpret_cast<internal::HeapObject*>(*p))));
03845   }
03846   return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
03847 }
03848 
03849 
03850 template <class T>
03851 Persistent<T> Persistent<T>::New(Handle<T> that) {
03852   if (that.IsEmpty()) return Persistent<T>();
03853   internal::Object** p = reinterpret_cast<internal::Object**>(*that);
03854   return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
03855 }
03856 
03857 
03858 template <class T>
03859 bool Persistent<T>::IsNearDeath() const {
03860   if (this->IsEmpty()) return false;
03861   return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
03862 }
03863 
03864 
03865 template <class T>
03866 bool Persistent<T>::IsWeak() const {
03867   if (this->IsEmpty()) return false;
03868   return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this));
03869 }
03870 
03871 
03872 template <class T>
03873 void Persistent<T>::Dispose() {
03874   if (this->IsEmpty()) return;
03875   V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this));
03876 }
03877 
03878 
03879 template <class T>
03880 Persistent<T>::Persistent() : Handle<T>() { }
03881 
03882 template <class T>
03883 void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
03884   V8::MakeWeak(reinterpret_cast<internal::Object**>(**this),
03885                parameters,
03886                callback);
03887 }
03888 
03889 template <class T>
03890 void Persistent<T>::ClearWeak() {
03891   V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));
03892 }
03893 
03894 template <class T>
03895 void Persistent<T>::MarkIndependent() {
03896   V8::MarkIndependent(reinterpret_cast<internal::Object**>(**this));
03897 }
03898 
03899 template <class T>
03900 void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
03901   V8::SetWrapperClassId(reinterpret_cast<internal::Object**>(**this), class_id);
03902 }
03903 
03904 Arguments::Arguments(internal::Object** implicit_args,
03905                      internal::Object** values, int length,
03906                      bool is_construct_call)
03907     : implicit_args_(implicit_args),
03908       values_(values),
03909       length_(length),
03910       is_construct_call_(is_construct_call) { }
03911 
03912 
03913 Local<Value> Arguments::operator[](int i) const {
03914   if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
03915   return Local<Value>(reinterpret_cast<Value*>(values_ - i));
03916 }
03917 
03918 
03919 Local<Function> Arguments::Callee() const {
03920   return Local<Function>(reinterpret_cast<Function*>(
03921       &implicit_args_[kCalleeIndex]));
03922 }
03923 
03924 
03925 Local<Object> Arguments::This() const {
03926   return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
03927 }
03928 
03929 
03930 Local<Object> Arguments::Holder() const {
03931   return Local<Object>(reinterpret_cast<Object*>(
03932       &implicit_args_[kHolderIndex]));
03933 }
03934 
03935 
03936 Local<Value> Arguments::Data() const {
03937   return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
03938 }
03939 
03940 
03941 bool Arguments::IsConstructCall() const {
03942   return is_construct_call_;
03943 }
03944 
03945 
03946 int Arguments::Length() const {
03947   return length_;
03948 }
03949 
03950 
03951 template <class T>
03952 Local<T> HandleScope::Close(Handle<T> value) {
03953   internal::Object** before = reinterpret_cast<internal::Object**>(*value);
03954   internal::Object** after = RawClose(before);
03955   return Local<T>(reinterpret_cast<T*>(after));
03956 }
03957 
03958 Handle<Value> ScriptOrigin::ResourceName() const {
03959   return resource_name_;
03960 }
03961 
03962 
03963 Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
03964   return resource_line_offset_;
03965 }
03966 
03967 
03968 Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
03969   return resource_column_offset_;
03970 }
03971 
03972 
03973 Handle<Boolean> Boolean::New(bool value) {
03974   return value ? True() : False();
03975 }
03976 
03977 
03978 void Template::Set(const char* name, v8::Handle<Data> value) {
03979   Set(v8::String::New(name), value);
03980 }
03981 
03982 
03983 Local<Value> Object::GetInternalField(int index) {
03984 #ifndef V8_ENABLE_CHECKS
03985   Local<Value> quick_result = UncheckedGetInternalField(index);
03986   if (!quick_result.IsEmpty()) return quick_result;
03987 #endif
03988   return CheckedGetInternalField(index);
03989 }
03990 
03991 
03992 Local<Value> Object::UncheckedGetInternalField(int index) {
03993   typedef internal::Object O;
03994   typedef internal::Internals I;
03995   O* obj = *reinterpret_cast<O**>(this);
03996   if (I::GetInstanceType(obj) == I::kJSObjectType) {
03997     // If the object is a plain JSObject, which is the common case,
03998     // we know where to find the internal fields and can return the
03999     // value directly.
04000     int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
04001     O* value = I::ReadField<O*>(obj, offset);
04002     O** result = HandleScope::CreateHandle(value);
04003     return Local<Value>(reinterpret_cast<Value*>(result));
04004   } else {
04005     return Local<Value>();
04006   }
04007 }
04008 
04009 
04010 void* External::Unwrap(Handle<v8::Value> obj) {
04011 #ifdef V8_ENABLE_CHECKS
04012   return FullUnwrap(obj);
04013 #else
04014   return QuickUnwrap(obj);
04015 #endif
04016 }
04017 
04018 
04019 void* External::QuickUnwrap(Handle<v8::Value> wrapper) {
04020   typedef internal::Object O;
04021   O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
04022   return internal::Internals::GetExternalPointer(obj);
04023 }
04024 
04025 
04026 void* Object::GetPointerFromInternalField(int index) {
04027   typedef internal::Object O;
04028   typedef internal::Internals I;
04029 
04030   O* obj = *reinterpret_cast<O**>(this);
04031 
04032   if (I::GetInstanceType(obj) == I::kJSObjectType) {
04033     // If the object is a plain JSObject, which is the common case,
04034     // we know where to find the internal fields and can return the
04035     // value directly.
04036     int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
04037     O* value = I::ReadField<O*>(obj, offset);
04038     return I::GetExternalPointer(value);
04039   }
04040 
04041   return SlowGetPointerFromInternalField(index);
04042 }
04043 
04044 
04045 String* String::Cast(v8::Value* value) {
04046 #ifdef V8_ENABLE_CHECKS
04047   CheckCast(value);
04048 #endif
04049   return static_cast<String*>(value);
04050 }
04051 
04052 
04053 String::ExternalStringResource* String::GetExternalStringResource() const {
04054   typedef internal::Object O;
04055   typedef internal::Internals I;
04056   O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
04057   String::ExternalStringResource* result;
04058   if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
04059     void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
04060     result = reinterpret_cast<String::ExternalStringResource*>(value);
04061   } else {
04062     result = NULL;
04063   }
04064 #ifdef V8_ENABLE_CHECKS
04065   VerifyExternalStringResource(result);
04066 #endif
04067   return result;
04068 }
04069 
04070 
04071 bool Value::IsString() const {
04072 #ifdef V8_ENABLE_CHECKS
04073   return FullIsString();
04074 #else
04075   return QuickIsString();
04076 #endif
04077 }
04078 
04079 bool Value::QuickIsString() const {
04080   typedef internal::Object O;
04081   typedef internal::Internals I;
04082   O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this));
04083   if (!I::HasHeapObjectTag(obj)) return false;
04084   return (I::GetInstanceType(obj) < I::kFirstNonstringType);
04085 }
04086 
04087 
04088 Number* Number::Cast(v8::Value* value) {
04089 #ifdef V8_ENABLE_CHECKS
04090   CheckCast(value);
04091 #endif
04092   return static_cast<Number*>(value);
04093 }
04094 
04095 
04096 Integer* Integer::Cast(v8::Value* value) {
04097 #ifdef V8_ENABLE_CHECKS
04098   CheckCast(value);
04099 #endif
04100   return static_cast<Integer*>(value);
04101 }
04102 
04103 
04104 Date* Date::Cast(v8::Value* value) {
04105 #ifdef V8_ENABLE_CHECKS
04106   CheckCast(value);
04107 #endif
04108   return static_cast<Date*>(value);
04109 }
04110 
04111 
04112 StringObject* StringObject::Cast(v8::Value* value) {
04113 #ifdef V8_ENABLE_CHECKS
04114   CheckCast(value);
04115 #endif
04116   return static_cast<StringObject*>(value);
04117 }
04118 
04119 
04120 NumberObject* NumberObject::Cast(v8::Value* value) {
04121 #ifdef V8_ENABLE_CHECKS
04122   CheckCast(value);
04123 #endif
04124   return static_cast<NumberObject*>(value);
04125 }
04126 
04127 
04128 BooleanObject* BooleanObject::Cast(v8::Value* value) {
04129 #ifdef V8_ENABLE_CHECKS
04130   CheckCast(value);
04131 #endif
04132   return static_cast<BooleanObject*>(value);
04133 }
04134 
04135 
04136 RegExp* RegExp::Cast(v8::Value* value) {
04137 #ifdef V8_ENABLE_CHECKS
04138   CheckCast(value);
04139 #endif
04140   return static_cast<RegExp*>(value);
04141 }
04142 
04143 
04144 Object* Object::Cast(v8::Value* value) {
04145 #ifdef V8_ENABLE_CHECKS
04146   CheckCast(value);
04147 #endif
04148   return static_cast<Object*>(value);
04149 }
04150 
04151 
04152 Array* Array::Cast(v8::Value* value) {
04153 #ifdef V8_ENABLE_CHECKS
04154   CheckCast(value);
04155 #endif
04156   return static_cast<Array*>(value);
04157 }
04158 
04159 
04160 Function* Function::Cast(v8::Value* value) {
04161 #ifdef V8_ENABLE_CHECKS
04162   CheckCast(value);
04163 #endif
04164   return static_cast<Function*>(value);
04165 }
04166 
04167 
04168 External* External::Cast(v8::Value* value) {
04169 #ifdef V8_ENABLE_CHECKS
04170   CheckCast(value);
04171 #endif
04172   return static_cast<External*>(value);
04173 }
04174 
04175 
04176 Local<Value> AccessorInfo::Data() const {
04177   return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
04178 }
04179 
04180 
04181 Local<Object> AccessorInfo::This() const {
04182   return Local<Object>(reinterpret_cast<Object*>(&args_[0]));
04183 }
04184 
04185 
04186 Local<Object> AccessorInfo::Holder() const {
04187   return Local<Object>(reinterpret_cast<Object*>(&args_[-1]));
04188 }
04189 
04190 
04203 }  // namespace v8
04204 
04205 
04206 #undef V8EXPORT
04207 #undef TYPE_CHECK
04208 
04209 
04210 #endif  // V8_H_

Generated on Thu Oct 6 2011 12:01:33 for V8 by  doxygen 1.7.1