v8  5.8.282(node8.0.0)
V8 is Google's open source JavaScript engine
v8.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 /** \mainpage V8 API Reference Guide
6  *
7  * V8 is Google's open source JavaScript engine.
8  *
9  * This set of documents provides reference material generated from the
10  * V8 header file, include/v8.h.
11  *
12  * For other documentation see http://code.google.com/apis/v8/
13  */
14 
15 #ifndef INCLUDE_V8_H_
16 #define INCLUDE_V8_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <memory>
22 #include <utility>
23 #include <vector>
24 
25 #include "v8-version.h" // NOLINT(build/include)
26 #include "v8config.h" // NOLINT(build/include)
27 
28 // We reserve the V8_* prefix for macros defined in V8 public API and
29 // assume there are no name conflicts with the embedder's code.
30 
31 #ifdef V8_OS_WIN
32 
33 // Setup for Windows DLL export/import. When building the V8 DLL the
34 // BUILDING_V8_SHARED needs to be defined. When building a program which uses
35 // the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
36 // static library or building a program which uses the V8 static library neither
37 // BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
38 #ifdef BUILDING_V8_SHARED
39 # define V8_EXPORT __declspec(dllexport)
40 #elif USING_V8_SHARED
41 # define V8_EXPORT __declspec(dllimport)
42 #else
43 # define V8_EXPORT
44 #endif // BUILDING_V8_SHARED
45 
46 #else // V8_OS_WIN
47 
48 // Setup for Linux shared library export.
49 #if V8_HAS_ATTRIBUTE_VISIBILITY
50 # ifdef BUILDING_V8_SHARED
51 # define V8_EXPORT __attribute__ ((visibility("default")))
52 # else
53 # define V8_EXPORT
54 # endif
55 #else
56 # define V8_EXPORT
57 #endif
58 
59 #endif // V8_OS_WIN
60 
61 /**
62  * The v8 JavaScript engine.
63  */
64 namespace v8 {
65 
66 class AccessorSignature;
67 class Array;
68 class ArrayBuffer;
69 class Boolean;
70 class BooleanObject;
71 class Context;
72 class CpuProfiler;
73 class Data;
74 class Date;
75 class External;
76 class Function;
77 class FunctionTemplate;
78 class HeapProfiler;
79 class ImplementationUtilities;
80 class Int32;
81 class Integer;
82 class Isolate;
83 template <class T>
84 class Maybe;
85 class Name;
86 class Number;
87 class NumberObject;
88 class Object;
89 class ObjectOperationDescriptor;
90 class ObjectTemplate;
91 class Platform;
92 class Primitive;
93 class Promise;
94 class PropertyDescriptor;
95 class Proxy;
96 class RawOperationDescriptor;
97 class Script;
98 class SharedArrayBuffer;
99 class Signature;
100 class StartupData;
101 class StackFrame;
102 class StackTrace;
103 class String;
104 class StringObject;
105 class Symbol;
106 class SymbolObject;
107 class Private;
108 class Uint32;
109 class Utils;
110 class Value;
111 template <class T> class Local;
112 template <class T>
113 class MaybeLocal;
114 template <class T> class Eternal;
115 template<class T> class NonCopyablePersistentTraits;
116 template<class T> class PersistentBase;
117 template <class T, class M = NonCopyablePersistentTraits<T> >
118 class Persistent;
119 template <class T>
120 class Global;
121 template<class K, class V, class T> class PersistentValueMap;
122 template <class K, class V, class T>
124 template <class K, class V, class T>
125 class GlobalValueMap;
126 template<class V, class T> class PersistentValueVector;
127 template<class T, class P> class WeakCallbackObject;
128 class FunctionTemplate;
129 class ObjectTemplate;
130 class Data;
131 template<typename T> class FunctionCallbackInfo;
132 template<typename T> class PropertyCallbackInfo;
133 class StackTrace;
134 class StackFrame;
135 class Isolate;
136 class CallHandlerHelper;
138 template<typename T> class ReturnValue;
139 
140 namespace experimental {
141 class FastAccessorBuilder;
142 } // namespace experimental
143 
144 namespace internal {
145 class Arguments;
146 class Heap;
147 class HeapObject;
148 class Isolate;
149 class Object;
150 struct StreamedSource;
151 template<typename T> class CustomArguments;
152 class PropertyCallbackArguments;
153 class FunctionCallbackArguments;
154 class GlobalHandles;
155 } // namespace internal
156 
157 
158 /**
159  * General purpose unique identifier.
160  */
161 class UniqueId {
162  public:
163  explicit UniqueId(intptr_t data)
164  : data_(data) {}
165 
166  bool operator==(const UniqueId& other) const {
167  return data_ == other.data_;
168  }
169 
170  bool operator!=(const UniqueId& other) const {
171  return data_ != other.data_;
172  }
173 
174  bool operator<(const UniqueId& other) const {
175  return data_ < other.data_;
176  }
177 
178  private:
179  intptr_t data_;
180 };
181 
182 // --- Handles ---
183 
184 #define TYPE_CHECK(T, S)
185  while (false) {
186  *(static_cast<T* volatile*>(0)) = static_cast<S*>(0);
187  }
188 
189 
190 /**
191  * An object reference managed by the v8 garbage collector.
192  *
193  * All objects returned from v8 have to be tracked by the garbage
194  * collector so that it knows that the objects are still alive. Also,
195  * because the garbage collector may move objects, it is unsafe to
196  * point directly to an object. Instead, all objects are stored in
197  * handles which are known by the garbage collector and updated
198  * whenever an object moves. Handles should always be passed by value
199  * (except in cases like out-parameters) and they should never be
200  * allocated on the heap.
201  *
202  * There are two types of handles: local and persistent handles.
203  * Local handles are light-weight and transient and typically used in
204  * local operations. They are managed by HandleScopes. Persistent
205  * handles can be used when storing objects across several independent
206  * operations and have to be explicitly deallocated when they're no
207  * longer used.
208  *
209  * It is safe to extract the object stored in the handle by
210  * dereferencing the handle (for instance, to extract the Object* from
211  * a Local<Object>); the value will still be governed by a handle
212  * behind the scenes and the same rules apply to these values as to
213  * their handles.
214  */
215 template <class T>
216 class Local {
217  public:
218  V8_INLINE Local() : val_(0) {}
219  template <class S>
220  V8_INLINE Local(Local<S> that)
221  : val_(reinterpret_cast<T*>(*that)) {
222  /**
223  * This check fails when trying to convert between incompatible
224  * handles. For example, converting from a Local<String> to a
225  * Local<Number>.
226  */
227  TYPE_CHECK(T, S);
228  }
229 
230  /**
231  * Returns true if the handle is empty.
232  */
233  V8_INLINE bool IsEmpty() const { return val_ == 0; }
234 
235  /**
236  * Sets the handle to be empty. IsEmpty() will then return true.
237  */
238  V8_INLINE void Clear() { val_ = 0; }
239 
240  V8_INLINE T* operator->() const { return val_; }
241 
242  V8_INLINE T* operator*() const { return val_; }
243 
244  /**
245  * Checks whether two handles are the same.
246  * Returns true if both are empty, or if the objects
247  * to which they refer are identical.
248  * The handles' references are not checked.
249  */
250  template <class S>
251  V8_INLINE bool operator==(const Local<S>& that) const {
252  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
253  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
254  if (a == 0) return b == 0;
255  if (b == 0) return false;
256  return *a == *b;
257  }
258 
259  template <class S> V8_INLINE bool operator==(
260  const PersistentBase<S>& that) const {
261  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
262  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
263  if (a == 0) return b == 0;
264  if (b == 0) return false;
265  return *a == *b;
266  }
267 
268  /**
269  * Checks whether two handles are different.
270  * Returns true if only one of the handles is empty, or if
271  * the objects to which they refer are different.
272  * The handles' references are not checked.
273  */
274  template <class S>
275  V8_INLINE bool operator!=(const Local<S>& that) const {
276  return !operator==(that);
277  }
278 
279  template <class S> V8_INLINE bool operator!=(
280  const Persistent<S>& that) const {
281  return !operator==(that);
282  }
283 
284  template <class S> V8_INLINE static Local<T> Cast(Local<S> that) {
285 #ifdef V8_ENABLE_CHECKS
286  // If we're going to perform the type check then we have to check
287  // that the handle isn't empty before doing the checked cast.
288  if (that.IsEmpty()) return Local<T>();
289 #endif
290  return Local<T>(T::Cast(*that));
291  }
292 
293  template <class S>
294  V8_INLINE Local<S> As() const {
295  return Local<S>::Cast(*this);
296  }
297 
298  /**
299  * Create a local handle for the content of another handle.
300  * The referee is kept alive by the local handle even when
301  * the original handle is destroyed/disposed.
302  */
303  V8_INLINE static Local<T> New(Isolate* isolate, Local<T> that);
304  V8_INLINE static Local<T> New(Isolate* isolate,
305  const PersistentBase<T>& that);
306 
307  private:
308  friend class Utils;
309  template<class F> friend class Eternal;
310  template<class F> friend class PersistentBase;
311  template<class F, class M> friend class Persistent;
312  template<class F> friend class Local;
313  template <class F>
314  friend class MaybeLocal;
315  template<class F> friend class FunctionCallbackInfo;
316  template<class F> friend class PropertyCallbackInfo;
317  friend class String;
318  friend class Object;
319  friend class Context;
320  friend class Private;
321  template<class F> friend class internal::CustomArguments;
323  friend Local<Primitive> Null(Isolate* isolate);
324  friend Local<Boolean> True(Isolate* isolate);
325  friend Local<Boolean> False(Isolate* isolate);
326  friend class HandleScope;
327  friend class EscapableHandleScope;
328  template <class F1, class F2, class F3>
330  template<class F1, class F2> friend class PersistentValueVector;
331  template <class F>
332  friend class ReturnValue;
333 
334  explicit V8_INLINE Local(T* that) : val_(that) {}
335  V8_INLINE static Local<T> New(Isolate* isolate, T* that);
336  T* val_;
337 };
338 
339 
340 #if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
341 // Handle is an alias for Local for historical reasons.
342 template <class T>
343 using Handle = Local<T>;
344 #endif
345 
346 
347 /**
348  * A MaybeLocal<> is a wrapper around Local<> that enforces a check whether
349  * the Local<> is empty before it can be used.
350  *
351  * If an API method returns a MaybeLocal<>, the API method can potentially fail
352  * either because an exception is thrown, or because an exception is pending,
353  * e.g. because a previous API call threw an exception that hasn't been caught
354  * yet, or because a TerminateExecution exception was thrown. In that case, an
355  * empty MaybeLocal is returned.
356  */
357 template <class T>
358 class MaybeLocal {
359  public:
361  template <class S>
362  V8_INLINE MaybeLocal(Local<S> that)
363  : val_(reinterpret_cast<T*>(*that)) {
364  TYPE_CHECK(T, S);
365  }
366 
367  V8_INLINE bool IsEmpty() const { return val_ == nullptr; }
368 
369  template <class S>
370  V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const {
371  out->val_ = IsEmpty() ? nullptr : this->val_;
372  return !IsEmpty();
373  }
374 
375  // Will crash if the MaybeLocal<> is empty.
376  V8_INLINE Local<T> ToLocalChecked();
377 
378  template <class S>
379  V8_INLINE Local<S> FromMaybe(Local<S> default_value) const {
380  return IsEmpty() ? default_value : Local<S>(val_);
381  }
382 
383  private:
384  T* val_;
385 };
386 
387 
388 // Eternal handles are set-once handles that live for the life of the isolate.
389 template <class T> class Eternal {
390  public:
391  V8_INLINE Eternal() : index_(kInitialValue) { }
392  template<class S>
393  V8_INLINE Eternal(Isolate* isolate, Local<S> handle) : index_(kInitialValue) {
394  Set(isolate, handle);
395  }
396  // Can only be safely called if already set.
397  V8_INLINE Local<T> Get(Isolate* isolate);
398  V8_INLINE bool IsEmpty() { return index_ == kInitialValue; }
399  template<class S> V8_INLINE void Set(Isolate* isolate, Local<S> handle);
400 
401  private:
402  static const int kInitialValue = -1;
403  int index_;
404 };
405 
406 
407 static const int kInternalFieldsInWeakCallback = 2;
408 
409 
410 template <typename T>
412  public:
413  typedef void (*Callback)(const WeakCallbackInfo<T>& data);
414 
415  WeakCallbackInfo(Isolate* isolate, T* parameter,
416  void* internal_fields[kInternalFieldsInWeakCallback],
417  Callback* callback)
418  : isolate_(isolate), parameter_(parameter), callback_(callback) {
419  for (int i = 0; i < kInternalFieldsInWeakCallback; ++i) {
420  internal_fields_[i] = internal_fields[i];
421  }
422  }
423 
424  V8_INLINE Isolate* GetIsolate() const { return isolate_; }
425  V8_INLINE T* GetParameter() const { return parameter_; }
426  V8_INLINE void* GetInternalField(int index) const;
427 
428  V8_INLINE V8_DEPRECATED("use indexed version",
429  void* GetInternalField1() const) {
430  return internal_fields_[0];
431  }
432  V8_INLINE V8_DEPRECATED("use indexed version",
433  void* GetInternalField2() const) {
434  return internal_fields_[1];
435  }
436 
437  V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.",
438  bool IsFirstPass() const) {
439  return callback_ != nullptr;
440  }
441 
442  // When first called, the embedder MUST Reset() the Global which triggered the
443  // callback. The Global itself is unusable for anything else. No v8 other api
444  // calls may be called in the first callback. Should additional work be
445  // required, the embedder must set a second pass callback, which will be
446  // called after all the initial callbacks are processed.
447  // Calling SetSecondPassCallback on the second pass will immediately crash.
448  void SetSecondPassCallback(Callback callback) const { *callback_ = callback; }
449 
450  private:
451  Isolate* isolate_;
452  T* parameter_;
453  Callback* callback_;
454  void* internal_fields_[kInternalFieldsInWeakCallback];
455 };
456 
457 
458 // kParameter will pass a void* parameter back to the callback, kInternalFields
459 // will pass the first two internal fields back to the callback, kFinalizer
460 // will pass a void* parameter back, but is invoked before the object is
461 // actually collected, so it can be resurrected. In the last case, it is not
462 // possible to request a second pass callback.
464 
465 /**
466  * An object reference that is independent of any handle scope. Where
467  * a Local handle only lives as long as the HandleScope in which it was
468  * allocated, a PersistentBase handle remains valid until it is explicitly
469  * disposed.
470  *
471  * A persistent handle contains a reference to a storage cell within
472  * the v8 engine which holds an object value and which is updated by
473  * the garbage collector whenever the object is moved. A new storage
474  * cell can be created using the constructor or PersistentBase::Reset and
475  * existing handles can be disposed using PersistentBase::Reset.
476  *
477  */
478 template <class T> class PersistentBase {
479  public:
480  /**
481  * If non-empty, destroy the underlying storage cell
482  * IsEmpty() will return true after this call.
483  */
484  V8_INLINE void Reset();
485  /**
486  * If non-empty, destroy the underlying storage cell
487  * and create a new one with the contents of other if other is non empty
488  */
489  template <class S>
490  V8_INLINE void Reset(Isolate* isolate, const Local<S>& other);
491 
492  /**
493  * If non-empty, destroy the underlying storage cell
494  * and create a new one with the contents of other if other is non empty
495  */
496  template <class S>
497  V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other);
498 
499  V8_INLINE bool IsEmpty() const { return val_ == NULL; }
500  V8_INLINE void Empty() { val_ = 0; }
501 
502  V8_INLINE Local<T> Get(Isolate* isolate) const {
503  return Local<T>::New(isolate, *this);
504  }
505 
506  template <class S>
507  V8_INLINE bool operator==(const PersistentBase<S>& that) const {
508  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
509  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
510  if (a == NULL) return b == NULL;
511  if (b == NULL) return false;
512  return *a == *b;
513  }
514 
515  template <class S>
516  V8_INLINE bool operator==(const Local<S>& that) const {
517  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
518  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
519  if (a == NULL) return b == NULL;
520  if (b == NULL) return false;
521  return *a == *b;
522  }
523 
524  template <class S>
525  V8_INLINE bool operator!=(const PersistentBase<S>& that) const {
526  return !operator==(that);
527  }
528 
529  template <class S>
530  V8_INLINE bool operator!=(const Local<S>& that) const {
531  return !operator==(that);
532  }
533 
534  /**
535  * Install a finalization callback on this object.
536  * NOTE: There is no guarantee as to *when* or even *if* the callback is
537  * invoked. The invocation is performed solely on a best effort basis.
538  * As always, GC-based finalization should *not* be relied upon for any
539  * critical form of resource management!
540  */
541  template <typename P>
542  V8_INLINE void SetWeak(P* parameter,
543  typename WeakCallbackInfo<P>::Callback callback,
544  WeakCallbackType type);
545 
546  /**
547  * Turns this handle into a weak phantom handle without finalization callback.
548  * The handle will be reset automatically when the garbage collector detects
549  * that the object is no longer reachable.
550  * A related function Isolate::NumberOfPhantomHandleResetsSinceLastCall
551  * returns how many phantom handles were reset by the garbage collector.
552  */
553  V8_INLINE void SetWeak();
554 
555  template<typename P>
556  V8_INLINE P* ClearWeak();
557 
558  // TODO(dcarney): remove this.
559  V8_INLINE void ClearWeak() { ClearWeak<void>(); }
560 
561  /**
562  * Allows the embedder to tell the v8 garbage collector that a certain object
563  * is alive. Only allowed when the embedder is asked to trace its heap by
564  * EmbedderHeapTracer.
565  */
566  V8_INLINE void RegisterExternalReference(Isolate* isolate) const;
567 
568  /**
569  * Marks the reference to this object independent. Garbage collector is free
570  * to ignore any object groups containing this object. Weak callback for an
571  * independent handle should not assume that it will be preceded by a global
572  * GC prologue callback or followed by a global GC epilogue callback.
573  */
574  V8_INLINE void MarkIndependent();
575 
576  /**
577  * Marks the reference to this object as active. The scavenge garbage
578  * collection should not reclaim the objects marked as active.
579  * This bit is cleared after the each garbage collection pass.
580  */
581  V8_INLINE void MarkActive();
582 
583  V8_INLINE bool IsIndependent() const;
584 
585  /** Checks if the handle holds the only reference to an object. */
586  V8_INLINE bool IsNearDeath() const;
587 
588  /** Returns true if the handle's reference is weak. */
589  V8_INLINE bool IsWeak() const;
590 
591  /**
592  * Assigns a wrapper class ID to the handle. See RetainedObjectInfo interface
593  * description in v8-profiler.h for details.
594  */
595  V8_INLINE void SetWrapperClassId(uint16_t class_id);
596 
597  /**
598  * Returns the class ID previously assigned to this handle or 0 if no class ID
599  * was previously assigned.
600  */
601  V8_INLINE uint16_t WrapperClassId() const;
602 
603  PersistentBase(const PersistentBase& other) = delete; // NOLINT
604  void operator=(const PersistentBase&) = delete;
605 
606  private:
607  friend class Isolate;
608  friend class Utils;
609  template<class F> friend class Local;
610  template<class F1, class F2> friend class Persistent;
611  template <class F>
612  friend class Global;
613  template<class F> friend class PersistentBase;
614  template<class F> friend class ReturnValue;
615  template <class F1, class F2, class F3>
617  template<class F1, class F2> friend class PersistentValueVector;
618  friend class Object;
619 
620  explicit V8_INLINE PersistentBase(T* val) : val_(val) {}
621  V8_INLINE static T* New(Isolate* isolate, T* that);
622 
623  T* val_;
624 };
625 
626 
627 /**
628  * Default traits for Persistent. This class does not allow
629  * use of the copy constructor or assignment operator.
630  * At present kResetInDestructor is not set, but that will change in a future
631  * version.
632  */
633 template<class T>
634 class NonCopyablePersistentTraits {
635  public:
636  typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
637  static const bool kResetInDestructor = false;
638  template<class S, class M>
639  V8_INLINE static void Copy(const Persistent<S, M>& source,
640  NonCopyablePersistent* dest) {
641  Uncompilable<Object>();
642  }
643  // TODO(dcarney): come up with a good compile error here.
644  template<class O> V8_INLINE static void Uncompilable() {
645  TYPE_CHECK(O, Primitive);
646  }
647 };
648 
649 
650 /**
651  * Helper class traits to allow copying and assignment of Persistent.
652  * This will clone the contents of storage cell, but not any of the flags, etc.
653  */
654 template<class T>
656  typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent;
657  static const bool kResetInDestructor = true;
658  template<class S, class M>
659  static V8_INLINE void Copy(const Persistent<S, M>& source,
660  CopyablePersistent* dest) {
661  // do nothing, just allow copy
662  }
663 };
664 
665 
666 /**
667  * A PersistentBase which allows copy and assignment.
668  *
669  * Copy, assignment and destructor behavior is controlled by the traits
670  * class M.
671  *
672  * Note: Persistent class hierarchy is subject to future changes.
673  */
674 template <class T, class M> class Persistent : public PersistentBase<T> {
675  public:
676  /**
677  * A Persistent with no storage cell.
678  */
679  V8_INLINE Persistent() : PersistentBase<T>(0) { }
680  /**
681  * Construct a Persistent from a Local.
682  * When the Local is non-empty, a new storage cell is created
683  * pointing to the same object, and no flags are set.
684  */
685  template <class S>
686  V8_INLINE Persistent(Isolate* isolate, Local<S> that)
687  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
688  TYPE_CHECK(T, S);
689  }
690  /**
691  * Construct a Persistent from a Persistent.
692  * When the Persistent is non-empty, a new storage cell is created
693  * pointing to the same object, and no flags are set.
694  */
695  template <class S, class M2>
696  V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that)
697  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
698  TYPE_CHECK(T, S);
699  }
700  /**
701  * The copy constructors and assignment operator create a Persistent
702  * exactly as the Persistent constructor, but the Copy function from the
703  * traits class is called, allowing the setting of flags based on the
704  * copied Persistent.
705  */
706  V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) {
707  Copy(that);
708  }
709  template <class S, class M2>
710  V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0) {
711  Copy(that);
712  }
713  V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT
714  Copy(that);
715  return *this;
716  }
717  template <class S, class M2>
718  V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLINT
719  Copy(that);
720  return *this;
721  }
722  /**
723  * The destructor will dispose the Persistent based on the
724  * kResetInDestructor flags in the traits class. Since not calling dispose
725  * can result in a memory leak, it is recommended to always set this flag.
726  */
728  if (M::kResetInDestructor) this->Reset();
729  }
730 
731  // TODO(dcarney): this is pretty useless, fix or remove
732  template <class S>
733  V8_INLINE static Persistent<T>& Cast(const Persistent<S>& that) { // NOLINT
734 #ifdef V8_ENABLE_CHECKS
735  // If we're going to perform the type check then we have to check
736  // that the handle isn't empty before doing the checked cast.
737  if (!that.IsEmpty()) T::Cast(*that);
738 #endif
739  return reinterpret_cast<Persistent<T>&>(const_cast<Persistent<S>&>(that));
740  }
741 
742  // TODO(dcarney): this is pretty useless, fix or remove
743  template <class S>
744  V8_INLINE Persistent<S>& As() const { // NOLINT
745  return Persistent<S>::Cast(*this);
746  }
747 
748  private:
749  friend class Isolate;
750  friend class Utils;
751  template<class F> friend class Local;
752  template<class F1, class F2> friend class Persistent;
753  template<class F> friend class ReturnValue;
754 
755  explicit V8_INLINE Persistent(T* that) : PersistentBase<T>(that) {}
756  V8_INLINE T* operator*() const { return this->val_; }
757  template<class S, class M2>
758  V8_INLINE void Copy(const Persistent<S, M2>& that);
759 };
760 
761 
762 /**
763  * A PersistentBase which has move semantics.
764  *
765  * Note: Persistent class hierarchy is subject to future changes.
766  */
767 template <class T>
768 class Global : public PersistentBase<T> {
769  public:
770  /**
771  * A Global with no storage cell.
772  */
774  /**
775  * Construct a Global from a Local.
776  * When the Local is non-empty, a new storage cell is created
777  * pointing to the same object, and no flags are set.
778  */
779  template <class S>
780  V8_INLINE Global(Isolate* isolate, Local<S> that)
781  : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) {
782  TYPE_CHECK(T, S);
783  }
784  /**
785  * Construct a Global from a PersistentBase.
786  * When the Persistent is non-empty, a new storage cell is created
787  * pointing to the same object, and no flags are set.
788  */
789  template <class S>
790  V8_INLINE Global(Isolate* isolate, const PersistentBase<S>& that)
791  : PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) {
792  TYPE_CHECK(T, S);
793  }
794  /**
795  * Move constructor.
796  */
797  V8_INLINE Global(Global&& other) : PersistentBase<T>(other.val_) { // NOLINT
798  other.val_ = nullptr;
799  }
800  V8_INLINE ~Global() { this->Reset(); }
801  /**
802  * Move via assignment.
803  */
804  template <class S>
805  V8_INLINE Global& operator=(Global<S>&& rhs) { // NOLINT
806  TYPE_CHECK(T, S);
807  if (this != &rhs) {
808  this->Reset();
809  this->val_ = rhs.val_;
810  rhs.val_ = nullptr;
811  }
812  return *this;
813  }
814  /**
815  * Pass allows returning uniques from functions, etc.
816  */
817  Global Pass() { return static_cast<Global&&>(*this); } // NOLINT
818 
819  /*
820  * For compatibility with Chromium's base::Bind (base::Passed).
821  */
822  typedef void MoveOnlyTypeForCPP03;
823 
824  Global(const Global&) = delete;
825  void operator=(const Global&) = delete;
826 
827  private:
828  template <class F>
829  friend class ReturnValue;
830  V8_INLINE T* operator*() const { return this->val_; }
831 };
832 
833 
834 // UniquePersistent is an alias for Global for historical reason.
835 template <class T>
836 using UniquePersistent = Global<T>;
837 
838 
839  /**
840  * A stack-allocated class that governs a number of local handles.
841  * After a handle scope has been created, all local handles will be
842  * allocated within that handle scope until either the handle scope is
843  * deleted or another handle scope is created. If there is already a
844  * handle scope and a new one is created, all allocations will take
845  * place in the new handle scope until it is deleted. After that,
846  * new handles will again be allocated in the original handle scope.
847  *
848  * After the handle scope of a local handle has been deleted the
849  * garbage collector will no longer track the object stored in the
850  * handle and may deallocate it. The behavior of accessing a handle
851  * for which the handle scope has been deleted is undefined.
852  */
854  public:
855  explicit HandleScope(Isolate* isolate);
856 
857  ~HandleScope();
858 
859  /**
860  * Counts the number of allocated handles.
861  */
862  static int NumberOfHandles(Isolate* isolate);
863 
865  return reinterpret_cast<Isolate*>(isolate_);
866  }
867 
868  HandleScope(const HandleScope&) = delete;
869  void operator=(const HandleScope&) = delete;
870  void* operator new(size_t size);
871  void operator delete(void*, size_t);
872 
873  protected:
875 
876  void Initialize(Isolate* isolate);
877 
878  static internal::Object** CreateHandle(internal::Isolate* isolate,
879  internal::Object* value);
880 
881  private:
882  // Uses heap_object to obtain the current Isolate.
883  static internal::Object** CreateHandle(internal::HeapObject* heap_object,
884  internal::Object* value);
885 
886  internal::Isolate* isolate_;
887  internal::Object** prev_next_;
888  internal::Object** prev_limit_;
889 
890  // Local::New uses CreateHandle with an Isolate* parameter.
891  template<class F> friend class Local;
892 
893  // Object::GetInternalField and Context::GetEmbedderData use CreateHandle with
894  // a HeapObject* in their shortcuts.
895  friend class Object;
896  friend class Context;
897 };
898 
899 
900 /**
901  * A HandleScope which first allocates a handle in the current scope
902  * which will be later filled with the escape value.
903  */
905  public:
906  explicit EscapableHandleScope(Isolate* isolate);
908 
909  /**
910  * Pushes the value into the previous scope and returns a handle to it.
911  * Cannot be called twice.
912  */
913  template <class T>
914  V8_INLINE Local<T> Escape(Local<T> value) {
915  internal::Object** slot =
916  Escape(reinterpret_cast<internal::Object**>(*value));
917  return Local<T>(reinterpret_cast<T*>(slot));
918  }
919 
921  void operator=(const EscapableHandleScope&) = delete;
922  void* operator new(size_t size);
923  void operator delete(void*, size_t);
924 
925  private:
926  internal::Object** Escape(internal::Object** escape_value);
927  internal::Object** escape_slot_;
928 };
929 
931  public:
932  SealHandleScope(Isolate* isolate);
933  ~SealHandleScope();
934 
935  SealHandleScope(const SealHandleScope&) = delete;
936  void operator=(const SealHandleScope&) = delete;
937  void* operator new(size_t size);
938  void operator delete(void*, size_t);
939 
940  private:
941  internal::Isolate* const isolate_;
942  internal::Object** prev_limit_;
943  int prev_sealed_level_;
944 };
945 
946 
947 // --- Special objects ---
948 
949 
950 /**
951  * The superclass of values and API object templates.
952  */
954  private:
955  Data();
956 };
957 
958 
959 /**
960  * The optional attributes of ScriptOrigin.
961  */
963  public:
964  V8_INLINE ScriptOriginOptions(bool is_shared_cross_origin = false,
965  bool is_opaque = false, bool is_wasm = false,
966  bool is_module = false)
967  : flags_((is_shared_cross_origin ? kIsSharedCrossOrigin : 0) |
968  (is_wasm ? kIsWasm : 0) | (is_opaque ? kIsOpaque : 0) |
969  (is_module ? kIsModule : 0)) {}
971  : flags_(flags &
972  (kIsSharedCrossOrigin | kIsOpaque | kIsWasm | kIsModule)) {}
973 
974  bool IsSharedCrossOrigin() const {
975  return (flags_ & kIsSharedCrossOrigin) != 0;
976  }
977  bool IsOpaque() const { return (flags_ & kIsOpaque) != 0; }
978  bool IsWasm() const { return (flags_ & kIsWasm) != 0; }
979  bool IsModule() const { return (flags_ & kIsModule) != 0; }
980 
981  int Flags() const { return flags_; }
982 
983  private:
984  enum {
985  kIsSharedCrossOrigin = 1,
986  kIsOpaque = 1 << 1,
987  kIsWasm = 1 << 2,
988  kIsModule = 1 << 3
989  };
990  const int flags_;
991 };
992 
993 /**
994  * The origin, within a file, of a script.
995  */
997  public:
999  Local<Value> resource_name,
1000  Local<Integer> resource_line_offset = Local<Integer>(),
1001  Local<Integer> resource_column_offset = Local<Integer>(),
1002  Local<Boolean> resource_is_shared_cross_origin = Local<Boolean>(),
1003  Local<Integer> script_id = Local<Integer>(),
1004  Local<Value> source_map_url = Local<Value>(),
1005  Local<Boolean> resource_is_opaque = Local<Boolean>(),
1006  Local<Boolean> is_wasm = Local<Boolean>(),
1007  Local<Boolean> is_module = Local<Boolean>());
1008 
1009  V8_INLINE Local<Value> ResourceName() const;
1010  V8_INLINE Local<Integer> ResourceLineOffset() const;
1011  V8_INLINE Local<Integer> ResourceColumnOffset() const;
1012  /**
1013  * Returns true for embedder's debugger scripts
1014  */
1015  V8_INLINE Local<Integer> ScriptID() const;
1016  V8_INLINE Local<Value> SourceMapUrl() const;
1017  V8_INLINE ScriptOriginOptions Options() const { return options_; }
1018 
1019  private:
1020  Local<Value> resource_name_;
1021  Local<Integer> resource_line_offset_;
1022  Local<Integer> resource_column_offset_;
1023  ScriptOriginOptions options_;
1024  Local<Integer> script_id_;
1025  Local<Value> source_map_url_;
1026 };
1027 
1028 
1029 /**
1030  * A compiled JavaScript script, not yet tied to a Context.
1031  */
1033  public:
1034  /**
1035  * Binds the script to the currently entered context.
1036  */
1037  Local<Script> BindToCurrentContext();
1038 
1039  int GetId();
1040  Local<Value> GetScriptName();
1041 
1042  /**
1043  * Data read from magic sourceURL comments.
1044  */
1045  Local<Value> GetSourceURL();
1046  /**
1047  * Data read from magic sourceMappingURL comments.
1048  */
1049  Local<Value> GetSourceMappingURL();
1050 
1051  /**
1052  * Returns zero based line number of the code_pos location in the script.
1053  * -1 will be returned if no information available.
1054  */
1055  int GetLineNumber(int code_pos);
1056 
1057  static const int kNoScriptId = 0;
1058 };
1059 
1060 /**
1061  * This is an unfinished experimental feature, and is only exposed
1062  * here for internal testing purposes. DO NOT USE.
1063  *
1064  * A compiled JavaScript module.
1065  */
1067  public:
1068  /**
1069  * Returns the number of modules requested by this module.
1070  */
1071  int GetModuleRequestsLength() const;
1072 
1073  /**
1074  * Returns the ith module specifier in this module.
1075  * i must be < GetModuleRequestsLength() and >= 0.
1076  */
1077  Local<String> GetModuleRequest(int i) const;
1078 
1079  /**
1080  * Returns the identity hash for this object.
1081  */
1082  int GetIdentityHash() const;
1083 
1084  typedef MaybeLocal<Module> (*ResolveCallback)(Local<Context> context,
1085  Local<String> specifier,
1086  Local<Module> referrer);
1087 
1088  /**
1089  * ModuleDeclarationInstantiation
1090  *
1091  * Returns false if an exception occurred during instantiation.
1092  */
1093  V8_WARN_UNUSED_RESULT bool Instantiate(Local<Context> context,
1094  ResolveCallback callback);
1095 
1096  /**
1097  * ModuleEvaluation
1098  */
1099  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
1100 };
1101 
1102 /**
1103  * A compiled JavaScript script, tied to a Context which was active when the
1104  * script was compiled.
1105  */
1107  public:
1108  /**
1109  * A shorthand for ScriptCompiler::Compile().
1110  */
1111  static V8_DEPRECATE_SOON(
1112  "Use maybe version",
1113  Local<Script> Compile(Local<String> source,
1114  ScriptOrigin* origin = nullptr));
1115  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1116  Local<Context> context, Local<String> source,
1117  ScriptOrigin* origin = nullptr);
1118 
1119  static Local<Script> V8_DEPRECATE_SOON("Use maybe version",
1120  Compile(Local<String> source,
1121  Local<String> file_name));
1122 
1123  /**
1124  * Runs the script returning the resulting value. It will be run in the
1125  * context in which it was created (ScriptCompiler::CompileBound or
1126  * UnboundScript::BindToCurrentContext()).
1127  */
1128  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Run());
1129  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
1130 
1131  /**
1132  * Returns the corresponding context-unbound script.
1133  */
1135 };
1136 
1137 
1138 /**
1139  * For compiling scripts.
1140  */
1142  public:
1143  /**
1144  * Compilation data that the embedder can cache and pass back to speed up
1145  * future compilations. The data is produced if the CompilerOptions passed to
1146  * the compilation functions in ScriptCompiler contains produce_data_to_cache
1147  * = true. The data to cache can then can be retrieved from
1148  * UnboundScript.
1149  */
1154  };
1155 
1157  : data(NULL),
1158  length(0),
1159  rejected(false),
1161 
1162  // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
1163  // data and guarantees that it stays alive until the CachedData object is
1164  // destroyed. If the policy is BufferOwned, the given data will be deleted
1165  // (with delete[]) when the CachedData object is destroyed.
1166  CachedData(const uint8_t* data, int length,
1167  BufferPolicy buffer_policy = BufferNotOwned);
1168  ~CachedData();
1169  // TODO(marja): Async compilation; add constructors which take a callback
1170  // which will be called when V8 no longer needs the data.
1171  const uint8_t* data;
1172  int length;
1173  bool rejected;
1175 
1176  // Prevent copying.
1177  CachedData(const CachedData&) = delete;
1178  CachedData& operator=(const CachedData&) = delete;
1179  };
1180 
1181  /**
1182  * Source code which can be then compiled to a UnboundScript or Script.
1183  */
1184  class Source {
1185  public:
1186  // Source takes ownership of CachedData.
1187  V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
1188  CachedData* cached_data = NULL);
1189  V8_INLINE Source(Local<String> source_string,
1190  CachedData* cached_data = NULL);
1191  V8_INLINE ~Source();
1192 
1193  // Ownership of the CachedData or its buffers is *not* transferred to the
1194  // caller. The CachedData object is alive as long as the Source object is
1195  // alive.
1196  V8_INLINE const CachedData* GetCachedData() const;
1197 
1199 
1200  // Prevent copying.
1201  Source(const Source&) = delete;
1202  Source& operator=(const Source&) = delete;
1203 
1204  private:
1205  friend class ScriptCompiler;
1206 
1207  Local<String> source_string;
1208 
1209  // Origin information
1210  Local<Value> resource_name;
1211  Local<Integer> resource_line_offset;
1212  Local<Integer> resource_column_offset;
1213  ScriptOriginOptions resource_options;
1214  Local<Value> source_map_url;
1215 
1216  // Cached data from previous compilation (if a kConsume*Cache flag is
1217  // set), or hold newly generated cache data (kProduce*Cache flags) are
1218  // set when calling a compile method.
1219  CachedData* cached_data;
1220  };
1221 
1222  /**
1223  * For streaming incomplete script data to V8. The embedder should implement a
1224  * subclass of this class.
1225  */
1227  public:
1228  virtual ~ExternalSourceStream() {}
1229 
1230  /**
1231  * V8 calls this to request the next chunk of data from the embedder. This
1232  * function will be called on a background thread, so it's OK to block and
1233  * wait for the data, if the embedder doesn't have data yet. Returns the
1234  * length of the data returned. When the data ends, GetMoreData should
1235  * return 0. Caller takes ownership of the data.
1236  *
1237  * When streaming UTF-8 data, V8 handles multi-byte characters split between
1238  * two data chunks, but doesn't handle multi-byte characters split between
1239  * more than two data chunks. The embedder can avoid this problem by always
1240  * returning at least 2 bytes of data.
1241  *
1242  * If the embedder wants to cancel the streaming, they should make the next
1243  * GetMoreData call return 0. V8 will interpret it as end of data (and most
1244  * probably, parsing will fail). The streaming task will return as soon as
1245  * V8 has parsed the data it received so far.
1246  */
1247  virtual size_t GetMoreData(const uint8_t** src) = 0;
1248 
1249  /**
1250  * V8 calls this method to set a 'bookmark' at the current position in
1251  * the source stream, for the purpose of (maybe) later calling
1252  * ResetToBookmark. If ResetToBookmark is called later, then subsequent
1253  * calls to GetMoreData should return the same data as they did when
1254  * SetBookmark was called earlier.
1255  *
1256  * The embedder may return 'false' to indicate it cannot provide this
1257  * functionality.
1258  */
1259  virtual bool SetBookmark();
1260 
1261  /**
1262  * V8 calls this to return to a previously set bookmark.
1263  */
1264  virtual void ResetToBookmark();
1265  };
1266 
1267 
1268  /**
1269  * Source code which can be streamed into V8 in pieces. It will be parsed
1270  * while streaming. It can be compiled after the streaming is complete.
1271  * StreamedSource must be kept alive while the streaming task is ran (see
1272  * ScriptStreamingTask below).
1273  */
1275  public:
1277 
1278  StreamedSource(ExternalSourceStream* source_stream, Encoding encoding);
1279  ~StreamedSource();
1280 
1281  // Ownership of the CachedData or its buffers is *not* transferred to the
1282  // caller. The CachedData object is alive as long as the StreamedSource
1283  // object is alive.
1284  const CachedData* GetCachedData() const;
1285 
1286  internal::StreamedSource* impl() const { return impl_; }
1287 
1288  // Prevent copying.
1289  StreamedSource(const StreamedSource&) = delete;
1290  StreamedSource& operator=(const StreamedSource&) = delete;
1291 
1292  private:
1293  internal::StreamedSource* impl_;
1294  };
1295 
1296  /**
1297  * A streaming task which the embedder must run on a background thread to
1298  * stream scripts into V8. Returned by ScriptCompiler::StartStreamingScript.
1299  */
1301  public:
1302  virtual ~ScriptStreamingTask() {}
1303  virtual void Run() = 0;
1304  };
1305 
1312  };
1313 
1314  /**
1315  * Compiles the specified script (context-independent).
1316  * Cached data as part of the source object can be optionally produced to be
1317  * consumed later to speed up compilation of identical source scripts.
1318  *
1319  * Note that when producing cached data, the source must point to NULL for
1320  * cached data. When consuming cached data, the cached data must have been
1321  * produced by the same version of V8.
1322  *
1323  * \param source Script source code.
1324  * \return Compiled script object (context independent; for running it must be
1325  * bound to a context).
1326  */
1327  static V8_DEPRECATED("Use maybe version",
1328  Local<UnboundScript> CompileUnbound(
1329  Isolate* isolate, Source* source,
1330  CompileOptions options = kNoCompileOptions));
1332  Isolate* isolate, Source* source,
1333  CompileOptions options = kNoCompileOptions);
1334 
1335  /**
1336  * Compiles the specified script (bound to current context).
1337  *
1338  * \param source Script source code.
1339  * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
1340  * using pre_data speeds compilation if it's done multiple times.
1341  * Owned by caller, no references are kept when this function returns.
1342  * \return Compiled script object, bound to the context that was active
1343  * when this function was called. When run it will always use this
1344  * context.
1345  */
1346  static V8_DEPRECATED(
1347  "Use maybe version",
1348  Local<Script> Compile(Isolate* isolate, Source* source,
1349  CompileOptions options = kNoCompileOptions));
1350  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1351  Local<Context> context, Source* source,
1352  CompileOptions options = kNoCompileOptions);
1353 
1354  /**
1355  * Returns a task which streams script data into V8, or NULL if the script
1356  * cannot be streamed. The user is responsible for running the task on a
1357  * background thread and deleting it. When ran, the task starts parsing the
1358  * script, and it will request data from the StreamedSource as needed. When
1359  * ScriptStreamingTask::Run exits, all data has been streamed and the script
1360  * can be compiled (see Compile below).
1361  *
1362  * This API allows to start the streaming with as little data as possible, and
1363  * the remaining data (for example, the ScriptOrigin) is passed to Compile.
1364  */
1366  Isolate* isolate, StreamedSource* source,
1367  CompileOptions options = kNoCompileOptions);
1368 
1369  /**
1370  * Compiles a streamed script (bound to current context).
1371  *
1372  * This can only be called after the streaming has finished
1373  * (ScriptStreamingTask has been run). V8 doesn't construct the source string
1374  * during streaming, so the embedder needs to pass the full source here.
1375  */
1376  static V8_DEPRECATED("Use maybe version",
1377  Local<Script> Compile(Isolate* isolate,
1378  StreamedSource* source,
1379  Local<String> full_source_string,
1380  const ScriptOrigin& origin));
1381  static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
1382  Local<Context> context, StreamedSource* source,
1383  Local<String> full_source_string, const ScriptOrigin& origin);
1384 
1385  /**
1386  * Return a version tag for CachedData for the current V8 version & flags.
1387  *
1388  * This value is meant only for determining whether a previously generated
1389  * CachedData instance is still valid; the tag has no other meaing.
1390  *
1391  * Background: The data carried by CachedData may depend on the exact
1392  * V8 version number or currently compiler flags. This means when
1393  * persisting CachedData, the embedder must take care to not pass in
1394  * data from another V8 version, or the same version with different
1395  * features enabled.
1396  *
1397  * The easiest way to do so is to clear the embedder's cache on any
1398  * such change.
1399  *
1400  * Alternatively, this tag can be stored alongside the cached data and
1401  * compared when it is being used.
1402  */
1403  static uint32_t CachedDataVersionTag();
1404 
1405  /**
1406  * This is an unfinished experimental feature, and is only exposed
1407  * here for internal testing purposes. DO NOT USE.
1408  *
1409  * Compile an ES module, returning a Module that encapsulates
1410  * the compiled code.
1411  *
1412  * Corresponds to the ParseModule abstract operation in the
1413  * ECMAScript specification.
1414  */
1415  static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
1416  Isolate* isolate, Source* source);
1417 
1418  /**
1419  * Compile a function for a given context. This is equivalent to running
1420  *
1421  * with (obj) {
1422  * return function(args) { ... }
1423  * }
1424  *
1425  * It is possible to specify multiple context extensions (obj in the above
1426  * example).
1427  */
1428  static V8_DEPRECATE_SOON("Use maybe version",
1429  Local<Function> CompileFunctionInContext(
1430  Isolate* isolate, Source* source,
1431  Local<Context> context, size_t arguments_count,
1432  Local<String> arguments[],
1433  size_t context_extension_count,
1434  Local<Object> context_extensions[]));
1436  Local<Context> context, Source* source, size_t arguments_count,
1437  Local<String> arguments[], size_t context_extension_count,
1438  Local<Object> context_extensions[]);
1439 
1440  private:
1441  static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
1442  Isolate* isolate, Source* source, CompileOptions options);
1443 };
1444 
1445 
1446 /**
1447  * An error message.
1448  */
1450  public:
1451  Local<String> Get() const;
1452 
1453  V8_DEPRECATE_SOON("Use maybe version", Local<String> GetSourceLine() const);
1455  Local<Context> context) const;
1456 
1457  /**
1458  * Returns the origin for the script from where the function causing the
1459  * error originates.
1460  */
1461  ScriptOrigin GetScriptOrigin() const;
1462 
1463  /**
1464  * Returns the resource name for the script from where the function causing
1465  * the error originates.
1466  */
1467  Local<Value> GetScriptResourceName() const;
1468 
1469  /**
1470  * Exception stack trace. By default stack traces are not captured for
1471  * uncaught exceptions. SetCaptureStackTraceForUncaughtExceptions allows
1472  * to change this option.
1473  */
1474  Local<StackTrace> GetStackTrace() const;
1475 
1476  /**
1477  * Returns the number, 1-based, of the line where the error occurred.
1478  */
1479  V8_DEPRECATE_SOON("Use maybe version", int GetLineNumber() const);
1480  V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
1481 
1482  /**
1483  * Returns the index within the script of the first character where
1484  * the error occurred.
1485  */
1486  int GetStartPosition() const;
1487 
1488  /**
1489  * Returns the index within the script of the last character where
1490  * the error occurred.
1491  */
1492  int GetEndPosition() const;
1493 
1494  /**
1495  * Returns the error level of the message.
1496  */
1497  int ErrorLevel() const;
1498 
1499  /**
1500  * Returns the index within the line of the first character where
1501  * the error occurred.
1502  */
1503  V8_DEPRECATE_SOON("Use maybe version", int GetStartColumn() const);
1504  V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;
1505 
1506  /**
1507  * Returns the index within the line of the last character where
1508  * the error occurred.
1509  */
1510  V8_DEPRECATED("Use maybe version", int GetEndColumn() const);
1511  V8_WARN_UNUSED_RESULT Maybe<int> GetEndColumn(Local<Context> context) const;
1512 
1513  /**
1514  * Passes on the value set by the embedder when it fed the script from which
1515  * this Message was generated to V8.
1516  */
1517  bool IsSharedCrossOrigin() const;
1518  bool IsOpaque() const;
1519 
1520  // TODO(1245381): Print to a string instead of on a FILE.
1521  static void PrintCurrentStackTrace(Isolate* isolate, FILE* out);
1522 
1523  static const int kNoLineNumberInfo = 0;
1524  static const int kNoColumnInfo = 0;
1525  static const int kNoScriptIdInfo = 0;
1526 };
1527 
1528 
1529 /**
1530  * Representation of a JavaScript stack trace. The information collected is a
1531  * snapshot of the execution stack and the information remains valid after
1532  * execution continues.
1533  */
1535  public:
1536  /**
1537  * Flags that determine what information is placed captured for each
1538  * StackFrame when grabbing the current stack trace.
1539  */
1543  kScriptName = 1 << 2,
1544  kFunctionName = 1 << 3,
1545  kIsEval = 1 << 4,
1546  kIsConstructor = 1 << 5,
1548  kScriptId = 1 << 7,
1552  };
1553 
1554  /**
1555  * Returns a StackFrame at a particular index.
1556  */
1557  Local<StackFrame> GetFrame(uint32_t index) const;
1558 
1559  /**
1560  * Returns the number of StackFrames.
1561  */
1562  int GetFrameCount() const;
1563 
1564  /**
1565  * Returns StackTrace as a v8::Array that contains StackFrame objects.
1566  */
1567  Local<Array> AsArray();
1568 
1569  /**
1570  * Grab a snapshot of the current JavaScript execution stack.
1571  *
1572  * \param frame_limit The maximum number of stack frames we want to capture.
1573  * \param options Enumerates the set of things we will capture for each
1574  * StackFrame.
1575  */
1576  static Local<StackTrace> CurrentStackTrace(
1577  Isolate* isolate,
1578  int frame_limit,
1579  StackTraceOptions options = kOverview);
1580 };
1581 
1582 
1583 /**
1584  * A single JavaScript stack frame.
1585  */
1587  public:
1588  /**
1589  * Returns the number, 1-based, of the line for the associate function call.
1590  * This method will return Message::kNoLineNumberInfo if it is unable to
1591  * retrieve the line number, or if kLineNumber was not passed as an option
1592  * when capturing the StackTrace.
1593  */
1594  int GetLineNumber() const;
1595 
1596  /**
1597  * Returns the 1-based column offset on the line for the associated function
1598  * call.
1599  * This method will return Message::kNoColumnInfo if it is unable to retrieve
1600  * the column number, or if kColumnOffset was not passed as an option when
1601  * capturing the StackTrace.
1602  */
1603  int GetColumn() const;
1604 
1605  /**
1606  * Returns the id of the script for the function for this StackFrame.
1607  * This method will return Message::kNoScriptIdInfo if it is unable to
1608  * retrieve the script id, or if kScriptId was not passed as an option when
1609  * capturing the StackTrace.
1610  */
1611  int GetScriptId() const;
1612 
1613  /**
1614  * Returns the name of the resource that contains the script for the
1615  * function for this StackFrame.
1616  */
1617  Local<String> GetScriptName() const;
1618 
1619  /**
1620  * Returns the name of the resource that contains the script for the
1621  * function for this StackFrame or sourceURL value if the script name
1622  * is undefined and its source ends with //# sourceURL=... string or
1623  * deprecated //@ sourceURL=... string.
1624  */
1625  Local<String> GetScriptNameOrSourceURL() const;
1626 
1627  /**
1628  * Returns the name of the function associated with this stack frame.
1629  */
1630  Local<String> GetFunctionName() const;
1631 
1632  /**
1633  * Returns whether or not the associated function is compiled via a call to
1634  * eval().
1635  */
1636  bool IsEval() const;
1637 
1638  /**
1639  * Returns whether or not the associated function is called as a
1640  * constructor via "new".
1641  */
1642  bool IsConstructor() const;
1643 };
1644 
1645 
1646 // A StateTag represents a possible state of the VM.
1648 
1649 // A RegisterState represents the current state of registers used
1650 // by the sampling profiler API.
1653  void* pc; // Instruction pointer.
1654  void* sp; // Stack pointer.
1655  void* fp; // Frame pointer.
1656 };
1657 
1658 // The output structure filled up by GetStackSample API function.
1659 struct SampleInfo {
1660  size_t frames_count; // Number of frames collected.
1661  StateTag vm_state; // Current VM state.
1662  void* external_callback_entry; // External callback address if VM is
1663  // executing an external callback.
1664 };
1665 
1666 /**
1667  * A JSON Parser and Stringifier.
1668  */
1670  public:
1671  /**
1672  * Tries to parse the string |json_string| and returns it as value if
1673  * successful.
1674  *
1675  * \param json_string The string to parse.
1676  * \return The corresponding value if successfully parsed.
1677  */
1678  static V8_DEPRECATED("Use the maybe version taking context",
1679  Local<Value> Parse(Local<String> json_string));
1680  static V8_DEPRECATE_SOON("Use the maybe version taking context",
1681  MaybeLocal<Value> Parse(Isolate* isolate,
1682  Local<String> json_string));
1683  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> Parse(
1684  Local<Context> context, Local<String> json_string);
1685 
1686  /**
1687  * Tries to stringify the JSON-serializable object |json_object| and returns
1688  * it as string if successful.
1689  *
1690  * \param json_object The JSON-serializable object to stringify.
1691  * \return The corresponding string if successfully stringified.
1692  */
1693  static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
1694  Local<Context> context, Local<Object> json_object,
1695  Local<String> gap = Local<String>());
1696 };
1697 
1698 /**
1699  * Value serialization compatible with the HTML structured clone algorithm.
1700  * The format is backward-compatible (i.e. safe to store to disk).
1701  *
1702  * WARNING: This API is under development, and changes (including incompatible
1703  * changes to the API or wire format) may occur without notice until this
1704  * warning is removed.
1705  */
1707  public:
1709  public:
1710  virtual ~Delegate() {}
1711 
1712  /*
1713  * Handles the case where a DataCloneError would be thrown in the structured
1714  * clone spec. Other V8 embedders may throw some other appropriate exception
1715  * type.
1716  */
1717  virtual void ThrowDataCloneError(Local<String> message) = 0;
1718 
1719  /*
1720  * The embedder overrides this method to write some kind of host object, if
1721  * possible. If not, a suitable exception should be thrown and
1722  * Nothing<bool>() returned.
1723  */
1724  virtual Maybe<bool> WriteHostObject(Isolate* isolate, Local<Object> object);
1725 
1726  /*
1727  * Called when the ValueSerializer is going to serialize a
1728  * SharedArrayBuffer object. The embedder must return an ID for the
1729  * object, using the same ID if this SharedArrayBuffer has already been
1730  * serialized in this buffer. When deserializing, this ID will be passed to
1731  * ValueDeserializer::TransferSharedArrayBuffer as |transfer_id|.
1732  *
1733  * If the object cannot be serialized, an
1734  * exception should be thrown and Nothing<uint32_t>() returned.
1735  */
1736  virtual Maybe<uint32_t> GetSharedArrayBufferId(
1737  Isolate* isolate, Local<SharedArrayBuffer> shared_array_buffer);
1738 
1739  /*
1740  * Allocates memory for the buffer of at least the size provided. The actual
1741  * size (which may be greater or equal) is written to |actual_size|. If no
1742  * buffer has been allocated yet, nullptr will be provided.
1743  *
1744  * If the memory cannot be allocated, nullptr should be returned.
1745  * |actual_size| will be ignored. It is assumed that |old_buffer| is still
1746  * valid in this case and has not been modified.
1747  */
1748  virtual void* ReallocateBufferMemory(void* old_buffer, size_t size,
1749  size_t* actual_size);
1750 
1751  /*
1752  * Frees a buffer allocated with |ReallocateBufferMemory|.
1753  */
1754  virtual void FreeBufferMemory(void* buffer);
1755  };
1756 
1757  explicit ValueSerializer(Isolate* isolate);
1758  ValueSerializer(Isolate* isolate, Delegate* delegate);
1759  ~ValueSerializer();
1760 
1761  /*
1762  * Writes out a header, which includes the format version.
1763  */
1764  void WriteHeader();
1765 
1766  /*
1767  * Serializes a JavaScript value into the buffer.
1768  */
1769  V8_WARN_UNUSED_RESULT Maybe<bool> WriteValue(Local<Context> context,
1770  Local<Value> value);
1771 
1772  /*
1773  * Returns the stored data. This serializer should not be used once the buffer
1774  * is released. The contents are undefined if a previous write has failed.
1775  */
1776  V8_DEPRECATE_SOON("Use Release()", std::vector<uint8_t> ReleaseBuffer());
1777 
1778  /*
1779  * Returns the stored data (allocated using the delegate's
1780  * AllocateBufferMemory) and its size. This serializer should not be used once
1781  * the buffer is released. The contents are undefined if a previous write has
1782  * failed.
1783  */
1785 
1786  /*
1787  * Marks an ArrayBuffer as havings its contents transferred out of band.
1788  * Pass the corresponding ArrayBuffer in the deserializing context to
1789  * ValueDeserializer::TransferArrayBuffer.
1790  */
1791  void TransferArrayBuffer(uint32_t transfer_id,
1792  Local<ArrayBuffer> array_buffer);
1793 
1794  /*
1795  * Similar to TransferArrayBuffer, but for SharedArrayBuffer.
1796  */
1797  V8_DEPRECATE_SOON("Use Delegate::GetSharedArrayBufferId",
1798  void TransferSharedArrayBuffer(
1799  uint32_t transfer_id,
1800  Local<SharedArrayBuffer> shared_array_buffer));
1801 
1802  /*
1803  * Indicate whether to treat ArrayBufferView objects as host objects,
1804  * i.e. pass them to Delegate::WriteHostObject. This should not be
1805  * called when no Delegate was passed.
1806  *
1807  * The default is not to treat ArrayBufferViews as host objects.
1808  */
1809  void SetTreatArrayBufferViewsAsHostObjects(bool mode);
1810 
1811  /*
1812  * Write raw data in various common formats to the buffer.
1813  * Note that integer types are written in base-128 varint format, not with a
1814  * binary copy. For use during an override of Delegate::WriteHostObject.
1815  */
1816  void WriteUint32(uint32_t value);
1817  void WriteUint64(uint64_t value);
1818  void WriteDouble(double value);
1819  void WriteRawBytes(const void* source, size_t length);
1820 
1821  private:
1822  ValueSerializer(const ValueSerializer&) = delete;
1823  void operator=(const ValueSerializer&) = delete;
1824 
1825  struct PrivateData;
1826  PrivateData* private_;
1827 };
1828 
1829 /**
1830  * Deserializes values from data written with ValueSerializer, or a compatible
1831  * implementation.
1832  *
1833  * WARNING: This API is under development, and changes (including incompatible
1834  * changes to the API or wire format) may occur without notice until this
1835  * warning is removed.
1836  */
1838  public:
1840  public:
1841  virtual ~Delegate() {}
1842 
1843  /*
1844  * The embedder overrides this method to read some kind of host object, if
1845  * possible. If not, a suitable exception should be thrown and
1846  * MaybeLocal<Object>() returned.
1847  */
1848  virtual MaybeLocal<Object> ReadHostObject(Isolate* isolate);
1849  };
1850 
1851  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size);
1852  ValueDeserializer(Isolate* isolate, const uint8_t* data, size_t size,
1853  Delegate* delegate);
1854  ~ValueDeserializer();
1855 
1856  /*
1857  * Reads and validates a header (including the format version).
1858  * May, for example, reject an invalid or unsupported wire format.
1859  */
1860  V8_WARN_UNUSED_RESULT Maybe<bool> ReadHeader(Local<Context> context);
1861 
1862  /*
1863  * Deserializes a JavaScript value from the buffer.
1864  */
1865  V8_WARN_UNUSED_RESULT MaybeLocal<Value> ReadValue(Local<Context> context);
1866 
1867  /*
1868  * Accepts the array buffer corresponding to the one passed previously to
1869  * ValueSerializer::TransferArrayBuffer.
1870  */
1871  void TransferArrayBuffer(uint32_t transfer_id,
1872  Local<ArrayBuffer> array_buffer);
1873 
1874  /*
1875  * Similar to TransferArrayBuffer, but for SharedArrayBuffer.
1876  * The id is not necessarily in the same namespace as unshared ArrayBuffer
1877  * objects.
1878  */
1879  void TransferSharedArrayBuffer(uint32_t id,
1880  Local<SharedArrayBuffer> shared_array_buffer);
1881 
1882  /*
1883  * Must be called before ReadHeader to enable support for reading the legacy
1884  * wire format (i.e., which predates this being shipped).
1885  *
1886  * Don't use this unless you need to read data written by previous versions of
1887  * blink::ScriptValueSerializer.
1888  */
1889  void SetSupportsLegacyWireFormat(bool supports_legacy_wire_format);
1890 
1891  /*
1892  * Reads the underlying wire format version. Likely mostly to be useful to
1893  * legacy code reading old wire format versions. Must be called after
1894  * ReadHeader.
1895  */
1896  uint32_t GetWireFormatVersion() const;
1897 
1898  /*
1899  * Reads raw data in various common formats to the buffer.
1900  * Note that integer types are read in base-128 varint format, not with a
1901  * binary copy. For use during an override of Delegate::ReadHostObject.
1902  */
1903  V8_WARN_UNUSED_RESULT bool ReadUint32(uint32_t* value);
1904  V8_WARN_UNUSED_RESULT bool ReadUint64(uint64_t* value);
1905  V8_WARN_UNUSED_RESULT bool ReadDouble(double* value);
1906  V8_WARN_UNUSED_RESULT bool ReadRawBytes(size_t length, const void** data);
1907 
1908  private:
1909  ValueDeserializer(const ValueDeserializer&) = delete;
1910  void operator=(const ValueDeserializer&) = delete;
1911 
1912  struct PrivateData;
1913  PrivateData* private_;
1914 };
1915 
1916 /**
1917  * A map whose keys are referenced weakly. It is similar to JavaScript WeakMap
1918  * but can be created without entering a v8::Context and hence shouldn't
1919  * escape to JavaScript.
1920  */
1921 class V8_EXPORT NativeWeakMap : public Data {
1922  public:
1923  static Local<NativeWeakMap> New(Isolate* isolate);
1924  void Set(Local<Value> key, Local<Value> value);
1925  Local<Value> Get(Local<Value> key);
1926  bool Has(Local<Value> key);
1927  bool Delete(Local<Value> key);
1928 };
1929 
1930 
1931 // --- Value ---
1932 
1933 
1934 /**
1935  * The superclass of all JavaScript values and objects.
1936  */
1937 class V8_EXPORT Value : public Data {
1938  public:
1939  /**
1940  * Returns true if this value is the undefined value. See ECMA-262
1941  * 4.3.10.
1942  */
1943  V8_INLINE bool IsUndefined() const;
1944 
1945  /**
1946  * Returns true if this value is the null value. See ECMA-262
1947  * 4.3.11.
1948  */
1949  V8_INLINE bool IsNull() const;
1950 
1951  /**
1952  * Returns true if this value is either the null or the undefined value.
1953  * See ECMA-262
1954  * 4.3.11. and 4.3.12
1955  */
1956  V8_INLINE bool IsNullOrUndefined() const;
1957 
1958  /**
1959  * Returns true if this value is true.
1960  */
1961  bool IsTrue() const;
1962 
1963  /**
1964  * Returns true if this value is false.
1965  */
1966  bool IsFalse() const;
1967 
1968  /**
1969  * Returns true if this value is a symbol or a string.
1970  */
1971  bool IsName() const;
1972 
1973  /**
1974  * Returns true if this value is an instance of the String type.
1975  * See ECMA-262 8.4.
1976  */
1977  V8_INLINE bool IsString() const;
1978 
1979  /**
1980  * Returns true if this value is a symbol.
1981  */
1982  bool IsSymbol() const;
1983 
1984  /**
1985  * Returns true if this value is a function.
1986  */
1987  bool IsFunction() const;
1988 
1989  /**
1990  * Returns true if this value is an array. Note that it will return false for
1991  * an Proxy for an array.
1992  */
1993  bool IsArray() const;
1994 
1995  /**
1996  * Returns true if this value is an object.
1997  */
1998  bool IsObject() const;
1999 
2000  /**
2001  * Returns true if this value is boolean.
2002  */
2003  bool IsBoolean() const;
2004 
2005  /**
2006  * Returns true if this value is a number.
2007  */
2008  bool IsNumber() const;
2009 
2010  /**
2011  * Returns true if this value is external.
2012  */
2013  bool IsExternal() const;
2014 
2015  /**
2016  * Returns true if this value is a 32-bit signed integer.
2017  */
2018  bool IsInt32() const;
2019 
2020  /**
2021  * Returns true if this value is a 32-bit unsigned integer.
2022  */
2023  bool IsUint32() const;
2024 
2025  /**
2026  * Returns true if this value is a Date.
2027  */
2028  bool IsDate() const;
2029 
2030  /**
2031  * Returns true if this value is an Arguments object.
2032  */
2033  bool IsArgumentsObject() const;
2034 
2035  /**
2036  * Returns true if this value is a Boolean object.
2037  */
2038  bool IsBooleanObject() const;
2039 
2040  /**
2041  * Returns true if this value is a Number object.
2042  */
2043  bool IsNumberObject() const;
2044 
2045  /**
2046  * Returns true if this value is a String object.
2047  */
2048  bool IsStringObject() const;
2049 
2050  /**
2051  * Returns true if this value is a Symbol object.
2052  */
2053  bool IsSymbolObject() const;
2054 
2055  /**
2056  * Returns true if this value is a NativeError.
2057  */
2058  bool IsNativeError() const;
2059 
2060  /**
2061  * Returns true if this value is a RegExp.
2062  */
2063  bool IsRegExp() const;
2064 
2065  /**
2066  * Returns true if this value is an async function.
2067  */
2068  bool IsAsyncFunction() const;
2069 
2070  /**
2071  * Returns true if this value is a Generator function.
2072  */
2073  bool IsGeneratorFunction() const;
2074 
2075  /**
2076  * Returns true if this value is a Generator object (iterator).
2077  */
2078  bool IsGeneratorObject() const;
2079 
2080  /**
2081  * Returns true if this value is a Promise.
2082  */
2083  bool IsPromise() const;
2084 
2085  /**
2086  * Returns true if this value is a Map.
2087  */
2088  bool IsMap() const;
2089 
2090  /**
2091  * Returns true if this value is a Set.
2092  */
2093  bool IsSet() const;
2094 
2095  /**
2096  * Returns true if this value is a Map Iterator.
2097  */
2098  bool IsMapIterator() const;
2099 
2100  /**
2101  * Returns true if this value is a Set Iterator.
2102  */
2103  bool IsSetIterator() const;
2104 
2105  /**
2106  * Returns true if this value is a WeakMap.
2107  */
2108  bool IsWeakMap() const;
2109 
2110  /**
2111  * Returns true if this value is a WeakSet.
2112  */
2113  bool IsWeakSet() const;
2114 
2115  /**
2116  * Returns true if this value is an ArrayBuffer.
2117  */
2118  bool IsArrayBuffer() const;
2119 
2120  /**
2121  * Returns true if this value is an ArrayBufferView.
2122  */
2123  bool IsArrayBufferView() const;
2124 
2125  /**
2126  * Returns true if this value is one of TypedArrays.
2127  */
2128  bool IsTypedArray() const;
2129 
2130  /**
2131  * Returns true if this value is an Uint8Array.
2132  */
2133  bool IsUint8Array() const;
2134 
2135  /**
2136  * Returns true if this value is an Uint8ClampedArray.
2137  */
2138  bool IsUint8ClampedArray() const;
2139 
2140  /**
2141  * Returns true if this value is an Int8Array.
2142  */
2143  bool IsInt8Array() const;
2144 
2145  /**
2146  * Returns true if this value is an Uint16Array.
2147  */
2148  bool IsUint16Array() const;
2149 
2150  /**
2151  * Returns true if this value is an Int16Array.
2152  */
2153  bool IsInt16Array() const;
2154 
2155  /**
2156  * Returns true if this value is an Uint32Array.
2157  */
2158  bool IsUint32Array() const;
2159 
2160  /**
2161  * Returns true if this value is an Int32Array.
2162  */
2163  bool IsInt32Array() const;
2164 
2165  /**
2166  * Returns true if this value is a Float32Array.
2167  */
2168  bool IsFloat32Array() const;
2169 
2170  /**
2171  * Returns true if this value is a Float64Array.
2172  */
2173  bool IsFloat64Array() const;
2174 
2175  /**
2176  * Returns true if this value is a DataView.
2177  */
2178  bool IsDataView() const;
2179 
2180  /**
2181  * Returns true if this value is a SharedArrayBuffer.
2182  * This is an experimental feature.
2183  */
2184  bool IsSharedArrayBuffer() const;
2185 
2186  /**
2187  * Returns true if this value is a JavaScript Proxy.
2188  */
2189  bool IsProxy() const;
2190 
2191  bool IsWebAssemblyCompiledModule() const;
2192 
2194  Local<Context> context) const;
2196  Local<Context> context) const;
2198  Local<Context> context) const;
2200  Local<Context> context) const;
2202  Local<Context> context) const;
2204  Local<Context> context) const;
2206  Local<Context> context) const;
2207  V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
2208 
2209  V8_DEPRECATE_SOON("Use maybe version",
2210  Local<Boolean> ToBoolean(Isolate* isolate) const);
2211  V8_DEPRECATE_SOON("Use maybe version",
2212  Local<Number> ToNumber(Isolate* isolate) const);
2213  V8_DEPRECATE_SOON("Use maybe version",
2214  Local<String> ToString(Isolate* isolate) const);
2215  V8_DEPRECATED("Use maybe version",
2216  Local<String> ToDetailString(Isolate* isolate) const);
2217  V8_DEPRECATE_SOON("Use maybe version",
2218  Local<Object> ToObject(Isolate* isolate) const);
2219  V8_DEPRECATE_SOON("Use maybe version",
2220  Local<Integer> ToInteger(Isolate* isolate) const);
2221  V8_DEPRECATED("Use maybe version",
2222  Local<Uint32> ToUint32(Isolate* isolate) const);
2223  V8_DEPRECATE_SOON("Use maybe version",
2224  Local<Int32> ToInt32(Isolate* isolate) const);
2225 
2226  inline V8_DEPRECATE_SOON("Use maybe version",
2227  Local<Boolean> ToBoolean() const);
2228  inline V8_DEPRECATED("Use maybe version", Local<Number> ToNumber() const);
2229  inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
2230  inline V8_DEPRECATED("Use maybe version",
2231  Local<String> ToDetailString() const);
2232  inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
2233  inline V8_DEPRECATE_SOON("Use maybe version",
2234  Local<Integer> ToInteger() const);
2235  inline V8_DEPRECATED("Use maybe version", Local<Uint32> ToUint32() const);
2236  inline V8_DEPRECATED("Use maybe version", Local<Int32> ToInt32() const);
2237 
2238  /**
2239  * Attempts to convert a string to an array index.
2240  * Returns an empty handle if the conversion fails.
2241  */
2242  V8_DEPRECATED("Use maybe version", Local<Uint32> ToArrayIndex() const);
2244  Local<Context> context) const;
2245 
2246  V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(Local<Context> context) const;
2247  V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
2248  V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
2249  Local<Context> context) const;
2250  V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
2251  Local<Context> context) const;
2252  V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
2253 
2254  V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
2255  V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
2256  V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
2257  V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
2258  V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
2259 
2260  /** JS == */
2261  V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
2262  V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
2263  Local<Value> that) const;
2264  bool StrictEquals(Local<Value> that) const;
2265  bool SameValue(Local<Value> that) const;
2266 
2267  template <class T> V8_INLINE static Value* Cast(T* value);
2268 
2269  Local<String> TypeOf(Isolate*);
2270 
2271  private:
2272  V8_INLINE bool QuickIsUndefined() const;
2273  V8_INLINE bool QuickIsNull() const;
2274  V8_INLINE bool QuickIsNullOrUndefined() const;
2275  V8_INLINE bool QuickIsString() const;
2276  bool FullIsUndefined() const;
2277  bool FullIsNull() const;
2278  bool FullIsString() const;
2279 };
2280 
2281 
2282 /**
2283  * The superclass of primitive values. See ECMA-262 4.3.2.
2284  */
2285 class V8_EXPORT Primitive : public Value { };
2286 
2287 
2288 /**
2289  * A primitive boolean value (ECMA-262, 4.3.14). Either the true
2290  * or false value.
2291  */
2292 class V8_EXPORT Boolean : public Primitive {
2293  public:
2294  bool Value() const;
2295  V8_INLINE static Boolean* Cast(v8::Value* obj);
2296  V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
2297 
2298  private:
2299  static void CheckCast(v8::Value* obj);
2300 };
2301 
2302 
2303 /**
2304  * A superclass for symbols and strings.
2305  */
2306 class V8_EXPORT Name : public Primitive {
2307  public:
2308  /**
2309  * Returns the identity hash for this object. The current implementation
2310  * uses an inline property on the object to store the identity hash.
2311  *
2312  * The return value will never be 0. Also, it is not guaranteed to be
2313  * unique.
2314  */
2315  int GetIdentityHash();
2316 
2317  V8_INLINE static Name* Cast(Value* obj);
2318 
2319  private:
2320  static void CheckCast(Value* obj);
2321 };
2322 
2323 
2325 
2326 
2327 /**
2328  * A JavaScript string value (ECMA-262, 4.3.17).
2329  */
2330 class V8_EXPORT String : public Name {
2331  public:
2332  static const int kMaxLength = (1 << 28) - 16;
2333 
2334  enum Encoding {
2338  };
2339  /**
2340  * Returns the number of characters in this string.
2341  */
2342  int Length() const;
2343 
2344  /**
2345  * Returns the number of bytes in the UTF-8 encoded
2346  * representation of this string.
2347  */
2348  int Utf8Length() const;
2349 
2350  /**
2351  * Returns whether this string is known to contain only one byte data.
2352  * Does not read the string.
2353  * False negatives are possible.
2354  */
2355  bool IsOneByte() const;
2356 
2357  /**
2358  * Returns whether this string contain only one byte data.
2359  * Will read the entire string in some cases.
2360  */
2361  bool ContainsOnlyOneByte() const;
2362 
2363  /**
2364  * Write the contents of the string to an external buffer.
2365  * If no arguments are given, expects the buffer to be large
2366  * enough to hold the entire string and NULL terminator. Copies
2367  * the contents of the string and the NULL terminator into the
2368  * buffer.
2369  *
2370  * WriteUtf8 will not write partial UTF-8 sequences, preferring to stop
2371  * before the end of the buffer.
2372  *
2373  * Copies up to length characters into the output buffer.
2374  * Only null-terminates if there is enough space in the buffer.
2375  *
2376  * \param buffer The buffer into which the string will be copied.
2377  * \param start The starting position within the string at which
2378  * copying begins.
2379  * \param length The number of characters to copy from the string. For
2380  * WriteUtf8 the number of bytes in the buffer.
2381  * \param nchars_ref The number of characters written, can be NULL.
2382  * \param options Various options that might affect performance of this or
2383  * subsequent operations.
2384  * \return The number of characters copied to the buffer excluding the null
2385  * terminator. For WriteUtf8: The number of bytes copied to the buffer
2386  * including the null terminator (if written).
2387  */
2393  // Used by WriteUtf8 to replace orphan surrogate code units with the
2394  // unicode replacement character. Needs to be set to guarantee valid UTF-8
2395  // output.
2397  };
2398 
2399  // 16-bit character codes.
2400  int Write(uint16_t* buffer,
2401  int start = 0,
2402  int length = -1,
2403  int options = NO_OPTIONS) const;
2404  // One byte characters.
2405  int WriteOneByte(uint8_t* buffer,
2406  int start = 0,
2407  int length = -1,
2408  int options = NO_OPTIONS) const;
2409  // UTF-8 encoded characters.
2410  int WriteUtf8(char* buffer,
2411  int length = -1,
2412  int* nchars_ref = NULL,
2413  int options = NO_OPTIONS) const;
2414 
2415  /**
2416  * A zero length string.
2417  */
2418  V8_INLINE static Local<String> Empty(Isolate* isolate);
2419 
2420  /**
2421  * Returns true if the string is external
2422  */
2423  bool IsExternal() const;
2424 
2425  /**
2426  * Returns true if the string is both external and one-byte.
2427  */
2428  bool IsExternalOneByte() const;
2429 
2431  public:
2433 
2434  virtual bool IsCompressible() const { return false; }
2435 
2436  protected:
2438 
2439  /**
2440  * Internally V8 will call this Dispose method when the external string
2441  * resource is no longer needed. The default implementation will use the
2442  * delete operator. This method can be overridden in subclasses to
2443  * control how allocated external string resources are disposed.
2444  */
2445  virtual void Dispose() { delete this; }
2446 
2447  // Disallow copying and assigning.
2449  void operator=(const ExternalStringResourceBase&) = delete;
2450 
2451  private:
2452  friend class internal::Heap;
2453  friend class v8::String;
2454  };
2455 
2456  /**
2457  * An ExternalStringResource is a wrapper around a two-byte string
2458  * buffer that resides outside V8's heap. Implement an
2459  * ExternalStringResource to manage the life cycle of the underlying
2460  * buffer. Note that the string data must be immutable.
2461  */
2463  : public ExternalStringResourceBase {
2464  public:
2465  /**
2466  * Override the destructor to manage the life cycle of the underlying
2467  * buffer.
2468  */
2470 
2471  /**
2472  * The string data from the underlying buffer.
2473  */
2474  virtual const uint16_t* data() const = 0;
2475 
2476  /**
2477  * The length of the string. That is, the number of two-byte characters.
2478  */
2479  virtual size_t length() const = 0;
2480 
2481  protected:
2483  };
2484 
2485  /**
2486  * An ExternalOneByteStringResource is a wrapper around an one-byte
2487  * string buffer that resides outside V8's heap. Implement an
2488  * ExternalOneByteStringResource to manage the life cycle of the
2489  * underlying buffer. Note that the string data must be immutable
2490  * and that the data must be Latin-1 and not UTF-8, which would require
2491  * special treatment internally in the engine and do not allow efficient
2492  * indexing. Use String::New or convert to 16 bit data for non-Latin1.
2493  */
2494 
2496  : public ExternalStringResourceBase {
2497  public:
2498  /**
2499  * Override the destructor to manage the life cycle of the underlying
2500  * buffer.
2501  */
2503  /** The string data from the underlying buffer.*/
2504  virtual const char* data() const = 0;
2505  /** The number of Latin-1 characters in the string.*/
2506  virtual size_t length() const = 0;
2507  protected:
2509  };
2510 
2511  /**
2512  * If the string is an external string, return the ExternalStringResourceBase
2513  * regardless of the encoding, otherwise return NULL. The encoding of the
2514  * string is returned in encoding_out.
2515  */
2517  Encoding* encoding_out) const;
2518 
2519  /**
2520  * Get the ExternalStringResource for an external string. Returns
2521  * NULL if IsExternal() doesn't return true.
2522  */
2524 
2525  /**
2526  * Get the ExternalOneByteStringResource for an external one-byte string.
2527  * Returns NULL if IsExternalOneByte() doesn't return true.
2528  */
2530 
2531  V8_INLINE static String* Cast(v8::Value* obj);
2532 
2533  // TODO(dcarney): remove with deprecation of New functions.
2535  kNormalString = static_cast<int>(v8::NewStringType::kNormal),
2537  };
2538 
2539  /** Allocates a new string from UTF-8 data.*/
2540  static V8_DEPRECATE_SOON(
2541  "Use maybe version",
2542  Local<String> NewFromUtf8(Isolate* isolate, const char* data,
2544  int length = -1));
2545 
2546  /** Allocates a new string from UTF-8 data. Only returns an empty value when
2547  * length > kMaxLength. **/
2548  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
2549  Isolate* isolate, const char* data, v8::NewStringType type,
2550  int length = -1);
2551 
2552  /** Allocates a new string from Latin-1 data.*/
2553  static V8_DEPRECATED(
2554  "Use maybe version",
2555  Local<String> NewFromOneByte(Isolate* isolate, const uint8_t* data,
2557  int length = -1));
2558 
2559  /** Allocates a new string from Latin-1 data. Only returns an empty value
2560  * when length > kMaxLength. **/
2561  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
2562  Isolate* isolate, const uint8_t* data, v8::NewStringType type,
2563  int length = -1);
2564 
2565  /** Allocates a new string from UTF-16 data.*/
2566  static V8_DEPRECATE_SOON(
2567  "Use maybe version",
2568  Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
2570  int length = -1));
2571 
2572  /** Allocates a new string from UTF-16 data. Only returns an empty value when
2573  * length > kMaxLength. **/
2574  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
2575  Isolate* isolate, const uint16_t* data, v8::NewStringType type,
2576  int length = -1);
2577 
2578  /**
2579  * Creates a new string by concatenating the left and the right strings
2580  * passed in as parameters.
2581  */
2582  static Local<String> Concat(Local<String> left, Local<String> right);
2583 
2584  /**
2585  * Creates a new external string using the data defined in the given
2586  * resource. When the external string is no longer live on V8's heap the
2587  * resource will be disposed by calling its Dispose method. The caller of
2588  * this function should not otherwise delete or modify the resource. Neither
2589  * should the underlying buffer be deallocated or modified except through the
2590  * destructor of the external string resource.
2591  */
2592  static V8_DEPRECATED("Use maybe version",
2593  Local<String> NewExternal(
2594  Isolate* isolate, ExternalStringResource* resource));
2595  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
2596  Isolate* isolate, ExternalStringResource* resource);
2597 
2598  /**
2599  * Associate an external string resource with this string by transforming it
2600  * in place so that existing references to this string in the JavaScript heap
2601  * will use the external string resource. The external string resource's
2602  * character contents need to be equivalent to this string.
2603  * Returns true if the string has been changed to be an external string.
2604  * The string is not modified if the operation fails. See NewExternal for
2605  * information on the lifetime of the resource.
2606  */
2607  bool MakeExternal(ExternalStringResource* resource);
2608 
2609  /**
2610  * Creates a new external string using the one-byte data defined in the given
2611  * resource. When the external string is no longer live on V8's heap the
2612  * resource will be disposed by calling its Dispose method. The caller of
2613  * this function should not otherwise delete or modify the resource. Neither
2614  * should the underlying buffer be deallocated or modified except through the
2615  * destructor of the external string resource.
2616  */
2617  static V8_DEPRECATE_SOON(
2618  "Use maybe version",
2619  Local<String> NewExternal(Isolate* isolate,
2620  ExternalOneByteStringResource* resource));
2621  static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
2622  Isolate* isolate, ExternalOneByteStringResource* resource);
2623 
2624  /**
2625  * Associate an external string resource with this string by transforming it
2626  * in place so that existing references to this string in the JavaScript heap
2627  * will use the external string resource. The external string resource's
2628  * character contents need to be equivalent to this string.
2629  * Returns true if the string has been changed to be an external string.
2630  * The string is not modified if the operation fails. See NewExternal for
2631  * information on the lifetime of the resource.
2632  */
2634 
2635  /**
2636  * Returns true if this string can be made external.
2637  */
2638  bool CanMakeExternal();
2639 
2640  /**
2641  * Converts an object to a UTF-8-encoded character array. Useful if
2642  * you want to print the object. If conversion to a string fails
2643  * (e.g. due to an exception in the toString() method of the object)
2644  * then the length() method returns 0 and the * operator returns
2645  * NULL.
2646  */
2648  public:
2649  explicit Utf8Value(Local<v8::Value> obj);
2650  ~Utf8Value();
2651  char* operator*() { return str_; }
2652  const char* operator*() const { return str_; }
2653  int length() const { return length_; }
2654 
2655  // Disallow copying and assigning.
2656  Utf8Value(const Utf8Value&) = delete;
2657  void operator=(const Utf8Value&) = delete;
2658 
2659  private:
2660  char* str_;
2661  int length_;
2662  };
2663 
2664  /**
2665  * Converts an object to a two-byte string.
2666  * If conversion to a string fails (eg. due to an exception in the toString()
2667  * method of the object) then the length() method returns 0 and the * operator
2668  * returns NULL.
2669  */
2671  public:
2672  explicit Value(Local<v8::Value> obj);
2673  ~Value();
2674  uint16_t* operator*() { return str_; }
2675  const uint16_t* operator*() const { return str_; }
2676  int length() const { return length_; }
2677 
2678  // Disallow copying and assigning.
2679  Value(const Value&) = delete;
2680  void operator=(const Value&) = delete;
2681 
2682  private:
2683  uint16_t* str_;
2684  int length_;
2685  };
2686 
2687  private:
2688  void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
2689  Encoding encoding) const;
2690  void VerifyExternalStringResource(ExternalStringResource* val) const;
2691  static void CheckCast(v8::Value* obj);
2692 };
2693 
2694 
2695 /**
2696  * A JavaScript symbol (ECMA-262 edition 6)
2697  */
2698 class V8_EXPORT Symbol : public Name {
2699  public:
2700  // Returns the print name string of the symbol, or undefined if none.
2701  Local<Value> Name() const;
2702 
2703  // Create a symbol. If name is not empty, it will be used as the description.
2704  static Local<Symbol> New(Isolate* isolate,
2705  Local<String> name = Local<String>());
2706 
2707  // Access global symbol registry.
2708  // Note that symbols created this way are never collected, so
2709  // they should only be used for statically fixed properties.
2710  // Also, there is only one global name space for the names used as keys.
2711  // To minimize the potential for clashes, use qualified names as keys.
2712  static Local<Symbol> For(Isolate *isolate, Local<String> name);
2713 
2714  // Retrieve a global symbol. Similar to |For|, but using a separate
2715  // registry that is not accessible by (and cannot clash with) JavaScript code.
2716  static Local<Symbol> ForApi(Isolate *isolate, Local<String> name);
2717 
2718  // Well-known symbols
2719  static Local<Symbol> GetIterator(Isolate* isolate);
2720  static Local<Symbol> GetUnscopables(Isolate* isolate);
2721  static Local<Symbol> GetToPrimitive(Isolate* isolate);
2722  static Local<Symbol> GetToStringTag(Isolate* isolate);
2723  static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
2724 
2725  V8_INLINE static Symbol* Cast(Value* obj);
2726 
2727  private:
2728  Symbol();
2729  static void CheckCast(Value* obj);
2730 };
2731 
2732 
2733 /**
2734  * A private symbol
2735  *
2736  * This is an experimental feature. Use at your own risk.
2737  */
2738 class V8_EXPORT Private : public Data {
2739  public:
2740  // Returns the print name string of the private symbol, or undefined if none.
2741  Local<Value> Name() const;
2742 
2743  // Create a private symbol. If name is not empty, it will be the description.
2744  static Local<Private> New(Isolate* isolate,
2745  Local<String> name = Local<String>());
2746 
2747  // Retrieve a global private symbol. If a symbol with this name has not
2748  // been retrieved in the same isolate before, it is created.
2749  // Note that private symbols created this way are never collected, so
2750  // they should only be used for statically fixed properties.
2751  // Also, there is only one global name space for the names used as keys.
2752  // To minimize the potential for clashes, use qualified names as keys,
2753  // e.g., "Class#property".
2754  static Local<Private> ForApi(Isolate* isolate, Local<String> name);
2755 
2756  private:
2757  Private();
2758 };
2759 
2760 
2761 /**
2762  * A JavaScript number value (ECMA-262, 4.3.20)
2763  */
2764 class V8_EXPORT Number : public Primitive {
2765  public:
2766  double Value() const;
2767  static Local<Number> New(Isolate* isolate, double value);
2768  V8_INLINE static Number* Cast(v8::Value* obj);
2769  private:
2770  Number();
2771  static void CheckCast(v8::Value* obj);
2772 };
2773 
2774 
2775 /**
2776  * A JavaScript value representing a signed integer.
2777  */
2778 class V8_EXPORT Integer : public Number {
2779  public:
2780  static Local<Integer> New(Isolate* isolate, int32_t value);
2781  static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
2782  int64_t Value() const;
2783  V8_INLINE static Integer* Cast(v8::Value* obj);
2784  private:
2785  Integer();
2786  static void CheckCast(v8::Value* obj);
2787 };
2788 
2789 
2790 /**
2791  * A JavaScript value representing a 32-bit signed integer.
2792  */
2793 class V8_EXPORT Int32 : public Integer {
2794  public:
2795  int32_t Value() const;
2796  V8_INLINE static Int32* Cast(v8::Value* obj);
2797 
2798  private:
2799  Int32();
2800  static void CheckCast(v8::Value* obj);
2801 };
2802 
2803 
2804 /**
2805  * A JavaScript value representing a 32-bit unsigned integer.
2806  */
2807 class V8_EXPORT Uint32 : public Integer {
2808  public:
2809  uint32_t Value() const;
2810  V8_INLINE static Uint32* Cast(v8::Value* obj);
2811 
2812  private:
2813  Uint32();
2814  static void CheckCast(v8::Value* obj);
2815 };
2816 
2817 /**
2818  * PropertyAttribute.
2819  */
2821  /** None. **/
2822  None = 0,
2823  /** ReadOnly, i.e., not writable. **/
2824  ReadOnly = 1 << 0,
2825  /** DontEnum, i.e., not enumerable. **/
2826  DontEnum = 1 << 1,
2827  /** DontDelete, i.e., not configurable. **/
2828  DontDelete = 1 << 2
2829 };
2830 
2831 /**
2832  * Accessor[Getter|Setter] are used as callback functions when
2833  * setting|getting a particular property. See Object and ObjectTemplate's
2834  * method SetAccessor.
2835  */
2836 typedef void (*AccessorGetterCallback)(
2837  Local<String> property,
2838  const PropertyCallbackInfo<Value>& info);
2840  Local<Name> property,
2841  const PropertyCallbackInfo<Value>& info);
2842 
2843 
2844 typedef void (*AccessorSetterCallback)(
2845  Local<String> property,
2846  Local<Value> value,
2847  const PropertyCallbackInfo<void>& info);
2849  Local<Name> property,
2850  Local<Value> value,
2851  const PropertyCallbackInfo<void>& info);
2852 
2853 
2854 /**
2855  * Access control specifications.
2856  *
2857  * Some accessors should be accessible across contexts. These
2858  * accessors have an explicit access control parameter which specifies
2859  * the kind of cross-context access that should be allowed.
2860  *
2861  * TODO(dcarney): Remove PROHIBITS_OVERWRITING as it is now unused.
2862  */
2864  DEFAULT = 0,
2866  ALL_CAN_WRITE = 1 << 1,
2868 };
2869 
2870 /**
2871  * Property filter bits. They can be or'ed to build a composite filter.
2872  */
2880 };
2881 
2882 /**
2883  * Keys/Properties filter enums:
2884  *
2885  * KeyCollectionMode limits the range of collected properties. kOwnOnly limits
2886  * the collected properties to the given Object only. kIncludesPrototypes will
2887  * include all keys of the objects's prototype chain as well.
2888  */
2890 
2891 /**
2892  * kIncludesIndices allows for integer indices to be collected, while
2893  * kSkipIndices will exclude integer indicies from being collected.
2894  */
2896 
2897 /**
2898  * Integrity level for objects.
2899  */
2901 
2902 /**
2903  * A JavaScript object (ECMA-262, 4.3.3)
2904  */
2905 class V8_EXPORT Object : public Value {
2906  public:
2907  V8_DEPRECATE_SOON("Use maybe version",
2908  bool Set(Local<Value> key, Local<Value> value));
2909  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context,
2910  Local<Value> key, Local<Value> value);
2911 
2912  V8_DEPRECATE_SOON("Use maybe version",
2913  bool Set(uint32_t index, Local<Value> value));
2914  V8_WARN_UNUSED_RESULT Maybe<bool> Set(Local<Context> context, uint32_t index,
2915  Local<Value> value);
2916 
2917  // Implements CreateDataProperty (ECMA-262, 7.3.4).
2918  //
2919  // Defines a configurable, writable, enumerable property with the given value
2920  // on the object unless the property already exists and is not configurable
2921  // or the object is not extensible.
2922  //
2923  // Returns true on success.
2924  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2925  Local<Name> key,
2926  Local<Value> value);
2927  V8_WARN_UNUSED_RESULT Maybe<bool> CreateDataProperty(Local<Context> context,
2928  uint32_t index,
2929  Local<Value> value);
2930 
2931  // Implements DefineOwnProperty.
2932  //
2933  // In general, CreateDataProperty will be faster, however, does not allow
2934  // for specifying attributes.
2935  //
2936  // Returns true on success.
2938  Local<Context> context, Local<Name> key, Local<Value> value,
2939  PropertyAttribute attributes = None);
2940 
2941  // Implements Object.DefineProperty(O, P, Attributes), see Ecma-262 19.1.2.4.
2942  //
2943  // The defineProperty function is used to add an own property or
2944  // update the attributes of an existing own property of an object.
2945  //
2946  // Both data and accessor descriptors can be used.
2947  //
2948  // In general, CreateDataProperty is faster, however, does not allow
2949  // for specifying attributes or an accessor descriptor.
2950  //
2951  // The PropertyDescriptor can change when redefining a property.
2952  //
2953  // Returns true on success.
2955  Local<Context> context, Local<Name> key, PropertyDescriptor& descriptor);
2956 
2957  // Sets an own property on this object bypassing interceptors and
2958  // overriding accessors or read-only properties.
2959  //
2960  // Note that if the object has an interceptor the property will be set
2961  // locally, but since the interceptor takes precedence the local property
2962  // will only be returned if the interceptor doesn't return a value.
2963  //
2964  // Note also that this only works for named properties.
2965  V8_DEPRECATED("Use CreateDataProperty / DefineOwnProperty",
2966  bool ForceSet(Local<Value> key, Local<Value> value,
2967  PropertyAttribute attribs = None));
2968  V8_DEPRECATE_SOON("Use CreateDataProperty / DefineOwnProperty",
2969  Maybe<bool> ForceSet(Local<Context> context,
2970  Local<Value> key, Local<Value> value,
2971  PropertyAttribute attribs = None));
2972 
2973  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(Local<Value> key));
2974  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2975  Local<Value> key);
2976 
2977  V8_DEPRECATE_SOON("Use maybe version", Local<Value> Get(uint32_t index));
2978  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
2979  uint32_t index);
2980 
2981  /**
2982  * Gets the property attributes of a property which can be None or
2983  * any combination of ReadOnly, DontEnum and DontDelete. Returns
2984  * None when the property doesn't exist.
2985  */
2986  V8_DEPRECATED("Use maybe version",
2987  PropertyAttribute GetPropertyAttributes(Local<Value> key));
2989  Local<Context> context, Local<Value> key);
2990 
2991  /**
2992  * Returns Object.getOwnPropertyDescriptor as per ES5 section 15.2.3.3.
2993  */
2994  V8_DEPRECATED("Use maybe version",
2995  Local<Value> GetOwnPropertyDescriptor(Local<String> key));
2997  Local<Context> context, Local<String> key);
2998 
2999  V8_DEPRECATE_SOON("Use maybe version", bool Has(Local<Value> key));
3000  /**
3001  * Object::Has() calls the abstract operation HasProperty(O, P) described
3002  * in ECMA-262, 7.3.10. Has() returns
3003  * true, if the object has the property, either own or on the prototype chain.
3004  * Interceptors, i.e., PropertyQueryCallbacks, are called if present.
3005  *
3006  * Has() has the same side effects as JavaScript's `variable in object`.
3007  * For example, calling Has() on a revoked proxy will throw an exception.
3008  *
3009  * \note Has() converts the key to a name, which possibly calls back into
3010  * JavaScript.
3011  *
3012  * See also v8::Object::HasOwnProperty() and
3013  * v8::Object::HasRealNamedProperty().
3014  */
3015  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3016  Local<Value> key);
3017 
3018  V8_DEPRECATE_SOON("Use maybe version", bool Delete(Local<Value> key));
3019  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3020  Maybe<bool> Delete(Local<Context> context, Local<Value> key);
3021 
3022  V8_DEPRECATED("Use maybe version", bool Has(uint32_t index));
3023  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context, uint32_t index);
3024 
3025  V8_DEPRECATED("Use maybe version", bool Delete(uint32_t index));
3026  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3027  Maybe<bool> Delete(Local<Context> context, uint32_t index);
3028 
3029  V8_DEPRECATED("Use maybe version",
3030  bool SetAccessor(Local<String> name,
3031  AccessorGetterCallback getter,
3032  AccessorSetterCallback setter = 0,
3033  Local<Value> data = Local<Value>(),
3034  AccessControl settings = DEFAULT,
3035  PropertyAttribute attribute = None));
3036  V8_DEPRECATED("Use maybe version",
3037  bool SetAccessor(Local<Name> name,
3039  AccessorNameSetterCallback setter = 0,
3040  Local<Value> data = Local<Value>(),
3041  AccessControl settings = DEFAULT,
3042  PropertyAttribute attribute = None));
3043  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3044  Maybe<bool> SetAccessor(Local<Context> context, Local<Name> name,
3046  AccessorNameSetterCallback setter = 0,
3047  MaybeLocal<Value> data = MaybeLocal<Value>(),
3048  AccessControl settings = DEFAULT,
3049  PropertyAttribute attribute = None);
3050 
3051  void SetAccessorProperty(Local<Name> name, Local<Function> getter,
3052  Local<Function> setter = Local<Function>(),
3053  PropertyAttribute attribute = None,
3054  AccessControl settings = DEFAULT);
3055 
3056  /**
3057  * Functionality for private properties.
3058  * This is an experimental feature, use at your own risk.
3059  * Note: Private properties are not inherited. Do not rely on this, since it
3060  * may change.
3061  */
3062  Maybe<bool> HasPrivate(Local<Context> context, Local<Private> key);
3063  Maybe<bool> SetPrivate(Local<Context> context, Local<Private> key,
3064  Local<Value> value);
3065  Maybe<bool> DeletePrivate(Local<Context> context, Local<Private> key);
3066  MaybeLocal<Value> GetPrivate(Local<Context> context, Local<Private> key);
3067 
3068  /**
3069  * Returns an array containing the names of the enumerable properties
3070  * of this object, including properties from prototype objects. The
3071  * array returned by this method contains the same values as would
3072  * be enumerated by a for-in statement over this object.
3073  */
3074  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
3076  Local<Context> context);
3078  Local<Context> context, KeyCollectionMode mode,
3079  PropertyFilter property_filter, IndexFilter index_filter);
3080 
3081  /**
3082  * This function has the same functionality as GetPropertyNames but
3083  * the returned array doesn't contain the names of properties from
3084  * prototype objects.
3085  */
3086  V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetOwnPropertyNames());
3088  Local<Context> context);
3089 
3090  /**
3091  * Returns an array containing the names of the filtered properties
3092  * of this object, including properties from prototype objects. The
3093  * array returned by this method contains the same values as would
3094  * be enumerated by a for-in statement over this object.
3095  */
3097  Local<Context> context, PropertyFilter filter);
3098 
3099  /**
3100  * Get the prototype object. This does not skip objects marked to
3101  * be skipped by __proto__ and it does not consult the security
3102  * handler.
3103  */
3104  Local<Value> GetPrototype();
3105 
3106  /**
3107  * Set the prototype object. This does not skip objects marked to
3108  * be skipped by __proto__ and it does not consult the security
3109  * handler.
3110  */
3111  V8_DEPRECATED("Use maybe version", bool SetPrototype(Local<Value> prototype));
3112  V8_WARN_UNUSED_RESULT Maybe<bool> SetPrototype(Local<Context> context,
3113  Local<Value> prototype);
3114 
3115  /**
3116  * Finds an instance of the given function template in the prototype
3117  * chain.
3118  */
3120 
3121  /**
3122  * Call builtin Object.prototype.toString on this object.
3123  * This is different from Value::ToString() that may call
3124  * user-defined toString function. This one does not.
3125  */
3126  V8_DEPRECATED("Use maybe version", Local<String> ObjectProtoToString());
3128  Local<Context> context);
3129 
3130  /**
3131  * Returns the name of the function invoked as a constructor for this object.
3132  */
3133  Local<String> GetConstructorName();
3134 
3135  /**
3136  * Sets the integrity level of the object.
3137  */
3138  Maybe<bool> SetIntegrityLevel(Local<Context> context, IntegrityLevel level);
3139 
3140  /** Gets the number of internal fields for this Object. */
3141  int InternalFieldCount();
3142 
3143  /** Same as above, but works for Persistents */
3145  const PersistentBase<Object>& object) {
3146  return object.val_->InternalFieldCount();
3147  }
3148 
3149  /** Gets the value from an internal field. */
3150  V8_INLINE Local<Value> GetInternalField(int index);
3151 
3152  /** Sets the value in an internal field. */
3153  void SetInternalField(int index, Local<Value> value);
3154 
3155  /**
3156  * Gets a 2-byte-aligned native pointer from an internal field. This field
3157  * must have been set by SetAlignedPointerInInternalField, everything else
3158  * leads to undefined behavior.
3159  */
3161 
3162  /** Same as above, but works for Persistents */
3164  const PersistentBase<Object>& object, int index) {
3165  return object.val_->GetAlignedPointerFromInternalField(index);
3166  }
3167 
3168  /**
3169  * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
3170  * a field, GetAlignedPointerFromInternalField must be used, everything else
3171  * leads to undefined behavior.
3172  */
3173  void SetAlignedPointerInInternalField(int index, void* value);
3174  void SetAlignedPointerInInternalFields(int argc, int indices[],
3175  void* values[]);
3176 
3177  // Testers for local properties.
3178  V8_DEPRECATED("Use maybe version", bool HasOwnProperty(Local<String> key));
3179 
3180  /**
3181  * HasOwnProperty() is like JavaScript's Object.prototype.hasOwnProperty().
3182  *
3183  * See also v8::Object::Has() and v8::Object::HasRealNamedProperty().
3184  */
3185  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3186  Local<Name> key);
3187  V8_WARN_UNUSED_RESULT Maybe<bool> HasOwnProperty(Local<Context> context,
3188  uint32_t index);
3189  V8_DEPRECATE_SOON("Use maybe version",
3190  bool HasRealNamedProperty(Local<String> key));
3191  /**
3192  * Use HasRealNamedProperty() if you want to check if an object has an own
3193  * property without causing side effects, i.e., without calling interceptors.
3194  *
3195  * This function is similar to v8::Object::HasOwnProperty(), but it does not
3196  * call interceptors.
3197  *
3198  * \note Consider using non-masking interceptors, i.e., the interceptors are
3199  * not called if the receiver has the real named property. See
3200  * `v8::PropertyHandlerFlags::kNonMasking`.
3201  *
3202  * See also v8::Object::Has().
3203  */
3204  V8_WARN_UNUSED_RESULT Maybe<bool> HasRealNamedProperty(Local<Context> context,
3205  Local<Name> key);
3206  V8_DEPRECATE_SOON("Use maybe version",
3207  bool HasRealIndexedProperty(uint32_t index));
3209  Local<Context> context, uint32_t index);
3210  V8_DEPRECATE_SOON("Use maybe version",
3211  bool HasRealNamedCallbackProperty(Local<String> key));
3213  Local<Context> context, Local<Name> key);
3214 
3215  /**
3216  * If result.IsEmpty() no real property was located in the prototype chain.
3217  * This means interceptors in the prototype chain are not called.
3218  */
3219  V8_DEPRECATED(
3220  "Use maybe version",
3221  Local<Value> GetRealNamedPropertyInPrototypeChain(Local<String> key));
3223  Local<Context> context, Local<Name> key);
3224 
3225  /**
3226  * Gets the property attributes of a real property in the prototype chain,
3227  * which can be None or any combination of ReadOnly, DontEnum and DontDelete.
3228  * Interceptors in the prototype chain are not called.
3229  */
3230  V8_DEPRECATED(
3231  "Use maybe version",
3232  Maybe<PropertyAttribute> GetRealNamedPropertyAttributesInPrototypeChain(
3233  Local<String> key));
3236  Local<Name> key);
3237 
3238  /**
3239  * If result.IsEmpty() no real property was located on the object or
3240  * in the prototype chain.
3241  * This means interceptors in the prototype chain are not called.
3242  */
3243  V8_DEPRECATED("Use maybe version",
3244  Local<Value> GetRealNamedProperty(Local<String> key));
3246  Local<Context> context, Local<Name> key);
3247 
3248  /**
3249  * Gets the property attributes of a real property which can be
3250  * None or any combination of ReadOnly, DontEnum and DontDelete.
3251  * Interceptors in the prototype chain are not called.
3252  */
3253  V8_DEPRECATED("Use maybe version",
3254  Maybe<PropertyAttribute> GetRealNamedPropertyAttributes(
3255  Local<String> key));
3257  Local<Context> context, Local<Name> key);
3258 
3259  /** Tests for a named lookup interceptor.*/
3261 
3262  /** Tests for an index lookup interceptor.*/
3264 
3265  /**
3266  * Returns the identity hash for this object. The current implementation
3267  * uses a hidden property on the object to store the identity hash.
3268  *
3269  * The return value will never be 0. Also, it is not guaranteed to be
3270  * unique.
3271  */
3272  int GetIdentityHash();
3273 
3274  /**
3275  * Clone this object with a fast but shallow copy. Values will point
3276  * to the same values as the original object.
3277  */
3278  // TODO(dcarney): take an isolate and optionally bail out?
3279  Local<Object> Clone();
3280 
3281  /**
3282  * Returns the context in which the object was created.
3283  */
3284  Local<Context> CreationContext();
3285 
3286  /** Same as above, but works for Persistents */
3288  const PersistentBase<Object>& object) {
3289  return object.val_->CreationContext();
3290  }
3291 
3292  /**
3293  * Checks whether a callback is set by the
3294  * ObjectTemplate::SetCallAsFunctionHandler method.
3295  * When an Object is callable this method returns true.
3296  */
3297  bool IsCallable();
3298 
3299  /**
3300  * True if this object is a constructor.
3301  */
3302  bool IsConstructor();
3303 
3304  /**
3305  * Call an Object as a function if a callback is set by the
3306  * ObjectTemplate::SetCallAsFunctionHandler method.
3307  */
3308  V8_DEPRECATED("Use maybe version",
3309  Local<Value> CallAsFunction(Local<Value> recv, int argc,
3310  Local<Value> argv[]));
3311  V8_WARN_UNUSED_RESULT MaybeLocal<Value> CallAsFunction(Local<Context> context,
3312  Local<Value> recv,
3313  int argc,
3314  Local<Value> argv[]);
3315 
3316  /**
3317  * Call an Object as a constructor if a callback is set by the
3318  * ObjectTemplate::SetCallAsFunctionHandler method.
3319  * Note: This method behaves like the Function::NewInstance method.
3320  */
3321  V8_DEPRECATED("Use maybe version",
3322  Local<Value> CallAsConstructor(int argc, Local<Value> argv[]));
3324  Local<Context> context, int argc, Local<Value> argv[]);
3325 
3326  /**
3327  * Return the isolate to which the Object belongs to.
3328  */
3329  V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
3330 
3331  static Local<Object> New(Isolate* isolate);
3332 
3333  V8_INLINE static Object* Cast(Value* obj);
3334 
3335  private:
3336  Object();
3337  static void CheckCast(Value* obj);
3338  Local<Value> SlowGetInternalField(int index);
3339  void* SlowGetAlignedPointerFromInternalField(int index);
3340 };
3341 
3342 
3343 /**
3344  * An instance of the built-in array constructor (ECMA-262, 15.4.2).
3345  */
3346 class V8_EXPORT Array : public Object {
3347  public:
3348  uint32_t Length() const;
3349 
3350  /**
3351  * Clones an element at index |index|. Returns an empty
3352  * handle if cloning fails (for any reason).
3353  */
3354  V8_DEPRECATED("Cloning is not supported.",
3355  Local<Object> CloneElementAt(uint32_t index));
3356  V8_DEPRECATED("Cloning is not supported.",
3357  MaybeLocal<Object> CloneElementAt(Local<Context> context,
3358  uint32_t index));
3359 
3360  /**
3361  * Creates a JavaScript array with the given length. If the length
3362  * is negative the returned array will have length 0.
3363  */
3364  static Local<Array> New(Isolate* isolate, int length = 0);
3365 
3366  V8_INLINE static Array* Cast(Value* obj);
3367  private:
3368  Array();
3369  static void CheckCast(Value* obj);
3370 };
3371 
3372 
3373 /**
3374  * An instance of the built-in Map constructor (ECMA-262, 6th Edition, 23.1.1).
3375  */
3376 class V8_EXPORT Map : public Object {
3377  public:
3378  size_t Size() const;
3379  void Clear();
3380  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Get(Local<Context> context,
3381  Local<Value> key);
3382  V8_WARN_UNUSED_RESULT MaybeLocal<Map> Set(Local<Context> context,
3383  Local<Value> key,
3384  Local<Value> value);
3385  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3386  Local<Value> key);
3387  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3388  Local<Value> key);
3389 
3390  /**
3391  * Returns an array of length Size() * 2, where index N is the Nth key and
3392  * index N + 1 is the Nth value.
3393  */
3394  Local<Array> AsArray() const;
3395 
3396  /**
3397  * Creates a new empty Map.
3398  */
3399  static Local<Map> New(Isolate* isolate);
3400 
3401  V8_INLINE static Map* Cast(Value* obj);
3402 
3403  private:
3404  Map();
3405  static void CheckCast(Value* obj);
3406 };
3407 
3408 
3409 /**
3410  * An instance of the built-in Set constructor (ECMA-262, 6th Edition, 23.2.1).
3411  */
3412 class V8_EXPORT Set : public Object {
3413  public:
3414  size_t Size() const;
3415  void Clear();
3416  V8_WARN_UNUSED_RESULT MaybeLocal<Set> Add(Local<Context> context,
3417  Local<Value> key);
3418  V8_WARN_UNUSED_RESULT Maybe<bool> Has(Local<Context> context,
3419  Local<Value> key);
3420  V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
3421  Local<Value> key);
3422 
3423  /**
3424  * Returns an array of the keys in this Set.
3425  */
3426  Local<Array> AsArray() const;
3427 
3428  /**
3429  * Creates a new empty Set.
3430  */
3431  static Local<Set> New(Isolate* isolate);
3432 
3433  V8_INLINE static Set* Cast(Value* obj);
3434 
3435  private:
3436  Set();
3437  static void CheckCast(Value* obj);
3438 };
3439 
3440 
3441 template<typename T>
3442 class ReturnValue {
3443  public:
3444  template <class S> V8_INLINE ReturnValue(const ReturnValue<S>& that)
3445  : value_(that.value_) {
3446  TYPE_CHECK(T, S);
3447  }
3448  // Local setters
3449  template <typename S>
3450  V8_INLINE V8_DEPRECATE_SOON("Use Global<> instead",
3451  void Set(const Persistent<S>& handle));
3452  template <typename S>
3453  V8_INLINE void Set(const Global<S>& handle);
3454  template <typename S>
3455  V8_INLINE void Set(const Local<S> handle);
3456  // Fast primitive setters
3457  V8_INLINE void Set(bool value);
3458  V8_INLINE void Set(double i);
3459  V8_INLINE void Set(int32_t i);
3460  V8_INLINE void Set(uint32_t i);
3461  // Fast JS primitive setters
3462  V8_INLINE void SetNull();
3463  V8_INLINE void SetUndefined();
3464  V8_INLINE void SetEmptyString();
3465  // Convenience getter for Isolate
3466  V8_INLINE Isolate* GetIsolate() const;
3467 
3468  // Pointer setter: Uncompilable to prevent inadvertent misuse.
3469  template <typename S>
3470  V8_INLINE void Set(S* whatever);
3471 
3472  // Getter. Creates a new Local<> so it comes with a certain performance
3473  // hit. If the ReturnValue was not yet set, this will return the undefined
3474  // value.
3475  V8_INLINE Local<Value> Get() const;
3476 
3477  private:
3478  template<class F> friend class ReturnValue;
3479  template<class F> friend class FunctionCallbackInfo;
3480  template<class F> friend class PropertyCallbackInfo;
3481  template <class F, class G, class H>
3483  V8_INLINE void SetInternal(internal::Object* value) { *value_ = value; }
3484  V8_INLINE internal::Object* GetDefaultValue();
3485  V8_INLINE explicit ReturnValue(internal::Object** slot);
3486  internal::Object** value_;
3487 };
3488 
3489 
3490 /**
3491  * The argument information given to function call callbacks. This
3492  * class provides access to information about the context of the call,
3493  * including the receiver, the number and values of arguments, and
3494  * the holder of the function.
3495  */
3496 template<typename T>
3497 class FunctionCallbackInfo {
3498  public:
3499  V8_INLINE int Length() const;
3500  V8_INLINE Local<Value> operator[](int i) const;
3501  V8_INLINE V8_DEPRECATED("Use Data() to explicitly pass Callee instead",
3502  Local<Function> Callee() const);
3503  V8_INLINE Local<Object> This() const;
3504  V8_INLINE Local<Object> Holder() const;
3505  V8_INLINE Local<Value> NewTarget() const;
3506  V8_INLINE bool IsConstructCall() const;
3507  V8_INLINE Local<Value> Data() const;
3508  V8_INLINE Isolate* GetIsolate() const;
3509  V8_INLINE ReturnValue<T> GetReturnValue() const;
3510  // This shouldn't be public, but the arm compiler needs it.
3511  static const int kArgsLength = 8;
3512 
3513  protected:
3516  static const int kHolderIndex = 0;
3517  static const int kIsolateIndex = 1;
3518  static const int kReturnValueDefaultValueIndex = 2;
3519  static const int kReturnValueIndex = 3;
3520  static const int kDataIndex = 4;
3521  static const int kCalleeIndex = 5;
3522  static const int kContextSaveIndex = 6;
3523  static const int kNewTargetIndex = 7;
3524 
3525  V8_INLINE FunctionCallbackInfo(internal::Object** implicit_args,
3526  internal::Object** values, int length);
3528  internal::Object** values_;
3529  int length_;
3530 };
3531 
3532 
3533 /**
3534  * The information passed to a property callback about the context
3535  * of the property access.
3536  */
3537 template<typename T>
3538 class PropertyCallbackInfo {
3539  public:
3540  /**
3541  * \return The isolate of the property access.
3542  */
3543  V8_INLINE Isolate* GetIsolate() const;
3544 
3545  /**
3546  * \return The data set in the configuration, i.e., in
3547  * `NamedPropertyHandlerConfiguration` or
3548  * `IndexedPropertyHandlerConfiguration.`
3549  */
3550  V8_INLINE Local<Value> Data() const;
3551 
3552  /**
3553  * \return The receiver. In many cases, this is the object on which the
3554  * property access was intercepted. When using
3555  * `Reflect.get`, `Function.prototype.call`, or similar functions, it is the
3556  * object passed in as receiver or thisArg.
3557  *
3558  * \code
3559  * void GetterCallback(Local<Name> name,
3560  * const v8::PropertyCallbackInfo<v8::Value>& info) {
3561  * auto context = info.GetIsolate()->GetCurrentContext();
3562  *
3563  * v8::Local<v8::Value> a_this =
3564  * info.This()
3565  * ->GetRealNamedProperty(context, v8_str("a"))
3566  * .ToLocalChecked();
3567  * v8::Local<v8::Value> a_holder =
3568  * info.Holder()
3569  * ->GetRealNamedProperty(context, v8_str("a"))
3570  * .ToLocalChecked();
3571  *
3572  * CHECK(v8_str("r")->Equals(context, a_this).FromJust());
3573  * CHECK(v8_str("obj")->Equals(context, a_holder).FromJust());
3574  *
3575  * info.GetReturnValue().Set(name);
3576  * }
3577  *
3578  * v8::Local<v8::FunctionTemplate> templ =
3579  * v8::FunctionTemplate::New(isolate);
3580  * templ->InstanceTemplate()->SetHandler(
3581  * v8::NamedPropertyHandlerConfiguration(GetterCallback));
3582  * LocalContext env;
3583  * env->Global()
3584  * ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
3585  * .ToLocalChecked()
3586  * ->NewInstance(env.local())
3587  * .ToLocalChecked())
3588  * .FromJust();
3589  *
3590  * CompileRun("obj.a = 'obj'; var r = {a: 'r'}; Reflect.get(obj, 'x', r)");
3591  * \endcode
3592  */
3593  V8_INLINE Local<Object> This() const;
3594 
3595  /**
3596  * \return The object in the prototype chain of the receiver that has the
3597  * interceptor. Suppose you have `x` and its prototype is `y`, and `y`
3598  * has an interceptor. Then `info.This()` is `x` and `info.Holder()` is `y`.
3599  * The Holder() could be a hidden object (the global object, rather
3600  * than the global proxy).
3601  *
3602  * \note For security reasons, do not pass the object back into the runtime.
3603  */
3604  V8_INLINE Local<Object> Holder() const;
3605 
3606  /**
3607  * \return The return value of the callback.
3608  * Can be changed by calling Set().
3609  * \code
3610  * info.GetReturnValue().Set(...)
3611  * \endcode
3612  *
3613  */
3614  V8_INLINE ReturnValue<T> GetReturnValue() const;
3615 
3616  /**
3617  * \return True if the intercepted function should throw if an error occurs.
3618  * Usually, `true` corresponds to `'use strict'`.
3619  *
3620  * \note Always `false` when intercepting `Reflect.set()`
3621  * independent of the language mode.
3622  */
3623  V8_INLINE bool ShouldThrowOnError() const;
3624 
3625  // This shouldn't be public, but the arm compiler needs it.
3626  static const int kArgsLength = 7;
3627 
3628  protected:
3629  friend class MacroAssembler;
3632  static const int kShouldThrowOnErrorIndex = 0;
3633  static const int kHolderIndex = 1;
3634  static const int kIsolateIndex = 2;
3635  static const int kReturnValueDefaultValueIndex = 3;
3636  static const int kReturnValueIndex = 4;
3637  static const int kDataIndex = 5;
3638  static const int kThisIndex = 6;
3639 
3640  V8_INLINE PropertyCallbackInfo(internal::Object** args) : args_(args) {}
3641  internal::Object** args_;
3642 };
3643 
3644 
3645 typedef void (*FunctionCallback)(const FunctionCallbackInfo<Value>& info);
3646 
3648 
3649 /**
3650  * A JavaScript function object (ECMA-262, 15.3).
3651  */
3652 class V8_EXPORT Function : public Object {
3653  public:
3654  /**
3655  * Create a function in the current execution context
3656  * for a given FunctionCallback.
3657  */
3658  static MaybeLocal<Function> New(
3659  Local<Context> context, FunctionCallback callback,
3660  Local<Value> data = Local<Value>(), int length = 0,
3662  static V8_DEPRECATE_SOON(
3663  "Use maybe version",
3664  Local<Function> New(Isolate* isolate, FunctionCallback callback,
3665  Local<Value> data = Local<Value>(), int length = 0));
3666 
3667  V8_DEPRECATED("Use maybe version",
3668  Local<Object> NewInstance(int argc, Local<Value> argv[]) const);
3670  Local<Context> context, int argc, Local<Value> argv[]) const;
3671 
3672  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
3674  Local<Context> context) const {
3675  return NewInstance(context, 0, nullptr);
3676  }
3677 
3678  V8_DEPRECATE_SOON("Use maybe version",
3679  Local<Value> Call(Local<Value> recv, int argc,
3680  Local<Value> argv[]));
3681  V8_WARN_UNUSED_RESULT MaybeLocal<Value> Call(Local<Context> context,
3682  Local<Value> recv, int argc,
3683  Local<Value> argv[]);
3684 
3685  void SetName(Local<String> name);
3686  Local<Value> GetName() const;
3687 
3688  /**
3689  * Name inferred from variable or property assignment of this function.
3690  * Used to facilitate debugging and profiling of JavaScript code written
3691  * in an OO style, where many functions are anonymous but are assigned
3692  * to object properties.
3693  */
3694  Local<Value> GetInferredName() const;
3695 
3696  /**
3697  * displayName if it is set, otherwise name if it is configured, otherwise
3698  * function name, otherwise inferred name.
3699  */
3700  Local<Value> GetDebugName() const;
3701 
3702  /**
3703  * User-defined name assigned to the "displayName" property of this function.
3704  * Used to facilitate debugging and profiling of JavaScript code.
3705  */
3706  Local<Value> GetDisplayName() const;
3707 
3708  /**
3709  * Returns zero based line number of function body and
3710  * kLineOffsetNotFound if no information available.
3711  */
3712  int GetScriptLineNumber() const;
3713  /**
3714  * Returns zero based column number of function body and
3715  * kLineOffsetNotFound if no information available.
3716  */
3717  int GetScriptColumnNumber() const;
3718 
3719  /**
3720  * Tells whether this function is builtin.
3721  */
3722  V8_DEPRECATED("this should no longer be used.", bool IsBuiltin() const);
3723 
3724  /**
3725  * Returns scriptId.
3726  */
3727  int ScriptId() const;
3728 
3729  /**
3730  * Returns the original function if this function is bound, else returns
3731  * v8::Undefined.
3732  */
3733  Local<Value> GetBoundFunction() const;
3734 
3735  ScriptOrigin GetScriptOrigin() const;
3736  V8_INLINE static Function* Cast(Value* obj);
3737  static const int kLineOffsetNotFound;
3738 
3739  private:
3740  Function();
3741  static void CheckCast(Value* obj);
3742 };
3743 
3744 
3745 /**
3746  * An instance of the built-in Promise constructor (ES6 draft).
3747  */
3748 class V8_EXPORT Promise : public Object {
3749  public:
3750  /**
3751  * State of the promise. Each value corresponds to one of the possible values
3752  * of the [[PromiseState]] field.
3753  */
3755 
3756  class V8_EXPORT Resolver : public Object {
3757  public:
3758  /**
3759  * Create a new resolver, along with an associated promise in pending state.
3760  */
3761  static V8_DEPRECATE_SOON("Use maybe version",
3762  Local<Resolver> New(Isolate* isolate));
3763  static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
3764  Local<Context> context);
3765 
3766  /**
3767  * Extract the associated promise.
3768  */
3769  Local<Promise> GetPromise();
3770 
3771  /**
3772  * Resolve/reject the associated promise with a given value.
3773  * Ignored if the promise is no longer pending.
3774  */
3775  V8_DEPRECATE_SOON("Use maybe version", void Resolve(Local<Value> value));
3776  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3777  Maybe<bool> Resolve(Local<Context> context, Local<Value> value);
3778 
3779  V8_DEPRECATE_SOON("Use maybe version", void Reject(Local<Value> value));
3780  // TODO(dcarney): mark V8_WARN_UNUSED_RESULT
3781  Maybe<bool> Reject(Local<Context> context, Local<Value> value);
3782 
3783  V8_INLINE static Resolver* Cast(Value* obj);
3784 
3785  private:
3786  Resolver();
3787  static void CheckCast(Value* obj);
3788  };
3789 
3790  /**
3791  * Register a resolution/rejection handler with a promise.
3792  * The handler is given the respective resolution/rejection value as
3793  * an argument. If the promise is already resolved/rejected, the handler is
3794  * invoked at the end of turn.
3795  */
3796  V8_DEPRECATED("Use maybe version",
3797  Local<Promise> Catch(Local<Function> handler));
3798  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Catch(Local<Context> context,
3799  Local<Function> handler);
3800 
3801  V8_DEPRECATED("Use maybe version",
3802  Local<Promise> Then(Local<Function> handler));
3803  V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Then(Local<Context> context,
3804  Local<Function> handler);
3805 
3806  /**
3807  * Returns true if the promise has at least one derived promise, and
3808  * therefore resolve/reject handlers (including default handler).
3809  */
3810  bool HasHandler();
3811 
3812  /**
3813  * Returns the content of the [[PromiseResult]] field. The Promise must not
3814  * be pending.
3815  */
3816  Local<Value> Result();
3817 
3818  /**
3819  * Returns the value of the [[PromiseState]] field.
3820  */
3821  PromiseState State();
3822 
3823  V8_INLINE static Promise* Cast(Value* obj);
3824 
3825  private:
3826  Promise();
3827  static void CheckCast(Value* obj);
3828 };
3829 
3830 /**
3831  * An instance of a Property Descriptor, see Ecma-262 6.2.4.
3832  *
3833  * Properties in a descriptor are present or absent. If you do not set
3834  * `enumerable`, `configurable`, and `writable`, they are absent. If `value`,
3835  * `get`, or `set` are absent, but you must specify them in the constructor, use
3836  * empty handles.
3837  *
3838  * Accessors `get` and `set` must be callable or undefined if they are present.
3839  *
3840  * \note Only query properties if they are present, i.e., call `x()` only if
3841  * `has_x()` returns true.
3842  *
3843  * \code
3844  * // var desc = {writable: false}
3845  * v8::PropertyDescriptor d(Local<Value>()), false);
3846  * d.value(); // error, value not set
3847  * if (d.has_writable()) {
3848  * d.writable(); // false
3849  * }
3850  *
3851  * // var desc = {value: undefined}
3852  * v8::PropertyDescriptor d(v8::Undefined(isolate));
3853  *
3854  * // var desc = {get: undefined}
3855  * v8::PropertyDescriptor d(v8::Undefined(isolate), Local<Value>()));
3856  * \endcode
3857  */
3859  public:
3860  // GenericDescriptor
3862 
3863  // DataDescriptor
3864  PropertyDescriptor(Local<Value> value);
3865 
3866  // DataDescriptor with writable property
3867  PropertyDescriptor(Local<Value> value, bool writable);
3868 
3869  // AccessorDescriptor
3870  PropertyDescriptor(Local<Value> get, Local<Value> set);
3871 
3872  ~PropertyDescriptor();
3873 
3874  Local<Value> value() const;
3875  bool has_value() const;
3876 
3877  Local<Value> get() const;
3878  bool has_get() const;
3879  Local<Value> set() const;
3880  bool has_set() const;
3881 
3882  void set_enumerable(bool enumerable);
3883  bool enumerable() const;
3884  bool has_enumerable() const;
3885 
3886  void set_configurable(bool configurable);
3887  bool configurable() const;
3888  bool has_configurable() const;
3889 
3890  bool writable() const;
3891  bool has_writable() const;
3892 
3893  struct PrivateData;
3894  PrivateData* get_private() const { return private_; }
3895 
3896  PropertyDescriptor(const PropertyDescriptor&) = delete;
3897  void operator=(const PropertyDescriptor&) = delete;
3898 
3899  private:
3900  PrivateData* private_;
3901 };
3902 
3903 /**
3904  * An instance of the built-in Proxy constructor (ECMA-262, 6th Edition,
3905  * 26.2.1).
3906  */
3907 class V8_EXPORT Proxy : public Object {
3908  public:
3909  Local<Object> GetTarget();
3910  Local<Value> GetHandler();
3911  bool IsRevoked();
3912  void Revoke();
3913 
3914  /**
3915  * Creates a new Proxy for the target object.
3916  */
3917  static MaybeLocal<Proxy> New(Local<Context> context,
3918  Local<Object> local_target,
3919  Local<Object> local_handler);
3920 
3921  V8_INLINE static Proxy* Cast(Value* obj);
3922 
3923  private:
3924  Proxy();
3925  static void CheckCast(Value* obj);
3926 };
3927 
3929  public:
3931  // A buffer that is owned by the caller.
3933  // Get the wasm-encoded bytes that were used to compile this module.
3934  Local<String> GetWasmWireBytes();
3935 
3936  // Serialize the compiled module. The serialized data does not include the
3937  // uncompiled bytes.
3939 
3940  // If possible, deserialize the module, otherwise compile it from the provided
3941  // uncompiled bytes.
3942  static MaybeLocal<WasmCompiledModule> DeserializeOrCompile(
3943  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
3944  const CallerOwnedBuffer& wire_bytes);
3945  V8_INLINE static WasmCompiledModule* Cast(Value* obj);
3946 
3947  private:
3948  static MaybeLocal<WasmCompiledModule> Deserialize(
3949  Isolate* isolate, const CallerOwnedBuffer& serialized_module,
3950  const CallerOwnedBuffer& wire_bytes);
3951  static MaybeLocal<WasmCompiledModule> Compile(Isolate* isolate,
3952  const uint8_t* start,
3953  size_t length);
3954  WasmCompiledModule();
3955  static void CheckCast(Value* obj);
3956 };
3957 
3958 #ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT
3959 // The number of required internal fields can be defined by embedder.
3960 #define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2
3961 #endif
3962 
3963 
3965 
3966 
3967 /**
3968  * An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5).
3969  */
3970 class V8_EXPORT ArrayBuffer : public Object {
3971  public:
3972  /**
3973  * A thread-safe allocator that V8 uses to allocate |ArrayBuffer|'s memory.
3974  * The allocator is a global V8 setting. It has to be set via
3975  * Isolate::CreateParams.
3976  *
3977  * Memory allocated through this allocator by V8 is accounted for as external
3978  * memory by V8. Note that V8 keeps track of the memory for all internalized
3979  * |ArrayBuffer|s. Responsibility for tracking external memory (using
3980  * Isolate::AdjustAmountOfExternalAllocatedMemory) is handed over to the
3981  * embedder upon externalization and taken over upon internalization (creating
3982  * an internalized buffer from an existing buffer).
3983  *
3984  * Note that it is unsafe to call back into V8 from any of the allocator
3985  * functions.
3986  */
3987  class V8_EXPORT Allocator { // NOLINT
3988  public:
3989  virtual ~Allocator() {}
3990 
3991  /**
3992  * Allocate |length| bytes. Return NULL if allocation is not successful.
3993  * Memory should be initialized to zeroes.
3994  */
3995  virtual void* Allocate(size_t length) = 0;
3996 
3997  /**
3998  * Allocate |length| bytes. Return NULL if allocation is not successful.
3999  * Memory does not have to be initialized.
4000  */
4001  virtual void* AllocateUninitialized(size_t length) = 0;
4002 
4003  /**
4004  * Free the memory block of size |length|, pointed to by |data|.
4005  * That memory is guaranteed to be previously allocated by |Allocate|.
4006  */
4007  virtual void Free(void* data, size_t length) = 0;
4008 
4009  /**
4010  * malloc/free based convenience allocator.
4011  *
4012  * Caller takes ownership.
4013  */
4014  static Allocator* NewDefaultAllocator();
4015  };
4016 
4017  /**
4018  * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer|
4019  * returns an instance of this class, populated, with a pointer to data
4020  * and byte length.
4021  *
4022  * The Data pointer of ArrayBuffer::Contents is always allocated with
4023  * Allocator::Allocate that is set via Isolate::CreateParams.
4024  */
4025  class V8_EXPORT Contents { // NOLINT
4026  public:
4027  Contents() : data_(NULL), byte_length_(0) {}
4028 
4029  void* Data() const { return data_; }
4030  size_t ByteLength() const { return byte_length_; }
4031 
4032  private:
4033  void* data_;
4034  size_t byte_length_;
4035 
4036  friend class ArrayBuffer;
4037  };
4038 
4039 
4040  /**
4041  * Data length in bytes.
4042  */
4043  size_t ByteLength() const;
4044 
4045  /**
4046  * Create a new ArrayBuffer. Allocate |byte_length| bytes.
4047  * Allocated memory will be owned by a created ArrayBuffer and
4048  * will be deallocated when it is garbage-collected,
4049  * unless the object is externalized.
4050  */
4051  static Local<ArrayBuffer> New(Isolate* isolate, size_t byte_length);
4052 
4053  /**
4054  * Create a new ArrayBuffer over an existing memory block.
4055  * The created array buffer is by default immediately in externalized state.
4056  * The memory block will not be reclaimed when a created ArrayBuffer
4057  * is garbage-collected.
4058  */
4059  static Local<ArrayBuffer> New(
4060  Isolate* isolate, void* data, size_t byte_length,
4062 
4063  /**
4064  * Returns true if ArrayBuffer is externalized, that is, does not
4065  * own its memory block.
4066  */
4067  bool IsExternal() const;
4068 
4069  /**
4070  * Returns true if this ArrayBuffer may be neutered.
4071  */
4072  bool IsNeuterable() const;
4073 
4074  /**
4075  * Neuters this ArrayBuffer and all its views (typed arrays).
4076  * Neutering sets the byte length of the buffer and all typed arrays to zero,
4077  * preventing JavaScript from ever accessing underlying backing store.
4078  * ArrayBuffer should have been externalized and must be neuterable.
4079  */
4080  void Neuter();
4081 
4082  /**
4083  * Make this ArrayBuffer external. The pointer to underlying memory block
4084  * and byte length are returned as |Contents| structure. After ArrayBuffer
4085  * had been externalized, it does no longer own the memory block. The caller
4086  * should take steps to free memory when it is no longer needed.
4087  *
4088  * The memory block is guaranteed to be allocated with |Allocator::Allocate|
4089  * that has been set via Isolate::CreateParams.
4090  */
4092 
4093  /**
4094  * Get a pointer to the ArrayBuffer's underlying memory block without
4095  * externalizing it. If the ArrayBuffer is not externalized, this pointer
4096  * will become invalid as soon as the ArrayBuffer gets garbage collected.
4097  *
4098  * The embedder should make sure to hold a strong reference to the
4099  * ArrayBuffer while accessing this pointer.
4100  *
4101  * The memory block is guaranteed to be allocated with |Allocator::Allocate|.
4102  */
4104 
4105  V8_INLINE static ArrayBuffer* Cast(Value* obj);
4106 
4108 
4109  private:
4110  ArrayBuffer();
4111  static void CheckCast(Value* obj);
4112 };
4113 
4114 
4115 #ifndef V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT
4116 // The number of required internal fields can be defined by embedder.
4117 #define V8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT 2
4118 #endif
4119 
4120 
4121 /**
4122  * A base class for an instance of one of "views" over ArrayBuffer,
4123  * including TypedArrays and DataView (ES6 draft 15.13).
4124  */
4126  public:
4127  /**
4128  * Returns underlying ArrayBuffer.
4129  */
4130  Local<ArrayBuffer> Buffer();
4131  /**
4132  * Byte offset in |Buffer|.
4133  */
4134  size_t ByteOffset();
4135  /**
4136  * Size of a view in bytes.
4137  */
4138  size_t ByteLength();
4139 
4140  /**
4141  * Copy the contents of the ArrayBufferView's buffer to an embedder defined
4142  * memory without additional overhead that calling ArrayBufferView::Buffer
4143  * might incur.
4144  *
4145  * Will write at most min(|byte_length|, ByteLength) bytes starting at
4146  * ByteOffset of the underlying buffer to the memory starting at |dest|.
4147  * Returns the number of bytes actually written.
4148  */
4150 
4151  /**
4152  * Returns true if ArrayBufferView's backing ArrayBuffer has already been
4153  * allocated.
4154  */
4155  bool HasBuffer() const;
4156 
4157  V8_INLINE static ArrayBufferView* Cast(Value* obj);
4158 
4159  static const int kInternalFieldCount =
4161 
4162  private:
4163  ArrayBufferView();
4164  static void CheckCast(Value* obj);
4165 };
4166 
4167 
4168 /**
4169  * A base class for an instance of TypedArray series of constructors
4170  * (ES6 draft 15.13.6).
4171  */
4173  public:
4174  /**
4175  * Number of elements in this typed array
4176  * (e.g. for Int16Array, |ByteLength|/2).
4177  */
4178  size_t Length();
4179 
4180  V8_INLINE static TypedArray* Cast(Value* obj);
4181 
4182  private:
4183  TypedArray();
4184  static void CheckCast(Value* obj);
4185 };
4186 
4187 
4188 /**
4189  * An instance of Uint8Array constructor (ES6 draft 15.13.6).
4190  */
4192  public:
4193  static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
4194  size_t byte_offset, size_t length);
4195  static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4196  size_t byte_offset, size_t length);
4197  V8_INLINE static Uint8Array* Cast(Value* obj);
4198 
4199  private:
4200  Uint8Array();
4201  static void CheckCast(Value* obj);
4202 };
4203 
4204 
4205 /**
4206  * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
4207  */
4209  public:
4210  static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
4211  size_t byte_offset, size_t length);
4212  static Local<Uint8ClampedArray> New(
4213  Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
4214  size_t length);
4215  V8_INLINE static Uint8ClampedArray* Cast(Value* obj);
4216 
4217  private:
4218  Uint8ClampedArray();
4219  static void CheckCast(Value* obj);
4220 };
4221 
4222 /**
4223  * An instance of Int8Array constructor (ES6 draft 15.13.6).
4224  */
4226  public:
4227  static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
4228  size_t byte_offset, size_t length);
4229  static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4230  size_t byte_offset, size_t length);
4231  V8_INLINE static Int8Array* Cast(Value* obj);
4232 
4233  private:
4234  Int8Array();
4235  static void CheckCast(Value* obj);
4236 };
4237 
4238 
4239 /**
4240  * An instance of Uint16Array constructor (ES6 draft 15.13.6).
4241  */
4243  public:
4244  static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
4245  size_t byte_offset, size_t length);
4246  static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4247  size_t byte_offset, size_t length);
4248  V8_INLINE static Uint16Array* Cast(Value* obj);
4249 
4250  private:
4251  Uint16Array();
4252  static void CheckCast(Value* obj);
4253 };
4254 
4255 
4256 /**
4257  * An instance of Int16Array constructor (ES6 draft 15.13.6).
4258  */
4260  public:
4261  static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
4262  size_t byte_offset, size_t length);
4263  static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4264  size_t byte_offset, size_t length);
4265  V8_INLINE static Int16Array* Cast(Value* obj);
4266 
4267  private:
4268  Int16Array();
4269  static void CheckCast(Value* obj);
4270 };
4271 
4272 
4273 /**
4274  * An instance of Uint32Array constructor (ES6 draft 15.13.6).
4275  */
4277  public:
4278  static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
4279  size_t byte_offset, size_t length);
4280  static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4281  size_t byte_offset, size_t length);
4282  V8_INLINE static Uint32Array* Cast(Value* obj);
4283 
4284  private:
4285  Uint32Array();
4286  static void CheckCast(Value* obj);
4287 };
4288 
4289 
4290 /**
4291  * An instance of Int32Array constructor (ES6 draft 15.13.6).
4292  */
4294  public:
4295  static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
4296  size_t byte_offset, size_t length);
4297  static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4298  size_t byte_offset, size_t length);
4299  V8_INLINE static Int32Array* Cast(Value* obj);
4300 
4301  private:
4302  Int32Array();
4303  static void CheckCast(Value* obj);
4304 };
4305 
4306 
4307 /**
4308  * An instance of Float32Array constructor (ES6 draft 15.13.6).
4309  */
4311  public:
4312  static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
4313  size_t byte_offset, size_t length);
4314  static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4315  size_t byte_offset, size_t length);
4316  V8_INLINE static Float32Array* Cast(Value* obj);
4317 
4318  private:
4319  Float32Array();
4320  static void CheckCast(Value* obj);
4321 };
4322 
4323 
4324 /**
4325  * An instance of Float64Array constructor (ES6 draft 15.13.6).
4326  */
4328  public:
4329  static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
4330  size_t byte_offset, size_t length);
4331  static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
4332  size_t byte_offset, size_t length);
4333  V8_INLINE static Float64Array* Cast(Value* obj);
4334 
4335  private:
4336  Float64Array();
4337  static void CheckCast(Value* obj);
4338 };
4339 
4340 
4341 /**
4342  * An instance of DataView constructor (ES6 draft 15.13.7).
4343  */
4345  public:
4346  static Local<DataView> New(Local<ArrayBuffer> array_buffer,
4347  size_t byte_offset, size_t length);
4348  static Local<DataView> New(Local<SharedArrayBuffer> shared_array_buffer,
4349  size_t byte_offset, size_t length);
4350  V8_INLINE static DataView* Cast(Value* obj);
4351 
4352  private:
4353  DataView();
4354  static void CheckCast(Value* obj);
4355 };
4356 
4357 
4358 /**
4359  * An instance of the built-in SharedArrayBuffer constructor.
4360  * This API is experimental and may change significantly.
4361  */
4363  public:
4364  /**
4365  * The contents of an |SharedArrayBuffer|. Externalization of
4366  * |SharedArrayBuffer| returns an instance of this class, populated, with a
4367  * pointer to data and byte length.
4368  *
4369  * The Data pointer of SharedArrayBuffer::Contents is always allocated with
4370  * |ArrayBuffer::Allocator::Allocate| by the allocator specified in
4371  * v8::Isolate::CreateParams::array_buffer_allocator.
4372  *
4373  * This API is experimental and may change significantly.
4374  */
4375  class V8_EXPORT Contents { // NOLINT
4376  public:
4377  Contents() : data_(NULL), byte_length_(0) {}
4378 
4379  void* Data() const { return data_; }
4380  size_t ByteLength() const { return byte_length_; }
4381 
4382  private:
4383  void* data_;
4384  size_t byte_length_;
4385 
4386  friend class SharedArrayBuffer;
4387  };
4388 
4389 
4390  /**
4391  * Data length in bytes.
4392  */
4393  size_t ByteLength() const;
4394 
4395  /**
4396  * Create a new SharedArrayBuffer. Allocate |byte_length| bytes.
4397  * Allocated memory will be owned by a created SharedArrayBuffer and
4398  * will be deallocated when it is garbage-collected,
4399  * unless the object is externalized.
4400  */
4401  static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length);
4402 
4403  /**
4404  * Create a new SharedArrayBuffer over an existing memory block. The created
4405  * array buffer is immediately in externalized state unless otherwise
4406  * specified. The memory block will not be reclaimed when a created
4407  * SharedArrayBuffer is garbage-collected.
4408  */
4409  static Local<SharedArrayBuffer> New(
4410  Isolate* isolate, void* data, size_t byte_length,
4412 
4413  /**
4414  * Returns true if SharedArrayBuffer is externalized, that is, does not
4415  * own its memory block.
4416  */
4417  bool IsExternal() const;
4418 
4419  /**
4420  * Make this SharedArrayBuffer external. The pointer to underlying memory
4421  * block and byte length are returned as |Contents| structure. After
4422  * SharedArrayBuffer had been externalized, it does no longer own the memory
4423  * block. The caller should take steps to free memory when it is no longer
4424  * needed.
4425  *
4426  * The memory block is guaranteed to be allocated with |Allocator::Allocate|
4427  * by the allocator specified in
4428  * v8::Isolate::CreateParams::array_buffer_allocator.
4429  *
4430  */
4432 
4433  /**
4434  * Get a pointer to the ArrayBuffer's underlying memory block without
4435  * externalizing it. If the ArrayBuffer is not externalized, this pointer
4436  * will become invalid as soon as the ArrayBuffer became garbage collected.
4437  *
4438  * The embedder should make sure to hold a strong reference to the
4439  * ArrayBuffer while accessing this pointer.
4440  *
4441  * The memory block is guaranteed to be allocated with |Allocator::Allocate|
4442  * by the allocator specified in
4443  * v8::Isolate::CreateParams::array_buffer_allocator.
4444  */
4446 
4447  V8_INLINE static SharedArrayBuffer* Cast(Value* obj);
4448 
4450 
4451  private:
4452  SharedArrayBuffer();
4453  static void CheckCast(Value* obj);
4454 };
4455 
4456 
4457 /**
4458  * An instance of the built-in Date constructor (ECMA-262, 15.9).
4459  */
4460 class V8_EXPORT Date : public Object {
4461  public:
4462  static V8_DEPRECATE_SOON("Use maybe version.",
4463  Local<Value> New(Isolate* isolate, double time));
4464  static V8_WARN_UNUSED_RESULT MaybeLocal<Value> New(Local<Context> context,
4465  double time);
4466 
4467  /**
4468  * A specialization of Value::NumberValue that is more efficient
4469  * because we know the structure of this object.
4470  */
4471  double ValueOf() const;
4472 
4473  V8_INLINE static Date* Cast(Value* obj);
4474 
4475  /**
4476  * Notification that the embedder has changed the time zone,
4477  * daylight savings time, or other date / time configuration
4478  * parameters. V8 keeps a cache of various values used for
4479  * date / time computation. This notification will reset
4480  * those cached values for the current context so that date /
4481  * time configuration changes would be reflected in the Date
4482  * object.
4483  *
4484  * This API should not be called more than needed as it will
4485  * negatively impact the performance of date operations.
4486  */
4487  static void DateTimeConfigurationChangeNotification(Isolate* isolate);
4488 
4489  private:
4490  static void CheckCast(Value* obj);
4491 };
4492 
4493 
4494 /**
4495  * A Number object (ECMA-262, 4.3.21).
4496  */
4498  public:
4499  static Local<Value> New(Isolate* isolate, double value);
4500 
4501  double ValueOf() const;
4502 
4503  V8_INLINE static NumberObject* Cast(Value* obj);
4504 
4505  private:
4506  static void CheckCast(Value* obj);
4507 };
4508 
4509 
4510 /**
4511  * A Boolean object (ECMA-262, 4.3.15).
4512  */
4514  public:
4515  static Local<Value> New(Isolate* isolate, bool value);
4516  V8_DEPRECATED("Pass an isolate", static Local<Value> New(bool value));
4517 
4518  bool ValueOf() const;
4519 
4520  V8_INLINE static BooleanObject* Cast(Value* obj);
4521 
4522  private:
4523  static void CheckCast(Value* obj);
4524 };
4525 
4526 
4527 /**
4528  * A String object (ECMA-262, 4.3.18).
4529  */
4531  public:
4532  static Local<Value> New(Local<String> value);
4533 
4534  Local<String> ValueOf() const;
4535 
4536  V8_INLINE static StringObject* Cast(Value* obj);
4537 
4538  private:
4539  static void CheckCast(Value* obj);
4540 };
4541 
4542 
4543 /**
4544  * A Symbol object (ECMA-262 edition 6).
4545  */
4547  public:
4548  static Local<Value> New(Isolate* isolate, Local<Symbol> value);
4549 
4550  Local<Symbol> ValueOf() const;
4551 
4552  V8_INLINE static SymbolObject* Cast(Value* obj);
4553 
4554  private:
4555  static void CheckCast(Value* obj);
4556 };
4557 
4558 
4559 /**
4560  * An instance of the built-in RegExp constructor (ECMA-262, 15.10).
4561  */
4562 class V8_EXPORT RegExp : public Object {
4563  public:
4564  /**
4565  * Regular expression flag bits. They can be or'ed to enable a set
4566  * of flags.
4567  */
4568  enum Flags {
4569  kNone = 0,
4570  kGlobal = 1,
4573  kSticky = 8,
4575  };
4576 
4577  /**
4578  * Creates a regular expression from the given pattern string and
4579  * the flags bit field. May throw a JavaScript exception as
4580  * described in ECMA-262, 15.10.4.1.
4581  *
4582  * For example,
4583  * RegExp::New(v8::String::New("foo"),
4584  * static_cast<RegExp::Flags>(kGlobal | kMultiline))
4585  * is equivalent to evaluating "/foo/gm".
4586  */
4587  static V8_DEPRECATE_SOON("Use maybe version",
4588  Local<RegExp> New(Local<String> pattern,
4589  Flags flags));
4590  static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
4591  Local<String> pattern,
4592  Flags flags);
4593 
4594  /**
4595  * Returns the value of the source property: a string representing
4596  * the regular expression.
4597  */
4598  Local<String> GetSource() const;
4599 
4600  /**
4601  * Returns the flags bit field.
4602  */
4603  Flags GetFlags() const;
4604 
4605  V8_INLINE static RegExp* Cast(Value* obj);
4606 
4607  private:
4608  static void CheckCast(Value* obj);
4609 };
4610 
4611 
4612 /**
4613  * A JavaScript value that wraps a C++ void*. This type of value is mainly used
4614  * to associate C++ data structures with JavaScript objects.
4615  */
4616 class V8_EXPORT External : public Value {
4617  public:
4618  static Local<External> New(Isolate* isolate, void* value);
4619  V8_INLINE static External* Cast(Value* obj);
4620  void* Value() const;
4621  private:
4622  static void CheckCast(v8::Value* obj);
4623 };
4624 
4625 #define V8_INTRINSICS_LIST(F)
4626  F(ArrayProto_entries, array_entries_iterator)
4627  F(ArrayProto_forEach, array_for_each_iterator)
4628  F(ArrayProto_keys, array_keys_iterator)
4629  F(ArrayProto_values, array_values_iterator)
4630 
4632 #define V8_DECL_INTRINSIC(name, iname) k##name,
4634 #undef V8_DECL_INTRINSIC
4635 };
4636 
4637 
4638 // --- Templates ---
4639 
4640 
4641 /**
4642  * The superclass of object and function templates.
4643  */
4644 class V8_EXPORT Template : public Data {
4645  public:
4646  /**
4647  * Adds a property to each instance created by this template.
4648  *
4649  * The property must be defined either as a primitive value, or a template.
4650  */
4651  void Set(Local<Name> name, Local<Data> value,
4652  PropertyAttribute attributes = None);
4653  void SetPrivate(Local<Private> name, Local<Data> value,
4654  PropertyAttribute attributes = None);
4655  V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
4656 
4657  void SetAccessorProperty(
4658  Local<Name> name,
4659  Local<FunctionTemplate> getter = Local<FunctionTemplate>(),
4660  Local<FunctionTemplate> setter = Local<FunctionTemplate>(),
4661  PropertyAttribute attribute = None,
4662  AccessControl settings = DEFAULT);
4663 
4664  /**
4665  * Whenever the property with the given name is accessed on objects
4666  * created from this Template the getter and setter callbacks
4667  * are called instead of getting and setting the property directly
4668  * on the JavaScript object.
4669  *
4670  * \param name The name of the property for which an accessor is added.
4671  * \param getter The callback to invoke when getting the property.
4672  * \param setter The callback to invoke when setting the property.
4673  * \param data A piece of data that will be passed to the getter and setter
4674  * callbacks whenever they are invoked.
4675  * \param settings Access control settings for the accessor. This is a bit
4676  * field consisting of one of more of
4677  * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
4678  * The default is to not allow cross-context access.
4679  * ALL_CAN_READ means that all cross-context reads are allowed.
4680  * ALL_CAN_WRITE means that all cross-context writes are allowed.
4681  * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
4682  * cross-context access.
4683  * \param attribute The attributes of the property for which an accessor
4684  * is added.
4685  * \param signature The signature describes valid receivers for the accessor
4686  * and is used to perform implicit instance checks against them. If the
4687  * receiver is incompatible (i.e. is not an instance of the constructor as
4688  * defined by FunctionTemplate::HasInstance()), an implicit TypeError is
4689  * thrown and no callback is invoked.
4690  */
4691  void SetNativeDataProperty(
4692  Local<String> name, AccessorGetterCallback getter,
4693  AccessorSetterCallback setter = 0,
4694  // TODO(dcarney): gcc can't handle Local below
4695  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4696  Local<AccessorSignature> signature = Local<AccessorSignature>(),
4697  AccessControl settings = DEFAULT);
4698  void SetNativeDataProperty(
4699  Local<Name> name, AccessorNameGetterCallback getter,
4700  AccessorNameSetterCallback setter = 0,
4701  // TODO(dcarney): gcc can't handle Local below
4702  Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
4703  Local<AccessorSignature> signature = Local<AccessorSignature>(),
4704  AccessControl settings = DEFAULT);
4705 
4706  /**
4707  * Like SetNativeDataProperty, but V8 will replace the native data property
4708  * with a real data property on first access.
4709  */
4710  void SetLazyDataProperty(Local<Name> name, AccessorNameGetterCallback getter,
4711  Local<Value> data = Local<Value>(),
4712  PropertyAttribute attribute = None);
4713 
4714  /**
4715  * During template instantiation, sets the value with the intrinsic property
4716  * from the correct context.
4717  */
4718  void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
4719  PropertyAttribute attribute = None);
4720 
4721  private:
4722  Template();
4723 
4724  friend class ObjectTemplate;
4725  friend class FunctionTemplate;
4726 };
4727 
4728 
4729 /**
4730  * NamedProperty[Getter|Setter] are used as interceptors on object.
4731  * See ObjectTemplate::SetNamedPropertyHandler.
4732  */
4734  Local<String> property,
4735  const PropertyCallbackInfo<Value>& info);
4736 
4737 
4738 /**
4739  * Returns the value if the setter intercepts the request.
4740  * Otherwise, returns an empty handle.
4741  */
4743  Local<String> property,
4744  Local<Value> value,
4745  const PropertyCallbackInfo<Value>& info);
4746 
4747 
4748 /**
4749  * Returns a non-empty handle if the interceptor intercepts the request.
4750  * The result is an integer encoding property attributes (like v8::None,
4751  * v8::DontEnum, etc.)
4752  */
4754  Local<String> property,
4755  const PropertyCallbackInfo<Integer>& info);
4756 
4757 
4758 /**
4759  * Returns a non-empty handle if the deleter intercepts the request.
4760  * The return value is true if the property could be deleted and false
4761  * otherwise.
4762  */
4764  Local<String> property,
4765  const PropertyCallbackInfo<Boolean>& info);
4766 
4767 
4768 /**
4769  * Returns an array containing the names of the properties the named
4770  * property getter intercepts.
4771  */
4773  const PropertyCallbackInfo<Array>& info);
4774 
4775 
4776 // TODO(dcarney): Deprecate and remove previous typedefs, and replace
4777 // GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
4778 
4779 /**
4780  * Interceptor for get requests on an object.
4781  *
4782  * Use `info.GetReturnValue().Set()` to set the return value of the
4783  * intercepted get request.
4784  *
4785  * \param property The name of the property for which the request was
4786  * intercepted.
4787  * \param info Information about the intercepted request, such as
4788  * isolate, receiver, return value, or whether running in `'use strict`' mode.
4789  * See `PropertyCallbackInfo`.
4790  *
4791  * \code
4792  * void GetterCallback(
4793  * Local<Name> name,
4794  * const v8::PropertyCallbackInfo<v8::Value>& info) {
4795  * info.GetReturnValue().Set(v8_num(42));
4796  * }
4797  *
4798  * v8::Local<v8::FunctionTemplate> templ =
4799  * v8::FunctionTemplate::New(isolate);
4800  * templ->InstanceTemplate()->SetHandler(
4801  * v8::NamedPropertyHandlerConfiguration(GetterCallback));
4802  * LocalContext env;
4803  * env->Global()
4804  * ->Set(env.local(), v8_str("obj"), templ->GetFunction(env.local())
4805  * .ToLocalChecked()
4806  * ->NewInstance(env.local())
4807  * .ToLocalChecked())
4808  * .FromJust();
4809  * v8::Local<v8::Value> result = CompileRun("obj.a = 17; obj.a");
4810  * CHECK(v8_num(42)->Equals(env.local(), result).FromJust());
4811  * \endcode
4812  *
4813  * See also `ObjectTemplate::SetHandler`.
4814  */
4816  Local<Name> property, const PropertyCallbackInfo<Value>& info);
4817 
4818 /**
4819  * Interceptor for set requests on an object.
4820  *
4821  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
4822  * or not. If the setter successfully intercepts the request, i.e., if the
4823  * request should not be further executed, call
4824  * `info.GetReturnValue().Set(value)`. If the setter
4825  * did not intercept the request, i.e., if the request should be handled as
4826  * if no interceptor is present, do not not call `Set()`.
4827  *
4828  * \param property The name of the property for which the request was
4829  * intercepted.
4830  * \param value The value which the property will have if the request
4831  * is not intercepted.
4832  * \param info Information about the intercepted request, such as
4833  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4834  * See `PropertyCallbackInfo`.
4835  *
4836  * See also
4837  * `ObjectTemplate::SetHandler.`
4838  */
4840  Local<Name> property, Local<Value> value,
4841  const PropertyCallbackInfo<Value>& info);
4842 
4843 /**
4844  * Intercepts all requests that query the attributes of the
4845  * property, e.g., getOwnPropertyDescriptor(), propertyIsEnumerable(), and
4846  * defineProperty().
4847  *
4848  * Use `info.GetReturnValue().Set(value)` to set the property attributes. The
4849  * value is an interger encoding a `v8::PropertyAttribute`.
4850  *
4851  * \param property The name of the property for which the request was
4852  * intercepted.
4853  * \param info Information about the intercepted request, such as
4854  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4855  * See `PropertyCallbackInfo`.
4856  *
4857  * \note Some functions query the property attributes internally, even though
4858  * they do not return the attributes. For example, `hasOwnProperty()` can
4859  * trigger this interceptor depending on the state of the object.
4860  *
4861  * See also
4862  * `ObjectTemplate::SetHandler.`
4863  */
4865  Local<Name> property, const PropertyCallbackInfo<Integer>& info);
4866 
4867 /**
4868  * Interceptor for delete requests on an object.
4869  *
4870  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
4871  * or not. If the deleter successfully intercepts the request, i.e., if the
4872  * request should not be further executed, call
4873  * `info.GetReturnValue().Set(value)` with a boolean `value`. The `value` is
4874  * used as the return value of `delete`.
4875  *
4876  * \param property The name of the property for which the request was
4877  * intercepted.
4878  * \param info Information about the intercepted request, such as
4879  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4880  * See `PropertyCallbackInfo`.
4881  *
4882  * \note If you need to mimic the behavior of `delete`, i.e., throw in strict
4883  * mode instead of returning false, use `info.ShouldThrowOnError()` to determine
4884  * if you are in strict mode.
4885  *
4886  * See also `ObjectTemplate::SetHandler.`
4887  */
4889  Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
4890 
4891 
4892 /**
4893  * Returns an array containing the names of the properties the named
4894  * property getter intercepts.
4895  */
4897  const PropertyCallbackInfo<Array>& info);
4898 
4899 /**
4900  * Interceptor for defineProperty requests on an object.
4901  *
4902  * Use `info.GetReturnValue()` to indicate whether the request was intercepted
4903  * or not. If the definer successfully intercepts the request, i.e., if the
4904  * request should not be further executed, call
4905  * `info.GetReturnValue().Set(value)`. If the definer
4906  * did not intercept the request, i.e., if the request should be handled as
4907  * if no interceptor is present, do not not call `Set()`.
4908  *
4909  * \param property The name of the property for which the request was
4910  * intercepted.
4911  * \param desc The property descriptor which is used to define the
4912  * property if the request is not intercepted.
4913  * \param info Information about the intercepted request, such as
4914  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4915  * See `PropertyCallbackInfo`.
4916  *
4917  * See also `ObjectTemplate::SetHandler`.
4918  */
4920  Local<Name> property, const PropertyDescriptor& desc,
4921  const PropertyCallbackInfo<Value>& info);
4922 
4923 /**
4924  * Interceptor for getOwnPropertyDescriptor requests on an object.
4925  *
4926  * Use `info.GetReturnValue().Set()` to set the return value of the
4927  * intercepted request. The return value must be an object that
4928  * can be converted to a PropertyDescriptor, e.g., a `v8::value` returned from
4929  * `v8::Object::getOwnPropertyDescriptor`.
4930  *
4931  * \param property The name of the property for which the request was
4932  * intercepted.
4933  * \info Information about the intercepted request, such as
4934  * isolate, receiver, return value, or whether running in `'use strict'` mode.
4935  * See `PropertyCallbackInfo`.
4936  *
4937  * \note If GetOwnPropertyDescriptor is intercepted, it will
4938  * always return true, i.e., indicate that the property was found.
4939  *
4940  * See also `ObjectTemplate::SetHandler`.
4941  */
4943  Local<Name> property, const PropertyCallbackInfo<Value>& info);
4944 
4945 /**
4946  * See `v8::GenericNamedPropertyGetterCallback`.
4947  */
4949  uint32_t index,
4950  const PropertyCallbackInfo<Value>& info);
4951 
4952 /**
4953  * See `v8::GenericNamedPropertySetterCallback`.
4954  */
4956  uint32_t index,
4957  Local<Value> value,
4958  const PropertyCallbackInfo<Value>& info);
4959 
4960 /**
4961  * See `v8::GenericNamedPropertyQueryCallback`.
4962  */
4964  uint32_t index,
4965  const PropertyCallbackInfo<Integer>& info);
4966 
4967 /**
4968  * See `v8::GenericNamedPropertyDeleterCallback`.
4969  */
4971  uint32_t index,
4972  const PropertyCallbackInfo<Boolean>& info);
4973 
4974 /**
4975  * See `v8::GenericNamedPropertyEnumeratorCallback`.
4976  */
4978  const PropertyCallbackInfo<Array>& info);
4979 
4980 /**
4981  * See `v8::GenericNamedPropertyDefinerCallback`.
4982  */
4984  uint32_t index, const PropertyDescriptor& desc,
4985  const PropertyCallbackInfo<Value>& info);
4986 
4987 /**
4988  * See `v8::GenericNamedPropertyDescriptorCallback`.
4989  */
4991  uint32_t index, const PropertyCallbackInfo<Value>& info);
4992 
4993 /**
4994  * Access type specification.
4995  */
5002 };
5003 
5004 
5005 /**
5006  * Returns true if the given context should be allowed to access the given
5007  * object.
5008  */
5009 typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
5010  Local<Object> accessed_object,
5011  Local<Value> data);
5012 
5013 /**
5014  * A FunctionTemplate is used to create functions at runtime. There
5015  * can only be one function created from a FunctionTemplate in a
5016  * context. The lifetime of the created function is equal to the
5017  * lifetime of the context. So in case the embedder needs to create
5018  * temporary functions that can be collected using Scripts is
5019  * preferred.
5020  *
5021  * Any modification of a FunctionTemplate after first instantiation will trigger
5022  * a crash.
5023  *
5024  * A FunctionTemplate can have properties, these properties are added to the
5025  * function object when it is created.
5026  *
5027  * A FunctionTemplate has a corresponding instance template which is
5028  * used to create object instances when the function is used as a
5029  * constructor. Properties added to the instance template are added to
5030  * each object instance.
5031  *
5032  * A FunctionTemplate can have a prototype template. The prototype template
5033  * is used to create the prototype object of the function.
5034  *
5035  * The following example shows how to use a FunctionTemplate:
5036  *
5037  * \code
5038  * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
5039  * t->Set(isolate, "func_property", v8::Number::New(isolate, 1));
5040  *
5041  * v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
5042  * proto_t->Set(isolate,
5043  * "proto_method",
5044  * v8::FunctionTemplate::New(isolate, InvokeCallback));
5045  * proto_t->Set(isolate, "proto_const", v8::Number::New(isolate, 2));
5046  *
5047  * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
5048  * instance_t->SetAccessor(String::NewFromUtf8(isolate, "instance_accessor"),
5049  * InstanceAccessorCallback);
5050  * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback);
5051  * instance_t->Set(String::NewFromUtf8(isolate, "instance_property"),
5052  * Number::New(isolate, 3));
5053  *
5054  * v8::Local<v8::Function> function = t->GetFunction();
5055  * v8::Local<v8::Object> instance = function->NewInstance();
5056  * \endcode
5057  *
5058  * Let's use "function" as the JS variable name of the function object
5059  * and "instance" for the instance object created above. The function
5060  * and the instance will have the following properties:
5061  *
5062  * \code
5063  * func_property in function == true;
5064  * function.func_property == 1;
5065  *
5066  * function.prototype.proto_method() invokes 'InvokeCallback'
5067  * function.prototype.proto_const == 2;
5068  *
5069  * instance instanceof function == true;
5070  * instance.instance_accessor calls 'InstanceAccessorCallback'
5071  * instance.instance_property == 3;
5072  * \endcode
5073  *
5074  * A FunctionTemplate can inherit from another one by calling the
5075  * FunctionTemplate::Inherit method. The following graph illustrates
5076  * the semantics of inheritance:
5077  *
5078  * \code
5079  * FunctionTemplate Parent -> Parent() . prototype -> { }
5080  * ^ ^
5081  * | Inherit(Parent) | .__proto__
5082  * | |
5083  * FunctionTemplate Child -> Child() . prototype -> { }
5084  * \endcode
5085  *
5086  * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
5087  * object of the Child() function has __proto__ pointing to the
5088  * Parent() function's prototype object. An instance of the Child
5089  * function has all properties on Parent's instance templates.
5090  *
5091  * Let Parent be the FunctionTemplate initialized in the previous
5092  * section and create a Child FunctionTemplate by:
5093  *
5094  * \code
5095  * Local<FunctionTemplate> parent = t;
5096  * Local<FunctionTemplate> child = FunctionTemplate::New();
5097  * child->Inherit(parent);
5098  *
5099  * Local<Function> child_function = child->GetFunction();
5100  * Local<Object> child_instance = child_function->NewInstance();
5101  * \endcode
5102  *
5103  * The Child function and Child instance will have the following
5104  * properties:
5105  *
5106  * \code
5107  * child_func.prototype.__proto__ == function.prototype;
5108  * child_instance.instance_accessor calls 'InstanceAccessorCallback'
5109  * child_instance.instance_property == 3;
5110  * \endcode
5111  */
5113  public:
5114  /** Creates a function template.*/
5115  static Local<FunctionTemplate> New(
5116  Isolate* isolate, FunctionCallback callback = 0,
5117  Local<Value> data = Local<Value>(),
5118  Local<Signature> signature = Local<Signature>(), int length = 0,
5120 
5121  /** Get a template included in the snapshot by index. */
5122  static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
5123  size_t index);
5124 
5125  /**
5126  * Creates a function template with a fast handler. If a fast handler is set,
5127  * the callback cannot be null.
5128  */
5129  static Local<FunctionTemplate> NewWithFastHandler(
5130  Isolate* isolate, FunctionCallback callback,
5131  experimental::FastAccessorBuilder* fast_handler = nullptr,
5132  Local<Value> data = Local<Value>(),
5133  Local<Signature> signature = Local<Signature>(), int length = 0);
5134 
5135  /**
5136  * Creates a function template backed/cached by a private property.
5137  */
5138  static Local<FunctionTemplate> NewWithCache(
5139  Isolate* isolate, FunctionCallback callback,
5140  Local<Private> cache_property, Local<Value> data = Local<Value>(),
5141  Local<Signature> signature = Local<Signature>(), int length = 0);
5142 
5143  /** Returns the unique function instance in the current execution context.*/
5144  V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
5146  Local<Context> context);
5147 
5148  /**
5149  * Similar to Context::NewRemoteContext, this creates an instance that
5150  * isn't backed by an actual object.
5151  *
5152  * The InstanceTemplate of this FunctionTemplate must have access checks with
5153  * handlers installed.
5154  */
5156 
5157  /**
5158  * Set the call-handler callback for a FunctionTemplate. This
5159  * callback is called whenever the function created from this
5160  * FunctionTemplate is called.
5161  */
5162  void SetCallHandler(
5163  FunctionCallback callback, Local<Value> data = Local<Value>(),
5164  experimental::FastAccessorBuilder* fast_handler = nullptr);
5165 
5166  /** Set the predefined length property for the FunctionTemplate. */
5167  void SetLength(int length);
5168 
5169  /** Get the InstanceTemplate. */
5171 
5172  /**
5173  * Causes the function template to inherit from a parent function template.
5174  * This means the the function's prototype.__proto__ is set to the parent
5175  * function's prototype.
5176  **/
5177  void Inherit(Local<FunctionTemplate> parent);
5178 
5179  /**
5180  * A PrototypeTemplate is the template used to create the prototype object
5181  * of the function created by this template.
5182  */
5184 
5185  /**
5186  * A PrototypeProviderTemplate is another function template whose prototype
5187  * property is used for this template. This is mutually exclusive with setting
5188  * a prototype template indirectly by calling PrototypeTemplate() or using
5189  * Inherit().
5190  **/
5191  void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
5192 
5193  /**
5194  * Set the class name of the FunctionTemplate. This is used for
5195  * printing objects created with the function created from the
5196  * FunctionTemplate as its constructor.
5197  */
5198  void SetClassName(Local<String> name);
5199 
5200 
5201  /**
5202  * When set to true, no access check will be performed on the receiver of a
5203  * function call. Currently defaults to true, but this is subject to change.
5204  */
5205  void SetAcceptAnyReceiver(bool value);
5206 
5207  /**
5208  * Determines whether the __proto__ accessor ignores instances of
5209  * the function template. If instances of the function template are
5210  * ignored, __proto__ skips all instances and instead returns the
5211  * next object in the prototype chain.
5212  *
5213  * Call with a value of true to make the __proto__ accessor ignore
5214  * instances of the function template. Call with a value of false
5215  * to make the __proto__ accessor not ignore instances of the
5216  * function template. By default, instances of a function template
5217  * are not ignored.
5218  */
5219  void SetHiddenPrototype(bool value);
5220 
5221  /**
5222  * Sets the ReadOnly flag in the attributes of the 'prototype' property
5223  * of functions created from this FunctionTemplate to true.
5224  */
5225  void ReadOnlyPrototype();
5226 
5227  /**
5228  * Removes the prototype property from functions created from this
5229  * FunctionTemplate.
5230  */
5231  void RemovePrototype();
5232 
5233  /**
5234  * Returns true if the given object is an instance of this function
5235  * template.
5236  */
5237  bool HasInstance(Local<Value> object);
5238 
5239  private:
5240  FunctionTemplate();
5241  friend class Context;
5242  friend class ObjectTemplate;
5243 };