~statik/v8/couchdb

« back to all changes in this revision

Viewing changes to public/v8.h

  • Committer: mads.s.ager at gmail
  • Date: 2008-09-01 07:55:01 UTC
  • Revision ID: svn-v3-trunk0:ce2b1a6d-e550-0410-aec6-3dcde31c8c00:trunk:60
Included mjsunit JavaScript test suite and C++ unit tests.

Changed the shell sample to not print the result of executing a script provided on the command line.

Fixed issue when building samples on Windows using a shared V8 library.  Added visibility option on Linux build which makes the generated library 18% smaller.

Changed build system to accept multiple build modes in one build and generate separate objects, libraries and executables for each mode.

Removed deferred negation optimization (a * -b => -(a * b)) since this visibly changes operand conversion order.

Improved parsing performance by introducing stack guard in preparsing.  Without a stack guard preparsing always bails out with stack overflow.

Changed shell sample to take flags directly from the command-line. Added API call that implements this.

Added load, quit and version functions to the shell sample so it's easier to run benchmarks and tests.

Fixed issue with building samples and cctests on 64-bit machines.

Fixed bug in the runtime system where the prototype chain was not always searched for a setter when setting a property that does not exist locally.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
 
28
 
/** \mainpage V8 API Reference Guide
29
 
 
30
 
  Add text to introduce,
31
 
 
32
 
  point back to code.google.com/apis/v8/index.html
33
 
 
34
 
  etc etc etc
 
28
/** V8 API Reference Guide
 
29
 
 
30
V8 is Google's open source JavaScript engine. This set of documents 
 
31
provides reference material generated from the V8 header file, v8.h.
 
32
 
 
33
For introductory material see http://code.google.com/apis/v8/
 
34
 
 
35
 
 
36
 
 
37
 
 
38
 
35
39
 */
36
40
#ifndef _V8
37
41
#define _V8
41
45
#ifdef _WIN32
42
46
typedef int int32_t;
43
47
typedef unsigned int uint32_t;
44
 
typedef unsigned short uint16_t;
45
 
typedef long long int64_t;
 
48
typedef unsigned short uint16_t;  // NOLINT
 
49
typedef long long int64_t;  // NOLINT
 
50
 
 
51
// Setup for Windows DLL export/import. When building the V8 DLL the
 
52
// BUILDING_V8_SHARED needs to be defined. When building a program which uses
 
53
// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
 
54
// static library or building a program which uses the V8 static library neither
 
55
// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
 
56
// The reason for having both EXPORT and EXPORT_INLINE is that classes which
 
57
// have their code inside this header file needs to have __declspec(dllexport)
 
58
// when building the DLL but cannot have __declspec(dllimport) when building
 
59
// a program which uses the DLL.
 
60
#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
 
61
#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
 
62
  build configuration to ensure that at most one of these is set
 
63
#endif
 
64
 
 
65
#ifdef BUILDING_V8_SHARED
 
66
#define EXPORT __declspec(dllexport)
 
67
#define EXPORT_INLINE __declspec(dllexport)
 
68
#elif USING_V8_SHARED
 
69
#define EXPORT __declspec(dllimport)
 
70
#define EXPORT_INLINE
46
71
#else
 
72
#define EXPORT
 
73
#define EXPORT_INLINE
 
74
#endif  // BUILDING_V8_SHARED
 
75
 
 
76
#else  // _WIN32
 
77
 
47
78
#include <stdint.h>
48
 
#endif
 
79
 
 
80
// Setup for Linux shared library export. There is no need to destinguish
 
81
// neither between building or using the V8 shared library nor between using
 
82
// the shared or static V8 library as there is on Windows. Therefore there is
 
83
// on checking of BUILDING_V8_SHARED and USING_V8_SHARED.
 
84
#if defined(__GNUC__) && (__GNUC__ >= 4)
 
85
#define EXPORT __attribute__ ((visibility("default")))
 
86
#define EXPORT_INLINE __attribute__ ((visibility("default")))
 
87
#else  // defined(__GNUC__) && (__GNUC__ >= 4)
 
88
#define EXPORT
 
89
#define EXPORT_INLINE
 
90
#endif  // defined(__GNUC__) && (__GNUC__ >= 4)
 
91
 
 
92
#endif  // _WIN32
49
93
 
50
94
/**
51
95
 * The v8 javascript engine.
122
166
 * behind the scenes and the same rules apply to these values as to
123
167
 * their handles.
124
168
 */
125
 
template <class T> class Handle {
 
169
template <class T> class EXPORT_INLINE Handle {
126
170
 public:
127
171
 
128
172
  /**
210
254
 * handle scope are destroyed when the handle scope is destroyed.  Hence it
211
255
 * is not necessary to explicitly deallocate local handles.
212
256
 */
213
 
template <class T> class Local : public Handle<T> {
 
257
template <class T> class EXPORT_INLINE Local : public Handle<T> {
214
258
 public:
215
259
  Local();
216
260
  template <class S> inline Local(Local<S> that)
253
297
 * different storage cells but rather two references to the same
254
298
 * storage cell.
255
299
 */
256
 
template <class T> class Persistent : public Handle<T> {
 
300
template <class T> class EXPORT_INLINE Persistent : public Handle<T> {
257
301
 public:
258
302
 
259
303
  /**
348
392
 * handle and may deallocate it.  The behavior of accessing a handle
349
393
 * for which the handle scope has been deleted is undefined.
350
394
 */
351
 
class HandleScope {
 
395
class EXPORT HandleScope {
352
396
 public:
353
397
  HandleScope() : previous_(current_), is_closed_(false) {
354
398
    current_.extensions = 0;
386
430
  void* operator new(size_t size);
387
431
  void operator delete(void*, size_t);
388
432
 
389
 
  class Data {
 
433
  class EXPORT Data {
390
434
   public:
391
435
    int extensions;
392
436
    void** next;
434
478
/**
435
479
 * The superclass of values and API object templates.
436
480
 */
437
 
class Data {
 
481
class EXPORT Data {
438
482
 private:
439
483
  Data();
440
484
};
446
490
 * compiling it, and stored between compilations.  When script data
447
491
 * is given to the compile method compilation will be faster.
448
492
 */
449
 
class ScriptData {
 
493
class EXPORT ScriptData {  // NOLINT
450
494
 public:
451
495
  virtual ~ScriptData() { }
452
496
  static ScriptData* PreCompile(const char* input, int length);
460
504
/**
461
505
 * The origin, within a file, of a script.
462
506
 */
463
 
class ScriptOrigin {
 
507
class EXPORT ScriptOrigin {
464
508
 public:
465
509
  ScriptOrigin(Handle<Value> resource_name,
466
510
               Handle<Integer> resource_line_offset = Handle<Integer>(),
481
525
/**
482
526
 * A compiled javascript script.
483
527
 */
484
 
class Script {
 
528
class EXPORT Script {
485
529
 public:
486
530
 
487
531
  /**
507
551
/**
508
552
 * An error message.
509
553
 */
510
 
class Message {
 
554
class EXPORT Message {
511
555
 public:
512
556
  Local<String> Get();
513
557
  Local<Value> GetSourceLine();
536
580
/**
537
581
 * The superclass of all javascript values and objects.
538
582
 */
539
 
class Value : public Data {
 
583
class EXPORT Value : public Data {
540
584
 public:
541
585
 
542
586
  /**
632
676
/**
633
677
 * The superclass of primitive values.  See ECMA-262 4.3.2.
634
678
 */
635
 
class Primitive : public Value { };
 
679
class EXPORT Primitive : public Value { };
636
680
 
637
681
 
638
682
/**
639
683
 * A primitive boolean value (ECMA-262, 4.3.14).  Either the true
640
684
 * or false value.
641
685
 */
642
 
class Boolean : public Primitive {
 
686
class EXPORT Boolean : public Primitive {
643
687
 public:
644
688
  bool Value();
645
689
  static inline Handle<Boolean> New(bool value);
649
693
/**
650
694
 * A javascript string value (ECMA-262, 4.3.17).
651
695
 */
652
 
class String : public Primitive {
 
696
class EXPORT String : public Primitive {
653
697
 public:
654
698
  int Length();
655
699
 
690
734
  * ExternalStringResource to manage the life cycle of the underlying
691
735
  * buffer.
692
736
  */
693
 
  class ExternalStringResource {
 
737
  class EXPORT ExternalStringResource {  // NOLINT
694
738
   public:
695
739
    /**
696
740
     * Override the destructor to manage the life cycle of the underlying
715
759
  * underlying buffer.
716
760
  */
717
761
 
718
 
  class ExternalAsciiStringResource {
 
762
  class EXPORT ExternalAsciiStringResource {  // NOLINT
719
763
   public:
720
764
    /**
721
765
     * Override the destructor to manage the life cycle of the underlying
794
838
   * Converts an object to an ascii string.
795
839
   * Useful if you want to print the object.
796
840
   */
797
 
  class AsciiValue {
 
841
  class EXPORT AsciiValue {
798
842
   public:
799
843
    explicit AsciiValue(Handle<v8::Value> obj);
800
844
    ~AsciiValue();
806
850
  /**
807
851
   * Converts an object to a two-byte string.
808
852
   */
809
 
  class Value {
 
853
  class EXPORT Value {
810
854
   public:
811
855
    explicit Value(Handle<v8::Value> obj);
812
856
    ~Value();
820
864
/**
821
865
 * A javascript number value (ECMA-262, 4.3.20)
822
866
 */
823
 
class Number : public Primitive {
 
867
class EXPORT Number : public Primitive {
824
868
 public:
825
869
  double Value();
826
870
  static Local<Number> New(double value);
833
877
/**
834
878
 * A javascript value representing a signed integer.
835
879
 */
836
 
class Integer : public Number {
 
880
class EXPORT Integer : public Number {
837
881
 public:
838
882
  static Local<Integer> New(int32_t value);
839
883
  int64_t Value();
846
890
/**
847
891
 * A javascript value representing a 32-bit signed integer.
848
892
 */
849
 
class Int32 : public Integer {
 
893
class EXPORT Int32 : public Integer {
850
894
 public:
851
895
  int32_t Value();
852
896
 private:
857
901
/**
858
902
 * A javascript value representing a 32-bit unsigned integer.
859
903
 */
860
 
class Uint32 : public Integer {
 
904
class EXPORT Uint32 : public Integer {
861
905
 public:
862
906
  uint32_t Value();
863
907
 private:
868
912
/**
869
913
 * An instance of the built-in Date constructor (ECMA-262, 15.9).
870
914
 */
871
 
class Date : public Value {
 
915
class EXPORT Date : public Value {
872
916
 public:
873
917
  static Local<Value> New(double time);
874
918
};
884
928
/**
885
929
 * A javascript object (ECMA-262, 4.3.3)
886
930
 */
887
 
class Object : public Value {
 
931
class EXPORT Object : public Value {
888
932
 public:
889
933
  bool Set(Handle<Value> key,
890
934
           Handle<Value> value,
947
991
/**
948
992
 * An instance of the built-in array constructor (ECMA-262, 15.4.2).
949
993
 */
950
 
class Array : public Object {
 
994
class EXPORT Array : public Object {
951
995
 public:
952
996
  uint32_t Length();
953
997
 
961
1005
/**
962
1006
 * A javascript function object (ECMA-262, 15.3).
963
1007
 */
964
 
class Function : public Object {
 
1008
class EXPORT Function : public Object {
965
1009
 public:
966
1010
  Local<Object> NewInstance();
967
1011
  Local<Object> NewInstance(int argc, Handle<Value> argv[]);
979
1023
 * mainly used to associate c++ data structures with javascript
980
1024
 * objects.
981
1025
 */
982
 
class External : public Value {
 
1026
class EXPORT External : public Value {
983
1027
 public:
984
1028
  static Local<External> New(void* value);
985
1029
  static External* Cast(Value* obj);
995
1039
/**
996
1040
 * The superclass of object and function templates.
997
1041
 */
998
 
class Template : public Data {
 
1042
class EXPORT Template : public Data {
999
1043
 public:
1000
1044
  /** Adds a property to each instance created by this template.*/
1001
1045
  void Set(Handle<String> name, Handle<Data> value,
1015
1059
 * including the receiver, the number and values of arguments, and
1016
1060
 * the holder of the function.
1017
1061
 */
1018
 
class Arguments {
 
1062
class EXPORT Arguments {
1019
1063
 public:
1020
1064
  inline int Length() const;
1021
1065
  inline Local<Value> operator[](int i) const;
1045
1089
 * The information passed to an accessor callback about the context
1046
1090
 * of the property access.
1047
1091
 */
1048
 
class AccessorInfo {
 
1092
class EXPORT AccessorInfo {
1049
1093
 public:
1050
1094
  inline AccessorInfo(Local<Object> self,
1051
1095
                      Local<Value> data,
1266
1310
 *   child_instance.instance_accessor calls InstanceAccessorCallback
1267
1311
 *   child_instance.instance_property == 3;
1268
1312
 */
1269
 
class FunctionTemplate : public Template {
 
1313
class EXPORT FunctionTemplate : public Template {
1270
1314
 public:
1271
1315
  /** Creates a function template.*/
1272
1316
  static Local<FunctionTemplate> New(InvocationCallback callback = 0,
1338
1382
/**
1339
1383
 * ObjectTemplate: (TODO(758124): Add comments.)
1340
1384
 */
1341
 
class ObjectTemplate : public Template {
 
1385
class EXPORT ObjectTemplate : public Template {
1342
1386
 public:
1343
1387
  static Local<ObjectTemplate> New();
1344
1388
  /** Creates a new instance of this template.*/
1433
1477
 * A function signature which specifies which receivers and arguments
1434
1478
 * in can legally be called with.
1435
1479
 */
1436
 
class Signature : public Data {
 
1480
class EXPORT Signature : public Data {
1437
1481
 public:
1438
1482
  static Local<Signature> New(Handle<FunctionTemplate> receiver =
1439
1483
                                  Handle<FunctionTemplate>(),
1448
1492
 * A utility for determining the type of objects based on which
1449
1493
 * template they were constructed from.
1450
1494
 */
1451
 
class TypeSwitch : public Data {
 
1495
class EXPORT TypeSwitch : public Data {
1452
1496
 public:
1453
1497
  static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
1454
1498
  static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
1464
1508
/**
1465
1509
 * Ignore
1466
1510
 */
1467
 
class Extension {
 
1511
class EXPORT Extension {  // NOLINT
1468
1512
 public:
1469
1513
  Extension(const char* name,
1470
1514
            const char* source = 0,
1492
1536
};
1493
1537
 
1494
1538
 
1495
 
void RegisterExtension(Extension* extension);
 
1539
void EXPORT RegisterExtension(Extension* extension);
1496
1540
 
1497
1541
 
1498
1542
/**
1499
1543
 * Ignore
1500
1544
 */
1501
 
class DeclareExtension {
 
1545
class EXPORT DeclareExtension {
1502
1546
 public:
1503
1547
  inline DeclareExtension(Extension* extension) {
1504
1548
    RegisterExtension(extension);
1509
1553
// --- S t a t i c s ---
1510
1554
 
1511
1555
 
1512
 
Handle<Primitive> Undefined();
1513
 
Handle<Primitive> Null();
1514
 
Handle<Boolean> True();
1515
 
Handle<Boolean> False();
 
1556
Handle<Primitive> EXPORT Undefined();
 
1557
Handle<Primitive> EXPORT Null();
 
1558
Handle<Boolean> EXPORT True();
 
1559
Handle<Boolean> EXPORT False();
1516
1560
 
1517
1561
 
1518
1562
/**
1519
1563
 * A set of constraints that specifies the limits of the runtime's
1520
1564
 * memory use.
1521
1565
 */
1522
 
class ResourceConstraints {
 
1566
class EXPORT ResourceConstraints {
1523
1567
 public:
1524
1568
  ResourceConstraints();
1525
1569
  int max_young_space_size() { return max_young_space_size_; }
1553
1597
 * operation; the caller must return immediately and only after the exception
1554
1598
 * has been handled does it become legal to invoke javascript operations.
1555
1599
 */
1556
 
Handle<Value> ThrowException(Handle<Value> exception);
 
1600
Handle<Value> EXPORT ThrowException(Handle<Value> exception);
1557
1601
 
1558
1602
/**
1559
1603
 * Create new error objects by calling the corresponding error object
1560
1604
 * constructor with the message.
1561
1605
 */
1562
 
class Exception {
 
1606
class EXPORT Exception {
1563
1607
 public:
1564
1608
  static Local<Value> RangeError(Handle<String> message);
1565
1609
  static Local<Value> ReferenceError(Handle<String> message);
1603
1647
/**
1604
1648
 * Container class for static utility functions.
1605
1649
 */
1606
 
class V8 {
 
1650
class EXPORT V8 {
1607
1651
 public:
1608
1652
  static void SetFatalErrorHandler(FatalErrorCallback that);
1609
1653
 
1633
1677
   */
1634
1678
  static void SetFlagsFromString(const char* str, int length);
1635
1679
 
 
1680
  /**
 
1681
   * Sets v8 flags from command line.
 
1682
   * TODO(758124): Describe flags?
 
1683
   */
 
1684
  static void SetFlagsFromCommandLine(int* argc,
 
1685
                                      char** argv,
 
1686
                                      bool remove_flags);
 
1687
 
1636
1688
  /** Get the version string. */
1637
1689
  static const char* GetVersion();
1638
1690
 
1711
1763
/**
1712
1764
 * An external exception handler.
1713
1765
 */
1714
 
class TryCatch {
 
1766
class EXPORT TryCatch {
1715
1767
 public:
1716
1768
 
1717
1769
  /**
1763
1815
/**
1764
1816
 * Ignore
1765
1817
 */
1766
 
class ExtensionConfiguration {
 
1818
class EXPORT ExtensionConfiguration {
1767
1819
 public:
1768
1820
  ExtensionConfiguration(int name_count, const char* names[])
1769
1821
      : name_count_(name_count), names_(names) { }
1778
1830
 * A sandboxed execution context with its own set of built-in objects
1779
1831
 * and functions.
1780
1832
 */
1781
 
class Context {
 
1833
class EXPORT Context {
1782
1834
 public:
1783
1835
  Local<Object> Global();
1784
1836
 
1821
1873
   * Stack-allocated class which sets the execution context for all
1822
1874
   * operations executed within a local scope.
1823
1875
   */
1824
 
  class Scope {
 
1876
  class EXPORT Scope {
1825
1877
   public:
1826
1878
    inline Scope(Handle<Context> context) : context_(context) {
1827
1879
      context_->Enter();
1901
1953
 * }
1902
1954
 * // V8 Now no longer locked.
1903
1955
 */
1904
 
class Unlocker {
 
1956
class EXPORT Unlocker {
1905
1957
 public:
1906
1958
  Unlocker();
1907
1959
  ~Unlocker();
1908
1960
};
1909
1961
 
1910
1962
 
1911
 
class Locker {
 
1963
class EXPORT Locker {
1912
1964
 public:
1913
1965
  Locker();
1914
1966
  ~Locker();
2100
2152
 
2101
2153
 
2102
2154
#undef EXPORT
 
2155
#undef EXPORT_INLINE
2103
2156
#undef TYPE_CHECK
2104
2157
 
2105
2158