v8.h revision 50ef84f5fad2def87d3fbc737bec4a32711fdef4
1a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Copyright 2007-2009 the V8 project authors. All rights reserved. 2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without 3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are 4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met: 5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions of source code must retain the above copyright 7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// notice, this list of conditions and the following disclaimer. 8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Redistributions in binary form must reproduce the above 9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// copyright notice, this list of conditions and the following 10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// disclaimer in the documentation and/or other materials provided 11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// with the distribution. 12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// * Neither the name of Google Inc. nor the names of its 13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// contributors may be used to endorse or promote products derived 14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// from this software without specific prior written permission. 15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** \mainpage V8 API Reference Guide 29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 is Google's open source JavaScript engine. 31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This set of documents provides reference material generated from the 33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 header file, include/v8.h. 34a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 35a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * For other documentation see http://code.google.com/apis/v8/ 36a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 37a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 38a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_H_ 39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_H_ 40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 41a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include <stdio.h> 42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef _WIN32 44a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// When compiling on MinGW stdint.h is available. 45a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef __MINGW32__ 46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include <stdint.h> 47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else // __MINGW32__ 48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef signed char int8_t; 49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned char uint8_t; 50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef short int16_t; // NOLINT 51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned short uint16_t; // NOLINT 52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int int32_t; 53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned int uint32_t; 54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef __int64 int64_t; 55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef unsigned __int64 uint64_t; 56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// intptr_t and friends are defined in crtdefs.h through stdio.h. 57a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // __MINGW32__ 58a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 59a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Windows DLL export/import. When building the V8 DLL the 60a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// BUILDING_V8_SHARED needs to be defined. When building a program which uses 61a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8 62a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// static library or building a program which uses the V8 static library neither 63a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined. 64a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED) 65a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\ 66a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block build configuration to ensure that at most one of these is set 67a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 68a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 69a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef BUILDING_V8_SHARED 70a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __declspec(dllexport) 71a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#elif USING_V8_SHARED 72a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __declspec(dllimport) 73a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else 74a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT 75a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // BUILDING_V8_SHARED 76a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 77a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else // _WIN32 78a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 79a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include <stdint.h> 80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setup for Linux shared library export. There is no need to distinguish 82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// between building or using the V8 shared library, but we should not 83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// export symbols when we are building a static library. 84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED) 85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT __attribute__ ((visibility("default"))) 86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else // defined(__GNUC__) && (__GNUC__ >= 4) 87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8EXPORT 88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // defined(__GNUC__) && (__GNUC__ >= 4) 89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // _WIN32 91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The v8 JavaScript engine. 94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 { 96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Context; 98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass String; 99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Value; 100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Utils; 101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Number; 102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Object; 103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Array; 104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Int32; 105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Uint32; 106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass External; 107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Primitive; 108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Boolean; 109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Integer; 110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Function; 111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Date; 112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ImplementationUtilities; 113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Signature; 114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Handle; 115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Local; 116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> class Persistent; 117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass FunctionTemplate; 118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ObjectTemplate; 119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Data; 120f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeclass AccessorInfo; 12125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackTrace; 12225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass StackFrame; 123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal { 125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Arguments; 127d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blockclass Object; 1287f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochclass Heap; 129d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blockclass Top; 130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- W e a k H a n d l e s 135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A weak reference callback function. 139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 14050ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * This callback should either explicitly invoke Dispose on |object| if 14150ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. 14250ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen * 143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param object the weak global object to be reclaimed by the garbage collector 144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param parameter the value passed in when making the weak global object 145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*WeakReferenceCallback)(Persistent<Value> object, 147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void* parameter); 148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- H a n d l e s --- 151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 15250ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen#define TYPE_CHECK(T, S) \ 15350ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen while (false) { \ 15450ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ 155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference managed by the v8 garbage collector. 159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * All objects returned from v8 have to be tracked by the garbage 161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * collector so that it knows that the objects are still alive. Also, 162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * because the garbage collector may move objects, it is unsafe to 163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * point directly to an object. Instead, all objects are stored in 164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles which are known by the garbage collector and updated 165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * whenever an object moves. Handles should always be passed by value 166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * (except in cases like out-parameters) and they should never be 167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated on the heap. 168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * There are two types of handles: local and persistent handles. 170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local handles are light-weight and transient and typically used in 171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * local operations. They are managed by HandleScopes. Persistent 172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles can be used when storing objects across several independent 173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operations and have to be explicitly deallocated when they're no 174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * longer used. 175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * It is safe to extract the object stored in the handle by 177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * dereferencing the handle (for instance, to extract the Object* from 178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * an Handle<Object>); the value will still be governed by a handle 179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * behind the scenes and the same rules apply to these values as to 180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * their handles. 181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1828defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Handle { 183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates an empty handle. 187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Handle(); 189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a new handle for the specified value. 192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1938defd9ff6930b4e24729971a61cf7469daf119beSteve Block inline explicit Handle(T* val) : val_(val) { } 194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a handle for the contents of the specified handle. This 197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor allows you to pass handles as arguments by value and 198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to assign between handles. However, if you try to assign between 199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * incompatible handles, for instance from a Handle<String> to a 200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Handle<Number> it will cause a compiletime error. Assigning 201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * between compatible handles, for instance assigning a 202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Handle<String> to a variable declared as Handle<Value>, is legal 203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * because String is a subclass of Value. 204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> inline Handle(Handle<S> that) 206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : val_(reinterpret_cast<T*>(*that)) { 207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This check fails when trying to convert between incompatible 209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles. For example, converting from a Handle<String> to a 210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Handle<Number>. 211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block TYPE_CHECK(T, S); 213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the handle is empty. 217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2188defd9ff6930b4e24729971a61cf7469daf119beSteve Block inline bool IsEmpty() const { return val_ == 0; } 219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2208defd9ff6930b4e24729971a61cf7469daf119beSteve Block inline T* operator->() const { return val_; } 221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2228defd9ff6930b4e24729971a61cf7469daf119beSteve Block inline T* operator*() const { return val_; } 223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets the handle to be empty. IsEmpty() will then return true. 226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2278defd9ff6930b4e24729971a61cf7469daf119beSteve Block inline void Clear() { this->val_ = 0; } 228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Checks whether two handles are the same. 231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if both are empty, or if the objects 232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to which they refer are identical. 233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The handles' references are not checked. 234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2358defd9ff6930b4e24729971a61cf7469daf119beSteve Block template <class S> inline bool operator==(Handle<S> that) const { 236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** a = reinterpret_cast<internal::Object**>(**this); 237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** b = reinterpret_cast<internal::Object**>(*that); 238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (a == 0) return b == 0; 239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (b == 0) return false; 240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return *a == *b; 241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Checks whether two handles are different. 245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if only one of the handles is empty, or if 246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the objects to which they refer are different. 247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The handles' references are not checked. 248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2498defd9ff6930b4e24729971a61cf7469daf119beSteve Block template <class S> inline bool operator!=(Handle<S> that) const { 250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return !operator==(that); 251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> static inline Handle<T> Cast(Handle<S> that) { 254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // If we're going to perform the type check then we have to check 256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // that the handle isn't empty before doing the checked cast. 257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (that.IsEmpty()) return Handle<T>(); 258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Handle<T>(T::Cast(*that)); 260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block template <class S> inline Handle<S> As() { 2636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return Handle<S>::Cast(*this); 2646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 2656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block T* val_; 268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A light-weight stack-allocated object handle. All operations 273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that return objects from within v8 return them in local handles. They 274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are created within HandleScopes, and all local handles allocated within a 275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope are destroyed when the handle scope is destroyed. Hence it 276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is not necessary to explicitly deallocate local handles. 277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2788defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Local : public Handle<T> { 279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local(); 281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> inline Local(Local<S> that) 282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : Handle<T>(reinterpret_cast<T*>(*that)) { 283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This check fails when trying to convert between incompatible 285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles. For example, converting from a Handle<String> to a 286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Handle<Number>. 287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block TYPE_CHECK(T, S); 289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> inline Local(S* that) : Handle<T>(that) { } 291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> static inline Local<T> Cast(Local<S> that) { 292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // If we're going to perform the type check then we have to check 294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // that the handle isn't empty before doing the checked cast. 295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (that.IsEmpty()) return Local<T>(); 296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<T>(T::Cast(*that)); 298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block template <class S> inline Local<S> As() { 3016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return Local<S>::Cast(*this); 3026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 3036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Create a local handle for the content of another handle. 305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The referee is kept alive by the local handle even when 306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the original handle is destroyed/disposed. 307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline static Local<T> New(Handle<T> that); 309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An object reference that is independent of any handle scope. Where 314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a Local handle only lives as long as the HandleScope in which it was 315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated, a Persistent handle remains valid until it is explicitly 316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * disposed. 317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A persistent handle contains a reference to a storage cell within 319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the v8 engine which holds an object value and which is updated by 320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the garbage collector whenever the object is moved. A new storage 321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * cell can be created using Persistent::New and existing handles can 322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be disposed using Persistent::Dispose. Since persistent handles 323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are passed by value you may have many persistent handle objects 324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that point to the same storage cell. For instance, if you pass a 325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * persistent handle as an argument to a function you will not get two 326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * different storage cells but rather two references to the same 327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * storage cell. 328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3298defd9ff6930b4e24729971a61cf7469daf119beSteve Blocktemplate <class T> class Persistent : public Handle<T> { 330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates an empty persistent handle that doesn't point to any 334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * storage cell. 335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Persistent(); 337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a persistent handle for the same storage cell as the 340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * specified handle. This constructor allows you to pass persistent 341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles as arguments by value and to assign between persistent 342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles. However, attempting to assign between incompatible 343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * persistent handles, for instance from a Persistent<String> to a 344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Persistent<Number> will cause a compiletime error. Assigning 345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * between compatible persistent handles, for instance assigning a 346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Persistent<String> to a variable declared as Persistent<Value>, 347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is allowed as String is a subclass of Value. 348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> inline Persistent(Persistent<S> that) 350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : Handle<T>(reinterpret_cast<T*>(*that)) { 351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This check fails when trying to convert between incompatible 353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles. For example, converting from a Handle<String> to a 354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Handle<Number>. 355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block TYPE_CHECK(T, S); 357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> inline Persistent(S* that) : Handle<T>(that) { } 360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * "Casts" a plain handle which is known to be a persistent handle 363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to a persistent handle. 364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> explicit inline Persistent(Handle<S> that) 366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : Handle<T>(*that) { } 367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class S> static inline Persistent<T> Cast(Persistent<S> that) { 369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // If we're going to perform the type check then we have to check 371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // that the handle isn't empty before doing the checked cast. 372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (that.IsEmpty()) return Persistent<T>(); 373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Persistent<T>(T::Cast(*that)); 375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block template <class S> inline Persistent<S> As() { 3786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return Persistent<S>::Cast(*this); 3796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block } 3806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a new persistent handle for an existing local or 383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * persistent handle. 384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline static Persistent<T> New(Handle<T> that); 386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Releases the storage cell referenced by this persistent handle. 389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Does not remove the reference to the cell from any handles. 390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This handle's reference, and any any other references to the storage 391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * cell remain and IsEmpty will still return false. 392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void Dispose(); 394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Make the reference to this object weak. When only weak handles 397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * refer to the object, the garbage collector will perform a 398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * callback to the given V8::WeakReferenceCallback function, passing 399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * it the object reference and the given parameters. 400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void MakeWeak(void* parameters, WeakReferenceCallback callback); 402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Clears the weak reference to this object.*/ 404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void ClearWeak(); 405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block *Checks if the handle holds the only reference to an object. 408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline bool IsNearDeath() const; 410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the handle's reference is weak. 413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline bool IsWeak() const; 415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class ImplementationUtilities; 418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class ObjectTemplate; 419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A stack-allocated class that governs a number of local handles. 424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After a handle scope has been created, all local handles will be 425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * allocated within that handle scope until either the handle scope is 426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * deleted or another handle scope is created. If there is already a 427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle scope and a new one is created, all allocations will take 428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * place in the new handle scope until it is deleted. After that, 429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * new handles will again be allocated in the original handle scope. 430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After the handle scope of a local handle has been deleted the 432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * garbage collector will no longer track the object stored in the 433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle and may deallocate it. The behavior of accessing a handle 434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for which the handle scope has been deleted is undefined. 435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT HandleScope { 437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block HandleScope(); 439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~HandleScope(); 441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Closes the handle scope and returns the value as a handle in the 444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * previous scope, which is the new current scope after the call. 445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class T> Local<T> Close(Handle<T> value); 447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Counts the number of allocated handles. 450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static int NumberOfHandles(); 452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a new handle with the given value. 455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static internal::Object** CreateHandle(internal::Object* value); 457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Make it impossible to create heap-allocated or illegal handle 460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // scopes by disallowing certain operations. 461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block HandleScope(const HandleScope&); 462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator=(const HandleScope&); 463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void* operator new(size_t size); 464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator delete(void*, size_t); 465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 466d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block // This Data class is accessible internally as HandleScopeData through a 467d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block // typedef in the ImplementationUtilities class. 468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block class V8EXPORT Data { 469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int extensions; 471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** next; 472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** limit; 473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void Initialize() { 474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block extensions = -1; 475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block next = limit = NULL; 476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Data previous_; 480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Allow for the active closing of HandleScopes which allows to pass a handle 482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // from the HandleScope being closed to the next top most HandleScope. 483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool is_closed_; 484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** RawClose(internal::Object** value); 485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class ImplementationUtilities; 487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- S p e c i a l o b j e c t s --- 491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of values and API object templates. 495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Data { 497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Data(); 499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Pre-compilation data that can be associated with a script. This 504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data can be calculated for a script in advance of actually 505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * compiling it, and can be stored between compilations. When script 506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * data is given to the compile method compilation will be faster. 507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ScriptData { // NOLINT 509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual ~ScriptData() { } 5117f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 512f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke /** 513f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Pre-compiles the specified script (context-independent). 514f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * 515f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * \param input Pointer to UTF-8 script source code. 516f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * \param length Length of UTF-8 script source code. 517f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static ScriptData* PreCompile(const char* input, int length); 519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 520f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke /** 5217f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * Pre-compiles the specified script (context-independent). 5227f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * 5237f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * NOTE: Pre-compilation using this method cannot happen on another thread 5247f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * without using Lockers. 5257f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * 5267f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * \param source Script source code. 5277f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch */ 5287f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch static ScriptData* PreCompile(Handle<String> source); 5297f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 5307f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch /** 531f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Load previous pre-compilation data. 532f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * 533f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * \param data Pointer to data returned by a call to Data() of a previous 534f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * ScriptData. Ownership is not transferred. 535f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * \param length Length of data. 536f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 537f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke static ScriptData* New(const char* data, int length); 538f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 539f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke /** 540f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Returns the length of Data(). 541f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual int Length() = 0; 543f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 544f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke /** 545f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Returns a serialized representation of this ScriptData that can later be 546f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * passed to New(). NOTE: Serialized data is platform-dependent. 547f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 548f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke virtual const char* Data() = 0; 549f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 550f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke /** 551f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Returns true if the source code could not be parsed. 552f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 553e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke virtual bool HasError() = 0; 554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The origin, within a file, of a script. 559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 5608defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass ScriptOrigin { 561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 5628defd9ff6930b4e24729971a61cf7469daf119beSteve Block inline ScriptOrigin( 5638defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Value> resource_name, 5648defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Integer> resource_line_offset = Handle<Integer>(), 5658defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Integer> resource_column_offset = Handle<Integer>()) 566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : resource_name_(resource_name), 567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block resource_line_offset_(resource_line_offset), 568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block resource_column_offset_(resource_column_offset) { } 569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Handle<Value> ResourceName() const; 570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Handle<Integer> ResourceLineOffset() const; 571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Handle<Integer> ResourceColumnOffset() const; 572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> resource_name_; 574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Integer> resource_line_offset_; 575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Integer> resource_column_offset_; 576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A compiled JavaScript script. 581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Script { 583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 585402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu /** 586402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Compiles the specified script (context-independent). 587402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * 588402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param source Script source code. 5896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * \param origin Script origin, owned by caller, no references are kept 590402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * when New() returns 591402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() 592402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * using pre_data speeds compilation if it's done multiple times. 593402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Owned by caller, no references are kept when New() returns. 594402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param script_data Arbitrary data associated with script. Using 5956ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * this has same effect as calling SetData(), but allows data to be 596402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * available to compile event handlers. 597402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \return Compiled script object (context independent; when run it 598402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * will use the currently entered context). 599402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu */ 600402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu static Local<Script> New(Handle<String> source, 601402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu ScriptOrigin* origin = NULL, 602402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu ScriptData* pre_data = NULL, 603402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu Handle<String> script_data = Handle<String>()); 604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 605402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu /** 606402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Compiles the specified script using the specified file name 607402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * object (typically a string) as the script's origin. 608402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * 609402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param source Script source code. 6106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * \param file_name file name object (typically a string) to be used 611402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * as the script's origin. 612402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \return Compiled script object (context independent; when run it 613402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * will use the currently entered context). 614402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu */ 615402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu static Local<Script> New(Handle<String> source, 616402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu Handle<Value> file_name); 617402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 618402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu /** 619402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Compiles the specified script (bound to current context). 620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 621402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param source Script source code. 6226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * \param origin Script origin, owned by caller, no references are kept 623402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * when Compile() returns 624402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile() 625402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * using pre_data speeds compilation if it's done multiple times. 626402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Owned by caller, no references are kept when Compile() returns. 627402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param script_data Arbitrary data associated with script. Using 628402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * this has same effect as calling SetData(), but makes data available 629402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * earlier (i.e. to compile event handlers). 630402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \return Compiled script object, bound to the context that was active 631402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * when this function was called. When run it will always use this 632402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * context. 633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Script> Compile(Handle<String> source, 635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ScriptOrigin* origin = NULL, 636402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu ScriptData* pre_data = NULL, 637402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu Handle<String> script_data = Handle<String>()); 638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Compiles the specified script using the specified file name 641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * object (typically a string) as the script's origin. 642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 643402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param source Script source code. 644402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param file_name File name to use as script's origin 645402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param script_data Arbitrary data associated with script. Using 646402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * this has same effect as calling SetData(), but makes data available 647402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * earlier (i.e. to compile event handlers). 648402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \return Compiled script object, bound to the context that was active 649402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * when this function was called. When run it will always use this 650402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * context. 651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Script> Compile(Handle<String> source, 653402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu Handle<Value> file_name, 654402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu Handle<String> script_data = Handle<String>()); 655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Runs the script returning the resulting value. If the script is 658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * context independent (created using ::New) it will be run in the 659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * currently entered context. If it is context specific (created 660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * using ::Compile) it will be run in the context in which it was 661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * compiled. 662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> Run(); 664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the script id value. 667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> Id(); 669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Associate an additional data object with the script. This is mainly used 672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * with the debugger as this data object is only available through the 673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * debugger API. 674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 675d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block void SetData(Handle<String> data); 676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An error message. 681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Message { 683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<String> Get() const; 685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<String> GetSourceLine() const; 686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the resource name for the script from where the function causing 689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the error originates. 690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> GetScriptResourceName() const; 692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the resource data for the script from where the function causing 695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the error originates. 696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> GetScriptData() const; 698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 7003bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch * Exception stack trace. By default stack traces are not captured for 7013bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows 7023bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch * to change this option. 7033bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch */ 7043bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch Handle<StackTrace> GetStackTrace() const; 7053bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch 7063bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch /** 707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the number, 1-based, of the line where the error occurred. 708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int GetLineNumber() const; 710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the index within the script of the first character where 713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the error occurred. 714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int GetStartPosition() const; 716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the index within the script of the last character where 719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the error occurred. 720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int GetEndPosition() const; 722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the index within the line of the first character where 725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the error occurred. 726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int GetStartColumn() const; 728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the index within the line of the last character where 731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the error occurred. 732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int GetEndColumn() const; 734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // TODO(1245381): Print to a string instead of on a FILE. 736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void PrintCurrentStackTrace(FILE* out); 73725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 73825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen static const int kNoLineNumberInfo = 0; 73925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen static const int kNoColumnInfo = 0; 74025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen}; 74125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 74225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 74325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/** 74425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Representation of a JavaScript stack trace. The information collected is a 74525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * snapshot of the execution stack and the information remains valid after 74625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * execution continues. 74725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 74825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackTrace { 74925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public: 75025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 75125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Flags that determine what information is placed captured for each 75225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * StackFrame when grabbing the current stack trace. 75325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 75425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen enum StackTraceOptions { 75525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kLineNumber = 1, 75625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kColumnOffset = 1 << 1 | kLineNumber, 75725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kScriptName = 1 << 2, 75825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kFunctionName = 1 << 3, 75925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kIsEval = 1 << 4, 76025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kIsConstructor = 1 << 5, 76125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName, 76225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen kDetailed = kOverview | kIsEval | kIsConstructor 76325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen }; 76425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 76525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 76625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns a StackFrame at a particular index. 76725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 76825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen Local<StackFrame> GetFrame(uint32_t index) const; 76925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 77025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 77125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns the number of StackFrames. 77225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 77325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen int GetFrameCount() const; 77425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 77525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 77625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns StackTrace as a v8::Array that contains StackFrame objects. 77725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 77825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen Local<Array> AsArray(); 77925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 78025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 78125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Grab a snapshot of the the current JavaScript execution stack. 78225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * 78325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * \param frame_limit The maximum number of stack frames we want to capture. 78425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * \param options Enumerates the set of things we will capture for each 78525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * StackFrame. 78625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 78725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen static Local<StackTrace> CurrentStackTrace( 78825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen int frame_limit, 78925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen StackTraceOptions options = kOverview); 79025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen}; 79125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 79225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 79325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen/** 79425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * A single JavaScript stack frame. 79525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 79625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenclass V8EXPORT StackFrame { 79725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen public: 79825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 79925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns the number, 1-based, of the line for the associate function call. 80025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * This method will return Message::kNoLineNumberInfo if it is unable to 80125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * retrieve the line number, or if kLineNumber was not passed as an option 80225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * when capturing the StackTrace. 80325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 80425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen int GetLineNumber() const; 80525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 80625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 80725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns the 1-based column offset on the line for the associated function 80825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * call. 80925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * This method will return Message::kNoColumnInfo if it is unable to retrieve 81025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * the column number, or if kColumnOffset was not passed as an option when 81125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * capturing the StackTrace. 81225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 81325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen int GetColumn() const; 81425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 81525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 81625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns the name of the resource that contains the script for the 81725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * function for this StackFrame. 81825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 81925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen Local<String> GetScriptName() const; 82025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 82125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 82225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns the name of the function associated with this stack frame. 82325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 82425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen Local<String> GetFunctionName() const; 82525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 82625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 82725f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns whether or not the associated function is compiled via a call to 82825f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * eval(). 82925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 83025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen bool IsEval() const; 83125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen 83225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen /** 83325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * Returns whther or not the associated function is called as a 83425f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen * constructor via "new". 83525f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen */ 83625f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen bool IsConstructor() const; 837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- V a l u e --- 841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of all JavaScript values and objects. 845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8468defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Value : public Data { 847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is the undefined value. See ECMA-262 851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 4.3.10. 852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8538defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsUndefined() const; 854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is the null value. See ECMA-262 857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 4.3.11. 858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8598defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsNull() const; 860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is true. 863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8648defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsTrue() const; 865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is false. 868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8698defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsFalse() const; 870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is an instance of the String type. 873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ECMA-262 8.4. 874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline bool IsString() const; 876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is a function. 879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8808defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsFunction() const; 881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is an array. 884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8858defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsArray() const; 886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is an object. 889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8908defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsObject() const; 891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is boolean. 894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 8958defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsBoolean() const; 896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is a number. 899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9008defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsNumber() const; 901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is external. 904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9058defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsExternal() const; 906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is a 32-bit signed integer. 909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9108defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsInt32() const; 911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 9136ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Returns true if this value is a 32-bit unsigned integer. 9146ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 9158defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsUint32() const; 9166ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 9176ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this value is a Date. 919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9208defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsDate() const; 921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 9228defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Boolean> ToBoolean() const; 9238defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Number> ToNumber() const; 9248defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<String> ToString() const; 9258defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<String> ToDetailString() const; 9268defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Object> ToObject() const; 9278defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Integer> ToInteger() const; 9288defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Uint32> ToUint32() const; 9298defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Int32> ToInt32() const; 930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Attempts to convert a string to an array index. 933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an empty handle if the conversion fails. 934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9358defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Uint32> ToArrayIndex() const; 936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 9378defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool BooleanValue() const; 9388defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT double NumberValue() const; 9398defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int64_t IntegerValue() const; 9408defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT uint32_t Uint32Value() const; 9418defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int32_t Int32Value() const; 942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** JS == */ 9448defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Equals(Handle<Value> that) const; 9458defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool StrictEquals(Handle<Value> that) const; 9463ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline bool QuickIsString() const; 9498defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool FullIsString() const; 950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of primitive values. See ECMA-262 4.3.2. 955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9568defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Primitive : public Value { }; 957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A primitive boolean value (ECMA-262, 4.3.14). Either the true 961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * or false value. 962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9638defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Boolean : public Primitive { 964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 9658defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Value() const; 966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Handle<Boolean> New(bool value); 967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript string value (ECMA-262, 4.3.17). 972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9738defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass String : public Primitive { 974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the number of characters in this string. 978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9798defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int Length() const; 980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the number of bytes in the UTF-8 encoded 983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * representation of this string. 984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 9858defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int Utf8Length() const; 986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Write the contents of the string to an external buffer. 989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If no arguments are given, expects the buffer to be large 990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * enough to hold the entire string and NULL terminator. Copies 991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the contents of the string and the NULL terminator into the 992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * buffer. 993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Copies up to length characters into the output buffer. 995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Only null-terminates if there is enough space in the buffer. 996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param buffer The buffer into which the string will be copied. 998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param start The starting position within the string at which 999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * copying begins. 1000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param length The number of bytes to copy from the string. 10016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * \param nchars_ref The number of characters written, can be NULL. 10026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * \param hints Various hints that might affect performance of this or 10036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * subsequent operations. 10046ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * \return The number of bytes copied to the buffer 1005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * excluding the NULL terminator. 1006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 10076ded16be15dd865a9b21ea304d5273c8be299c87Steve Block enum WriteHints { 10086ded16be15dd865a9b21ea304d5273c8be299c87Steve Block NO_HINTS = 0, 10096ded16be15dd865a9b21ea304d5273c8be299c87Steve Block HINT_MANY_WRITES_EXPECTED = 1 10106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block }; 10116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 10128defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int Write(uint16_t* buffer, 10138defd9ff6930b4e24729971a61cf7469daf119beSteve Block int start = 0, 10148defd9ff6930b4e24729971a61cf7469daf119beSteve Block int length = -1, 10158defd9ff6930b4e24729971a61cf7469daf119beSteve Block WriteHints hints = NO_HINTS) const; // UTF-16 10168defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int WriteAscii(char* buffer, 10178defd9ff6930b4e24729971a61cf7469daf119beSteve Block int start = 0, 10188defd9ff6930b4e24729971a61cf7469daf119beSteve Block int length = -1, 10198defd9ff6930b4e24729971a61cf7469daf119beSteve Block WriteHints hints = NO_HINTS) const; // ASCII 10208defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int WriteUtf8(char* buffer, 10218defd9ff6930b4e24729971a61cf7469daf119beSteve Block int length = -1, 10228defd9ff6930b4e24729971a61cf7469daf119beSteve Block int* nchars_ref = NULL, 10238defd9ff6930b4e24729971a61cf7469daf119beSteve Block WriteHints hints = NO_HINTS) const; // UTF-8 1024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A zero length string. 1027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 10288defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static v8::Local<v8::String> Empty(); 1029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the string is external 1032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 10338defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsExternal() const; 1034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the string is both external and ascii 1037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 10388defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsExternalAscii() const; 1039e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke 1040e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke class V8EXPORT ExternalStringResourceBase { 1041e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke public: 1042e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke virtual ~ExternalStringResourceBase() {} 10437f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 1044e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke protected: 1045e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke ExternalStringResourceBase() {} 10467f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 10477f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch /** 10487f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * Internally V8 will call this Dispose method when the external string 10497f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * resource is no longer needed. The default implementation will use the 10507f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * delete operator. This method can be overridden in subclasses to 10517f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * control how allocated external string resources are disposed. 10527f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch */ 10537f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch virtual void Dispose() { delete this; } 10547f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 1055e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke private: 1056e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke // Disallow copying and assigning. 1057e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke ExternalStringResourceBase(const ExternalStringResourceBase&); 1058e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke void operator=(const ExternalStringResourceBase&); 10597f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 10607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch friend class v8::internal::Heap; 1061e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke }; 1062e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke 1063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An ExternalStringResource is a wrapper around a two-byte string 1065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * buffer that resides outside V8's heap. Implement an 1066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ExternalStringResource to manage the life cycle of the underlying 1067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * buffer. Note that the string data must be immutable. 1068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1069e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke class V8EXPORT ExternalStringResource 1070e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke : public ExternalStringResourceBase { 1071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Override the destructor to manage the life cycle of the underlying 1074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * buffer. 1075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual ~ExternalStringResource() {} 10777f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 10787f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch /** 10797f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * The string data from the underlying buffer. 10807f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch */ 1081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual const uint16_t* data() const = 0; 10827f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 10837f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch /** 10847f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * The length of the string. That is, the number of two-byte characters. 10857f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch */ 1086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual size_t length() const = 0; 10877f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch 1088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected: 1089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ExternalStringResource() {} 1090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 1091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An ExternalAsciiStringResource is a wrapper around an ascii 1094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * string buffer that resides outside V8's heap. Implement an 1095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ExternalAsciiStringResource to manage the life cycle of the 1096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * underlying buffer. Note that the string data must be immutable 1097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and that the data must be strict 7-bit ASCII, not Latin1 or 1098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * UTF-8, which would require special treatment internally in the 1099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * engine and, in the case of UTF-8, do not allow efficient indexing. 1100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Use String::New or convert to 16 bit data for non-ASCII. 1101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1103e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke class V8EXPORT ExternalAsciiStringResource 1104e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke : public ExternalStringResourceBase { 1105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Override the destructor to manage the life cycle of the underlying 1108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * buffer. 1109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual ~ExternalAsciiStringResource() {} 1111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** The string data from the underlying buffer.*/ 1112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual const char* data() const = 0; 1113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** The number of ascii characters in the string.*/ 1114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual size_t length() const = 0; 1115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected: 1116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ExternalAsciiStringResource() {} 1117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 1118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Get the ExternalStringResource for an external string. Returns 1121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * NULL if IsExternal() doesn't return true. 1122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline ExternalStringResource* GetExternalStringResource() const; 1124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Get the ExternalAsciiStringResource for an external ascii string. 1127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns NULL if IsExternalAscii() doesn't return true. 1128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 11298defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT ExternalAsciiStringResource* GetExternalAsciiStringResource() const; 1130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline String* Cast(v8::Value* obj); 1132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Allocates a new string from either utf-8 encoded or ascii data. 1135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The second parameter 'length' gives the buffer length. 1136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If the data is utf-8 encoded, the caller must 1137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be careful to supply the length parameter. 1138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If it is not given, the function calls 1139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 'strlen' to determine the buffer length, it might be 1140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * wrong if 'data' contains a null character. 1141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 11428defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> New(const char* data, int length = -1); 1143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Allocates a new string from utf16 data.*/ 11458defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> New(const uint16_t* data, int length = -1); 1146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Creates a symbol. Returns one if it exists already.*/ 11488defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> NewSymbol(const char* data, int length = -1); 1149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 11513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Creates a new string by concatenating the left and the right strings 11523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * passed in as parameters. 11533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block */ 11548defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> Concat(Handle<String> left, 11558defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<String>right); 11563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 11573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block /** 1158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a new external string using the data defined in the given 11597f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * resource. When the external string is no longer live on V8's heap the 11607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * resource will be disposed by calling its Dispose method. The caller of 11617f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * this function should not otherwise delete or modify the resource. Neither 11627f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * should the underlying buffer be deallocated or modified except through the 11637f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * destructor of the external string resource. 1164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 11658defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); 1166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Associate an external string resource with this string by transforming it 1169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * in place so that existing references to this string in the JavaScript heap 1170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * will use the external string resource. The external string resource's 1171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * character contents needs to be equivalent to this string. 1172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the string has been changed to be an external string. 11737f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * The string is not modified if the operation fails. See NewExternal for 11747f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * information on the lifetime of the resource. 1175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 11768defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool MakeExternal(ExternalStringResource* resource); 1177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a new external string using the ascii data defined in the given 11807f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * resource. When the external string is no longer live on V8's heap the 11817f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * resource will be disposed by calling its Dispose method. The caller of 11827f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * this function should not otherwise delete or modify the resource. Neither 11837f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * should the underlying buffer be deallocated or modified except through the 11847f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * destructor of the external string resource. 1185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 11868defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> NewExternal( 11878defd9ff6930b4e24729971a61cf7469daf119beSteve Block ExternalAsciiStringResource* resource); 1188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Associate an external string resource with this string by transforming it 1191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * in place so that existing references to this string in the JavaScript heap 1192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * will use the external string resource. The external string resource's 1193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * character contents needs to be equivalent to this string. 1194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the string has been changed to be an external string. 11957f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * The string is not modified if the operation fails. See NewExternal for 11967f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch * information on the lifetime of the resource. 1197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 11988defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool MakeExternal(ExternalAsciiStringResource* resource); 1199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this string can be made external. 1202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 12038defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool CanMakeExternal(); 1204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Creates an undetectable string from the supplied ascii or utf-8 data.*/ 12068defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> NewUndetectable(const char* data, 12078defd9ff6930b4e24729971a61cf7469daf119beSteve Block int length = -1); 1208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Creates an undetectable string from the supplied utf-16 data.*/ 12108defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<String> NewUndetectable(const uint16_t* data, 12118defd9ff6930b4e24729971a61cf7469daf119beSteve Block int length = -1); 1212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Converts an object to a utf8-encoded character array. Useful if 1215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * you want to print the object. If conversion to a string fails 1216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * (eg. due to an exception in the toString() method of the object) 1217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * then the length() method returns 0 and the * operator returns 1218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * NULL. 1219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block class V8EXPORT Utf8Value { 1221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block explicit Utf8Value(Handle<v8::Value> obj); 1223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~Utf8Value(); 1224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block char* operator*() { return str_; } 1225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* operator*() const { return str_; } 1226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length() const { return length_; } 1227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 1228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block char* str_; 1229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length_; 1230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Disallow copying and assigning. 1232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Utf8Value(const Utf8Value&); 1233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator=(const Utf8Value&); 1234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 1235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Converts an object to an ascii string. 1238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Useful if you want to print the object. 1239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If conversion to a string fails (eg. due to an exception in the toString() 1240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * method of the object) then the length() method returns 0 and the * operator 1241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * returns NULL. 1242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block class V8EXPORT AsciiValue { 1244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block explicit AsciiValue(Handle<v8::Value> obj); 1246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~AsciiValue(); 1247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block char* operator*() { return str_; } 1248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* operator*() const { return str_; } 1249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length() const { return length_; } 1250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 1251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block char* str_; 1252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length_; 1253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Disallow copying and assigning. 1255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AsciiValue(const AsciiValue&); 1256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator=(const AsciiValue&); 1257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 1258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Converts an object to a two-byte string. 1261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If conversion to a string fails (eg. due to an exception in the toString() 1262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * method of the object) then the length() method returns 0 and the * operator 1263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * returns NULL. 1264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block class V8EXPORT Value { 1266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block explicit Value(Handle<v8::Value> obj); 1268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~Value(); 1269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uint16_t* operator*() { return str_; } 1270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const uint16_t* operator*() const { return str_; } 1271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length() const { return length_; } 1272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 1273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uint16_t* str_; 1274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length_; 1275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Disallow copying and assigning. 1277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Value(const Value&); 1278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator=(const Value&); 1279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 12803ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 1281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 12828defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; 12838defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static void CheckCast(v8::Value* obj); 1284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript number value (ECMA-262, 4.3.20) 1289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 12908defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Number : public Primitive { 1291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 12928defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT double Value() const; 12938defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<Number> New(double value); 1294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Number* Cast(v8::Value* obj); 1295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 12968defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Number(); 1297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void CheckCast(v8::Value* obj); 1298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a signed integer. 1303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 13048defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Integer : public Number { 1305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 13068defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<Integer> New(int32_t value); 13078defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<Integer> NewFromUnsigned(uint32_t value); 13088defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int64_t Value() const; 1309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Integer* Cast(v8::Value* obj); 1310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 13118defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Integer(); 13128defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static void CheckCast(v8::Value* obj); 1313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit signed integer. 1318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 13198defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Int32 : public Integer { 1320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 13218defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int32_t Value() const; 1322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 13238defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Int32(); 1324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value representing a 32-bit unsigned integer. 1329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 13308defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Uint32 : public Integer { 1331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 13328defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT uint32_t Value() const; 1333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 13348defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Uint32(); 1335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An instance of the built-in Date constructor (ECMA-262, 15.9). 1340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 13418defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Date : public Value { 1342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 13438defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<Value> New(double time); 1344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A specialization of Value::NumberValue that is more efficient 1347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * because we know the structure of this object. 1348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 13498defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT double NumberValue() const; 1350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Date* Cast(v8::Value* obj); 1352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 13538defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static void CheckCast(v8::Value* obj); 1354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum PropertyAttribute { 1358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block None = 0, 1359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ReadOnly = 1 << 0, 1360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block DontEnum = 1 << 1, 1361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block DontDelete = 1 << 2 1362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 13643ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockenum ExternalArrayType { 13653ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block kExternalByteArray = 1, 13663ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block kExternalUnsignedByteArray, 13673ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block kExternalShortArray, 13683ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block kExternalUnsignedShortArray, 13693ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block kExternalIntArray, 13703ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block kExternalUnsignedIntArray, 13713ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block kExternalFloatArray 13723ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block}; 13733ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 1374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1375f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Accessor[Getter|Setter] are used as callback functions when 1376f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * setting|getting a particular property. See Object and ObjectTemplate's 1377f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * method SetAccessor. 1378f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 1379f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef Handle<Value> (*AccessorGetter)(Local<String> property, 1380f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke const AccessorInfo& info); 1381f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 1382f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 1383f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarketypedef void (*AccessorSetter)(Local<String> property, 1384f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke Local<Value> value, 1385f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke const AccessorInfo& info); 1386f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 1387f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 1388f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/** 1389f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Access control specifications. 1390f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * 1391f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Some accessors should be accessible across contexts. These 1392f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors have an explicit access control parameter which specifies 1393f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * the kind of cross-context access that should be allowed. 1394f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * 1395f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Additionally, for security, accessors can prohibit overwriting by 1396f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors defined in JavaScript. For objects that have such 1397f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * accessors either locally or in their prototype chain it is not 1398f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * possible to overwrite the accessor by using __defineGetter__ or 1399f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * __defineSetter__ from JavaScript code. 1400f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 1401f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarkeenum AccessControl { 1402f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke DEFAULT = 0, 1403f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke ALL_CAN_READ = 1, 1404f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke ALL_CAN_WRITE = 1 << 1, 1405f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke PROHIBITS_OVERWRITING = 1 << 2 1406f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke}; 1407f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 1408f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 1409f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke/** 1410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript object (ECMA-262, 4.3.3) 1411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 14128defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Object : public Value { 1413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 14148defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Set(Handle<Value> key, 14158defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Value> value, 14168defd9ff6930b4e24729971a61cf7469daf119beSteve Block PropertyAttribute attribs = None); 1417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14188defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Set(uint32_t index, 14198defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Value> value); 14206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 1421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Sets a local property on this object bypassing interceptors and 1422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // overriding accessors or read-only properties. 1423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // 1424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Note that if the object has an interceptor the property will be set 1425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // locally, but since the interceptor takes precedence the local property 1426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // will only be returned if the interceptor doesn't return a value. 1427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // 1428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Note also that this only works for named properties. 14298defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool ForceSet(Handle<Value> key, 14308defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Value> value, 14318defd9ff6930b4e24729971a61cf7469daf119beSteve Block PropertyAttribute attribs = None); 1432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14338defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> Get(Handle<Value> key); 1434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14358defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> Get(uint32_t index); 14366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 1437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // TODO(1245389): Replace the type-specific versions of these 1438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // functions with generic ones that accept a Handle<Value> key. 14398defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Has(Handle<String> key); 1440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14418defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Delete(Handle<String> key); 1442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Delete a property on this object bypassing interceptors and 1444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // ignoring dont-delete attributes. 14458defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool ForceDelete(Handle<Value> key); 1446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14478defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Has(uint32_t index); 1448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14498defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool Delete(uint32_t index); 1450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 14518defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool SetAccessor(Handle<String> name, 14528defd9ff6930b4e24729971a61cf7469daf119beSteve Block AccessorGetter getter, 14538defd9ff6930b4e24729971a61cf7469daf119beSteve Block AccessorSetter setter = 0, 14548defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Value> data = Handle<Value>(), 14558defd9ff6930b4e24729971a61cf7469daf119beSteve Block AccessControl settings = DEFAULT, 14568defd9ff6930b4e24729971a61cf7469daf119beSteve Block PropertyAttribute attribute = None); 1457f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke 1458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the names of the enumerable properties 1460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * of this object, including properties from prototype objects. The 1461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * array returned by this method contains the same values as would 1462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be enumerated by a for-in statement over this object. 1463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 14648defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Array> GetPropertyNames(); 1465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Get the prototype object. This does not skip objects marked to 1468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be skipped by __proto__ and it does not consult the security 1469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handler. 1470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 14718defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> GetPrototype(); 1472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1474402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Set the prototype object. This does not skip objects marked to 1475402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * be skipped by __proto__ and it does not consult the security 1476402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * handler. 1477402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu */ 14788defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool SetPrototype(Handle<Value> prototype); 1479402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 1480402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu /** 1481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Finds an instance of the given function template in the prototype 1482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * chain. 1483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 14848defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Object> FindInstanceInPrototypeChain( 14858defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<FunctionTemplate> tmpl); 1486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Call builtin Object.prototype.toString on this object. 1489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This is different from Value::ToString() that may call 1490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * user-defined toString function. This one does not. 1491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 14928defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<String> ObjectProtoToString(); 1493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Gets the number of internal fields for this Object. */ 14958defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int InternalFieldCount(); 1496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Gets the value in an internal field. */ 1497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Value> GetInternalField(int index); 1498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Sets the value in an internal field. */ 14998defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void SetInternalField(int index, Handle<Value> value); 1500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Gets a native pointer from an internal field. */ 1502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void* GetPointerFromInternalField(int index); 15033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 1504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Sets a native pointer in an internal field. */ 15058defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void SetPointerInInternalField(int index, void* value); 1506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Testers for local properties. 15088defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool HasRealNamedProperty(Handle<String> key); 15098defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool HasRealIndexedProperty(uint32_t index); 15108defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); 1511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If result.IsEmpty() no real property was located in the prototype chain. 1514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This means interceptors in the prototype chain are not called. 1515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15168defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> GetRealNamedPropertyInPrototypeChain( 15178defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<String> key); 1518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If result.IsEmpty() no real property was located on the object or 1521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * in the prototype chain. 1522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This means interceptors in the prototype chain are not called. 1523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15248defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> GetRealNamedProperty(Handle<String> key); 1525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Tests for a named lookup interceptor.*/ 15278defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool HasNamedLookupInterceptor(); 1528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Tests for an index lookup interceptor.*/ 15308defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool HasIndexedLookupInterceptor(); 1531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Turns on access check on the object if the object is an instance of 1534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a template that has access check callbacks. If an object has no 1535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * access check info, the object cannot be accessed by anyone. 1536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15378defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void TurnOnAccessCheck(); 1538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the identity hash for this object. The current implemenation uses 1541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a hidden property on the object to store the identity hash. 1542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value will never be 0. Also, it is not guaranteed to be 1544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * unique. 1545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15468defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int GetIdentityHash(); 1547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Access hidden properties on JavaScript objects. These properties are 1550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * hidden from the executing JavaScript and only accessible through the V8 1551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * C++ API. Hidden properties introduced by V8 internally (for example the 1552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * identity hash) are prefixed with "v8::". 1553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15548defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool SetHiddenValue(Handle<String> key, Handle<Value> value); 15558defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> GetHiddenValue(Handle<String> key); 15568defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool DeleteHiddenValue(Handle<String> key); 15573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 1558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if this is an instance of an api function (one 1560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * created from a function created from a function template) and has 1561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * been modified since it was created. Note that this method is 1562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * conservative and may return true for objects that haven't actually 1563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * been modified. 1564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15658defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT bool IsDirty(); 1566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Clone this object with a fast but shallow copy. Values will point 1569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to the same values as the original object. 1570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15718defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Object> Clone(); 1572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Set the backing store of the indexed properties to be managed by the 1575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * embedding layer. Access to the indexed properties will follow the rules 1576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * spelled out in CanvasPixelArray. 1577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Note: The embedding program still owns the data and needs to ensure that 1578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the backing store is preserved while V8 has a reference. 1579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 15808defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void SetIndexedPropertiesToPixelData(uint8_t* data, int length); 15819dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen bool HasIndexedPropertiesInPixelData(); 15829dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen uint8_t* GetIndexedPropertiesPixelData(); 15839dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen int GetIndexedPropertiesPixelDataLength(); 1584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 15853ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block /** 15863ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Set the backing store of the indexed properties to be managed by the 15873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * embedding layer. Access to the indexed properties will follow the rules 15883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * spelled out for the CanvasArray subtypes in the WebGL specification. 15893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Note: The embedding program still owns the data and needs to ensure that 15903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * the backing store is preserved while V8 has a reference. 15913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block */ 15928defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void SetIndexedPropertiesToExternalArrayData( 15938defd9ff6930b4e24729971a61cf7469daf119beSteve Block void* data, 15948defd9ff6930b4e24729971a61cf7469daf119beSteve Block ExternalArrayType array_type, 15958defd9ff6930b4e24729971a61cf7469daf119beSteve Block int number_of_elements); 15969dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen bool HasIndexedPropertiesInExternalArrayData(); 15979dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen void* GetIndexedPropertiesExternalArrayData(); 15989dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen ExternalArrayType GetIndexedPropertiesExternalArrayDataType(); 15999dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen int GetIndexedPropertiesExternalArrayDataLength(); 16003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 16018defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<Object> New(); 1602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Object* Cast(Value* obj); 1603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 16048defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Object(); 16058defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static void CheckCast(Value* obj); 16068defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> CheckedGetInternalField(int index); 16078defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void* SlowGetPointerFromInternalField(int index); 1608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If quick access to the internal field is possible this method 16113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * returns the value. Otherwise an empty handle is returned. 1612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Value> UncheckedGetInternalField(int index); 1614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An instance of the built-in array constructor (ECMA-262, 15.4.2). 1619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 16208defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Array : public Object { 1621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 16228defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT uint32_t Length() const; 1623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Clones an element at index |index|. Returns an empty 1626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handle if cloning fails (for any reason). 1627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 16288defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Object> CloneElementAt(uint32_t index); 1629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 16308defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<Array> New(int length = 0); 1631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Array* Cast(Value* obj); 1632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 16338defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Array(); 1634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void CheckCast(Value* obj); 1635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript function object (ECMA-262, 15.3). 1640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 16418defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Function : public Object { 1642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 16438defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Object> NewInstance() const; 16448defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Object> NewInstance(int argc, Handle<Value> argv[]) const; 16458defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Local<Value> Call(Handle<Object> recv, 16468defd9ff6930b4e24729971a61cf7469daf119beSteve Block int argc, 16478defd9ff6930b4e24729971a61cf7469daf119beSteve Block Handle<Value> argv[]); 16488defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void SetName(Handle<String> name); 16498defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Handle<Value> GetName() const; 1650402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu 1651402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu /** 1652402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Returns zero based line number of function body and 1653402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * kLineOffsetNotFound if no information available. 1654402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu */ 16558defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT int GetScriptLineNumber() const; 16568defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT ScriptOrigin GetScriptOrigin() const; 1657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline Function* Cast(Value* obj); 16588defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static const int kLineOffsetNotFound; 1659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 16608defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT Function(); 16618defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static void CheckCast(Value* obj); 1662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A JavaScript value that wraps a C++ void*. This type of value is 1667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * mainly used to associate C++ data structures with JavaScript 1668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects. 1669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Wrap function V8 will return the most optimal Value object wrapping the 1671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * C++ void*. The type of the value is not guaranteed to be an External object 1672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and no assumptions about its type should be made. To access the wrapped 1673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * value Unwrap should be used, all other operations on that object will lead 1674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to unpredictable results. 1675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 16768defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass External : public Value { 1677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 16788defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<Value> Wrap(void* data); 1679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline void* Unwrap(Handle<Value> obj); 1680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 16818defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static Local<External> New(void* value); 1682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline External* Cast(Value* obj); 16838defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT void* Value() const; 1684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 16858defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT External(); 16868defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static void CheckCast(v8::Value* obj); 1687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline void* QuickUnwrap(Handle<v8::Value> obj); 16888defd9ff6930b4e24729971a61cf7469daf119beSteve Block V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj); 1689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- T e m p l a t e s --- 1693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The superclass of object and function templates. 1697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Template : public Data { 1699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Adds a property to each instance created by this template.*/ 1701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void Set(Handle<String> name, Handle<Data> value, 1702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PropertyAttribute attributes = None); 1703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline void Set(const char* name, Handle<Data> value); 1704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 1705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Template(); 1706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class ObjectTemplate; 1708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class FunctionTemplate; 1709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The argument information given to function call callbacks. This 1714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * class provides access to information about the context of the call, 1715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * including the receiver, the number and values of arguments, and 1716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the holder of the function. 1717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 17188defd9ff6930b4e24729971a61cf7469daf119beSteve Blockclass Arguments { 1719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline int Length() const; 1721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Value> operator[](int i) const; 1722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Function> Callee() const; 1723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Object> This() const; 1724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Object> Holder() const; 1725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline bool IsConstructCall() const; 1726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Value> Data() const; 1727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 1728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class ImplementationUtilities; 1729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Arguments(Local<Value> data, 1730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Object> holder, 1731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Function> callee, 1732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool is_construct_call, 1733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void** values, int length); 1734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> data_; 1735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Object> holder_; 1736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Function> callee_; 1737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool is_construct_call_; 1738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void** values_; 1739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int length_; 1740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1741a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1742a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The information passed to an accessor callback about the context 1745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * of the property access. 1746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT AccessorInfo { 1748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline AccessorInfo(internal::Object** args) 1750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : args_(args) { } 1751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Value> Data() const; 1752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Object> This() const; 1753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Local<Object> Holder() const; 1754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 1755a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** args_; 1756a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*InvocationCallback)(const Arguments& args); 1760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int (*LookupCallback)(Local<Object> self, Local<String> name); 1762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * NamedProperty[Getter|Setter] are used as interceptors on object. 1765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ObjectTemplate::SetNamedPropertyHandler. 1766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertyGetter)(Local<String> property, 1768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const AccessorInfo& info); 1769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1772a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request. 1773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle. 1774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*NamedPropertySetter)(Local<String> property, 1776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> value, 1777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const AccessorInfo& info); 1778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request. 17819dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * The result is an integer encoding property attributes (like v8::None, 17829dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * v8::DontEnum, etc.) 1783a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 17847f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochtypedef Handle<Integer> (*NamedPropertyQuery)(Local<String> property, 17857f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch const AccessorInfo& info); 1786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1787a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request. 1790a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false 1791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise. 1792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property, 1794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const AccessorInfo& info); 1795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the names of the properties the named 1798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property getter intercepts. 1799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info); 1801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value of the property if the getter intercepts the 1805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * request. Otherwise, returns an empty handle. 1806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index, 1808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const AccessorInfo& info); 1809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the value if the setter intercepts the request. 1813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Otherwise, returns an empty handle. 1814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Value> (*IndexedPropertySetter)(uint32_t index, 1816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> value, 1817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const AccessorInfo& info); 1818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the interceptor intercepts the request. 1822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The result is true if the property exists and false otherwise. 1823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*IndexedPropertyQuery)(uint32_t index, 1825a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const AccessorInfo& info); 1826a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1827a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1828a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns a non-empty handle if the deleter intercepts the request. 1829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The return value is true if the property could be deleted and false 1830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * otherwise. 1831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index, 1833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const AccessorInfo& info); 1834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns an array containing the indices of the properties the 1837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * indexed property getter intercepts. 1838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info); 1840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Access type specification. 1844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum AccessType { 1846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ACCESS_GET, 1847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ACCESS_SET, 1848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ACCESS_HAS, 1849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ACCESS_DELETE, 1850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ACCESS_KEYS 1851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 1852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the named 1856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given key on the host object. 1857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*NamedSecurityCallback)(Local<Object> host, 1859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> key, 1860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessType type, 1861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> data); 1862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if cross-context access should be allowed to the indexed 1866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property with the given index on the host object. 1867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef bool (*IndexedSecurityCallback)(Local<Object> host, 1869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uint32_t index, 1870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessType type, 1871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> data); 1872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 1875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate is used to create functions at runtime. There 1876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * can only be one function created from a FunctionTemplate in a 1877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * context. The lifetime of the created function is equal to the 1878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * lifetime of the context. So in case the embedder needs to create 1879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * temporary functions that can be collected using Scripts is 1880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * preferred. 1881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have properties, these properties are added to the 1883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function object when it is created. 1884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate has a corresponding instance template which is 1886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * used to create object instances when the function is used as a 1887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor. Properties added to the instance template are added to 1888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * each object instance. 1889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can have a prototype template. The prototype template 1891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is used to create the prototype object of the function. 1892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The following example shows how to use a FunctionTemplate: 1894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 1896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 1897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * t->Set("func_property", v8::Number::New(1)); 1898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Local<v8::Template> proto_t = t->PrototypeTemplate(); 1900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback)); 1901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * proto_t->Set("proto_const", v8::Number::New(2)); 1902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate(); 1904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback); 1905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...); 1906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * instance_t->Set("instance_property", Number::New(3)); 1907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Local<v8::Function> function = t->GetFunction(); 1909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Local<v8::Object> instance = function->NewInstance(); 1910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 1911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let's use "function" as the JS variable name of the function object 1913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and "instance" for the instance object created above. The function 1914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and the instance will have the following properties: 1915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 1917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * func_property in function == true; 1918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function.func_property == 1; 1919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function.prototype.proto_method() invokes 'InvokeCallback' 1921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function.prototype.proto_const == 2; 1922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * instance instanceof function == true; 1924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * instance.instance_accessor calls 'InstanceAccessorCallback' 1925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * instance.instance_property == 3; 1926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 1927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate can inherit from another one by calling the 1929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate::Inherit method. The following graph illustrates 1930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the semantics of inheritance: 1931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 1933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate Parent -> Parent() . prototype -> { } 1934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ^ ^ 1935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * | Inherit(Parent) | .__proto__ 1936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * | | 1937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate Child -> Child() . prototype -> { } 1938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 1939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A FunctionTemplate 'Child' inherits from 'Parent', the prototype 1941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * object of the Child() function has __proto__ pointing to the 1942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Parent() function's prototype object. An instance of the Child 1943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function has all properties on Parent's instance templates. 1944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Let Parent be the FunctionTemplate initialized in the previous 1946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * section and create a Child FunctionTemplate by: 1947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 1949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local<FunctionTemplate> parent = t; 1950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local<FunctionTemplate> child = FunctionTemplate::New(); 1951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * child->Inherit(parent); 1952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local<Function> child_function = child->GetFunction(); 1954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Local<Object> child_instance = child_function->NewInstance(); 1955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 1956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Child function and Child instance will have the following 1958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * properties: 1959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 1960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 1961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * child_func.prototype.__proto__ == function.prototype; 1962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * child_instance.instance_accessor calls 'InstanceAccessorCallback' 1963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * child_instance.instance_property == 3; 1964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 1965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT FunctionTemplate : public Template { 1967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 1968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Creates a function template.*/ 1969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<FunctionTemplate> New( 1970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block InvocationCallback callback = 0, 1971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data = Handle<Value>(), 1972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Signature> signature = Handle<Signature>()); 1973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Returns the unique function instance in the current execution context.*/ 1974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Function> GetFunction(); 1975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Set the call-handler callback for a FunctionTemplate. This 1978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * callback is called whenever the function created from this 1979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate is called. 1980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetCallHandler(InvocationCallback callback, 1982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data = Handle<Value>()); 1983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Get the InstanceTemplate. */ 1985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<ObjectTemplate> InstanceTemplate(); 1986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Causes the function template to inherit from a parent function template.*/ 1988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void Inherit(Handle<FunctionTemplate> parent); 1989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A PrototypeTemplate is the template used to create the prototype object 1992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * of the function created by this template. 1993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 1994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<ObjectTemplate> PrototypeTemplate(); 1995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 1997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 1998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Set the class name of the FunctionTemplate. This is used for 1999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * printing objects created with the function created from the 2000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * FunctionTemplate as its constructor. 2001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetClassName(Handle<String> name); 2003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Determines whether the __proto__ accessor ignores instances of 2006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the function template. If instances of the function template are 2007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ignored, __proto__ skips all instances and instead returns the 2008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * next object in the prototype chain. 2009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Call with a value of true to make the __proto__ accessor ignore 2011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * instances of the function template. Call with a value of false 2012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to make the __proto__ accessor not ignore instances of the 2013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function template. By default, instances of a function template 2014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are not ignored. 2015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetHiddenPrototype(bool value); 2017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the given object is an instance of this function 2020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * template. 2021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool HasInstance(Handle<Value> object); 2023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block FunctionTemplate(); 2026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void AddInstancePropertyAccessor(Handle<String> name, 2027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessorGetter getter, 2028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessorSetter setter, 2029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data, 2030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessControl settings, 2031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PropertyAttribute attributes); 2032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetNamedInstancePropertyHandler(NamedPropertyGetter getter, 2033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertySetter setter, 2034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertyQuery query, 2035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertyDeleter remover, 2036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertyEnumerator enumerator, 20379dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen Handle<Value> data); 2038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter, 2039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertySetter setter, 2040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertyQuery query, 2041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertyDeleter remover, 2042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertyEnumerator enumerator, 2043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data); 2044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetInstanceCallAsFunctionHandler(InvocationCallback callback, 2045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data); 2046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class Context; 2048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class ObjectTemplate; 2049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An ObjectTemplate is used to create objects at runtime. 2054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Properties added to an ObjectTemplate are added to each object 2056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * created from the ObjectTemplate. 2057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ObjectTemplate : public Template { 2059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Creates an ObjectTemplate. */ 2061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<ObjectTemplate> New(); 2062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Creates a new instance of this template.*/ 2064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Object> NewInstance(); 2065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets an accessor on the object template. 2068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Whenever the property with the given name is accessed on objects 2070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * created from this ObjectTemplate the getter and setter callbacks 2071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * are called instead of getting and setting the property directly 2072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * on the JavaScript object. 2073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param name The name of the property for which an accessor is added. 2075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param getter The callback to invoke when getting the property. 2076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param setter The callback to invoke when setting the property. 2077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param data A piece of data that will be passed to the getter and setter 2078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * callbacks whenever they are invoked. 2079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param settings Access control settings for the accessor. This is a bit 2080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * field consisting of one of more of 2081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2. 2082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The default is to not allow cross-context access. 2083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ALL_CAN_READ means that all cross-context reads are allowed. 2084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ALL_CAN_WRITE means that all cross-context writes are allowed. 2085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all 2086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * cross-context access. 2087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param attribute The attributes of the property for which an accessor 2088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is added. 2089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetAccessor(Handle<String> name, 2091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessorGetter getter, 2092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessorSetter setter = 0, 2093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data = Handle<Value>(), 2094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessControl settings = DEFAULT, 2095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PropertyAttribute attribute = None); 2096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets a named property handler on the object template. 2099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Whenever a named property is accessed on objects created from 2101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * this object template, the provided callback is invoked instead of 2102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * accessing the property directly on the JavaScript object. 2103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param getter The callback to invoke when getting a property. 2105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param setter The callback to invoke when setting a property. 21069dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * \param query The callback to invoke to check if a property is present, 21079dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen * and if present, get its attributes. 2108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param deleter The callback to invoke when deleting a property. 2109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param enumerator The callback to invoke to enumerate all the named 2110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * properties of an object. 2111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param data A piece of data that will be passed to the callbacks 2112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * whenever they are invoked. 2113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetNamedPropertyHandler(NamedPropertyGetter getter, 2115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertySetter setter = 0, 2116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertyQuery query = 0, 2117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertyDeleter deleter = 0, 2118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block NamedPropertyEnumerator enumerator = 0, 21199dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen Handle<Value> data = Handle<Value>()); 2120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets an indexed property handler on the object template. 2123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Whenever an indexed property is accessed on objects created from 2125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * this object template, the provided callback is invoked instead of 2126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * accessing the property directly on the JavaScript object. 2127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param getter The callback to invoke when getting a property. 2129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param setter The callback to invoke when setting a property. 2130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param query The callback to invoke to check is an object has a property. 2131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param deleter The callback to invoke when deleting a property. 2132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param enumerator The callback to invoke to enumerate all the indexed 2133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * properties of an object. 2134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param data A piece of data that will be passed to the callbacks 2135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * whenever they are invoked. 2136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetIndexedPropertyHandler(IndexedPropertyGetter getter, 2138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertySetter setter = 0, 2139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertyQuery query = 0, 2140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertyDeleter deleter = 0, 2141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedPropertyEnumerator enumerator = 0, 2142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data = Handle<Value>()); 2143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets the callback to be used when calling instances created from 2145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * this template as a function. If no callback is set, instances 2146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * behave like normal JavaScript objects that cannot be called as a 2147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function. 2148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetCallAsFunctionHandler(InvocationCallback callback, 2150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data = Handle<Value>()); 2151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Mark object instances of the template as undetectable. 2154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * In many ways, undetectable objects behave as though they are not 2156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * there. They behave like 'undefined' in conditionals and when 2157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * printed. However, properties can be accessed and called as on 2158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * normal objects. 2159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void MarkAsUndetectable(); 2161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets access check callbacks on the object template. 2164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * When accessing properties on instances of this object template, 2166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the access check callback will be called to determine whether or 2167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * not to allow cross-context access to the properties. 2168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The last parameter specifies whether access checks are turned 2169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * on by default on instances. If access checks are off by default, 2170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * they can be turned on on individual instances by calling 2171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Object::TurnOnAccessCheck(). 2172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetAccessCheckCallbacks(NamedSecurityCallback named_handler, 2174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block IndexedSecurityCallback indexed_handler, 2175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data = Handle<Value>(), 2176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool turned_on_by_default = true); 2177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Gets the number of internal fields for objects generated from 2180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * this template. 2181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int InternalFieldCount(); 2183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets the number of internal fields for objects generated from 2186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * this template. 2187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetInternalFieldCount(int value); 2189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ObjectTemplate(); 2192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor); 2193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class FunctionTemplate; 2194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A Signature specifies which receivers and arguments a function can 2199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * legally be called with. 2200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Signature : public Data { 2202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Signature> New(Handle<FunctionTemplate> receiver = 2204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<FunctionTemplate>(), 2205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int argc = 0, 2206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<FunctionTemplate> argv[] = 0); 2207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Signature(); 2209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A utility for determining the type of objects based on the template 2214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * they were constructed from. 2215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TypeSwitch : public Data { 2217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<TypeSwitch> New(Handle<FunctionTemplate> type); 2219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]); 2220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int match(Handle<Value> value); 2221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block TypeSwitch(); 2223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- E x t e n s i o n s --- 2227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore 2231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Extension { // NOLINT 2233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Extension(const char* name, 2235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* source = 0, 2236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int dep_count = 0, 2237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char** deps = 0); 2238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual ~Extension() { } 2239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block virtual v8::Handle<v8::FunctionTemplate> 2240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block GetNativeFunction(v8::Handle<v8::String> name) { 2241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return v8::Handle<v8::FunctionTemplate>(); 2242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 2243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* name() { return name_; } 2245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* source() { return source_; } 2246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int dependency_count() { return dep_count_; } 2247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char** dependencies() { return deps_; } 2248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void set_auto_enable(bool value) { auto_enable_ = value; } 2249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool auto_enable() { return auto_enable_; } 2250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* name_; 2253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char* source_; 2254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int dep_count_; 2255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char** deps_; 2256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool auto_enable_; 2257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Disallow copying and assigning. 2259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Extension(const Extension&); 2260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator=(const Extension&); 2261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid V8EXPORT RegisterExtension(Extension* extension); 2265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore 2269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT DeclareExtension { 2271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline DeclareExtension(Extension* extension) { 2273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block RegisterExtension(extension); 2274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 2275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- S t a t i c s --- 2279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Undefined(); 2282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Primitive> V8EXPORT Null(); 2283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT True(); 2284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> V8EXPORT False(); 2285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A set of constraints that specifies the limits of the runtime's memory use. 2289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * You must set the heap size before initializing the VM - the size cannot be 2290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * adjusted after the VM is initialized. 2291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you are using threads then you should hold the V8::Locker lock while 2293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * setting the stack limit and you must set a non-default stack limit separately 2294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for each thread. 2295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ResourceConstraints { 2297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ResourceConstraints(); 2299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int max_young_space_size() const { return max_young_space_size_; } 2300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void set_max_young_space_size(int value) { max_young_space_size_ = value; } 2301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int max_old_space_size() const { return max_old_space_size_; } 2302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void set_max_old_space_size(int value) { max_old_space_size_ = value; } 2303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uint32_t* stack_limit() const { return stack_limit_; } 2304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Sets an address beyond which the VM's stack may not grow. 2305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void set_stack_limit(uint32_t* value) { stack_limit_ = value; } 2306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int max_young_space_size_; 2308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int max_old_space_size_; 2309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uint32_t* stack_limit_; 2310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 231325f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsenbool V8EXPORT SetResourceConstraints(ResourceConstraints* constraints); 2314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- E x c e p t i o n s --- 2317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FatalErrorCallback)(const char* location, const char* message); 2320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data); 2323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Schedules an exception to be thrown when returning to JavaScript. When an 2327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * exception has been scheduled it is illegal to invoke any JavaScript 2328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operation; the caller must return immediately and only after the exception 2329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * has been handled does it become legal to invoke JavaScript operations. 2330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> V8EXPORT ThrowException(Handle<Value> exception); 2332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Create new error objects by calling the corresponding error object 2335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * constructor with the message. 2336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Exception { 2338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Value> RangeError(Handle<String> message); 2340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Value> ReferenceError(Handle<String> message); 2341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Value> SyntaxError(Handle<String> message); 2342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Value> TypeError(Handle<String> message); 2343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Value> Error(Handle<String> message); 2344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- C o u n t e r s C a l l b a c k s --- 2348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef int* (*CounterLookupCallback)(const char* name); 2350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void* (*CreateHistogramCallback)(const char* name, 2352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int min, 2353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int max, 2354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block size_t buckets); 2355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*AddHistogramSampleCallback)(void* histogram, int sample); 2357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- F a i l e d A c c e s s C h e c k C a l l b a c k --- 2359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*FailedAccessCheckCallback)(Local<Object> target, 2360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block AccessType type, 2361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> data); 2362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- G a r b a g e C o l l e c t i o n C a l l b a c k s 2364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 23666ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Applications can register callback functions which will be called 23676ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * before and after a garbage collection. Allocations are not 23686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * allowed in the callback functions, you therefore cannot manipulate 2369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * objects (set or delete properties for example) since it is possible 2370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * such operations will result in the allocation of objects. 2371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 23726ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCType { 23736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block kGCTypeScavenge = 1 << 0, 23746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block kGCTypeMarkSweepCompact = 1 << 1, 23756ded16be15dd865a9b21ea304d5273c8be299c87Steve Block kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact 23766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block}; 23776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 23786ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockenum GCCallbackFlags { 23796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block kNoGCCallbackFlags = 0, 23806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block kGCCallbackFlagCompacted = 1 << 0 23816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block}; 23826ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 23836ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags); 23846ded16be15dd865a9b21ea304d5273c8be299c87Steve Blocktypedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags); 23856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 2386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktypedef void (*GCCallback)(); 2387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Profiler modules. 2391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * In V8, profiler consists of several modules: CPU profiler, and different 2393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * kinds of heap profiling. Each can be turned on / off independently. 2394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * When PROFILER_MODULE_HEAP_SNAPSHOT flag is passed to ResumeProfilerEx, 2395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * modules are enabled only temporarily for making a snapshot of the heap. 2396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum ProfilerModules { 2398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PROFILER_MODULE_NONE = 0, 2399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PROFILER_MODULE_CPU = 1, 2400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PROFILER_MODULE_HEAP_STATS = 1 << 1, 2401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PROFILER_MODULE_JS_CONSTRUCTORS = 1 << 2, 2402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block PROFILER_MODULE_HEAP_SNAPSHOT = 1 << 16 2403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 24073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Collection of V8 heap information. 24083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * 24093ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Instances of this class can be passed to v8::V8::HeapStatistics to 24103ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * get heap statistics from V8. 24113ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block */ 24123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass V8EXPORT HeapStatistics { 24133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public: 24143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block HeapStatistics(); 24153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block size_t total_heap_size() { return total_heap_size_; } 24163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block size_t used_heap_size() { return used_heap_size_; } 24173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 24183ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private: 24193ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block void set_total_heap_size(size_t size) { total_heap_size_ = size; } 24203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block void set_used_heap_size(size_t size) { used_heap_size_ = size; } 24213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 24223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block size_t total_heap_size_; 24233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block size_t used_heap_size_; 24243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 24253ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block friend class V8; 24263ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block}; 24273ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 24283ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 24293ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block/** 2430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Container class for static utility functions. 2431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT V8 { 2433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Set the callback to invoke in case of fatal errors. */ 2435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetFatalErrorHandler(FatalErrorCallback that); 2436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore out-of-memory exceptions. 2439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 running out of memory is treated as a fatal error by default. 2441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This means that the fatal error handler is called and that V8 is 2442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * terminated. 2443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * IgnoreOutOfMemoryException can be used to not treat a 2445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * out-of-memory situation as a fatal error. This way, the contexts 2446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that did not cause the out of memory problem might be able to 2447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * continue execution. 2448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void IgnoreOutOfMemoryException(); 2450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Check if V8 is dead and therefore unusable. This is the case after 2453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * fatal errors such as out-of-memory situations. 2454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool IsDead(); 2456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Adds a message listener. 2459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The same message listener can be added more than once and it that 2461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * case it will be called more than once for each message. 2462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool AddMessageListener(MessageCallback that, 2464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> data = Handle<Value>()); 2465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Remove all message listeners from the specified callback function. 2468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void RemoveMessageListeners(MessageCallback that); 2470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 24723bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch * Tells V8 to capture current stack trace when uncaught exception occurs 24733bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch * and report it to the message listeners. The option is off by default. 24743bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch */ 24753bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch static void SetCaptureStackTraceForUncaughtExceptions( 24763bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch bool capture, 24773bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch int frame_limit = 10, 24783bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch StackTrace::StackTraceOptions options = StackTrace::kOverview); 24793bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch 24803bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch /** 2481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets V8 flags from a string. 2482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetFlagsFromString(const char* str, int length); 2484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets V8 flags from the command line. 2487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetFlagsFromCommandLine(int* argc, 2489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block char** argv, 2490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool remove_flags); 2491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Get the version string. */ 2493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const char* GetVersion(); 2494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Enables the host application to provide a mechanism for recording 2497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * statistics counters. 2498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetCounterFunction(CounterLookupCallback); 2500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Enables the host application to provide a mechanism for recording 2503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * histograms. The CreateHistogram function returns a 2504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * histogram which will later be passed to the AddHistogramSample 2505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function. 2506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetCreateHistogramFunction(CreateHistogramCallback); 2508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetAddHistogramSampleFunction(AddHistogramSampleCallback); 2509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Enables the computation of a sliding window of states. The sliding 2512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * window information is recorded in statistics counters. 2513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void EnableSlidingStateWindow(); 2515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Callback function for reporting failed access checks.*/ 2517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback); 2518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Enables the host application to receive a notification before a 25216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * garbage collection. Allocations are not allowed in the 25226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * callback function, you therefore cannot manipulate objects (set 25236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * or delete properties for example) since it is possible such 25246ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * operations will result in the allocation of objects. It is possible 25256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * to specify the GCType filter for your callback. But it is not possible to 25266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * register the same callback function two times with different 25276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * GCType filters. 25286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 25296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static void AddGCPrologueCallback( 25306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll); 25316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 25326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 25336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * This function removes callback which was installed by 25346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * AddGCPrologueCallback function. 25356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 25366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static void RemoveGCPrologueCallback(GCPrologueCallback callback); 25376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 25386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 25396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * The function is deprecated. Please use AddGCPrologueCallback instead. 25406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Enables the host application to receive a notification before a 25416ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * garbage collection. Allocations are not allowed in the 2542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * callback function, you therefore cannot manipulate objects (set 2543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * or delete properties for example) since it is possible such 2544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operations will result in the allocation of objects. 2545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetGlobalGCPrologueCallback(GCCallback); 2547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Enables the host application to receive a notification after a 25506ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * garbage collection. Allocations are not allowed in the 25516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * callback function, you therefore cannot manipulate objects (set 25526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * or delete properties for example) since it is possible such 25536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * operations will result in the allocation of objects. It is possible 25546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * to specify the GCType filter for your callback. But it is not possible to 25556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * register the same callback function two times with different 25566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * GCType filters. 25576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 25586ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static void AddGCEpilogueCallback( 25596ded16be15dd865a9b21ea304d5273c8be299c87Steve Block GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll); 25606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 25616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 25626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * This function removes callback which was installed by 25636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * AddGCEpilogueCallback function. 25646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 25656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static void RemoveGCEpilogueCallback(GCEpilogueCallback callback); 25666ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 25676ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 25686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * The function is deprecated. Please use AddGCEpilogueCallback instead. 25696ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Enables the host application to receive a notification after a 2570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * major garbage collection. Allocations are not allowed in the 2571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * callback function, you therefore cannot manipulate objects (set 2572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * or delete properties for example) since it is possible such 2573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operations will result in the allocation of objects. 2574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void SetGlobalGCEpilogueCallback(GCCallback); 2576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Allows the host application to group objects together. If one 2579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * object in the group is alive, all objects in the group are alive. 2580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After each garbage collection, object groups are removed. It is 2581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * intended to be used in the before-garbage-collection callback 2582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * function, for instance to simulate DOM tree connections among JS 2583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * wrapper objects. 2584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void AddObjectGroup(Persistent<Value>* objects, size_t length); 2586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Initializes from snapshot if possible. Otherwise, attempts to 2589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * initialize from scratch. This function is called implicitly if 2590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * you use the API without calling it first. 2591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool Initialize(); 2593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Adjusts the amount of registered external memory. Used to give 2596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 an indication of the amount of externally allocated memory 2597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that is kept alive by JavaScript objects. V8 uses this to decide 2598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * when to perform global garbage collections. Registering 2599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * externally allocated memory will trigger global garbage 2600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * collections more often than otherwise in an attempt to garbage 2601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * collect the JavaScript objects keeping the externally allocated 2602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * memory alive. 2603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param change_in_bytes the change in externally allocated memory 2605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that is kept alive by JavaScript objects. 2606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \returns the adjusted value. 2607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes); 2609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Suspends recording of tick samples in the profiler. 2612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * When the V8 profiling mode is enabled (usually via command line 2613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * switches) this function suspends recording of tick samples. 2614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Profiling ticks are discarded until ResumeProfiler() is called. 2615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See also the --prof and --prof_auto command line switches to 2617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * enable V8 profiling. 2618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void PauseProfiler(); 2620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Resumes recording of tick samples in the profiler. 2623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See also PauseProfiler(). 2624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void ResumeProfiler(); 2626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Return whether profiler is currently paused. 2629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool IsProfilerPaused(); 2631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2633402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Resumes specified profiler modules. Can be called several times to 2634402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * mark the opening of a profiler events block with the given tag. 2635402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * 2636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * "ResumeProfiler" is equivalent to "ResumeProfilerEx(PROFILER_MODULE_CPU)". 2637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ProfilerModules enum. 2638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param flags Flags specifying profiler modules. 2640402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param tag Profile tag. 2641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2642402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu static void ResumeProfilerEx(int flags, int tag = 0); 2643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2645402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * Pauses specified profiler modules. Each call to "PauseProfilerEx" closes 2646402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * a block of profiler events opened by a call to "ResumeProfilerEx" with the 2647402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * same tag value. There is no need for blocks to be properly nested. 2648402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * The profiler is paused when the last opened block is closed. 2649402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * 2650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * "PauseProfiler" is equivalent to "PauseProfilerEx(PROFILER_MODULE_CPU)". 2651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ProfilerModules enum. 2652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param flags Flags specifying profiler modules. 2654402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu * \param tag Profile tag. 2655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2656402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu static void PauseProfilerEx(int flags, int tag = 0); 2657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns active (resumed) profiler modules. 2660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * See ProfilerModules enum. 2661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \returns active profiler modules. 2663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static int GetActiveProfilerModules(); 2665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If logging is performed into a memory buffer (via --logfile=*), allows to 2668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * retrieve previously written messages. This can be used for retrieving 2669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * profiler log data in the application. This function is thread-safe. 2670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Caller provides a destination buffer that must exist during GetLogLines 2672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * call. Only whole log lines are copied into the buffer. 2673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param from_pos specified a point in a buffer to read from, 0 is the 2675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * beginning of a buffer. It is assumed that caller updates its current 2676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * position using returned size value from the previous call. 2677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param dest_buf destination buffer for log data. 2678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param max_size size of the destination buffer. 2679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \returns actual size of log data copied into buffer. 2680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static int GetLogLines(int from_pos, char* dest_buf, int max_size); 2682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 26846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * The minimum allowed size for a log lines buffer. If the size of 26856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * the buffer given will not be enough to hold a line of the maximum 26866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * length, an attempt to find a log line end in GetLogLines will 26876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * fail, and an empty result will be returned. 26886ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 26896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static const int kMinimumSizeForLogLinesBuffer = 2048; 26906ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 26916ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 2692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Retrieve the V8 thread id of the calling thread. 2693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The thread id for a thread should only be retrieved after the V8 2695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * lock has been acquired with a Locker object with that thread. 2696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static int GetCurrentThreadId(); 2698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Forcefully terminate execution of a JavaScript thread. This can 2701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be used to terminate long-running scripts. 2702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * TerminateExecution should only be called when then V8 lock has 2704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * been acquired with a Locker object. Therefore, in order to be 2705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * able to terminate long-running threads, preemption must be 2706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * enabled to allow the user of TerminateExecution to acquire the 2707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * lock. 2708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The termination is achieved by throwing an exception that is 2710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * uncatchable by JavaScript exception handlers. Termination 2711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * exceptions act as if they were caught by a C++ TryCatch exception 2712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handlers. If forceful termination is used, any C++ TryCatch 2713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * exception handler that catches an exception should check if that 2714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * exception is a termination exception and immediately return if 2715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that is the case. Returning immediately in that case will 2716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * continue the propagation of the termination exception if needed. 2717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The thread id passed to TerminateExecution must have been 2719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * obtained by calling GetCurrentThreadId on the thread in question. 2720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \param thread_id The thread id of the thread to terminate. 2722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void TerminateExecution(int thread_id); 2724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Forcefully terminate the current thread of JavaScript execution. 2727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This method can be used by any thread even if that thread has not 2729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * acquired the V8 lock with a Locker object. 2730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void TerminateExecution(); 2732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 27346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Is V8 terminating JavaScript execution. 27356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * 27366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Returns true if JavaScript execution is currently terminating 27376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * because of a call to TerminateExecution. In that case there are 27386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * still JavaScript frames on the stack and the termination 27396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * exception is still active. 27406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 27416ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static bool IsExecutionTerminating(); 27426ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 27436ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 2744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Releases any resources used by v8 and stops any utility threads 2745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that may be running. Note that disposing v8 is permanent, it 2746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * cannot be reinitialized. 2747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * It should generally not be necessary to dispose v8 before exiting 2749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a process, this should happen automatically. It is only necessary 2750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to use if the process needs the resources taken up by v8. 2751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool Dispose(); 2753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 27543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block /** 27553ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block * Get statistics about the heap memory usage. 27563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block */ 27573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static void GetHeapStatistics(HeapStatistics* heap_statistics); 2758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Optional notification that the embedder is idle. 2761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 uses the notification to reduce memory footprint. 2762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This call can be used repeatedly if the embedder remains idle. 2763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if the embedder should stop calling IdleNotification 2764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * until real work has been done. This indicates that V8 has done 2765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * as much cleanup as it will be able to do. 2766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 27673ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static bool IdleNotification(); 2768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Optional notification that the system is running low on memory. 2771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * V8 uses these notifications to attempt to free memory. 2772a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void LowMemoryNotification(); 2774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 27756ded16be15dd865a9b21ea304d5273c8be299c87Steve Block /** 27766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * Optional notification that a context has been disposed. V8 uses 27776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * these notifications to guide the GC heuristic. Returns the number 27786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * of context disposals - including this one - since the last time 27796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block * V8 had a chance to clean up. 27806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block */ 27816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static int ContextDisposedNotification(); 27826ded16be15dd865a9b21ea304d5273c8be299c87Steve Block 2783a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block V8(); 2785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static internal::Object** GlobalizeReference(internal::Object** handle); 2787a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void DisposeGlobal(internal::Object** global_handle); 2788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void MakeWeak(internal::Object** global_handle, 2789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void* data, 2790a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block WeakReferenceCallback); 2791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void ClearWeak(internal::Object** global_handle); 2792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool IsGlobalNearDeath(internal::Object** global_handle); 2793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool IsGlobalWeak(internal::Object** global_handle); 2794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class T> friend class Handle; 2796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class T> friend class Local; 2797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <class T> friend class Persistent; 2798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class Context; 2799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An external exception handler. 2804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT TryCatch { 2806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Creates a new try/catch block and registers it with v8. 2810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block TryCatch(); 2812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Unregisters and deletes this try/catch block. 2815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~TryCatch(); 2817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns true if an exception has been caught by this try/catch block. 2820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool HasCaught() const; 2822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * For certain types of exceptions, it makes no sense to continue 2825a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * execution. 2826a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2827a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Currently, the only type of exception that can be caught by a 2828a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * TryCatch handler and for which it does not make sense to continue 2829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is termination exception. Such exceptions are thrown when the 2830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * TerminateExecution methods are called to terminate a long-running 2831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * script. 2832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If CanContinue returns false, the correct action is to perform 2834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * any C++ cleanup needed and then return. 2835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool CanContinue() const; 2837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2839d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block * Throws the exception caught by this TryCatch in a way that avoids 2840d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block * it being caught again by this same TryCatch. As with ThrowException 2841d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block * it is illegal to execute any JavaScript operations after calling 2842d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block * ReThrow; the caller must return immediately to where the exception 2843d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block * is caught. 2844d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block */ 2845d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block Handle<Value> ReThrow(); 2846d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 2847d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block /** 2848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the exception caught by this try/catch block. If no exception has 2849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * been caught an empty handle is returned. 2850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The returned handle is valid until this TryCatch block has been destroyed. 2852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> Exception() const; 2854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the .stack property of the thrown object. If no .stack 2857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * property is present an empty handle is returned. 2858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> StackTrace() const; 2860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the message associated with this exception. If there is 2863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * no message associated an empty handle is returned. 2864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The returned handle is valid until this TryCatch block has been 2866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * destroyed. 2867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<v8::Message> Message() const; 2869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Clears any exceptions that may have been caught by this try/catch block. 2872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * After this method has been called, HasCaught() will return false. 2873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * It is not necessary to clear a try/catch block before using it again; if 2875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * another exception is thrown the previously caught exception will just be 2876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * overwritten. However, it is often a good idea since it makes it easier 2877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * to determine which operation threw a given exception. 2878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void Reset(); 2880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Set verbosity of the external exception handler. 2883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 2884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * By default, exceptions that are caught by an external exception 2885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handler are not reported. Call SetVerbose with true on an 2886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * external exception handler to have exceptions caught by the 2887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handler reported as if they were not caught. 2888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetVerbose(bool value); 2890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Set whether or not this TryCatch should capture a Message object 2893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * which holds source information about where the exception 2894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * occurred. True by default. 2895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetCaptureMessage(bool value); 2897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2898d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block private: 2899d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block void* next_; 2900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void* exception_; 2901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void* message_; 2902d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block bool is_verbose_ : 1; 2903d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block bool can_continue_ : 1; 2904d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block bool capture_message_ : 1; 2905d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block bool rethrow_ : 1; 2906d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 2907d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block friend class v8::internal::Top; 2908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- C o n t e x t --- 2912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Ignore 2916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT ExtensionConfiguration { 2918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ExtensionConfiguration(int name_count, const char* names[]) 2920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block : name_count_(name_count), names_(names) { } 2921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 2922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class ImplementationUtilities; 2923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int name_count_; 2924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block const char** names_; 2925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 2926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 2929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A sandboxed execution context with its own set of built-in objects 2930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and functions. 2931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Context { 2933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 2934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Returns the global object of the context. */ 2935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Object> Global(); 2936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Detaches the global object from its context before 2939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the global object can be reused to create a new context. 2940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void DetachGlobal(); 2942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 294374b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu /** 294474b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * Reattaches a global object to a context. This can be used to 294574b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * restore the connection between a global object and a context 294674b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * after DetachGlobal has been called. 294774b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * 294874b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * \param global_object The global object to reattach to the 294974b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * context. For this to work, the global object must be the global 295074b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * object that was associated with this context before a call to 295174b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu * DetachGlobal. 295274b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu */ 295374b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu void ReattachGlobal(Handle<Object> global_object); 295474b3c146906ea120f97974b0e16aec75c17ebf66Andrei Popescu 2955f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke /** Creates a new context. 2956f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * 2957f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * Returns a persistent handle to the newly allocated context. This 2958f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * persistent handle has to be disposed when the context is no 2959f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke * longer used so the context can be garbage collected. 2960f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke */ 2961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Persistent<Context> New( 29623100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu ExtensionConfiguration* extensions = NULL, 2963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(), 2964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> global_object = Handle<Value>()); 2965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Returns the last entered context. */ 2967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Context> GetEntered(); 2968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Returns the context that is on the top of the stack. */ 2970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Context> GetCurrent(); 2971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns the context of the calling JavaScript code. That is the 2974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * context of the top-most JavaScript frame. If there are no 2975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * JavaScript frames an empty handle is returned. 2976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static Local<Context> GetCalling(); 2978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Sets the security token for the context. To access an object in 2981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * another context, the security tokens must match. 2982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void SetSecurityToken(Handle<Value> token); 2984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Restores the security token to the default value. */ 2986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void UseDefaultSecurityToken(); 2987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Returns the security token of this context.*/ 2989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Value> GetSecurityToken(); 2990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 2992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Enter this context. After entering a context, all code compiled 2993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * and run is compiled and run in this context. If another context 2994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is already entered, this old context is saved so it can be 2995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * restored when the new context is exited. 2996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 2997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void Enter(); 2998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 2999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 3000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Exit this context. Exiting the current context restores the 3001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * context that was in place when entering the current context. 3002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void Exit(); 3004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Returns true if the context has experienced an out of memory situation. */ 3006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool HasOutOfMemoryException(); 3007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** Returns true if V8 has a current context. */ 3009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool InContext(); 3010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 3012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Associate an additional data object with the context. This is mainly used 3013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * with the debugger to provide additional information on the context through 3014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the debugger API. 3015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3016d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block void SetData(Handle<String> data); 3017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> GetData(); 3018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 3020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Stack-allocated class which sets the execution context for all 3021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * operations executed within a local scope. 3022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 30238defd9ff6930b4e24729971a61cf7469daf119beSteve Block class Scope { 3024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 3025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline Scope(Handle<Context> context) : context_(context) { 3026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block context_->Enter(); 3027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block inline ~Scope() { context_->Exit(); } 3029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 3030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Handle<Context> context_; 3031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block }; 3032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 3034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class Value; 3035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class Script; 3036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class Object; 3037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block friend class Function; 3038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 3039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 3042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Multiple threads in V8 are allowed, but only one thread at a time 3043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is allowed to use V8. The definition of 'using V8' includes 3044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * accessing handles or holding onto object pointers obtained from V8 3045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * handles. It is up to the user of V8 to ensure (perhaps with 3046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * locking) that this constraint is not violated. 3047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you wish to start using V8 in a thread you can do this by constructing 3049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * a v8::Locker object. After the code using V8 has completed for the 3050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * current thread you can call the destructor. This can be combined 3051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * with C++ scope-based construction as follows: 3052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 3054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ... 3055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * { 3056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Locker locker; 3057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ... 3058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // Code using V8 goes here. 3059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ... 3060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here 3061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 3062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * If you wish to stop using V8 in a thread A you can do this by either 3064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * by destroying the v8::Locker object as above or by constructing a 3065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Unlocker object: 3066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 3068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * { 3069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Unlocker unlocker; 3070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ... 3071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // Code not using V8 goes here while V8 can run in another thread. 3072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * ... 3073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } // Destructor called here. 3074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 3075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The Unlocker object is intended for use in a long-running callback 3077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * from V8, where you want to release the V8 lock for other threads to 3078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * use. 3079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * The v8::Locker is a recursive lock. That is, you can lock more than 3081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * once in a given thread. This can be useful if you have code that can 3082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * be called either from code that holds the lock or from code that does 3083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * not. The Unlocker is not recursive so you can not have several 3084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Unlockers on the stack at once, and you can not use an Unlocker in a 3085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * thread that is not inside a Locker's scope. 3086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * An unlocker will unlock several lockers if it has to and reinstate 3088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * the correct depth of locking on its destruction. eg.: 3089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \code 3091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 not locked. 3092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * { 3093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Locker locker; 3094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 locked. 3095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * { 3096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Locker another_locker; 3097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 still locked (2 levels). 3098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * { 3099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * v8::Unlocker unlocker; 3100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 not locked. 3101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } 3102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 locked again (2 levels). 3103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } 3104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 still locked (1 level). 3105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * } 3106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * // V8 Now no longer locked. 3107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \endcode 3108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Unlocker { 3110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 3111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Unlocker(); 3112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~Unlocker(); 3113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 3114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass V8EXPORT Locker { 3117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 3118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Locker(); 3119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block ~Locker(); 3120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 3122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Start preemption. 3123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * 3124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * When preemption is started, a timer is fired every n milli seconds 3125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * that will switch between multiple threads that are in contention 3126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * for the V8 lock. 3127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void StartPreemption(int every_n_ms); 3129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 3131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Stop preemption. 3132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static void StopPreemption(); 3134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 3136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns whether or not the locker is locked by the current thread. 3137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool IsLocked(); 3139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block /** 3141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * Returns whether v8::Locker is being used by this V8 instance. 3142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool IsActive() { return active_; } 3144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private: 3146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool has_lock_; 3147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block bool top_level_; 3148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static bool active_; 3150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // Disallow copying and assigning. 3152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Locker(const Locker&); 3153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void operator=(const Locker&); 3154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 3155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// --- I m p l e m e n t a t i o n --- 3159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal { 3162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for HeapObject. 3165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTag = 1; 3166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kHeapObjectTagSize = 2; 3167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; 3168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Tag information for Smi. 3170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTag = 0; 3171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kSmiTagSize = 1; 3172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; 3173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 31743ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <size_t ptr_size> struct SmiConstants; 31753ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 31763ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 32-bit systems. 31773ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <> struct SmiConstants<4> { 31783ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static const int kSmiShiftSize = 0; 31793ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static const int kSmiValueSize = 31; 31803ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static inline int SmiToInt(internal::Object* value) { 31813ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block int shift_bits = kSmiTagSize + kSmiShiftSize; 31823ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block // Throw away top 32 bits and shift down (requires >> to be sign extending). 31833ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; 31843ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } 31853ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block}; 31863ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 31873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi constants for 64-bit systems. 31883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blocktemplate <> struct SmiConstants<8> { 31893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static const int kSmiShiftSize = 31; 31903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static const int kSmiValueSize = 32; 31913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static inline int SmiToInt(internal::Object* value) { 31923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block int shift_bits = kSmiTagSize + kSmiShiftSize; 31933ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block // Shift down and throw away top 32 bits. 31943ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); 31953ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } 31963ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block}; 31973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 31983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockconst int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize; 31993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockconst int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize; 3200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3201d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <size_t ptr_size> struct InternalConstants; 3202d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 3203d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 32-bit systems. 3204d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<4> { 3205d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block static const int kStringResourceOffset = 3 * sizeof(void*); 3206d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block}; 3207d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 3208d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block// Internal constants for 64-bit systems. 3209d0582a6c46733687d045e4188a1bcd0123c758a1Steve Blocktemplate <> struct InternalConstants<8> { 32106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block static const int kStringResourceOffset = 3 * sizeof(void*); 3211d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block}; 3212d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 3213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 3214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * This class exports constants and functionality from within v8 that 3215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * is necessary to implement inline functions in the v8 api. Don't 3216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * depend on functions and constants defined here. 3217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Internals { 3219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public: 3220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // These values match non-compiler-dependent values defined within 3222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // the implementation of v8. 3223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const int kHeapObjectMapOffset = 0; 3224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int); 3225d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block static const int kStringResourceOffset = 3226d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block InternalConstants<sizeof(void*)>::kStringResourceOffset; 3227d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block 3228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const int kProxyProxyOffset = sizeof(void*); 3229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const int kJSObjectHeaderSize = 3 * sizeof(void*); 3230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static const int kFullStringRepresentationMask = 0x07; 32317f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch static const int kExternalTwoByteRepresentationTag = 0x02; 3232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 32339dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen static const int kJSObjectType = 0x9f; 32349dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen static const int kFirstNonstringType = 0x80; 32359dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen static const int kProxyType = 0x85; 3236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline bool HasHeapObjectTag(internal::Object* value) { 3238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == 3239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block kHeapObjectTag); 3240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline bool HasSmiTag(internal::Object* value) { 3243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); 3244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline int SmiValue(internal::Object* value) { 32473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return SmiConstants<sizeof(void*)>::SmiToInt(value); 32483ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } 32493ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 32503ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static inline int GetInstanceType(internal::Object* obj) { 32513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block typedef internal::Object O; 32523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block O* map = ReadField<O*>(obj, kHeapObjectMapOffset); 32533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return ReadField<uint8_t>(map, kMapInstanceTypeOffset); 32543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } 32553ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 32563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block static inline void* GetExternalPointer(internal::Object* obj) { 32573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block if (HasSmiTag(obj)) { 32583ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return obj; 32593ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } else if (GetInstanceType(obj) == kProxyType) { 32603ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return ReadField<void*>(obj, kProxyProxyOffset); 32613ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } else { 32623ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return NULL; 32633ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } 3264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline bool IsExternalTwoByteString(int instance_type) { 3267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int representation = (instance_type & kFullStringRepresentationMask); 3268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return representation == kExternalTwoByteRepresentationTag; 3269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block template <typename T> 3272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block static inline T ReadField(Object* ptr, int offset) { 3273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; 3274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return *reinterpret_cast<T*>(addr); 3275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block}; 3278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<T>::Handle() : val_(0) { } 3284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T>::Local() : Handle<T>() { } 3288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> Local<T>::New(Handle<T> that) { 3292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (that.IsEmpty()) return Local<T>(); 3293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** p = reinterpret_cast<internal::Object**>(*that); 3294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p))); 3295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T> Persistent<T>::New(Handle<T> that) { 3300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (that.IsEmpty()) return Persistent<T>(); 3301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** p = reinterpret_cast<internal::Object**>(*that); 3302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p))); 3303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsNearDeath() const { 3308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (this->IsEmpty()) return false; 3309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this)); 3310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Persistent<T>::IsWeak() const { 3315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (this->IsEmpty()) return false; 3316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return V8::IsGlobalWeak(reinterpret_cast<internal::Object**>(**this)); 3317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::Dispose() { 3322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (this->IsEmpty()) return; 3323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block V8::DisposeGlobal(reinterpret_cast<internal::Object**>(**this)); 3324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockPersistent<T>::Persistent() : Handle<T>() { } 3329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) { 3332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block V8::MakeWeak(reinterpret_cast<internal::Object**>(**this), 3333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block parameters, 3334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block callback); 3335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Persistent<T>::ClearWeak() { 3339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block V8::ClearWeak(reinterpret_cast<internal::Object**>(**this)); 3340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 33428defd9ff6930b4e24729971a61cf7469daf119beSteve Block 33438defd9ff6930b4e24729971a61cf7469daf119beSteve BlockArguments::Arguments(v8::Local<v8::Value> data, 33448defd9ff6930b4e24729971a61cf7469daf119beSteve Block v8::Local<v8::Object> holder, 33458defd9ff6930b4e24729971a61cf7469daf119beSteve Block v8::Local<v8::Function> callee, 33468defd9ff6930b4e24729971a61cf7469daf119beSteve Block bool is_construct_call, 33478defd9ff6930b4e24729971a61cf7469daf119beSteve Block void** values, int length) 33488defd9ff6930b4e24729971a61cf7469daf119beSteve Block : data_(data), holder_(holder), callee_(callee), 33498defd9ff6930b4e24729971a61cf7469daf119beSteve Block is_construct_call_(is_construct_call), 33508defd9ff6930b4e24729971a61cf7469daf119beSteve Block values_(values), length_(length) { } 33518defd9ff6930b4e24729971a61cf7469daf119beSteve Block 33528defd9ff6930b4e24729971a61cf7469daf119beSteve Block 3353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::operator[](int i) const { 3354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (i < 0 || length_ <= i) return Local<Value>(*Undefined()); 3355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<Value>(reinterpret_cast<Value*>(values_ - i)); 3356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Function> Arguments::Callee() const { 3360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return callee_; 3361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::This() const { 3365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<Object>(reinterpret_cast<Object*>(values_ + 1)); 3366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> Arguments::Holder() const { 3370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return holder_; 3371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Arguments::Data() const { 3375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return data_; 3376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Arguments::IsConstructCall() const { 3380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return is_construct_call_; 3381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockint Arguments::Length() const { 3385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return length_; 3386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class T> 3390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<T> HandleScope::Close(Handle<T> value) { 3391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** before = reinterpret_cast<internal::Object**>(*value); 3392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block internal::Object** after = RawClose(before); 3393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<T>(reinterpret_cast<T*>(after)); 3394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Value> ScriptOrigin::ResourceName() const { 3397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return resource_name_; 3398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceLineOffset() const { 3402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return resource_line_offset_; 3403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Integer> ScriptOrigin::ResourceColumnOffset() const { 3407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return resource_column_offset_; 3408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockHandle<Boolean> Boolean::New(bool value) { 3412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return value ? True() : False(); 3413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid Template::Set(const char* name, v8::Handle<Data> value) { 3417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Set(v8::String::New(name), value); 3418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::GetInternalField(int index) { 3422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_ENABLE_CHECKS 3423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block Local<Value> quick_result = UncheckedGetInternalField(index); 3424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (!quick_result.IsEmpty()) return quick_result; 3425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return CheckedGetInternalField(index); 3427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> Object::UncheckedGetInternalField(int index) { 3431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef internal::Object O; 3432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef internal::Internals I; 3433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block O* obj = *reinterpret_cast<O**>(this); 34343ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block if (I::GetInstanceType(obj) == I::kJSObjectType) { 3435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // If the object is a plain JSObject, which is the common case, 3436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // we know where to find the internal fields and can return the 3437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block // value directly. 3438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index); 3439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block O* value = I::ReadField<O*>(obj, offset); 3440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block O** result = HandleScope::CreateHandle(value); 3441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<Value>(reinterpret_cast<Value*>(result)); 3442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } else { 3443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<Value>(); 3444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::Unwrap(Handle<v8::Value> obj) { 3449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return FullUnwrap(obj); 3451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else 3452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return QuickUnwrap(obj); 3453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* External::QuickUnwrap(Handle<v8::Value> wrapper) { 3458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef internal::Object O; 3459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); 34603ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return internal::Internals::GetExternalPointer(obj); 3461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockvoid* Object::GetPointerFromInternalField(int index) { 34653ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block typedef internal::Object O; 34663ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block typedef internal::Internals I; 34673ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 34683ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block O* obj = *reinterpret_cast<O**>(this); 34693ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 34703ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block if (I::GetInstanceType(obj) == I::kJSObjectType) { 34713ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block // If the object is a plain JSObject, which is the common case, 34723ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block // we know where to find the internal fields and can return the 34733ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block // value directly. 34743ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index); 34753ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block O* value = I::ReadField<O*>(obj, offset); 34763ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return I::GetExternalPointer(value); 34773ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block } 34783ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block 34793ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return SlowGetPointerFromInternalField(index); 3480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString* String::Cast(v8::Value* value) { 3484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<String*>(value); 3488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockString::ExternalStringResource* String::GetExternalStringResource() const { 3492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef internal::Object O; 3493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef internal::Internals I; 3494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); 3495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block String::ExternalStringResource* result; 34963ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { 3497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); 3498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block result = reinterpret_cast<String::ExternalStringResource*>(value); 3499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } else { 3500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block result = NULL; 3501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block } 3502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block VerifyExternalStringResource(result); 3504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return result; 3506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::IsString() const { 3510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return FullIsString(); 3512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else 3513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return QuickIsString(); 3514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockbool Value::QuickIsString() const { 3518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef internal::Object O; 3519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block typedef internal::Internals I; 3520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); 3521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block if (!I::HasHeapObjectTag(obj)) return false; 35223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block return (I::GetInstanceType(obj) < I::kFirstNonstringType); 3523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockNumber* Number::Cast(v8::Value* value) { 3527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<Number*>(value); 3531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockInteger* Integer::Cast(v8::Value* value) { 3535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<Integer*>(value); 3539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockDate* Date::Cast(v8::Value* value) { 3543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<Date*>(value); 3547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockObject* Object::Cast(v8::Value* value) { 3551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<Object*>(value); 3555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockArray* Array::Cast(v8::Value* value) { 3559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<Array*>(value); 3563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockFunction* Function::Cast(v8::Value* value) { 3567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<Function*>(value); 3571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockExternal* External::Cast(v8::Value* value) { 3575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef V8_ENABLE_CHECKS 3576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block CheckCast(value); 3577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif 3578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return static_cast<External*>(value); 3579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Value> AccessorInfo::Data() const { 35836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block return Local<Value>(reinterpret_cast<Value*>(&args_[-2])); 3584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::This() const { 3588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<Object>(reinterpret_cast<Object*>(&args_[0])); 3589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve BlockLocal<Object> AccessorInfo::Holder() const { 3593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block return Local<Object>(reinterpret_cast<Object*>(&args_[-1])); 3594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} 3595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 3598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example shell.cc 3599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * A simple shell that takes a list of expressions on the 3600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * command-line and executes them. 3601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block/** 3605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block * \example process.cc 3606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block */ 3607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} // namespace v8 3610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef V8EXPORT 3613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef TYPE_CHECK 3614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block 3616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif // V8_H_ 3617